oxcategory.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxCategory extends oxI18n
00009 {
00014     protected $_aSubCats = array();
00015 
00020     protected $_aContentCats = array();
00021 
00027     protected $_sClassName = 'oxcategory';
00028 
00034     protected $_iNrOfArticles;
00035 
00041     protected $_blIsVisible;
00042 
00048     protected $_blExpanded;
00049 
00055     protected $_blHasSubCats;
00056 
00062     protected $_blHasVisibleSubCats;
00063 
00069     protected $_blIsSeoObject = true;
00070 
00076     protected $_blUseLazyLoading = false;
00077 
00083     protected $_sDynImageDir = null;
00084 
00090     protected $_blTopCategory = null;
00091 
00097     protected $_aIds = array();
00098 
00102     public function __construct()
00103     {
00104         parent::__construct();
00105         $this->init( 'oxcategories' );
00106     }
00107 
00115     public function __get( $sName )
00116     {
00117         switch ( $sName ) {
00118             case 'aSubCats':
00119                 return $this->_aSubCats;
00120 
00121             case 'aContent':
00122                 return $this->_aContentCats;
00123 
00124             case 'iArtCnt':
00125                 return $this->getNrOfArticles();
00126 
00127             case 'isVisible':
00128                 return $this->getIsVisible();
00129 
00130             case 'expanded':
00131                 return $this->getExpanded();
00132 
00133             case 'hasSubCats':
00134                 return $this->getHasSubCats();
00135 
00136             case 'hasVisibleSubCats':
00137                 return $this->getHasVisibleSubCats();
00138 
00139             case 'openlink':
00140             case 'closelink':
00141             case 'link':
00142                 //case 'toListLink':
00143                 //case 'noparamlink':
00144                 return $this->getLink();
00145             case 'dimagedir':
00146                 return $this->getPictureUrl();
00147             }
00148         return parent::__get($sName);
00149     }
00150 
00158     public function assign( $dbRecord )
00159     {
00160 
00161         parent::assign( $dbRecord );
00162 
00163         startProfile("parseThroughSmarty");
00164         // #1030C run through smarty
00165         $myConfig = $this->getConfig();
00166         if (!$this->_isInList() && !$this->isAdmin() && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00167             $this->oxcategories__oxlongdesc = new oxField( oxUtilsView::getInstance()->parseThroughSmarty( $this->oxcategories__oxlongdesc->value, $this->getId() ), oxField::T_RAW );
00168         }
00169 
00170         if ( !$this->isAdmin() && ( $myConfig->getConfigParam( 'bl_perfShowActionCatArticleCnt' ) || $myConfig->getConfigParam('blDontShowEmptyCategories')  ) ) {
00171             if ( $this->oxcategories__oxpricefrom->value || $this->oxcategories__oxpriceto->value ) {
00172                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getPriceCatArticleCount( $this->getId(), $this->oxcategories__oxpricefrom->value, $this->oxcategories__oxpriceto->value );
00173             } else {
00174                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getCatArticleCount( $this->getId() );
00175             }
00176         }
00177 
00178         stopProfile("parseThroughSmarty");
00179     }
00180 
00188     public function delete( $sOXID = null)
00189     {
00190         if ( !$this->getId() ) {
00191             $this->load( $sOXID);
00192         }
00193 
00194 
00195         $myConfig = $this->getConfig();
00196         $oDB      = oxDb::getDb();
00197         $blRet    = false;
00198 
00199         if ( $this->oxcategories__oxright->value == ($this->oxcategories__oxleft->value+1) ) {
00200             $myUtilsPic = oxUtilsPic::getInstance();
00201 
00202             // only delete empty categories
00203             // #1173M - not all pic are deleted, after article is removed
00204             $myUtilsPic->safePictureDelete($this->oxcategories__oxthumb->value, $myConfig->getAbsDynImageDir().'/0', 'oxcategories', 'oxthumb' );
00205 
00206             $myUtilsPic->safePictureDelete($this->oxcategories__oxicon->value, $myConfig->getAbsDynImageDir().'/icon', 'oxcategories', 'oxicon' );
00207 
00208             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00209 
00210             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT - 2
00211                             WHERE  OXROOTID = '".$this->oxcategories__oxrootid->value."'
00212                             AND OXLEFT >   ".$this->oxcategories__oxleft->value.$sAdd );
00213 
00214             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT - 2
00215                             WHERE  OXROOTID = '".$this->oxcategories__oxrootid->value."'
00216                             AND OXRIGHT >   ".$this->oxcategories__oxright->value.$sAdd );
00217 
00218             // delete entry
00219             $blRet = parent::delete();
00220 
00221             // delete links to articles
00222             $oDB->execute( "delete from oxobject2category where oxobject2category.oxcatnid='".$this->oxcategories__oxid->value."' ");
00223 
00224             // #657 ADDITIONAL delete links to attributes
00225             $oDB->execute( "delete from oxcategory2attribute where oxcategory2attribute.oxobjectid='".$this->oxcategories__oxid->value."' ");
00226 
00227             // A. removing assigned:
00228             // - deliveries
00229             $oDB->execute( "delete from oxobject2delivery where oxobject2delivery.oxobjectid='".$this->oxcategories__oxid->value."' ");
00230             // - discounts
00231             $oDB->execute( "delete from oxobject2discount where oxobject2discount.oxobjectid='".$this->oxcategories__oxid->value."' ");
00232 
00233             oxSeoEncoderCategory::getInstance()->onDeleteCategory($this);
00234         }
00235         return $blRet;
00236     }
00237 
00243     public function getSubCats()
00244     {
00245         return $this->_aSubCats;
00246     }
00247 
00255     public function getSubCat($sKey)
00256     {
00257         return $this->_aSubCats[$sKey];
00258     }
00259 
00267     public function setSubCats( $aCats )
00268     {
00269         $this->_aSubCats = $aCats;
00270 
00271         foreach ( $aCats as $oCat ) {
00272             if ( $oCat->getIsVisible() ) {
00273                 $this->setHasVisibleSubCats( true );
00274             }
00275         }
00276 
00277         $this->sortSubCats();
00278     }
00279 
00288     public function setSubCat($oCat, $sKey=null)
00289     {
00290         if ( $sKey ) {
00291             $this->_aSubCats[$sKey] = $oCat;
00292         } else {
00293             $this->_aSubCats[] = $oCat;
00294         }
00295 
00296         // keeping ref. to parent
00297         $oCat->setParentCategory( $this );
00298 
00299         if ( $oCat->getIsVisible() ) {
00300             $this->setHasVisibleSubCats( true );
00301         }
00302 
00303         $this->sortSubCats();
00304     }
00305 
00311     public function sortSubCats()
00312     {
00313         if ( count( $this->_aIds ) > 0 ) {
00314             uasort($this->_aSubCats, array( $this, 'cmpCat' ) );
00315         }
00316     }
00317 
00327     public function cmpCat( $a,$b )
00328     {
00329         if ( count( $this->_aIds ) == 0 ) {
00330             return;
00331         }
00332 
00333         $sNumA = $this->_aIds[$a->oxcategories__oxid->value];
00334         $sNumB = $this->_aIds[$b->oxcategories__oxid->value];
00335 
00336         if ($sNumA  < $sNumB ) {
00337             return -1;
00338         } if ( $sNumA == $sNumB) {
00339             return 0;
00340         }
00341         return 1;
00342     }
00343 
00351     public function setSortingIds( $aSorIds )
00352     {
00353         $this->_aIds = $aSorIds;
00354     }
00355 
00361     public function getContentCats()
00362     {
00363         return $this->_aContentCats;
00364     }
00365 
00373     public function setContentCats( $aContent )
00374     {
00375         $this->_aContentCats = $aContent;
00376     }
00377 
00386     public function setContentCat( $oContent, $sKey=null )
00387     {
00388         if ( $sKey ) {
00389             $this->_aContentCats[$sKey] = $oContent;
00390         } else {
00391             $this->_aContentCats[] = $oContent;
00392         }
00393     }
00394 
00400     public function getNrOfArticles()
00401     {
00402         if ( !$this->getConfig()->getConfigParam( 'bl_perfShowActionCatArticleCnt' ) && $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00403             return 0;
00404         }
00405 
00406         return $this->_iNrOfArticles;
00407     }
00408 
00416     public function setNrOfArticles( $iNum )
00417     {
00418         $this->_iNrOfArticles = $iNum;
00419     }
00420 
00426     public function getIsVisible()
00427     {
00428         if (!isset( $this->_blIsVisible ) ) {
00429 
00430             if ( $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00431                 $blEmpty = ($this->_iNrOfArticles < 1) && !$this->getHasVisibleSubCats();
00432             } else {
00433                 $blEmpty = false;
00434             }
00435 
00436             $this->_blIsVisible = !($blEmpty || $this->oxcategories__oxhidden->value);
00437         }
00438 
00439         return $this->_blIsVisible;
00440     }
00441 
00449     public function setIsVisible( $blVisible )
00450     {
00451         $this->_blIsVisible = $blVisible;
00452     }
00453 
00459     public function getPictureUrl()
00460     {
00461         if ( $this->_sDynImageDir === null ) {
00462             $sThisShop = $this->oxcategories__oxshopid->value;
00463             $this->_sDynImageDir = $this->getConfig()->getPictureUrl( null, false, null, null, $sThisShop);
00464         }
00465         return $this->_sDynImageDir;
00466     }
00467 
00475     public function getLink($iLang = null)
00476     {
00477         if (isset($iLang)) {
00478             $iLang = (int) $iLang;
00479             if ($iLang == (int) $this->getLanguage()) {
00480                 $iLang = null;
00481             }
00482         }
00483         if ( ($this->link === null ) || isset($iLang)) {
00484             if ( (!isset( $this->oxcategories__oxextlink->value ) || !$this->oxcategories__oxextlink->value ) &&
00485                  oxUtils::getInstance()->seoIsActive() ) {
00486                 $link = oxSeoEncoderCategory::getInstance()->getCategoryUrl( $this, $iLang );
00487             } else {
00488                 $link = $this->getStdLink($iLang);
00489             }
00490 
00491             if (isset($iLang)) {
00492                 return $link;
00493             } else {
00494                 $this->link = $link;
00495             }
00496         }
00497 
00498         return $this->link;
00499     }
00500 
00508     public function setLink( $sLink )
00509     {
00510         $this->link = $sLink;
00511     }
00512 
00520     public function getSqlActiveSnippet( $blForceCoreTable = false )
00521     {
00522             $sTable = $this->getCoreTableName();
00523 
00524         $sQ  = parent::getSqlActiveSnippet( $blForceCoreTable );
00525         $sQ .= ( strlen( $sQ )? ' and ' : '' ) . " $sTable.oxhidden = '0' ";
00526 
00527 
00528         return "( $sQ ) ";
00529     }
00530 
00538     public function getStdLink($iLang = null)
00539     {
00540         $sLink = '';
00541         if ( $this->oxcategories__oxextlink->value ) {
00542             return $this->getSession()->url( $this->oxcategories__oxextlink->value );
00543         } else {
00544             $sLink = $this->getConfig()->getShopHomeURL(). "cl=alist&amp;cnid=" . $this->getId();
00545         }
00546 
00547         if ( isset($iLang) && !oxUtils::getInstance()->seoIsActive() ) {
00548             $iLang = (int) $iLang;
00549             if ($iLang != (int) $this->getLanguage()) {
00550                 $sLink .= "&amp;lang={$iLang}";
00551             }
00552         }
00553 
00554         return $sLink;
00555     }
00556 
00562     public function getExpanded()
00563     {
00564         if ( !isset( $this->_blExpanded ) ) {
00565             $myConfig = $this->getConfig();
00566             $this->_blExpanded = ( $myConfig->getConfigParam( 'blLoadFullTree' ) && !$myConfig->getConfigParam( 'blTopNaviLayout' ) );
00567         }
00568 
00569         return $this->_blExpanded;
00570     }
00571 
00579     public function setExpanded( $blExpanded )
00580     {
00581         $this->_blExpanded = $blExpanded;
00582     }
00583 
00589     public function getHasSubCats()
00590     {
00591         if ( !isset( $this->_blHasSubCats ) ) {
00592             $this->_blHasSubCats = $this->oxcategories__oxright->value > $this->oxcategories__oxleft->value + 1 ;
00593         }
00594 
00595         return $this->_blHasSubCats;
00596     }
00597 
00603     public function getHasVisibleSubCats()
00604     {
00605         if ( !isset( $this->_blHasVisibleSubCats ) ) {
00606             $this->_blHasVisibleSubCats = false;
00607         }
00608 
00609         return $this->_blHasVisibleSubCats;
00610     }
00611 
00619     public function setHasVisibleSubCats( $blHasVisibleSubcats )
00620     {
00621         $this->_blHasVisibleSubCats = $blHasVisibleSubcats;
00622     }
00623 
00629     public function getAttributes()
00630     {
00631         $sActCat        = $this->sOXID;
00632         $aAttributes    = array();
00633         $blActiveFilter = false;
00634 
00635         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00636 
00637         $oArtList = oxNew( "oxarticlelist");
00638         $oArtList->loadCategoryIDs( $sActCat, $aSessionFilter );
00639 
00640         // Only if we have articles
00641         if (count($oArtList) > 0 ) {
00642             $sArtIds = implode("','", array_keys($oArtList->getArray()) );
00643             $sAttTbl = getViewName('oxattribute');
00644             $sO2ATbl = getViewName('oxobject2attribute');
00645             $sC2ATbl = getViewName('oxcategory2attribute');
00646             $sLngSuf = oxLang::getInstance()->getLanguageTag($this->getLanguage());
00647 
00648             $sSelect = "SELECT DISTINCT att.oxid, att.oxtitle{$sLngSuf}, o2a.oxvalue, o2a.oxvalue{$sLngSuf} ".
00649                        "FROM $sAttTbl as att, $sO2ATbl as o2a ,$sC2ATbl as c2a ".
00650                        "WHERE att.oxid = o2a.oxattrid AND c2a.oxobjectid = '{$sActCat}' AND c2a.oxattrid = att.oxid AND o2a.oxvalue{$sLngSuf} !='' AND o2a.oxobjectid IN ('$sArtIds') ".
00651                        "ORDER BY c2a.oxsort , att.oxpos, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf}";
00652 
00653             $rs = oxDb::getDb()->Execute( $sSelect);
00654             if ($rs != false && $rs->recordCount() > 0) {
00655                 $oStr = getStr();
00656                 while ( !$rs->EOF && list($sAttId,$sAttTitle,$sAttVid,$sAttValue) = $rs->fields ) {
00657                     if ( !isset( $aAttributes[$sAttId])) {
00658                         $oAttribute           = new stdClass();
00659                         $oAttribute->title    = $sAttTitle;
00660                         $oAttribute->aValues  = array();
00661                         $aAttributes[$sAttId] = $oAttribute;
00662                     }
00663                     $oValue             = new stdClass();
00664                     $oValue->id         = $oStr->htmlspecialchars( $sAttValue );
00665                     $oValue->value      = $oStr->htmlspecialchars( $sAttValue );
00666                     $oValue->blSelected = isset($aSessionFilter[$sActCat][$sAttId]) && $aSessionFilter[$sActCat][$sAttId] == $sAttValue;
00667 
00668                     $blActiveFilter = $blActiveFilter || $oValue->blSelected;
00669                     $aAttributes[$sAttId]->aValues[$sAttVid] = $oValue;
00670                     $rs->moveNext();
00671                 }
00672             }
00673 
00674         }
00675 
00676         if ( is_array($aSessionFilter[$sActCat]) && !$blActiveFilter ) {
00677             oxSession::setVar( "session_attrfilter", false);
00678         }
00679         return $aAttributes;
00680     }
00681 
00689     public function getCatInLang( $oActCategory = null )
00690     {
00691         $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00692         if ( $this->oxcategories__oxpricefrom->value || $this->oxcategories__oxpriceto->value) {
00693             // get it in base language
00694             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00695             $oCategoryInDefaultLanguage->loadInLang( 0, $this->getId());
00696         } else {
00697             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00698             $oCategoryInDefaultLanguage->loadInLang( 0, $oActCategory->getId());
00699         }
00700         return $oCategoryInDefaultLanguage;
00701     }
00702 
00710     public function setParentCategory( $oCategory )
00711     {
00712         $this->_oParent = $oCategory;
00713     }
00714 
00720     public function getParentCategory()
00721     {
00722         $oCat = null;
00723 
00724         // loading only if parent id is not rootid
00725         if ( $this->oxcategories__oxparentid->value && $this->oxcategories__oxparentid->value != 'oxrootid' ) {
00726 
00727             // checking if object itself has ref to parent
00728             if ( $this->_oParent ) {
00729                 $oCat = $this->_oParent;
00730             } else {
00731                 $oCat = oxNew( 'oxcategory' );
00732                 if ( !$oCat->loadInLang( $this->getLanguage(), $this->oxcategories__oxparentid->value ) ) {
00733                     $oCat = null;
00734                 }
00735             }
00736         }
00737         return $oCat;
00738     }
00739 
00747     public static function getRootId($sCategoryId)
00748     {
00749         if ( !isset( $sCategoryId ) ) {
00750             return;
00751         }
00752 
00753         return oxDb::getDb()->getOne( 'select oxrootid from '.getViewName('oxcategories').' where oxid = ?', array( $sCategoryId ) );
00754     }
00755 
00756 
00764     public function assignViewableRecord($sSelect)
00765     {
00766             if ( $this->assignRecord( $sSelect ) ) {
00767                 return  true;
00768             }
00769 
00770 
00771         return false;
00772     }
00773 
00779     protected function _insert()
00780     {
00781 
00782 
00783         if ( $this->oxcategories__oxparentid->value != "oxrootid") {
00784             // load parent
00785 
00786             $oParent = oxNew( "oxcategory" );
00787             //#M317 check if parent is loaded
00788             if ( !$oParent->load( $this->oxcategories__oxparentid->value) ) {
00789                 return false;
00790             }
00791 
00792             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00793 
00794             // update existing nodes
00795             $oDB = oxDb::getDb();
00796             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT + 2
00797                             WHERE  OXROOTID = '".$oParent->oxcategories__oxrootid->value."'
00798                             AND OXLEFT >   ".$oParent->oxcategories__oxright->value."
00799                             AND OXRIGHT >= ".$oParent->oxcategories__oxright->value.$sAdd);
00800 
00801 
00802             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT + 2
00803                             WHERE  OXROOTID = '".$oParent->oxcategories__oxrootid->value."'
00804                             AND OXRIGHT >= ".$oParent->oxcategories__oxright->value.$sAdd );
00805 
00806             //if ( !isset( $this->_sOXID) || trim( $this->_sOXID) == "")
00807             //    $this->_sOXID = oxUtilsObject::getInstance()->generateUID();
00808             //$this->oxcategories__oxid->setValue($this->_sOXID);
00809             //refactored to:
00810             if ( !$this->getId() ) {
00811                 $this->setId();
00812             }
00813 
00814             $this->oxcategories__oxrootid = new oxField($oParent->oxcategories__oxrootid->value, oxField::T_RAW);
00815             $this->oxcategories__oxleft = new oxField($oParent->oxcategories__oxright->value, oxField::T_RAW);
00816             $this->oxcategories__oxright = new oxField($oParent->oxcategories__oxright->value + 1, oxField::T_RAW);
00817             return parent::_insert();
00818         } else {
00819             // root entry
00820             if ( !$this->getId() ) {
00821                 $this->setId();
00822             }
00823 
00824             $this->oxcategories__oxrootid = new oxField($this->getId(), oxField::T_RAW);
00825             $this->oxcategories__oxleft = new oxField(1, oxField::T_RAW);
00826             $this->oxcategories__oxright = new oxField(2, oxField::T_RAW);
00827             return parent::_insert();
00828         }
00829     }
00830 
00836     protected function _update()
00837     {
00838 
00839         $oDB = oxDb::getDb();
00840 
00841         $sOldParentID = $oDB->getOne( "select oxparentid from oxcategories where oxid = '".$this->getId()."'");
00842 
00843         if ( $this->_blIsSeoObject && $this->isAdmin() ) {
00844             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00845         }
00846 
00847         $blRes = parent::_update();
00848 
00849         // #872C - need to update category tree oxleft and oxright values (nested sets),
00850         // then sub trees are moved inside one root, or to another root.
00851         // this is done in 3 basic steps
00852         // 1. increase oxleft and oxright values of target root tree by $iTreeSize, where oxleft>=$iMoveAfter , oxright>=$iMoveAfter
00853         // 2. modify current subtree, we want to move by adding $iDelta to it's oxleft and oxright,  where oxleft>=$sOldParentLeft and oxright<=$sOldParentRight values,
00854         //    in this step we also modify rootid's if they were changed
00855         // 3. decreasing oxleft and oxright values of current root tree, where oxleft >= $sOldParentRight+1 , oxright >= $sOldParentRight+1
00856 
00857         // did we change position in tree ?
00858         if ( $this->oxcategories__oxparentid->value != $sOldParentID) {
00859             $sOldParentLeft = $this->oxcategories__oxleft->value;
00860             $sOldParentRight = $this->oxcategories__oxright->value;
00861 
00862             $iTreeSize = $sOldParentRight-$sOldParentLeft+1;
00863 
00864             $sNewRootID = $oDB->getOne( "select oxrootid from oxcategories where oxid = '".$this->oxcategories__oxparentid->value."'");
00865 
00866             //If empty rootID, we set it to categorys oxid
00867             if ( $sNewRootID == "") {
00868                 //echo "<br>* ) Creating new root tree ( {$this->_sOXID} )";
00869                 $sNewRootID = $this->getId();
00870             }
00871 
00872             $sNewParentLeft = $oDB->getOne( "select oxleft from oxcategories where oxid = '".$this->oxcategories__oxparentid->value."'");
00873 
00874             //if(!$sNewParentLeft){
00875                 //the current node has become root node, (oxrootid == "oxrootid")
00876             //    $sNewParentLeft = 0;
00877             //}
00878 
00879             $iMoveAfter = $sNewParentLeft+1;
00880 
00881 
00882             //New parentid can not be set to it's child
00883             if ($sNewParentLeft > $sOldParentLeft && $sNewParentLeft < $sOldParentRight && $this->oxcategories__oxrootid->value == $sNewRootID) {
00884                 //echo "<br>* ) Can't asign category to it's child";
00885 
00886                 //Restoring old parentid, stoping further actions
00887                 $sRestoreOld = "UPDATE oxcategories SET OXPARENTID = '".$sOldParentID."' WHERE oxid = '".$this->getId()."'";
00888                 $oDB->execute( $sRestoreOld );
00889                 return false;
00890             }
00891 
00892             //Old parent will be shifted too, if it is in the same tree
00893             if ($sOldParentLeft > $iMoveAfter && $this->oxcategories__oxrootid->value == $sNewRootID) {
00894                 $sOldParentLeft += $iTreeSize;
00895                 $sOldParentRight += $iTreeSize;
00896             }
00897 
00898             $iDelta = $iMoveAfter-$sOldParentLeft;
00899 
00900             //echo "Size=$iTreeSize, NewStart=$iMoveAfter, delta=$iDelta";
00901 
00902             $sAddOld = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = '".$this->oxcategories__oxrootid->value."';";
00903             $sAddNew = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = '".$sNewRootID."';";
00904 
00905             //Updating everything after new position
00906             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iTreeSize.") WHERE OXLEFT >= ".$iMoveAfter.$sAddNew );
00907             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT + ".$iTreeSize.") WHERE OXRIGHT >= ".$iMoveAfter.$sAddNew );
00908             //echo "<br>1.) + $iTreeSize, >= $iMoveAfter";
00909 
00910             $sChangeRootID = "";
00911             if ($this->oxcategories__oxrootid->value != $sNewRootID) {
00912                 //echo "<br>* ) changing root IDs ( {$this->oxcategories__oxrootid->value} -> {$sNewRootID} )";
00913                 $sChangeRootID = ", OXROOTID='$sNewRootID'";
00914             }
00915 
00916             //Updating subtree
00917             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iDelta."), OXRIGHT = (OXRIGHT + ".$iDelta.") ".$sChangeRootID." WHERE OXLEFT >= ".$sOldParentLeft." AND OXRIGHT <= ".$sOldParentRight.$sAddOld );
00918             //echo "<br>2.) + $iDelta, >= $sOldParentLeft and <= $sOldParentRight";
00919 
00920             //Updating everything after old position
00921             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT - ".$iTreeSize.") WHERE OXLEFT >=   ".($sOldParentRight+1).$sAddOld );
00922             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT - ".$iTreeSize.") WHERE OXRIGHT >=   ".($sOldParentRight+1).$sAddOld );
00923             //echo "<br>3.) - $iTreeSize, >= ".($sOldParentRight+1);
00924         }
00925 
00926         if ( $blRes && $this->_blIsSeoObject && $this->isAdmin() ) {
00927             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00928         }
00929 
00930         return $blRes;
00931     }
00932 
00942     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00943     {
00944         //preliminar quick check saves 3% of execution time in category lists by avoiding redundant strtolower() call
00945         if ($sFieldName[2] == 'l' || $sFieldName[2] == 'L' || (isset($sFieldName[16]) && ($sFieldName[16] == 'l' || $sFieldName[16] == 'L') ) ) {
00946             if ('oxlongdesc' === strtolower($sFieldName) || 'oxcategories__oxlongdesc' === strtolower($sFieldName)) {
00947                 $iDataType = oxField::T_RAW;
00948             }
00949         }
00950         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00951     }
00952 
00953 
00959     public function getIconUrl()
00960     {
00961         return $this->getConfig()->getPictureUrl( 'icon/'.$this->oxcategories__oxicon->value );
00962     }
00963 
00969     public function isTopCategory()
00970     {
00971         if ( $this->_blTopCategory == null ) {
00972             $this->_blTopCategory = $this->oxcategories__oxparentid->value == 'oxrootid';
00973         }
00974         return $this->_blTopCategory;
00975     }
00976 }

Generated on Tue Apr 21 15:45:44 2009 for OXID eShop CE by  doxygen 1.5.5