Ncmodel.php
4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* @package anc_image
* @category magento
* @mailto code [at] netz.coop
* @author netz.coop eG*
* @copyright (c) 2014, netz.coop eG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class Anc_Image_Helper_Ncmodel extends Mage_Core_Helper_Abstract {
/**
* cache für anc_image/ncimage models
* @var array
*/
private $NcImages = array();
/**
* gibt zurück wie oft das bild schon für den kauf verwendet wurde
*
* @param int $param_ncimage_id
* @return Anc_Image_Model_Resource_Mysql4_Ncimage_Quoteitemoption_Collection
*/
public function getNcImageMetaData($param_ncimage_id) {
$collection = Mage::getModel('anc_image/ncimage_quoteitemoption')->getCollection();
$Quoteitemoption_Collection = $collection->addFieldToFilter('ncimage_id',$param_ncimage_id);
return $Quoteitemoption_Collection;
}
/**
*
* @param int $param_ncimage_id
* @return anc_image/ncimage
*/
public function getNcImage($param_ncimage_id) {
if($param_ncimage_id) {
if(!array_key_exists($param_ncimage_id, $this->NcImages)) {
// $ncimage = Mage::getModel('anc_image/ncimage')->load($param_ncimage_id);
$ncimage = Mage::helper('anc_lib/ncrights')->loadNcModel('anc_image/ncimage', $param_ncimage_id);
$this->NcImages[$param_ncimage_id] = $ncimage;
}
return $this->NcImages[$param_ncimage_id];
} else {
return false;
}
}
public function getNcImagesForCustomer($param_customerid=null) {
// D::ulli('$param_customerid'.$param_customerid ,1);
if(!$param_customerid){
$customerid = Mage::getSingleton('customer/session')->getCustomer()->getId();
}else{
$customerid=$param_customerid;
}
return Mage::getModel('anc_image/ncimage')->getCollection()->addFieldToFilter('customer_id', $customerid);
// return Mage::helper('anc_lib/ncrights')->getNcModelsByOneFilter('anc_image/ncimage', 'customer_id', $customerid);
}
public function getNcImagesForAlbum($param_album_id) {
// $customer = Mage::getSingleton('customer/session')->getCustomer();
// return Mage::getModel('anc_image/ncimage')->getCollection()->addFieldToFilter('ncalbum_id', $param_album_id);
$param_arrayFields = array(
'ncalbum_id',
'ordered'
);
$param_arrayContent = array(
array('eq' => $param_album_id),
array('null' => true),
);
return Mage::helper('anc_lib/ncrights')->getNcModelsByOneFilter('anc_image/ncimage', $param_arrayFields, $param_arrayContent);
// return Mage::helper('anc_lib/ncrights')->getNcModelsByOneFilter('anc_image/ncimage', 'ncalbum_id', $param_album_id);
}
public function saveNcImage(Anc_Image_Model_Ncimage $param_ncimage) {
if(is_object($param_ncimage)) {
$param_ncimage->save();
$this->NcImages[$param_ncimage->getId()] = $param_ncimage;
return $this->NcImages[$param_ncimage->getId()];
} else {
return false;
}
}
public function deleteNcImage(Anc_Image_Model_Ncimage $param_ncimage) {
if(is_object($param_ncimage)) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
if($customer->getId() && $customer->getId() === $param_ncimage->getCustomerId()) {
Mage::helper('anc_image/ncmodel')->deleteNcImageFiles($param_ncimage);
$param_ncimage->delete();
// D::s($param_ncimage, '$param_ncimage');
return true;
} else {
return false;
}
} else {
return false;
}
}
public function deleteNcImageFiles(Anc_Image_Model_Ncimage $param_ncimage) {
if(is_object($param_ncimage)) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
if($customer->getId() && $customer->getId() === $param_ncimage->getCustomerId()) {
// mcFile::deleteFile(Mage::getBaseDir().$param_ncimage->getPath());
mcFile::deleteFile(Mage::helper('anc_lib/ncfilepath')->getThisMagentoInstallationPath().$param_ncimage->getPath());
return true;
} else {
return false;
}
} else {
return false;
}
}
public function getBlancoNcImageQuoteitemoption() {
return Mage::getModel('anc_image/ncimage_quoteitemoption');
}
}