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 
00114         $soxId = $this->getEditObjectId();
00115         $aParams = oxConfig::getParameter( "editval");
00116         // checkbox handling
00117         if ( !isset( $aParams['oxarticles__oxissearch'])) {
00118             $aParams['oxarticles__oxissearch'] = 0;
00119         }
00120         if ( !isset( $aParams['oxarticles__oxblfixedprice'])) {
00121             $aParams['oxarticles__oxblfixedprice'] = 0;
00122         }
00123 
00124         // new way of handling bundled articles
00125         //#1517C - remove posibility to add Bundled Product
00126         //$this->setBundleId($aParams, $soxId);
00127 
00128         // default values
00129         $aParams = $this->addDefaultValues( $aParams);
00130 
00131         $oArticle = oxNew( "oxarticle" );
00132         $oArticle->loadInLang( $this->_iEditLang, $soxId);
00133 
00134         if ( $aParams['oxarticles__oxtprice'] != $oArticle->oxarticles__oxtprice->value &&  $aParams['oxarticles__oxtprice'] && $aParams['oxarticles__oxtprice'] < $oArticle->oxarticles__oxprice->value) {
00135             //$aParams['oxarticles__oxtprice'] = $oArticle->oxarticles__oxtprice->value;
00136             $this->_aViewData["errorsavingtprice"] = 1;
00137         }
00138 
00139         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00140         $oArticle->setLanguage(0);
00141         $oArticle->assign( $aParams);
00142         $oArticle->setLanguage($this->_iEditLang);
00143         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00144         $oArticle->save();
00145 
00146         //saving media file
00147         $sMediaUrl  = oxConfig::getParameter( "mediaUrl");
00148         $sMediaDesc = oxConfig::getParameter( "mediaDesc");
00149         $aMediaFile = $this->getConfig()->getUploadedFile( "mediaFile");
00150 
00151         if ( ( $sMediaUrl && $sMediaUrl != 'http://' ) || $aMediaFile['name'] || $sMediaDesc ) {
00152 
00153             if ( !$sMediaDesc ) {
00154                 return oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_NODESCRIPTIONADDED' );
00155             }
00156 
00157             if ( ( !$sMediaUrl || $sMediaUrl == 'http://' ) && !$aMediaFile['name'] ) {
00158                 return oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_NOMEDIAADDED' );
00159             }
00160 
00161             $oMediaUrl = oxNew( "oxMediaUrl" );
00162             $oMediaUrl->setLanguage( $this->_iEditLang );
00163             $oMediaUrl->oxmediaurls__oxisuploaded = new oxField( 0, oxField::T_RAW );
00164 
00165             //handle uploaded file
00166             if ($aMediaFile['name']) {
00167                 try {
00168                     $sMediaUrl = oxUtilsFile::getInstance()->processFile( 'mediaFile', 'out/media/' );
00169                     $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
00170                 } catch (Exception $e) {
00171                     return oxUtilsView::getInstance()->addErrorToDisplay( $e->getMessage() );
00172                 }
00173             }
00174 
00175             //save media url
00176             $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
00177             $oMediaUrl->oxmediaurls__oxurl      = new oxField($sMediaUrl, oxField::T_RAW);
00178             $oMediaUrl->oxmediaurls__oxdesc     = new oxField($sMediaDesc, oxField::T_RAW);
00179             $oMediaUrl->save();
00180         }
00181     }
00182 
00188     public function deletemedia()
00189     {
00190         $soxId = $this->getEditObjectId();
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 }