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         // all categories
00028         if ( $soxId != "-1" && isset( $soxId ) ) { // load object
00029             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00030 
00031 
00032             // load object in other languages
00033             $oOtherLang = $oArticle->getAvailableInLangs();
00034             if (!isset($oOtherLang[$this->_iEditLang])) {
00035                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00036                 $oArticle->loadInLang( key($oOtherLang), $soxId );
00037             }
00038 
00039             foreach ( $oOtherLang as $id => $language) {
00040                 $oLang= new oxStdClass();
00041                 $oLang->sLangDesc = $language;
00042                 $oLang->selected = ($id == $this->_iEditLang);
00043                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00044             }
00045 
00046             // variant handling
00047             if ( $oArticle->oxarticles__oxparentid->value) {
00048                 $oParentArticle = oxNew( 'oxarticle' );
00049                 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00050                 $this->_aViewData["parentarticle"] = $oParentArticle;
00051                 $this->_aViewData["oxparentid"]    = $oArticle->oxarticles__oxparentid->value;
00052             }
00053 
00054             $sO2CView = getViewName('oxobject2category');
00055         }
00056 
00057         if ( oxConfig::getParameter("aoc") ) {
00058 
00059             $aColumns = array();
00060             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00061             $this->_aViewData['oxajax'] = $aColumns;
00062 
00063             return "popups/article_extend.tpl";
00064         }
00065 
00066 
00067             $oDB = oxDb::GetDB();
00068             $myConfig = $this->getConfig();
00069             $suffix = ($this->_iEditLang)?"_$this->_iEditLang":"";
00070 
00071             $aList = array();
00072 
00073             $iArtCnt = $myConfig->getParameter( "iArtCnt");
00074 
00075             // only load them when DB is small as it anyway makes no sense to display 1000 of e.g. 100.000
00076             //if( $iArtCnt < $myConfig->getConfigParam( 'iMaxArticles' ) ) {
00077 
00078             $oArt = new stdClass();
00079             $oArt->oxarticles__oxid = new oxField("");
00080             $oArt->oxarticles__oxartnum = new oxField("");
00081             $oArt->oxarticles__oxtitle = new oxField(" -- ");
00082             $aList[] = $oArt;
00083 
00084             // #546
00085             $blHideVariants = !$myConfig->getConfigParam( 'blVariantsSelection' );
00086             $sHideVariants  = $blHideVariants?" where oxarticles.oxparentid = '' and ":" where ";
00087             // FS#1780 V
00088             $sHideItself    = "oxarticles.oxid != '$soxId' and ";
00089 
00090             $sSelect =  "select oxarticles.oxid, oxarticles.oxartnum, oxarticles.oxtitle$suffix, oxarticles.oxvarselect$suffix from oxarticles $sHideVariants ";
00091             $sSelect .= "$sHideItself oxarticles.oxshopid = '".$myConfig->getShopId()."' order by oxartnum, oxtitle";
00092             $rs = $oDB->Execute( $sSelect);
00093             if ($rs != false && $rs->RecordCount() > 0) {
00094                 while (!$rs->EOF) {
00095                     $oArt = new stdClass();    // #663
00096                     $oArt->oxarticles__oxid = new oxField($rs->fields[0]);
00097                     $oArt->oxarticles__oxnid = new oxField($rs->fields[0]);
00098                     $oArt->oxarticles__oxartnum = new oxField($rs->fields[1]);
00099                     $oArt->oxarticles__oxtitle = new oxField($rs->fields[2]);
00100                     if ( !$oArt->oxarticles__oxtitle->value && !$blHideVariants)
00101                         $oArt->oxarticles__oxtitle = new oxField($rs->fields[3]);
00102                     if( $oArt->oxarticles__oxid->value == $oArticle->oxarticles__oxbundleid->value) {
00103                         $oArt->selected = 1;
00104                     } else {
00105                         $oArt->selected = 0;
00106                     }
00107                     $aList[] = $oArt;
00108                     $rs->MoveNext();
00109                 }
00110             }
00111             /*
00112             }
00113             else
00114             {
00115                 $oArt = new stdClass();
00116                 $oArt->oxarticles__oxid = new oxField("");
00117                 $oArt->oxarticles__oxartnum = new oxField("");
00118                 $oArt->oxarticles__oxtitle = new oxField(" not available,too many Articles ");
00119                 $aList[] = $oArt;
00120             }*/
00121             $this->_aViewData["arttree"] =  $aList;
00122 
00123         //load media files
00124         $this->_aViewData['aMediaUrls'] = $oArticle->getMediaUrls();
00125 
00126         return "article_extend.tpl";
00127     }
00128 
00134     public function save()
00135     {
00136 
00137         $soxId      = oxConfig::getParameter( "oxid");
00138         $aParams    = oxConfig::getParameter( "editval");
00139         // checkbox handling
00140         if ( !isset( $aParams['oxarticles__oxissearch'])) {
00141             $aParams['oxarticles__oxissearch'] = 0;
00142         }
00143         if ( !isset( $aParams['oxarticles__oxblfixedprice'])) {
00144             $aParams['oxarticles__oxblfixedprice'] = 0;
00145         }
00146 
00147         // new way of handling bundled articles
00148         //#1517C - remove posibility to add Bundled Product
00149         //$this->setBundleId($aParams, $soxId);
00150 
00151         // default values
00152         $aParams = $this->addDefaultValues( $aParams);
00153 
00154         $oArticle = oxNew( "oxarticle" );
00155         $oArticle->loadInLang( $this->_iEditLang, $soxId);
00156 
00157         if ( $aParams['oxarticles__oxtprice'] != $oArticle->oxarticles__oxtprice->value &&  $aParams['oxarticles__oxtprice'] && $aParams['oxarticles__oxtprice'] < $oArticle->oxarticles__oxprice->value) {
00158             //$aParams['oxarticles__oxtprice'] = $oArticle->oxarticles__oxtprice->value;
00159             $this->_aViewData["errorsavingtprice"] = 1;
00160         }
00161 
00162         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00163         $oArticle->setLanguage(0);
00164         $oArticle->assign( $aParams);
00165         $oArticle->setLanguage($this->_iEditLang);
00166         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00167         $oArticle->save();
00168 
00169         //saving media file
00170         $sMediaUrl  = oxConfig::getParameter( "mediaUrl");
00171         $sMediaDesc = oxConfig::getParameter( "mediaDesc");
00172         $aMediaFile = $this->getConfig()->getUploadedFile( "mediaFile");
00173 
00174         if ($sMediaUrl || $aMediaFile['name'] || $sMediaDesc) {
00175 
00176             if ( !$sMediaDesc ) {
00177                 oxUtilsView::getInstance()->addErrorToDisplay('EXCEPTION_NODESCRIPTIONADDED');
00178                 return;
00179             }
00180 
00181             if ( !$sMediaUrl && !$aMediaFile['name'] ) {
00182                 oxUtilsView::getInstance()->addErrorToDisplay('EXCEPTION_NOMEDIAADDED');
00183                 return;
00184             }
00185 
00186             $oMediaUrl = oxNew("oxMediaUrl");
00187             $oMediaUrl->setLanguage( $this->_iEditLang );
00188             $oMediaUrl->oxmediaurls__oxisuploaded = new oxField( 0, oxField::T_RAW);
00189 
00190             //handle uploaded file
00191             if ($aMediaFile['name']) {
00192                 try {
00193                     $sMediaUrl = oxUtilsFile::getInstance()->handleUploadedFile($aMediaFile, 'out/media/');
00194                     $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
00195                 } catch (Exception $e) {
00196                     oxUtilsView::getInstance()->addErrorToDisplay($e->getMessage());
00197                     return;
00198                 }
00199             }
00200 
00201             //save media url
00202             $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
00203             $oMediaUrl->oxmediaurls__oxurl = new oxField($sMediaUrl, oxField::T_RAW);
00204             $oMediaUrl->oxmediaurls__oxdesc = new oxField(oxConfig::getParameter( "mediaDesc"), oxField::T_RAW);
00205             $oMediaUrl->save();
00206 
00207         }
00208     }
00209 
00215     public function deletemedia()
00216     {
00217         $soxId = oxConfig::getParameter( "oxid");
00218         $sMediaId = oxConfig::getParameter( "mediaid");
00219         if ($sMediaId && $soxId) {
00220             $oMediaUrl = oxNew("oxMediaUrl");
00221             $oMediaUrl->load($sMediaId);
00222             $oMediaUrl->delete();
00223         }
00224     }
00225 
00234     public function addDefaultValues( $aParams)
00235     {
00236         $aParams['oxarticles__oxexturl'] = str_replace( "http://", "", $aParams['oxarticles__oxexturl']);
00237 
00238         return $aParams;
00239     }
00240 
00246     public function updateMedia()
00247     {
00248         $aMediaUrls = oxConfig::getParameter( 'aMediaUrls' );
00249         if ( is_array( $aMediaUrls ) ) {
00250             foreach ( $aMediaUrls as $sMediaId => $aMediaParams ) {
00251                 $oMedia = oxNew("oxMediaUrl");
00252                 if ( $oMedia->load( $sMediaId ) ) {
00253                     $oMedia->setLanguage(0);
00254                     $oMedia->assign( $aMediaParams );
00255                     $oMedia->setLanguage( $this->_iEditLang );
00256                     $oMedia->save();
00257                 }
00258             }
00259         }
00260     }
00261 
00262 }

Generated on Wed Apr 22 12:26:29 2009 for OXID eShop CE by  doxygen 1.5.5