OXID eShop CE  4.10.8
 All Classes Namespaces Files Functions Variables Pages
article_pictures.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
18  public function render()
19  {
21 
22  $this->_aViewData["edit"] = $oArticle = oxNew("oxarticle");
23 
24  $soxId = $this->getEditObjectId();
25  if ($soxId != "-1" && isset($soxId)) {
26  // load object
27  $oArticle->load($soxId);
28 
29 
30  // variant handling
31  if ($oArticle->oxarticles__oxparentid->value) {
32  $oParentArticle = oxNew("oxarticle");
33  $oParentArticle->load($oArticle->oxarticles__oxparentid->value);
34  $this->_aViewData["parentarticle"] = $oParentArticle;
35  $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
36  }
37  }
38 
39  $this->_aViewData["iPicCount"] = $this->getConfig()->getConfigParam('iPicCount');
40 
41  return "article_pictures.tpl";
42  }
43 
49  public function save()
50  {
51  $myConfig = $this->getConfig();
52 
53  if ($myConfig->isDemoShop()) {
54  // disabling uploading pictures if this is demo shop
55  $oEx = oxNew("oxExceptionToDisplay");
56  $oEx->setMessage('ARTICLE_PICTURES_UPLOADISDISABLED');
57  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
58 
59  return;
60  }
61 
62  parent::save();
63 
64  $oArticle = oxNew("oxarticle");
65  if ($oArticle->load($this->getEditObjectId())) {
66  $oArticle->assign(oxRegistry::getConfig()->getRequestParameter("editval"));
67  oxRegistry::get("oxUtilsFile")->processFiles($oArticle);
68 
69  // Show that no new image added
70  if (oxRegistry::get("oxUtilsFile")->getNewFilesCounter() == 0) {
71  $oEx = oxNew("oxExceptionToDisplay");
72  $oEx->setMessage('NO_PICTURES_CHANGES');
73  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
74  }
75 
76  $oArticle->save();
77  }
78  }
79 
87  public function deletePicture()
88  {
89  $myConfig = $this->getConfig();
90 
91  if ($myConfig->isDemoShop()) {
92  // disabling uploading pictures if this is demo shop
93  $oEx = oxNew("oxExceptionToDisplay");
94  $oEx->setMessage('ARTICLE_PICTURES_UPLOADISDISABLED');
95  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
96 
97  return;
98  }
99 
100  $sOxId = $this->getEditObjectId();
101  $iIndex = oxRegistry::getConfig()->getRequestParameter("masterPicIndex");
102 
103  $oArticle = oxNew("oxarticle");
104  $oArticle->load($sOxId);
105 
106  if ($iIndex == "ICO") {
107  // deleting main icon
108  $this->_deleteMainIcon($oArticle);
109  } elseif ($iIndex == "TH") {
110  // deleting thumbnail
111  $this->_deleteThumbnail($oArticle);
112  } else {
113  $iIndex = (int) $iIndex;
114  if ($iIndex > 0) {
115  // deleting master picture
116  $this->_resetMasterPicture($oArticle, $iIndex, true);
117  }
118  }
119 
120  $oArticle->save();
121  }
122 
133  protected function _resetMasterPicture($oArticle, $iIndex, $blDeleteMaster = false)
134  {
135  if ($oArticle->{"oxarticles__oxpic" . $iIndex}->value) {
136 
137  if (!$oArticle->isDerived()) {
138  $oPicHandler = oxRegistry::get("oxPictureHandler");
139  $oPicHandler->deleteArticleMasterPicture($oArticle, $iIndex, $blDeleteMaster);
140  }
141 
142  if ($blDeleteMaster) {
143  //reseting master picture field
144  $oArticle->{"oxarticles__oxpic" . $iIndex} = new oxField();
145  }
146 
147  // cleaning oxzoom fields
148  if (isset($oArticle->{"oxarticles__oxzoom" . $iIndex})) {
149  $oArticle->{"oxarticles__oxzoom" . $iIndex} = new oxField();
150  }
151 
152  if ($iIndex == 1) {
153  $this->_cleanupCustomFields($oArticle);
154  }
155  }
156  }
157 
165  protected function _deleteMainIcon($oArticle)
166  {
167  if ($oArticle->oxarticles__oxicon->value) {
168 
169  if (!$oArticle->isDerived()) {
170  $oPicHandler = oxRegistry::get("oxPictureHandler");
171  $oPicHandler->deleteMainIcon($oArticle);
172  }
173 
174  //reseting field
175  $oArticle->oxarticles__oxicon = new oxField();
176  }
177  }
178 
186  protected function _deleteThumbnail($oArticle)
187  {
188  if ($oArticle->oxarticles__oxthumb->value) {
189 
190  if (!$oArticle->isDerived()) {
191  $oPicHandler = oxRegistry::get("oxPictureHandler");
192  $oPicHandler->deleteThumbnail($oArticle);
193  }
194 
195  //reseting field
196  $oArticle->oxarticles__oxthumb = new oxField();
197  }
198  }
199 
206  protected function _cleanupCustomFields($oArticle)
207  {
208  $myConfig = $this->getConfig();
209 
210  $sIcon = $oArticle->oxarticles__oxicon->value;
211  $sThumb = $oArticle->oxarticles__oxthumb->value;
212 
213  if ($sIcon == "nopic.jpg") {
214  $oArticle->oxarticles__oxicon = new oxField();
215  }
216 
217  if ($sThumb == "nopic.jpg") {
218  $oArticle->oxarticles__oxthumb = new oxField();
219  }
220  }
221 }