article_extend.php

Go to the documentation of this file.
00001 <?php
00002 
00010 class Article_Extend extends oxAdminDetails
00011 {
00018     public function render()
00019     {
00020         parent::render();
00021 
00022         $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00023 
00024         $soxId = $this->getEditObjectId();
00025         $sCatView = getViewName( 'oxcategories' );
00026 
00027         $sChosenArtCat = $this->_getCategoryTree( "artcattree", oxConfig::getParameter( "artcat"));
00028 
00029         // all categories
00030         if ( $soxId != "-1" && isset( $soxId ) ) {
00031             // load object
00032             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00033 
00034 
00035             // load object in other languages
00036             $oOtherLang = $oArticle->getAvailableInLangs();
00037             if (!isset($oOtherLang[$this->_iEditLang])) {
00038                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00039                 $oArticle->loadInLang( key($oOtherLang), $soxId );
00040             }
00041 
00042             foreach ( $oOtherLang as $id => $language) {
00043                 $oLang= new oxStdClass();
00044                 $oLang->sLangDesc = $language;
00045                 $oLang->selected = ($id == $this->_iEditLang);
00046                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00047             }
00048 
00049             // variant handling
00050             if ( $oArticle->oxarticles__oxparentid->value) {
00051                 $oParentArticle = oxNew( 'oxarticle' );
00052                 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00053                 $this->_aViewData["parentarticle"] = $oParentArticle;
00054                 $this->_aViewData["oxparentid"]    = $oArticle->oxarticles__oxparentid->value;
00055             }
00056 
00057             $sO2CView = getViewName('oxobject2category');
00058         }
00059 
00060 
00061             $oDB = oxDb::getDB();
00062             $myConfig = $this->getConfig();
00063 
00064             $sArticleTable = getViewName( 'oxarticles', $this->_iEditLang );
00065             $sSelect  = "select $sArticleTable.oxtitle, $sArticleTable.oxartnum, $sArticleTable.oxvarselect from $sArticleTable where 1 ";
00066             // #546
00067             $sSelect .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00068             $sSelect .= " and $sArticleTable.oxid = ".$oDB->quote( $oArticle->oxarticles__oxbundleid->value );
00069 
00070             $rs = $oDB->Execute( $sSelect);
00071             if ($rs != false && $rs->RecordCount() > 0) {
00072                 while (!$rs->EOF) {
00073                     $sArtNum = new oxField($rs->fields[1]);
00074                     $sArtTitle = new oxField($rs->fields[0]." ".$rs->fields[2]);
00075                     $rs->MoveNext();
00076                 }
00077             }
00078             $this->_aViewData['bundle_artnum'] = $sArtNum;
00079             $this->_aViewData['bundle_title'] = $sArtTitle;
00080 
00081 
00082         $aColumns = array();
00083         $iAoc = oxConfig::getParameter("aoc");
00084         if ( $iAoc == 1 ) {
00085 
00086             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00087             $this->_aViewData['oxajax'] = $aColumns;
00088 
00089             return "popups/article_extend.tpl";
00090         } elseif ( $iAoc == 2 ) {
00091 
00092             include_once 'inc/article_bundle.inc.php';
00093             $this->_aViewData['oxajax'] = $aColumns;
00094 
00095             return "popups/article_bundle.tpl";
00096         }
00097 
00098         //load media files
00099         $this->_aViewData['aMediaUrls'] = $oArticle->getMediaUrls();
00100 
00101         return "article_extend.tpl";
00102     }
00103 
00109     public function save()
00110     {
00111 
00112         $soxId = $this->getEditObjectId();
00113         $aParams = oxConfig::getParameter( "editval");
00114         // checkbox handling
00115         if ( !isset( $aParams['oxarticles__oxissearch'])) {
00116             $aParams['oxarticles__oxissearch'] = 0;
00117         }
00118         if ( !isset( $aParams['oxarticles__oxblfixedprice'])) {
00119             $aParams['oxarticles__oxblfixedprice'] = 0;
00120         }
00121 
00122         // new way of handling bundled articles
00123         //#1517C - remove posibility to add Bundled Product
00124         //$this->setBundleId($aParams, $soxId);
00125 
00126         // default values
00127         $aParams = $this->addDefaultValues( $aParams);
00128 
00129         $oArticle = oxNew( "oxarticle" );
00130         $oArticle->loadInLang( $this->_iEditLang, $soxId);
00131 
00132         if ( $aParams['oxarticles__oxtprice'] != $oArticle->oxarticles__oxtprice->value &&  $aParams['oxarticles__oxtprice'] && $aParams['oxarticles__oxtprice'] < $oArticle->oxarticles__oxprice->value) {
00133             //$aParams['oxarticles__oxtprice'] = $oArticle->oxarticles__oxtprice->value;
00134             $this->_aViewData["errorsavingtprice"] = 1;
00135         }
00136 
00137         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00138         $oArticle->setLanguage(0);
00139         $oArticle->assign( $aParams);
00140         $oArticle->setLanguage($this->_iEditLang);
00141         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00142         $oArticle->save();
00143 
00144         //saving media file
00145         $sMediaUrl  = oxConfig::getParameter( "mediaUrl");
00146         $sMediaDesc = oxConfig::getParameter( "mediaDesc");
00147         $aMediaFile = $this->getConfig()->getUploadedFile( "mediaFile");
00148 
00149         if ($sMediaUrl || $aMediaFile['name'] || $sMediaDesc) {
00150 
00151             if ( !$sMediaDesc ) {
00152                 return oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_NODESCRIPTIONADDED' );
00153             }
00154 
00155             if ( !$sMediaUrl && !$aMediaFile['name'] ) {
00156                 return oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_NOMEDIAADDED' );
00157             }
00158 
00159             $oMediaUrl = oxNew("oxMediaUrl");
00160             $oMediaUrl->setLanguage( $this->_iEditLang );
00161             $oMediaUrl->oxmediaurls__oxisuploaded = new oxField( 0, oxField::T_RAW);
00162 
00163             //handle uploaded file
00164             if ($aMediaFile['name']) {
00165                 try {
00166                     $sMediaUrl = oxUtilsFile::getInstance()->handleUploadedFile($aMediaFile, 'out/media/');
00167                     $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
00168                 } catch (Exception $e) {
00169                     return oxUtilsView::getInstance()->addErrorToDisplay( $e->getMessage() );
00170                 }
00171             }
00172 
00173             //save media url
00174             $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
00175             $oMediaUrl->oxmediaurls__oxurl = new oxField($sMediaUrl, oxField::T_RAW);
00176             $oMediaUrl->oxmediaurls__oxdesc = new oxField(oxConfig::getParameter( "mediaDesc"), oxField::T_RAW);
00177             $oMediaUrl->save();
00178 
00179         }
00180     }
00181 
00187     public function deletemedia()
00188     {
00189         $soxId = $this->getEditObjectId();
00190         $sMediaId = oxConfig::getParameter( "mediaid");
00191         if ($sMediaId && $soxId) {
00192             $oMediaUrl = oxNew("oxMediaUrl");
00193             $oMediaUrl->load($sMediaId);
00194             $oMediaUrl->delete();
00195         }
00196     }
00197 
00206     public function addDefaultValues( $aParams)
00207     {
00208         $aParams['oxarticles__oxexturl'] = str_replace( "http://", "", $aParams['oxarticles__oxexturl']);
00209 
00210         return $aParams;
00211     }
00212 
00218     public function updateMedia()
00219     {
00220         $aMediaUrls = oxConfig::getParameter( 'aMediaUrls' );
00221         if ( is_array( $aMediaUrls ) ) {
00222             foreach ( $aMediaUrls as $sMediaId => $aMediaParams ) {
00223                 $oMedia = oxNew("oxMediaUrl");
00224                 if ( $oMedia->load( $sMediaId ) ) {
00225                     $oMedia->setLanguage(0);
00226                     $oMedia->assign( $aMediaParams );
00227                     $oMedia->setLanguage( $this->_iEditLang );
00228                     $oMedia->save();
00229                 }
00230             }
00231         }
00232     }
00233 }