article_pictures.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Article_Pictures extends oxAdminDetails
00010 {
00011 
00018     public function render()
00019     {
00020         parent::render();
00021 
00022         $this->_aViewData["edit"] = $oArticle = oxNew("oxarticle");
00023 
00024         $soxId = $this->getEditObjectId();
00025         if ($soxId != "-1" && isset($soxId)) {
00026             // load object
00027             $oArticle->load($soxId);
00028 
00029 
00030             // variant handling
00031             if ($oArticle->oxarticles__oxparentid->value) {
00032                 $oParentArticle = oxNew("oxarticle");
00033                 $oParentArticle->load($oArticle->oxarticles__oxparentid->value);
00034                 $this->_aViewData["parentarticle"] = $oParentArticle;
00035                 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00036             }
00037         }
00038 
00039         $this->_aViewData["iPicCount"] = $this->getConfig()->getConfigParam('iPicCount');
00040 
00041         return "article_pictures.tpl";
00042     }
00043 
00049     public function save()
00050     {
00051         $myConfig = $this->getConfig();
00052 
00053         if ($myConfig->isDemoShop()) {
00054             // disabling uploading pictures if this is demo shop
00055             $oEx = oxNew("oxExceptionToDisplay");
00056             $oEx->setMessage('ARTICLE_PICTURES_UPLOADISDISABLED');
00057             oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
00058 
00059             return;
00060         }
00061 
00062         parent::save();
00063 
00064         $oArticle = oxNew("oxarticle");
00065         if ($oArticle->load($this->getEditObjectId())) {
00066             $oArticle->assign(oxRegistry::getConfig()->getRequestParameter("editval"));
00067             oxRegistry::get("oxUtilsFile")->processFiles($oArticle);
00068 
00069             // Show that no new image added
00070             if (oxRegistry::get("oxUtilsFile")->getNewFilesCounter() == 0) {
00071                 $oEx = oxNew("oxExceptionToDisplay");
00072                 $oEx->setMessage('NO_PICTURES_CHANGES');
00073                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
00074             }
00075 
00076             $oArticle->save();
00077         }
00078     }
00079 
00087     public function deletePicture()
00088     {
00089         $myConfig = $this->getConfig();
00090 
00091         if ($myConfig->isDemoShop()) {
00092             // disabling uploading pictures if this is demo shop
00093             $oEx = oxNew("oxExceptionToDisplay");
00094             $oEx->setMessage('ARTICLE_PICTURES_UPLOADISDISABLED');
00095             oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
00096 
00097             return;
00098         }
00099 
00100         $sOxId = $this->getEditObjectId();
00101         $iIndex = oxRegistry::getConfig()->getRequestParameter("masterPicIndex");
00102 
00103         $oArticle = oxNew("oxarticle");
00104         $oArticle->load($sOxId);
00105 
00106         if ($iIndex == "ICO") {
00107             // deleting main icon
00108             $this->_deleteMainIcon($oArticle);
00109         } elseif ($iIndex == "TH") {
00110             // deleting thumbnail
00111             $this->_deleteThumbnail($oArticle);
00112         } else {
00113             $iIndex = (int) $iIndex;
00114             if ($iIndex > 0) {
00115                 // deleting master picture
00116                 $this->_resetMasterPicture($oArticle, $iIndex, true);
00117             }
00118         }
00119 
00120         $oArticle->save();
00121     }
00122 
00133     protected function _resetMasterPicture($oArticle, $iIndex, $blDeleteMaster = false)
00134     {
00135         if ($oArticle->{"oxarticles__oxpic" . $iIndex}->value) {
00136 
00137             if (!$oArticle->isDerived()) {
00138                 $oPicHandler = oxRegistry::get("oxPictureHandler");
00139                 $oPicHandler->deleteArticleMasterPicture($oArticle, $iIndex, $blDeleteMaster);
00140             }
00141 
00142             if ($blDeleteMaster) {
00143                 //reseting master picture field
00144                 $oArticle->{"oxarticles__oxpic" . $iIndex} = new oxField();
00145             }
00146 
00147             // cleaning oxzoom fields
00148             if (isset($oArticle->{"oxarticles__oxzoom" . $iIndex})) {
00149                 $oArticle->{"oxarticles__oxzoom" . $iIndex} = new oxField();
00150             }
00151 
00152             if ($iIndex == 1) {
00153                 $this->_cleanupCustomFields($oArticle);
00154             }
00155         }
00156     }
00157 
00165     protected function _deleteMainIcon($oArticle)
00166     {
00167         if ($oArticle->oxarticles__oxicon->value) {
00168 
00169             if (!$oArticle->isDerived()) {
00170                 $oPicHandler = oxRegistry::get("oxPictureHandler");
00171                 $oPicHandler->deleteMainIcon($oArticle);
00172             }
00173 
00174             //reseting field
00175             $oArticle->oxarticles__oxicon = new oxField();
00176         }
00177     }
00178 
00186     protected function _deleteThumbnail($oArticle)
00187     {
00188         if ($oArticle->oxarticles__oxthumb->value) {
00189 
00190             if (!$oArticle->isDerived()) {
00191                 $oPicHandler = oxRegistry::get("oxPictureHandler");
00192                 $oPicHandler->deleteThumbnail($oArticle);
00193             }
00194 
00195             //reseting field
00196             $oArticle->oxarticles__oxthumb = new oxField();
00197         }
00198     }
00199 
00206     protected function _cleanupCustomFields($oArticle)
00207     {
00208         $myConfig = $this->getConfig();
00209 
00210         $sIcon = $oArticle->oxarticles__oxicon->value;
00211         $sThumb = $oArticle->oxarticles__oxthumb->value;
00212 
00213         if ($sIcon == "nopic.jpg") {
00214             $oArticle->oxarticles__oxicon = new oxField();
00215         }
00216 
00217         if ($sThumb == "nopic.jpg") {
00218             $oArticle->oxarticles__oxthumb = new oxField();
00219         }
00220     }
00221 }