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 = oxConfig::getParameter( 'oxid' );
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 = new oxExceptionToDisplay();
00055             $oEx->setMessage( 'ARTICLE_PICTURES_UPLOADISDISABLED' );
00056             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00057 
00058             return;
00059         }
00060 
00061 
00062         $soxId   = oxConfig::getParameter( "oxid");
00063         $aParams = oxConfig::getParameter( "editval");
00064 
00065         $oArticle = oxNew( "oxarticle");
00066         $oArticle->load( $soxId );
00067 
00068         // deleting master and all related images
00069         $aIndexes = $this->_getUploadedMasterPicIndexes();
00070         foreach ( $aIndexes as $iIndex ) {
00071             $this->_resetMasterPicture( $oArticle, $iIndex, true );
00072         }
00073 
00074         $oArticle->assign( $aParams );
00075         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00076         $oArticle->oxarticles__oxpicsgenerated = new oxField( 0 );
00077         $oArticle->save();
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 = new oxExceptionToDisplay();
00094             $oEx->setMessage( 'ARTICLE_PICTURES_UPLOADISDISABLED' );
00095             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00096 
00097             return;
00098         }
00099 
00100         $sOxId  = oxConfig::getParameter( "oxid" );
00101         $iIndex = oxConfig::getParameter( "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                 $oArticle->oxarticles__oxpicsgenerated = new oxField( 0 );
00118             }
00119         }
00120 
00121         $oArticle->save();
00122     }
00123 
00134     protected function _resetMasterPicture( $oArticle, $iIndex, $blDeleteMaster = false )
00135     {
00136         if ( $oArticle->{"oxarticles__oxpic".$iIndex}->value ) {
00137 
00138             if ( !$oArticle->isDerived() ) {
00139                 $oPicHandler = oxPictureHandler::getInstance();
00140                 $oPicHandler->deleteArticleMasterPicture( $oArticle, $iIndex, $blDeleteMaster );
00141             }
00142 
00143             if ( $blDeleteMaster ) {
00144                 //reseting master picture field
00145                 $oArticle->{"oxarticles__oxpic".$iIndex} = new oxField();
00146             }
00147 
00148             // cleaning oxzoom fields
00149             if ( isset( $oArticle->{"oxarticles__oxzoom".$iIndex} ) ) {
00150                 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00151             }
00152 
00153             if ( $iIndex == 1 ) {
00154                 $this->_cleanupCustomFields( $oArticle );
00155             }
00156         }
00157     }
00158 
00166     protected function _deleteMainIcon( $oArticle )
00167     {
00168         if ( $oArticle->oxarticles__oxicon->value ) {
00169 
00170             if ( !$oArticle->isDerived() ) {
00171                 $oPicHandler = oxPictureHandler::getInstance();
00172                 $oPicHandler->deleteMainIcon( $oArticle );
00173             }
00174 
00175             //reseting field
00176             $oArticle->oxarticles__oxicon = new oxField();
00177         }
00178     }
00179 
00187     protected function _deleteThumbnail( $oArticle )
00188     {
00189         if ( $oArticle->oxarticles__oxthumb->value ) {
00190 
00191             if ( !$oArticle->isDerived() ) {
00192                 $oPicHandler = oxPictureHandler::getInstance();
00193                 $oPicHandler->deleteThumbnail( $oArticle );
00194             }
00195 
00196             //reseting field
00197             $oArticle->oxarticles__oxthumb = new oxField();
00198         }
00199     }
00200 
00206     protected function _getUploadedMasterPicIndexes()
00207     {
00208         $aIndexes = array();
00209         if ( isset( $_FILES['myfile']['name'] ) ) {
00210             $oStr = getStr();
00211 
00212             while ( list( $sKey, $sValue ) = each( $_FILES['myfile']['name'] ) ) {
00213                 if ( $sValue ) {
00214                     $oStr->preg_match( "/^M(\d+)/", $sKey, $aMatches );
00215                     if ( isset( $aMatches[1] ) && !in_array( $aMatches[1], $aIndexes ) ) {
00216                         $aIndexes[] = $aMatches[1];
00217                     }
00218                 }
00219             }
00220         }
00221 
00222         return $aIndexes;
00223     }
00224 
00233     protected function _cleanupCustomFields( $oArticle )
00234     {
00235         $myConfig  = $this->getConfig();
00236 
00237         $sIcon  = $oArticle->oxarticles__oxicon->value;
00238         $sThumb = $oArticle->oxarticles__oxthumb->value;
00239 
00240         if ( $sIcon == "nopic_ico.jpg" ) {
00241             $oArticle->oxarticles__oxicon = new oxField();
00242         }
00243 
00244         if ( $sThumb == "nopic.jpg" ) {
00245             $oArticle->oxarticles__oxthumb = new oxField();
00246         }
00247     }
00248 }