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
00026 $oArticle->load( $soxId);
00027
00028
00029
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
00053 $soxId = oxConfig::getParameter( "oxid");
00054 $aParams = oxConfig::getParameter( "editval");
00055 $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
00056
00057 $oArticle = oxNew( "oxarticle");
00058 $oArticle->load( $soxId);
00059
00060
00061 $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop");
00062 $myUtilsPic = oxUtilsPic::getInstance();
00063
00064
00065 $this->_deleteMasterPicture( $oArticle, $iIndex );
00066
00067 $oArticle->assign( $aParams );
00068 $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00069
00070
00071 $this->_updateGeneratedPicsAmount( $oArticle );
00072
00073
00074 $this->_cleanupZoomFields( $oArticle );
00075
00076
00077
00078 $iFrom = $this->_getMinUploadedMasterPicIndex();
00079 for ( $i=$iFrom; $i<= $iPicCount; $i++ ) {
00080 $this->_resetMasterPicture( $oArticle, $i );
00081 }
00082
00083 $oArticle->save();
00084 }
00085
00093 public function deletePicture()
00094 {
00095 $sOxId = oxConfig::getParameter( "oxid");
00096 $iIndex = oxConfig::getParameter( "masterPicIndex" );
00097 $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
00098
00099 $oArticle = oxNew( "oxarticle" );
00100 $oArticle->load( $sOxId );
00101
00102
00103 if ( $iIndex == "ICO" ) {
00104 $this->_deleteMainIcon( $oArticle );
00105 }
00106
00107
00108 if ( $iIndex == "TH" ) {
00109 $this->_deleteThumbnail( $oArticle );
00110 }
00111
00112
00113 if ( (int)$iIndex > 0 ) {
00114 $this->_deleteMasterPicture( $oArticle, $iIndex );
00115
00116
00117
00118 for ( $i=$iIndex+1; $i<= $iPicCount; $i++ ) {
00119 $this->_resetMasterPicture( $oArticle, $i );
00120 }
00121
00122
00123 if ( $iIndex > 0 ) {
00124 $oArticle->updateAmountOfGeneratedPictures( $iIndex-1 );
00125 }
00126 }
00127
00128 $oArticle->save();
00129 }
00130
00140 protected function _deleteMasterPicture( $oArticle, $iIndex )
00141 {
00142 if ( $oArticle->{"oxarticles__oxpic".$iIndex}->value ) {
00143
00144 $oPicHandler = oxPictureHandler::getInstance();
00145 $oPicHandler->deleteArticleMasterPicture( $oArticle, $iIndex );
00146
00147
00148 $oArticle->{"oxarticles__oxpic".$iIndex} = new oxField();
00149
00150
00151 if ( isset( $oArticle->{"oxarticles__oxzoom".$iIndex} ) ) {
00152 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00153 }
00154
00155 if ( $iIndex == 1 ) {
00156 $this->_cleanupCustomFields( $oArticle );
00157 }
00158 }
00159 }
00160
00168 protected function _deleteMainIcon( $oArticle )
00169 {
00170 if ( $oArticle->oxarticles__oxicon->value ) {
00171
00172 $oPicHandler = oxPictureHandler::getInstance();
00173 $oPicHandler->deleteMainIcon( $oArticle );
00174
00175
00176 $oArticle->oxarticles__oxicon = new oxField();
00177 }
00178 }
00179
00187 protected function _deleteThumbnail( $oArticle )
00188 {
00189 if ( $oArticle->oxarticles__oxthumb->value ) {
00190
00191 $oPicHandler = oxPictureHandler::getInstance();
00192 $oPicHandler->deleteThumbnail( $oArticle );
00193
00194
00195 $oArticle->oxarticles__oxthumb = new oxField();
00196 }
00197 }
00198
00208 protected function _resetMasterPicture( $oArticle, $iIndex )
00209 {
00210 if ( $oArticle->{"oxarticles__oxpic".$iIndex}->value ) {
00211
00212 $oPicHandler = oxPictureHandler::getInstance();
00213 $oPicHandler->deleteArticleMasterPicture( $oArticle, $iIndex, false );
00214
00215
00216 if ( isset( $oArticle->{"oxarticles__oxzoom".$iIndex} ) ) {
00217 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00218 }
00219
00220 if ( $iIndex == 1 ) {
00221 $this->_cleanupCustomFields( $oArticle );
00222 }
00223 }
00224 }
00225
00226
00234 protected function _updateGeneratedPicsAmount( $oArticle )
00235 {
00236 $iMinUploadedIndex = $this->_getMinUploadedMasterPicIndex();
00237
00238 if ( $iMinUploadedIndex > 0 && $iMinUploadedIndex <= $oArticle->oxarticles__oxpicsgenerated->value ) {
00239 $oArticle->updateAmountOfGeneratedPictures( $iMinUploadedIndex-1 );
00240 }
00241 }
00242
00248 protected function _getMinUploadedMasterPicIndex()
00249 {
00250 if ( isset( $_FILES['myfile']['name'] ) ) {
00251 $iIndex = $this->getConfig()->getConfigParam( 'iPicCount' );
00252 $oStr = getStr();
00253
00254 while ( list( $sKey, $sValue ) = each( $_FILES['myfile']['name'] ) ) {
00255 if ( !empty($sValue) ) {
00256 $oStr->preg_match( "/^M(\d+)/", $sKey, $aMatches );
00257 $iPicIndex = $aMatches[1];
00258 $iIndex = ( $iIndex > $iPicIndex ) ? $iPicIndex : $iIndex;
00259 }
00260 }
00261 }
00262
00263 return (int)$iIndex;
00264 }
00265
00273 protected function _cleanupZoomFields( $oArticle )
00274 {
00275 $myConfig = $this->getConfig();
00276 if ( isset( $_FILES['myfile']['name'] ) ) {
00277 $iIndex = 0;
00278
00279 while ( list( $sKey, $sValue ) = each( $_FILES['myfile']['name'] ) ) {
00280 if ( !empty($sValue) ) {
00281 $iIndex = $this->_getUploadedMasterPicIndex( $sKey );
00282 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00283 }
00284 }
00285 }
00286 }
00287
00296 protected function _cleanupCustomFields( $oArticle )
00297 {
00298 $myConfig = $this->getConfig();
00299
00300 $sIcon = $oArticle->oxarticles__oxicon->value;
00301 $sThumb = $oArticle->oxarticles__oxthumb->value;
00302
00303 if ( $sIcon == "nopic_ico.jpg" ) {
00304 $oArticle->oxarticles__oxicon = new oxField();
00305 }
00306
00307 if ( $sThumb == "nopic.jpg" ) {
00308 $oArticle->oxarticles__oxthumb = new oxField();
00309 }
00310 }
00311
00319 protected function _getUploadedMasterPicIndex( $sFileType )
00320 {
00321 $iPicIndex = 0;
00322
00323 if ( getStr()->preg_match( "/^M(\d+)/", $sFileType, $aMatches ) ) {
00324 $iPicIndex = $aMatches[1];
00325 }
00326
00327 return (int) $iPicIndex;
00328 }
00329 }