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