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