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         $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
00065 
00066         $oArticle = oxNew( "oxarticle");
00067         $oArticle->load( $soxId );
00068 
00069         // deleting master and all related images
00070         $aIndexes = $this->_getUploadedMasterPicIndexes();
00071         $iMin = min( $aIndexes );
00072         $iMin = $iMin < 1 ? 1 : $iMin;
00073 
00074         for ( $i = $iMin; $i <= $this->getConfig()->getConfigParam( 'iPicCount' ); $i++ ) {
00075             $this->_resetMasterPicture( $oArticle, $iIndex, in_array( $i, $aIndexes ) );
00076         }
00077 
00078         $oArticle->assign( $aParams );
00079         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00080         $oArticle->updateAmountOfGeneratedPictures( $iMin - 1 );
00081         $oArticle->save();
00082     }
00083 
00091     public function deletePicture()
00092     {
00093         $myConfig = $this->getConfig();
00094 
00095         if ( $myConfig->isDemoShop() ) {
00096             // disabling uploading pictures if this is demo shop
00097             $oEx = new oxExceptionToDisplay();
00098             $oEx->setMessage( 'ARTICLE_PICTURES_UPLOADISDISABLED' );
00099             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00100 
00101             return;
00102         }
00103 
00104         $sOxId  = oxConfig::getParameter( "oxid" );
00105         $iIndex = oxConfig::getParameter( "masterPicIndex" );
00106 
00107         $oArticle = oxNew( "oxarticle" );
00108         $oArticle->load( $sOxId );
00109 
00110         if ( $iIndex == "ICO" ) {
00111             // deleting main icon
00112             $this->_deleteMainIcon( $oArticle );
00113         } elseif ( $iIndex == "TH" ) {
00114             // deleting thumbnail
00115             $this->_deleteThumbnail( $oArticle );
00116         } else {
00117             $iIndex = (int) $iIndex;
00118             if ( $iIndex > 0 ) {
00119                 // deleting master picture
00120                 $this->_resetMasterPicture( $oArticle, $iIndex, true );
00121 
00122                 // reseting others following master image
00123                 for ( $i = $iIndex + 1; $i <= $this->getConfig()->getConfigParam( 'iPicCount' ); $i++ ) {
00124                     $this->_resetMasterPicture( $oArticle, $iIndex );
00125                 }
00126 
00127                 $oArticle->updateAmountOfGeneratedPictures( $iIndex - 1 );
00128             }
00129         }
00130 
00131         $oArticle->save();
00132     }
00133 
00144     protected function _resetMasterPicture( $oArticle, $iIndex, $blDeleteMaster = false )
00145     {
00146         if ( $oArticle->{"oxarticles__oxpic".$iIndex}->value ) {
00147 
00148             $oPicHandler = oxPictureHandler::getInstance();
00149             $oPicHandler->deleteArticleMasterPicture( $oArticle, $iIndex, $blDeleteMaster );
00150 
00151             if ( $blDeleteMaster ) {
00152                 //reseting master picture field
00153                 $oArticle->{"oxarticles__oxpic".$iIndex} = new oxField();
00154             }
00155 
00156             // cleaning oxzoom fields
00157             if ( isset( $oArticle->{"oxarticles__oxzoom".$iIndex} ) ) {
00158                 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00159             }
00160 
00161             if ( $iIndex == 1 ) {
00162                 $this->_cleanupCustomFields( $oArticle );
00163             }
00164         }
00165     }
00166 
00174     protected function _deleteMainIcon( $oArticle )
00175     {
00176         if ( $oArticle->oxarticles__oxicon->value ) {
00177 
00178             $oPicHandler = oxPictureHandler::getInstance();
00179             $oPicHandler->deleteMainIcon( $oArticle );
00180 
00181             //reseting field
00182             $oArticle->oxarticles__oxicon = new oxField();
00183         }
00184     }
00185 
00193     protected function _deleteThumbnail( $oArticle )
00194     {
00195         if ( $oArticle->oxarticles__oxthumb->value ) {
00196 
00197             $oPicHandler = oxPictureHandler::getInstance();
00198             $oPicHandler->deleteThumbnail( $oArticle );
00199 
00200             //reseting field
00201             $oArticle->oxarticles__oxthumb = new oxField();
00202         }
00203     }
00204 
00210     protected function _getUploadedMasterPicIndexes()
00211     {
00212         $aIndexes = array();
00213         if ( isset( $_FILES['myfile']['name'] ) ) {
00214             $iIndex = $this->getConfig()->getConfigParam( 'iPicCount' );
00215             $oStr = getStr();
00216 
00217             while ( list( $sKey, $sValue ) = each( $_FILES['myfile']['name'] ) ) {
00218                 if ( $sValue ) {
00219                     $oStr->preg_match( "/^M(\d+)/", $sKey, $aMatches );
00220                     $iPicIndex = isset( $aMatches[1] ) ? (int) $aMatches[1] : 1;
00221                     $iPicIndex = ( $iPicIndex > $iIndex  ) ? $iIndex : $iPicIndex;
00222                     if ( !in_array( $iPicIndex, $aIndexes ) ) {
00223                         $aIndexes[] = $iPicIndex;
00224                     }
00225                 }
00226             }
00227         }
00228 
00229         return $aIndexes;
00230     }
00231 
00240     protected function _cleanupCustomFields( $oArticle )
00241     {
00242         $myConfig  = $this->getConfig();
00243 
00244         $sIcon  = $oArticle->oxarticles__oxicon->value;
00245         $sThumb = $oArticle->oxarticles__oxthumb->value;
00246 
00247         if ( $sIcon == "nopic_ico.jpg" ) {
00248             $oArticle->oxarticles__oxicon = new oxField();
00249         }
00250 
00251         if ( $sThumb == "nopic.jpg" ) {
00252             $oArticle->oxarticles__oxthumb = new oxField();
00253         }
00254     }
00255 }