article_files.php

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