article_pictures.php

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