article_main.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Article_Main extends oxAdminDetails
00010 {
00017     public function render()
00018     {
00019         $myConfig = $this->getConfig();
00020         parent::render();
00021 
00022         $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00023 
00024         $soxId = $this->getEditObjectId();
00025         $svoxId = oxConfig::getParameter( "voxid" );
00026         $soxparentId = oxConfig::getParameter( "oxparentid" );
00027 
00028         // new variant ?
00029         if ( isset( $svoxId ) && $svoxId == "-1" && isset($soxparentId) && $soxparentId && $soxparentId != "-1") {
00030             $oParentArticle = oxNew( "oxarticle");
00031             $oParentArticle->load( $soxparentId);
00032             $this->_aViewData["parentarticle"] = $oParentArticle;
00033             $this->_aViewData["oxparentid"] = $soxparentId;
00034 
00035             $this->_aViewData["oxid"] =  $soxId = "-1";
00036         }
00037 
00038         if (  $soxId && $soxId != "-1") {
00039 
00040             // load object
00041             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00042 
00043 
00044             // load object in other languages
00045             $oOtherLang = $oArticle->getAvailableInLangs();
00046             if (!isset($oOtherLang[$this->_iEditLang])) {
00047                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00048                 $oArticle->loadInLang( key($oOtherLang), $soxId );
00049             }
00050 
00051             // variant handling
00052             if ( $oArticle->oxarticles__oxparentid->value) {
00053                 $oParentArticle = oxNew( "oxarticle");
00054                 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00055                 $this->_aViewData["parentarticle"] = $oParentArticle;
00056                 $this->_aViewData["oxparentid"]    = $oArticle->oxarticles__oxparentid->value;
00057                 $this->_aViewData["issubvariant"]  = 1;
00058             }
00059 
00060             // #381A
00061             $this->_formJumpList($oArticle, $oParentArticle );
00062 
00063             //loading tags
00064             $oTagCloud = oxNew("oxTagCloud");
00065             $oArticle->tags = $oTagCloud->getTagTitle($oArticle->getTags());
00066 
00067             $aLang = array_diff (oxLang::getInstance()->getLanguageNames(), $oOtherLang);
00068             if ( count( $aLang))
00069                 $this->_aViewData["posslang"] = $aLang;
00070 
00071             foreach ( $oOtherLang as $id => $language) {
00072                 $oLang= new oxStdClass();
00073                 $oLang->sLangDesc = $language;
00074                 $oLang->selected = ($id == $this->_iEditLang);
00075                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00076             }
00077         }
00078 
00079         $this->_aViewData["editor"] = $this->_generateTextEditor( "100%", 300, $oArticle, "oxarticles__oxlongdesc", "details.tpl.css");
00080         $this->_aViewData["blUseTimeCheck"] = $myConfig->getConfigParam( 'blUseTimeCheck' );
00081 
00082         return "article_main.tpl";
00083     }
00084 
00093     protected function _getEditValue( $oObject, $sField )
00094     {
00095         $sEditObjectValue = '';
00096         if ( $oObject ) {
00097             $oDescField = $oObject->getArticleLongDesc();
00098             $sEditObjectValue = $this->_processEditValue( $oDescField->getRawValue() );
00099             $oDescField = new oxField( $sEditObjectValue, oxField::T_RAW );
00100         }
00101 
00102         return $sEditObjectValue;
00103     }
00104 
00110     public function save()
00111     {
00112         $myConfig = $this->getConfig();
00113         $soxId    = $this->getEditObjectId();
00114         $aParams  = oxConfig::getParameter( "editval" );
00115 
00116 
00117         // checkbox handling
00118         if ( !isset( $aParams['oxarticles__oxactive'] ) ) {
00119             $aParams['oxarticles__oxactive'] = 0;
00120         }
00121 
00122         // default values
00123         $aParams = $this->addDefaultValues( $aParams );
00124 
00125         // null values
00126         if ($aParams['oxarticles__oxvat'] === '') {
00127             $aParams['oxarticles__oxvat'] = null;
00128         }
00129 
00130         // varianthandling
00131         $soxparentId = oxConfig::getParameter( "oxparentid");
00132         if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1") {
00133             $aParams['oxarticles__oxparentid'] = $soxparentId;
00134         } else {
00135             unset( $aParams['oxarticles__oxparentid']);
00136         }
00137 
00138         $oArticle = oxNew( "oxarticle");
00139         $oArticle->setLanguage($this->_iEditLang);
00140 
00141         if ( $soxId != "-1") {
00142             $oArticle->loadInLang( $this->_iEditLang, $soxId);
00143         } else {
00144             $aParams['oxarticles__oxid']        = null;
00145             $aParams['oxarticles__oxissearch']  = 1;
00146             $aParams['oxarticles__oxstockflag'] = 1;
00147                 // shopid
00148                 $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop");
00149         }
00150 
00151         //article number handling, warns for artnum dublicates
00152         if ( isset( $aParams['oxarticles__oxartnum']) && strlen($aParams['oxarticles__oxartnum']) > 0 &&
00153             $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00154             $oArticle->oxarticles__oxartnum->value !=  $aParams['oxarticles__oxartnum']
00155             ) {
00156             $sSelect  = "select oxid from ".getViewName( 'oxarticles' );
00157             $sSelect .= " where oxartnum = '".$aParams['oxarticles__oxartnum']."'";
00158             $sSelect .= " and oxid != '".$aParams['oxarticles__oxid']."'";
00159             if ($oArticle->assignRecord( $sSelect ))
00160                 $this->_aViewData["errorsavingatricle"] = 1;
00161         }
00162 
00163             // #905A resetting article count in price categories if price has been changed
00164             if ( isset($aParams["oxarticles__oxprice"]) && $aParams["oxarticles__oxprice"] != $oArticle->oxarticles__oxprice->value) {
00165                 $this->resetCounter( "priceCatArticle", $oArticle->oxarticles__oxprice->value );
00166             }
00167 
00168             $aResetIds = array();
00169             if ( $aParams['oxarticles__oxactive'] != $oArticle->oxarticles__oxactive->value) {
00170                 $oDb = oxDb::getDb();
00171                 //check categories
00172                 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote( $oArticle->oxarticles__oxid->value );
00173                 $oRs = $oDb->execute($sQ);
00174                 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00175                     while (!$oRs->EOF) {
00176                         $this->resetCounter( "catArticle", $oRs->fields[0] );
00177                         $oRs->moveNext();
00178                     }
00179                 }
00180 
00181                 // vendors
00182                 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00183                 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00184             }
00185 
00186             // vendors
00187             if ( isset($aParams['oxarticles__oxvendorid']) && $aParams['oxarticles__oxvendorid'] != $oArticle->oxarticles__oxvendorid->value) {
00188                 $aResetIds['vendor'][$aParams['oxarticles__oxvendorid']] = 1;
00189                 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00190             }
00191 
00192             // manufacturers
00193             if ( isset($aParams['oxarticles__oxmanufacturerid']) && $aParams['oxarticles__oxmanufacturerid'] != $oArticle->oxarticles__oxmanufacturerid->value ) {
00194                 $aResetIds['manufacturer'][$aParams['oxarticles__oxmanufacturerid']] = 1;
00195                 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00196             }
00197 
00198             // resetting counts
00199             $this->_resetCounts( $aResetIds );
00200 
00201         $oArticle->setLanguage(0);
00202 
00203         //triming spaces from article title (M:876)
00204         $aParams['oxarticles__oxtitle'] = trim( $aParams['oxarticles__oxtitle'] );
00205 
00206         $oArticle->assign( $aParams );
00207         $oArticle->setArticleLongDesc( $this->_processLongDesc( $aParams['oxarticles__oxlongdesc'] ) );
00208         $oArticle->setLanguage($this->_iEditLang);
00209         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00210         $oArticle->save();
00211 
00212         // set oxid if inserted
00213         if ( $soxId == "-1") {
00214             $sFastCat = oxConfig::getParameter( "art_category");
00215             if ( $sFastCat != "-1") {
00216                 $this->addToCategory($sFastCat, $oArticle->getId());
00217             }
00218         }
00219 
00220         //saving tags
00221         $sTags = $aParams['tags'];
00222         if (!trim($sTags)) {
00223             $sTags = $oArticle->oxarticles__oxsearchkeys->value;
00224         }
00225         $oArticle->saveTags($sTags);
00226         $this->setEditObjectId( $oArticle->getId() );
00227     }
00228 
00236     protected function _processLongDesc( $sValue )
00237     {
00238         // TODO: the code below is redundant, optimize it, assignments should go smooth without conversions
00239         // hack, if editor screws up text, htmledit tends to do so
00240         $sValue = str_replace( '&amp;nbsp;', '&nbsp;', $sValue );
00241         $sValue = str_replace( '&amp;', '&', $sValue );
00242         $sValue = str_replace( '&quot;', '"', $sValue );
00243         $sValue = str_replace( '&lang=', '&amp;lang=', $sValue);
00244 
00245         return $sValue;
00246     }
00247 
00256     public function addToCategory($sCatID, $sOXID)
00257     {
00258         $myConfig  = $this->getConfig();
00259 
00260         $oNew = oxNew( "oxbase");
00261         $oNew->init( "oxobject2category" );
00262         $oNew->oxobject2category__oxtime     = new oxField( 0 );
00263         $oNew->oxobject2category__oxobjectid = new oxField( $sOXID );
00264         $oNew->oxobject2category__oxcatnid   = new oxField( $sCatID );
00265 
00266         $oNew->save();
00267 
00268             // resetting amount of articles in category
00269             $this->resetCounter( "catArticle", $sCatID );
00270     }
00271 
00281     public function copyArticle( $sOldId = null, $sNewId = null, $sParentId = null )
00282     {
00283         $myConfig = $this->getConfig();
00284 
00285         $sOldId = $sOldId ? $sOldId : $this->getEditObjectId();
00286         $sNewId = $sNewId ? $sNewId : oxUtilsObject::getInstance()->generateUID();
00287 
00288         $oArticle = oxNew( 'oxbase' );
00289         $oArticle->init( 'oxarticles' );
00290         if ( $oArticle->load( $sOldId ) ) {
00291 
00292             if ( $myConfig->getConfigParam( 'blDisableDublArtOnCopy' ) ) {
00293                 $oArticle->oxarticles__oxactive->setValue( 0 );
00294                 $oArticle->oxarticles__oxactivefrom->setValue( 0 );
00295                 $oArticle->oxarticles__oxactiveto->setValue( 0 );
00296             }
00297 
00298             // setting parent id
00299             if ( $sParentId ) {
00300                 $oArticle->oxarticles__oxparentid->setValue( $sParentId );
00301             }
00302 
00303             // setting oxinsert/oxtimestamp
00304             $iNow = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00305             $oArticle->oxarticles__oxinsert    = new oxField( $iNow );
00306             $oArticle->oxarticles__oxtimestamp = new oxField( $iNow );
00307 
00308             // mantis#0001590: OXRATING and OXRATINGCNT not set to 0 when copying article
00309             $oArticle->oxarticles__oxrating    = new oxField( 0 );
00310             $oArticle->oxarticles__oxratingcnt = new oxField( 0 );
00311 
00312             $oArticle->setId( $sNewId );
00313             $oArticle->save();
00314 
00315             //copy categories
00316             $this->_copyCategories( $sOldId, $sNewId );
00317 
00318             //atributes
00319             $this->_copyAttributes( $sOldId, $sNewId );
00320 
00321             //sellist
00322             $this->_copySelectlists( $sOldId, $sNewId );
00323 
00324             //crossseling
00325             $this->_copyCrossseling( $sOldId, $sNewId );
00326 
00327             //accessoire
00328             $this->_copyAccessoires( $sOldId, $sNewId );
00329 
00330             // #983A copying staffelpreis info
00331             $this->_copyStaffelpreis( $sOldId, $sNewId );
00332 
00333             //copy article extends (longdescription, tags)
00334             $this->_copyArtExtends( $sOldId, $sNewId);
00335 
00336                 // resetting
00337                 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00338                 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00339                 $this->_resetCounts( $aResetIds );
00340 
00341 
00342             $myUtilsObject = oxUtilsObject::getInstance();
00343             $oDb = oxDb::getDb();
00344 
00345             //copy variants
00346             $sQ = "select oxid from oxarticles where oxparentid = ".$oDb->quote( $sOldId );
00347             $oRs = $oDb->execute( $sQ );
00348             if ( $oRs !== false && $oRs->recordCount() > 0) {
00349                 while ( !$oRs->EOF ) {
00350                     $this->copyArticle( $oRs->fields[0], $myUtilsObject->generateUid(), $sNewId );
00351                     $oRs->moveNext();
00352                 }
00353             }
00354 
00355             // only for top articles
00356             if ( !$sParentId ) {
00357 
00358                 $this->setEditObjectId( $oArticle->getId() );
00359 
00360                 //article number handling, warns for artnum dublicates
00361                 if ( $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00362                      $oArticle->oxarticles__oxartnum->value && oxConfig::getParameter( 'fnc' ) == 'copyArticle' ) {
00363                     $sSelect = "select oxid from ".$oArticle->getCoreTableName()."
00364                                 where oxartnum = ".$oDb->quote( $oArticle->oxarticles__oxartnum->value )." and oxid != ".$oDb->quote( $sNewId );
00365 
00366                     if ( $oArticle->assignRecord( $sSelect ) ) {
00367                         $this->_aViewData["errorsavingatricle"] = 1;
00368                     }
00369                 }
00370             }
00371         }
00372     }
00373 
00382     protected function _copyCategories( $sOldId, $sNewId )
00383     {
00384         $myUtilsObject = oxUtilsObject::getInstance();
00385         $oDb = oxDb::getDb();
00386 
00387 
00388         $sO2CView = getViewName( 'oxobject2category' );
00389         $sQ = "select oxcatnid, oxtime from {$sO2CView} where oxobjectid = ".$oDb->quote( $sOldId );
00390         $oRs = $oDb->execute( $sQ );
00391         if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00392             while ( !$oRs->EOF ) {
00393                 $sUid = $myUtilsObject->generateUid();
00394                 $sCatId = $oRs->fields[0];
00395                 $sTime  = $oRs->fields[1];
00396 
00397 
00398                     $oDb->execute("insert into oxobject2category (oxid, oxobjectid, oxcatnid, oxtime) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sNewId ).", ".$oDb->quote( $sCatId ).", ".$oDb->quote( $sTime ).") ");
00399 
00400                 $oRs->moveNext();
00401 
00402                     // resetting article count in category
00403                     $this->resetCounter( "catArticle", $sCatId );
00404             }
00405         }
00406     }
00407 
00416     protected function _copyAttributes( $sOldId, $sNewId )
00417     {
00418         $myUtilsObject = oxUtilsObject::getInstance();
00419         $oDb = oxDb::getDb();
00420 
00421         $sQ = "select oxid from oxobject2attribute where oxobjectid = ".$oDb->quote( $sOldId );
00422         $oRs = $oDb->execute($sQ);
00423         if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00424             while ( !$oRs->EOF ) {
00425                 // #1055A
00426                 $oAttr = oxNew( "oxbase" );
00427                 $oAttr->init( "oxobject2attribute" );
00428                 $oAttr->load( $oRs->fields[0] );
00429                 $oAttr->setId( $myUtilsObject->generateUID() );
00430                 $oAttr->oxobject2attribute__oxobjectid->setValue( $sNewId );
00431                 $oAttr->save();
00432                 $oRs->moveNext();
00433             }
00434         }
00435     }
00436 
00445     protected function _copySelectlists( $sOldId, $sNewId )
00446     {
00447         $myUtilsObject = oxUtilsObject::getInstance();
00448         $oDb = oxDb::getDb();
00449 
00450         $sQ = "select oxselnid from oxobject2selectlist where oxobjectid = ".$oDb->quote( $sOldId );
00451         $oRs = $oDb->execute( $sQ );
00452         if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00453             while ( !$oRs->EOF ) {
00454                 $sUid = $myUtilsObject->generateUID();
00455                 $sId = $oRs->fields[0];
00456                 $oDb->execute( "insert into oxobject2selectlist (oxid, oxobjectid, oxselnid) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sNewId ).", ".$oDb->quote( $sId ).") " );
00457                 $oRs->moveNext();
00458             }
00459         }
00460     }
00461 
00470     protected function _copyCrossseling( $sOldId, $sNewId )
00471     {
00472         $myUtilsObject = oxUtilsObject::getInstance();
00473         $oDb = oxDb::getDb();
00474 
00475         $sQ = "select oxobjectid from oxobject2article where oxarticlenid = ".$oDb->quote( $sOldId );
00476         $oRs = $oDb->execute( $sQ );
00477         if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00478             while ( !$oRs->EOF ) {
00479                 $sUid = $myUtilsObject->generateUID();
00480                 $sId = $oRs->fields[0];
00481                 $oDb->execute("insert into oxobject2article (oxid, oxobjectid, oxarticlenid) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sId ).", ".$oDb->quote( $sNewId )." ) ");
00482                 $oRs->moveNext();
00483             }
00484         }
00485     }
00486 
00495     protected function _copyAccessoires( $sOldId, $sNewId )
00496     {
00497         $myUtilsObject = oxUtilsObject::getInstance();
00498         $oDb = oxDb::getDb();
00499 
00500         $sQ = "select oxobjectid from oxaccessoire2article where oxarticlenid= ".$oDb->quote( $sOldId );
00501         $oRs = $oDb->execute( $sQ );
00502         if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00503             while ( !$oRs->EOF ) {
00504                 $sUId = $myUtilsObject->generateUid();
00505                 $sId = $oRs->fields[0];
00506                 $oDb->execute( "insert into oxaccessoire2article (oxid, oxobjectid, oxarticlenid) VALUES (".$oDb->quote( $sUId ).", ".$oDb->quote( $sId ).", ".$oDb->quote( $sNewId ).") " );
00507                 $oRs->moveNext();
00508             }
00509         }
00510     }
00511 
00520     protected function _copyStaffelpreis( $sOldId, $sNewId )
00521     {
00522         $sShopId = $this->getConfig()->getShopId();
00523         $oPriceList = oxNew( "oxlist" );
00524         $oPriceList->init( "oxbase", "oxprice2article" );
00525         $sQ = "select * from oxprice2article where oxartid = '$sOldId' and oxshopid = '$sShopId' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00526         $oPriceList->selectString( $sQ );
00527         if ( $oPriceList->count() ) {
00528             foreach ( $oPriceList as $oItem ) {
00529                 $oItem->oxprice2article__oxid->setValue( $oItem->setId() );
00530                 $oItem->oxprice2article__oxartid->setValue( $sNewId );
00531                 $oItem->save();
00532             }
00533         }
00534     }
00535 
00544     protected function _copyArtExtends( $sOldId, $sNewId)
00545     {
00546         $oExt = oxNew( "oxbase");
00547         $oExt->init( "oxartextends" );
00548         $oExt->load( $sOldId );
00549         $oExt->setId( $sNewId );
00550         $oExt->save();
00551     }
00552 
00553 
00559     public function saveinnlang()
00560     {
00561         $this->save();
00562     }
00563 
00572     public function addDefaultValues( $aParams )
00573     {
00574         return $aParams;
00575     }
00576 
00585     protected function _formJumpList( $oArticle, $oParentArticle )
00586     {
00587         $aJumpList = array();
00588         //fetching parent article variants
00589         if ( isset( $oParentArticle ) ) {
00590             $aJumpList[] = array( $oParentArticle->oxarticles__oxid->value, $this->_getTitle( $oParentArticle ) );
00591             $oParentVariants = $oParentArticle->getAdminVariants( oxConfig::getParameter( "editlanguage" ) );
00592             if ( $oParentVariants->count()) {
00593                 foreach ( $oParentVariants as $oVar) {
00594                     $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar ) );
00595                     if ( $oVar->oxarticles__oxid->value == $oArticle->oxarticles__oxid->value ) {
00596                         $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00597                         if ( $oVariants->count() ) {
00598                             foreach ( $oVariants as $oVVar) {
00599                                 $aJumpList[] = array( $oVVar->oxarticles__oxid->value, " -- ".$this->_getTitle( $oVVar));
00600                             }
00601                         }
00602                     }
00603                 }
00604             }
00605         } else {
00606             $aJumpList[] = array( $oArticle->oxarticles__oxid->value, $this->_getTitle( $oArticle));
00607             //fetching this article variants data
00608             $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00609             if ( $oVariants && $oVariants->count())
00610                 foreach ($oVariants as $oVar) {
00611                     $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar));
00612                 }
00613         }
00614         if ( count($aJumpList) > 1)
00615             $this->_aViewData["thisvariantlist"] = $aJumpList;
00616     }
00617 
00625     protected function _getTitle( $oObj )
00626     {
00627         $sTitle = $oObj->oxarticles__oxtitle->value;
00628         if ( !strlen( $sTitle ) ) {
00629             $sTitle = $oObj->oxarticles__oxvarselect->value;
00630         }
00631 
00632         return $sTitle;
00633     }
00634 
00640     public function getCategoryList()
00641     {
00642         $oCatTree = oxNew( "oxCategoryList");
00643         $oCatTree->buildList( $this->getConfig()->getConfigParam( 'bl_perfLoadCatTree' ) );
00644         return $oCatTree;
00645     }
00646 
00652     public function getVendorList()
00653     {
00654         $oVendorlist = oxNew( "oxvendorlist" );
00655         $oVendorlist->loadVendorList();
00656 
00657         return $oVendorlist;
00658     }
00659 
00665     public function getManufacturerList()
00666     {
00667         $oManufacturerList = oxNew( "oxmanufacturerlist" );
00668         $oManufacturerList->loadManufacturerList();
00669 
00670         return $oManufacturerList;
00671     }
00672 }