article_files.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Article_Files extends oxAdminDetails
00009 {
00015     protected $_sThisTemplate = 'article_files.tpl';
00016 
00022     protected $_oArticle = null;
00023 
00030     public function render()
00031     {
00032         parent::render();
00033 
00034         if ( !$this->getConfig()->getConfigParam( 'blEnableDownloads' ) ) {
00035             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_DISABLED_DOWNLOADABLE_PRODUCTS' );
00036         }
00037         $oArticle = $this->getArticle();
00038         // variant handling
00039         if ( $oArticle->oxarticles__oxparentid->value) {
00040             $oParentArticle = oxNew( 'oxarticle' );
00041             $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00042             $oArticle->oxarticles__oxisdownloadable = new oxField( $oParentArticle->oxarticles__oxisdownloadable->value );
00043             $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00044         }
00045 
00046         return $this->_sThisTemplate;
00047     }
00048 
00055     public function save()
00056     {
00057         // save article changes
00058         $aArticleChanges = oxConfig::getParameter('editval');
00059         $oArticle = $this->getArticle();
00060         $oArticle->assign($aArticleChanges);
00061         $oArticle->save();
00062 
00063         //update article files
00064         $aArticleFiles = oxConfig::getParameter('article_files');
00065         if (count($aArticleFiles) > 0) {
00066             foreach ($aArticleFiles as $sArticleFileId => $aArticleFileUpdate) {
00067                 $oArticleFile = oxNew('oxFile');
00068                 $oArticleFile->load($sArticleFileId);
00069                 $aArticleFileUpdate  = $this->_processOptions($aArticleFileUpdate);
00070                 $oArticleFile->assign($aArticleFileUpdate);
00071                 $oArticleFile->save();
00072             }
00073         }
00074     }
00075 
00083     public function getArticle($blReset = false)
00084     {
00085         if ($this->_oArticle !== null && !$blReset) {
00086             return $this->_oArticle;
00087         }
00088         $sProductId = $this->getEditObjectId();
00089 
00090         $oProduct = oxNew( 'oxArticle' );
00091         $oProduct->load( $sProductId );
00092         $this->_oArticle = $oProduct;
00093 
00094         return $this->_oArticle;
00095     }
00096 
00102     public function upload()
00103     {
00104         $myConfig = $this->getConfig();
00105 
00106         if ( $myConfig->isDemoShop() ) {
00107             $oEx = oxNew( "oxExceptionToDisplay" );
00108             $oEx->setMessage( 'ARTICLE_EXTEND_UPLOADISDISABLED' );
00109             oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
00110 
00111             return;
00112         }
00113         
00114         $soxId = $this->getEditObjectId();
00115 
00116         $aParams  = oxConfig::getParameter( "newfile");
00117         $aParams  = $this->_processOptions($aParams);
00118         $aNewFile = $this->getConfig()->getUploadedFile( "newArticleFile");
00119 
00120         $sExistingFilename = trim(oxConfig::getParameter( "existingFilename"));
00121 
00122         //uploading and processing supplied file
00123         $oArticleFile = oxNew( "oxFile" );
00124         $oArticleFile->assign($aParams);
00125 
00126         if (!$aNewFile['name'] && !$oArticleFile->oxfiles__oxfilename->value) {
00127             return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_NOFILE' );
00128         }
00129 
00130         if ($aNewFile['name']) {
00131             $oArticleFile->oxfiles__oxfilename        = new oxField($aNewFile['name'], oxField::T_RAW);
00132             try {
00133                 $oArticleFile->processFile( 'newArticleFile' );
00134             } catch (Exception $e) {
00135                 return oxRegistry::get("oxUtilsView")->addErrorToDisplay( $e->getMessage() );
00136             }
00137         }
00138 
00139         //save media url
00140         $oArticleFile->oxfiles__oxartid       = new oxField($soxId, oxField::T_RAW);
00141         $oArticleFile->save();
00142     }
00143 
00149     public function deletefile()
00150     {
00151         $myConfig = $this->getConfig();
00152 
00153         if ( $myConfig->isDemoShop() ) {
00154             $oEx = oxNew( "oxExceptionToDisplay" );
00155             $oEx->setMessage( 'ARTICLE_EXTEND_UPLOADISDISABLED' );
00156             oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
00157 
00158             return;
00159         }
00160         
00161         $sArticleId = $this->getEditObjectId();
00162         $sArticleFileId = oxConfig::getParameter('fileid');
00163         $oArticleFile = oxNew('oxFile');
00164         $oArticleFile->load($sArticleFileId);
00165         if ($oArticleFile->hasValidDownloads()) {
00166             return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_DELETING_VALID_FILE' );
00167         }
00168         if ($oArticleFile->oxfiles__oxartid->value == $sArticleId) {
00169             $oArticleFile->delete();
00170         }
00171     }
00172 
00180     public function getConfigOptionValue( $iOption )
00181     {
00182         $iOption = ( $iOption < 0 ) ? "" : $iOption;
00183         return $iOption;
00184     }
00185 
00193     protected function _processOptions($aParams)
00194     {
00195         if (!is_array($aParams)) {
00196             $aParams = array();
00197         }
00198 
00199         if (!isset($aParams["oxfiles__oxdownloadexptime"]) || $aParams["oxfiles__oxdownloadexptime"] == "") {
00200             $aParams["oxfiles__oxdownloadexptime"] = -1;
00201         }
00202         if (!isset($aParams["oxfiles__oxlinkexptime"]) || $aParams["oxfiles__oxlinkexptime"] == "") {
00203             $aParams["oxfiles__oxlinkexptime"] = -1;
00204         }
00205         if (!isset($aParams["oxfiles__oxmaxunregdownloads"]) || $aParams["oxfiles__oxmaxunregdownloads"] == "") {
00206             $aParams["oxfiles__oxmaxunregdownloads"] = -1;
00207         }
00208         if (!isset($aParams["oxfiles__oxmaxdownloads"]) || $aParams["oxfiles__oxmaxdownloads"] == "") {
00209             $aParams["oxfiles__oxmaxdownloads"] = -1;
00210         }
00211         return $aParams;
00212     }
00213 }