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 = oxConfig::getParameter( 'oxid' );
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             $suffix = ($this->_iEditLang)?"_$this->_iEditLang":"";
00064 
00065             $sArticleTable = getViewName( 'oxarticles' );
00066             $sSelect  = "select $sArticleTable.oxtitle$suffix, $sArticleTable.oxartnum, $sArticleTable.oxvarselect$suffix from $sArticleTable where 1 ";
00067             // #546
00068             $sSelect .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00069             $sSelect .= " and $sArticleTable.oxid = ".$oDB->quote( $oArticle->oxarticles__oxbundleid->value );
00070 
00071             $rs = $oDB->Execute( $sSelect);
00072             if ($rs != false && $rs->RecordCount() > 0) {
00073                 while (!$rs->EOF) {
00074                     $sArtNum = new oxField($rs->fields[1]);
00075                     $sArtTitle = new oxField($rs->fields[0]." ".$rs->fields[2]);
00076                     $rs->MoveNext();
00077                 }
00078             }
00079             $this->_aViewData['bundle_artnum'] = $sArtNum;
00080             $this->_aViewData['bundle_title'] = $sArtTitle;
00081 
00082 
00083         $aColumns = array();
00084         $iAoc = oxConfig::getParameter("aoc");
00085         if ( $iAoc == 1 ) {
00086 
00087             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00088             $this->_aViewData['oxajax'] = $aColumns;
00089 
00090             return "popups/article_extend.tpl";
00091         } elseif ( $iAoc == 2 ) {
00092 
00093             include_once 'inc/article_bundle.inc.php';
00094             $this->_aViewData['oxajax'] = $aColumns;
00095 
00096             return "popups/article_bundle.tpl";
00097         }
00098 
00099         //load media files
00100         $this->_aViewData['aMediaUrls'] = $oArticle->getMediaUrls();
00101 
00102         return "article_extend.tpl";
00103     }
00104 
00110     public function save()
00111     {
00112 
00113         $soxId      = oxConfig::getParameter( "oxid");
00114         $aParams    = oxConfig::getParameter( "editval");
00115         // checkbox handling
00116         if ( !isset( $aParams['oxarticles__oxissearch'])) {
00117             $aParams['oxarticles__oxissearch'] = 0;
00118         }
00119         if ( !isset( $aParams['oxarticles__oxblfixedprice'])) {
00120             $aParams['oxarticles__oxblfixedprice'] = 0;
00121         }
00122 
00123         // new way of handling bundled articles
00124         //#1517C - remove posibility to add Bundled Product
00125         //$this->setBundleId($aParams, $soxId);
00126 
00127         // default values
00128         $aParams = $this->addDefaultValues( $aParams);
00129 
00130         $oArticle = oxNew( "oxarticle" );
00131         $oArticle->loadInLang( $this->_iEditLang, $soxId);
00132 
00133         if ( $aParams['oxarticles__oxtprice'] != $oArticle->oxarticles__oxtprice->value &&  $aParams['oxarticles__oxtprice'] && $aParams['oxarticles__oxtprice'] < $oArticle->oxarticles__oxprice->value) {
00134             //$aParams['oxarticles__oxtprice'] = $oArticle->oxarticles__oxtprice->value;
00135             $this->_aViewData["errorsavingtprice"] = 1;
00136         }
00137 
00138         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00139         $oArticle->setLanguage(0);
00140         $oArticle->assign( $aParams);
00141         $oArticle->setLanguage($this->_iEditLang);
00142         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00143         $oArticle->save();
00144 
00145         //saving media file
00146         $sMediaUrl  = oxConfig::getParameter( "mediaUrl");
00147         $sMediaDesc = oxConfig::getParameter( "mediaDesc");
00148         $aMediaFile = $this->getConfig()->getUploadedFile( "mediaFile");
00149 
00150         if ($sMediaUrl || $aMediaFile['name'] || $sMediaDesc) {
00151 
00152             if ( !$sMediaDesc ) {
00153                 return oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_NODESCRIPTIONADDED' );
00154             }
00155 
00156             if ( !$sMediaUrl && !$aMediaFile['name'] ) {
00157                 return oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_NOMEDIAADDED' );
00158             }
00159 
00160             $oMediaUrl = oxNew("oxMediaUrl");
00161             $oMediaUrl->setLanguage( $this->_iEditLang );
00162             $oMediaUrl->oxmediaurls__oxisuploaded = new oxField( 0, oxField::T_RAW);
00163 
00164             //handle uploaded file
00165             if ($aMediaFile['name']) {
00166                 try {
00167                     $sMediaUrl = oxUtilsFile::getInstance()->handleUploadedFile($aMediaFile, 'out/media/');
00168                     $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
00169                 } catch (Exception $e) {
00170                     return oxUtilsView::getInstance()->addErrorToDisplay( $e->getMessage() );
00171                 }
00172             }
00173 
00174             //save media url
00175             $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
00176             $oMediaUrl->oxmediaurls__oxurl = new oxField($sMediaUrl, oxField::T_RAW);
00177             $oMediaUrl->oxmediaurls__oxdesc = new oxField(oxConfig::getParameter( "mediaDesc"), oxField::T_RAW);
00178             $oMediaUrl->save();
00179 
00180         }
00181     }
00182 
00188     public function deletemedia()
00189     {
00190         $soxId = oxConfig::getParameter( "oxid");
00191         $sMediaId = oxConfig::getParameter( "mediaid");
00192         if ($sMediaId && $soxId) {
00193             $oMediaUrl = oxNew("oxMediaUrl");
00194             $oMediaUrl->load($sMediaId);
00195             $oMediaUrl->delete();
00196         }
00197     }
00198 
00207     public function addDefaultValues( $aParams)
00208     {
00209         $aParams['oxarticles__oxexturl'] = str_replace( "http://", "", $aParams['oxarticles__oxexturl']);
00210 
00211         return $aParams;
00212     }
00213 
00219     public function updateMedia()
00220     {
00221         $aMediaUrls = oxConfig::getParameter( 'aMediaUrls' );
00222         if ( is_array( $aMediaUrls ) ) {
00223             foreach ( $aMediaUrls as $sMediaId => $aMediaParams ) {
00224                 $oMedia = oxNew("oxMediaUrl");
00225                 if ( $oMedia->load( $sMediaId ) ) {
00226                     $oMedia->setLanguage(0);
00227                     $oMedia->assign( $aMediaParams );
00228                     $oMedia->setLanguage( $this->_iEditLang );
00229                     $oMedia->save();
00230                 }
00231             }
00232         }
00233     }
00234 }