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 = new oxExceptionToDisplay();
00055             $oEx->setMessage( 'ARTICLE_PICTURES_UPLOADISDISABLED' );
00056             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00057 
00058             return;
00059         }
00060 
00061 
00062         $oArticle = oxNew( "oxarticle");
00063         if ( $oArticle->load( $this->getEditObjectId() ) ) {
00064             $oArticle->assign( oxConfig::getParameter( "editval") );
00065             oxUtilsFile::getInstance()->processFiles( $oArticle );
00066             $oArticle->save();
00067         }
00068     }
00069 
00077     public function deletePicture()
00078     {
00079         $myConfig = $this->getConfig();
00080 
00081         if ( $myConfig->isDemoShop() ) {
00082             // disabling uploading pictures if this is demo shop
00083             $oEx = new oxExceptionToDisplay();
00084             $oEx->setMessage( 'ARTICLE_PICTURES_UPLOADISDISABLED' );
00085             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00086 
00087             return;
00088         }
00089 
00090         $sOxId = $this->getEditObjectId();
00091         $iIndex = oxConfig::getParameter( "masterPicIndex" );
00092 
00093         $oArticle = oxNew( "oxarticle" );
00094         $oArticle->load( $sOxId );
00095 
00096         if ( $iIndex == "ICO" ) {
00097             // deleting main icon
00098             $this->_deleteMainIcon( $oArticle );
00099         } elseif ( $iIndex == "TH" ) {
00100             // deleting thumbnail
00101             $this->_deleteThumbnail( $oArticle );
00102         } else {
00103             $iIndex = (int) $iIndex;
00104             if ( $iIndex > 0 ) {
00105                 // deleting master picture
00106                 $this->_resetMasterPicture( $oArticle, $iIndex, true );
00107                 $oArticle->oxarticles__oxpicsgenerated = new oxField( 0 );
00108             }
00109         }
00110 
00111         $oArticle->save();
00112     }
00113 
00124     protected function _resetMasterPicture( $oArticle, $iIndex, $blDeleteMaster = false )
00125     {
00126         if ( $oArticle->{"oxarticles__oxpic".$iIndex}->value ) {
00127 
00128             if ( !$oArticle->isDerived() ) {
00129                 $oPicHandler = oxPictureHandler::getInstance();
00130                 $oPicHandler->deleteArticleMasterPicture( $oArticle, $iIndex, $blDeleteMaster );
00131             }
00132 
00133             if ( $blDeleteMaster ) {
00134                 //reseting master picture field
00135                 $oArticle->{"oxarticles__oxpic".$iIndex} = new oxField();
00136             }
00137 
00138             // cleaning oxzoom fields
00139             if ( isset( $oArticle->{"oxarticles__oxzoom".$iIndex} ) ) {
00140                 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00141             }
00142 
00143             if ( $iIndex == 1 ) {
00144                 $this->_cleanupCustomFields( $oArticle );
00145             }
00146         }
00147     }
00148 
00156     protected function _deleteMainIcon( $oArticle )
00157     {
00158         if ( $oArticle->oxarticles__oxicon->value ) {
00159 
00160             if ( !$oArticle->isDerived() ) {
00161                 $oPicHandler = oxPictureHandler::getInstance();
00162                 $oPicHandler->deleteMainIcon( $oArticle );
00163             }
00164 
00165             //reseting field
00166             $oArticle->oxarticles__oxicon = new oxField();
00167         }
00168     }
00169 
00177     protected function _deleteThumbnail( $oArticle )
00178     {
00179         if ( $oArticle->oxarticles__oxthumb->value ) {
00180 
00181             if ( !$oArticle->isDerived() ) {
00182                 $oPicHandler = oxPictureHandler::getInstance();
00183                 $oPicHandler->deleteThumbnail( $oArticle );
00184             }
00185 
00186             //reseting field
00187             $oArticle->oxarticles__oxthumb = new oxField();
00188         }
00189     }
00190 
00198     protected function _getUploadedMasterPicIndexes()
00199     {
00200         $aIndexes = array();
00201         if ( isset( $_FILES['myfile']['name'] ) ) {
00202             $oStr = getStr();
00203 
00204             while ( list( $sKey, $sValue ) = each( $_FILES['myfile']['name'] ) ) {
00205                 if ( $sValue ) {
00206                     $oStr->preg_match( "/^M(\d+)/", $sKey, $aMatches );
00207                     if ( isset( $aMatches[1] ) && !in_array( $aMatches[1], $aIndexes ) ) {
00208                         $aIndexes[] = $aMatches[1];
00209                     }
00210                 }
00211             }
00212         }
00213 
00214         return $aIndexes;
00215     }
00216 
00225     protected function _cleanupCustomFields( $oArticle )
00226     {
00227         $myConfig  = $this->getConfig();
00228 
00229         $sIcon  = $oArticle->oxarticles__oxicon->value;
00230         $sThumb = $oArticle->oxarticles__oxthumb->value;
00231 
00232         if ( $sIcon == "nopic.jpg" ) {
00233             $oArticle->oxarticles__oxicon = new oxField();
00234         }
00235 
00236         if ( $sThumb == "nopic.jpg" ) {
00237             $oArticle->oxarticles__oxthumb = new oxField();
00238         }
00239     }
00240 }