article_extend.php

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