oxcategory.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxCategory extends oxI18n implements oxIUrl
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 
00099     protected $_aIds = array();
00100 
00106     protected $_aStdUrls = array();
00107 
00113     protected $_aSeoUrls = array();
00114 
00119     protected static $_aCatAttributes = array();
00120 
00126     protected $_oParent = null;
00127 
00131     public function __construct()
00132     {
00133         parent::__construct();
00134         $this->init( 'oxcategories' );
00135     }
00136 
00144     public function __get( $sName )
00145     {
00146         switch ( $sName ) {
00147             case 'aSubCats':
00148                 return $this->_aSubCats;
00149                 break;
00150             case 'aContent':
00151                 return $this->_aContentCats;
00152                 break;
00153             case 'iArtCnt':
00154                 return $this->getNrOfArticles();
00155                 break;
00156             case 'isVisible':
00157                 return $this->getIsVisible();
00158                 break;
00159             case 'expanded':
00160                 return $this->getExpanded();
00161                 break;
00162             case 'hasSubCats':
00163                 return $this->getHasSubCats();
00164                 break;
00165             case 'hasVisibleSubCats':
00166                 return $this->getHasVisibleSubCats();
00167                 break;
00168             case 'openlink':
00169             case 'closelink':
00170             case 'link':
00171                 //case 'toListLink':
00172                 //case 'noparamlink':
00173                 return $this->getLink();
00174                 break;
00175             case 'dimagedir':
00176                 return $this->getPictureUrl();
00177                 break;
00178         }
00179         return parent::__get($sName);
00180     }
00181 
00189     public function assign( $dbRecord )
00190     {
00191         $this->_iNrOfArticles = null;
00192         return parent::assign( $dbRecord );
00193     }
00194 
00202     public function delete( $sOXID = null)
00203     {
00204         if ( !$this->getId() ) {
00205             $this->load( $sOXID );
00206         }
00207 
00208         $sOXID = isset( $sOXID ) ? $sOXID : $this->getId();
00209 
00210 
00211         $myConfig = $this->getConfig();
00212         $oDb      = oxDb::getDb();
00213         $blRet    = false;
00214 
00215         if ( $this->oxcategories__oxright->value == ($this->oxcategories__oxleft->value+1) ) {
00216             $myUtilsPic = oxUtilsPic::getInstance();
00217             $sDir = $myConfig->getPictureDir(false);
00218 
00219             // only delete empty categories
00220             // #1173M - not all pic are deleted, after article is removed
00221             $myUtilsPic->safePictureDelete( $this->oxcategories__oxthumb->value, $sDir . oxUtilsFile::getInstance()->getImageDirByType('TC'), 'oxcategories', 'oxthumb' );
00222             $myUtilsPic->safePictureDelete( $this->oxcategories__oxicon->value, $sDir . oxUtilsFile::getInstance()->getImageDirByType('CICO'), 'oxcategories', 'oxicon' );
00223             $myUtilsPic->safePictureDelete( $this->oxcategories__oxpromoicon->value, $sDir . oxUtilsFile::getInstance()->getImageDirByType('PICO'), 'oxcategories', 'oxpromoicon' );
00224 
00225             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00226 
00227             $oDb->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT - 2
00228                             WHERE  OXROOTID = ".$oDb->quote($this->oxcategories__oxrootid->value)."
00229                             AND OXLEFT >   ".((int) $this->oxcategories__oxleft->value).$sAdd );
00230 
00231             $oDb->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT - 2
00232                             WHERE  OXROOTID = ".$oDb->quote($this->oxcategories__oxrootid->value)."
00233                             AND OXRIGHT >   ".((int) $this->oxcategories__oxright->value).$sAdd );
00234 
00235             // delete entry
00236             $blRet = parent::delete( $sOXID );
00237 
00238             $sOxidQuoted = $oDb->quote( $sOXID );
00239             // delete links to articles
00240             $oDb->execute( "delete from oxobject2category where oxobject2category.oxcatnid=$sOxidQuoted ");
00241 
00242             // #657 ADDITIONAL delete links to attributes
00243             $oDb->execute( "delete from oxcategory2attribute where oxcategory2attribute.oxobjectid=$sOxidQuoted ");
00244 
00245             // A. removing assigned:
00246             // - deliveries
00247             $oDb->execute( "delete from oxobject2delivery where oxobject2delivery.oxobjectid=$sOxidQuoted ");
00248             // - discounts
00249             $oDb->execute( "delete from oxobject2discount where oxobject2discount.oxobjectid=$sOxidQuoted ");
00250 
00251             oxSeoEncoderCategory::getInstance()->onDeleteCategory($this);
00252         }
00253         return $blRet;
00254     }
00255 
00261     public function getSubCats()
00262     {
00263         return $this->_aSubCats;
00264     }
00265 
00273     public function getSubCat($sKey)
00274     {
00275         return $this->_aSubCats[$sKey];
00276     }
00277 
00285     public function setSubCats( $aCats )
00286     {
00287         $this->_aSubCats = $aCats;
00288 
00289         foreach ( $aCats as $oCat ) {
00290 
00291             // keeping ref. to parent
00292             $oCat->setParentCategory( $this );
00293 
00294             if ( $oCat->getIsVisible() ) {
00295                 $this->setHasVisibleSubCats( true );
00296             }
00297         }
00298     }
00299 
00309     public function setSubCat($oCat, $sKey=null, $blSkipSorting = false)
00310     {
00311         if ( $sKey ) {
00312             $this->_aSubCats[$sKey] = $oCat;
00313         } else {
00314             $this->_aSubCats[] = $oCat;
00315         }
00316 
00317         // keeping ref. to parent
00318         $oCat->setParentCategory( $this );
00319 
00320         if ( $oCat->getIsVisible() ) {
00321             $this->setHasVisibleSubCats( true );
00322         }
00323     }
00324 
00332     public function sortSubCats()
00333     {
00334         if ( count( $this->_aIds ) > 0 ) {
00335             uasort($this->_aSubCats, array( $this, 'cmpCat' ) );
00336         }
00337     }
00338 
00350     public function cmpCat( $a,$b )
00351     {
00352         if ( count( $this->_aIds ) == 0 ) {
00353             return;
00354         }
00355 
00356         $sNumA = $this->_aIds[$a->oxcategories__oxid->value];
00357         $sNumB = $this->_aIds[$b->oxcategories__oxid->value];
00358 
00359         if ($sNumA  < $sNumB ) {
00360             return -1;
00361         } if ( $sNumA == $sNumB) {
00362             return 0;
00363         }
00364         return 1;
00365     }
00366 
00376     public function setSortingIds( $aSorIds )
00377     {
00378         $this->_aIds = $aSorIds;
00379     }
00380 
00386     public function getContentCats()
00387     {
00388         return $this->_aContentCats;
00389     }
00390 
00398     public function setContentCats( $aContent )
00399     {
00400         $this->_aContentCats = $aContent;
00401     }
00402 
00411     public function setContentCat( $oContent, $sKey=null )
00412     {
00413         if ( $sKey ) {
00414             $this->_aContentCats[$sKey] = $oContent;
00415         } else {
00416             $this->_aContentCats[] = $oContent;
00417         }
00418     }
00419 
00425     public function getNrOfArticles()
00426     {
00427         $myConfig = $this->getConfig();
00428 
00429         if ( !isset($this->_iNrOfArticles)
00430           && !$this->isAdmin()
00431           && (
00432                  $myConfig->getConfigParam( 'bl_perfShowActionCatArticleCnt' )
00433               || $myConfig->getConfigParam('blDontShowEmptyCategories')
00434              ) ) {
00435 
00436             if ( $this->isPriceCategory() ) {
00437                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getPriceCatArticleCount( $this->getId(), $this->oxcategories__oxpricefrom->value, $this->oxcategories__oxpriceto->value );
00438             } else {
00439                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getCatArticleCount( $this->getId() );
00440             }
00441         }
00442 
00443         return (int)$this->_iNrOfArticles;
00444     }
00445 
00453     public function setNrOfArticles( $iNum )
00454     {
00455         $this->_iNrOfArticles = $iNum;
00456     }
00457 
00463     public function getIsVisible()
00464     {
00465         if (!isset( $this->_blIsVisible ) ) {
00466 
00467             if ( $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00468                 $blEmpty = ($this->getNrOfArticles() < 1) && !$this->getHasVisibleSubCats();
00469             } else {
00470                 $blEmpty = false;
00471             }
00472 
00473             $this->_blIsVisible = !($blEmpty || $this->oxcategories__oxhidden->value);
00474         }
00475 
00476         return $this->_blIsVisible;
00477     }
00478 
00486     public function setIsVisible( $blVisible )
00487     {
00488         $this->_blIsVisible = $blVisible;
00489     }
00490 
00496     public function getPictureUrl()
00497     {
00498         if ( $this->_sDynImageDir === null ) {
00499             $sThisShop = $this->oxcategories__oxshopid->value;
00500             $this->_sDynImageDir = $this->getConfig()->getPictureUrl( null, false, null, null, $sThisShop);
00501         }
00502         return $this->_sDynImageDir;
00503     }
00504 
00513     public function getBaseSeoLink( $iLang, $iPage = 0 )
00514     {
00515         $oEncoder = oxSeoEncoderCategory::getInstance();
00516         if ( !$iPage ) {
00517             return $oEncoder->getCategoryUrl( $this, $iLang );
00518         }
00519         return $oEncoder->getCategoryPageUrl( $this, $iPage, $iLang );
00520     }
00521 
00529     public function getLink( $iLang = null )
00530     {
00531         if ( !oxUtils::getInstance()->seoIsActive() ||
00532              ( isset( $this->oxcategories__oxextlink ) && $this->oxcategories__oxextlink->value ) ) {
00533             return $this->getStdLink( $iLang );
00534         }
00535 
00536         if ( $iLang === null ) {
00537             $iLang = $this->getLanguage();
00538         }
00539 
00540         if ( !isset( $this->_aSeoUrls[$iLang] ) ) {
00541             $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink( $iLang );
00542         }
00543         return $this->_aSeoUrls[$iLang];
00544     }
00545 
00553     public function setLink( $sLink )
00554     {
00555         $iLang = $this->getLanguage();
00556         if ( oxUtils::getInstance()->seoIsActive() ) {
00557             $this->_aSeoUrls[$iLang] = $sLink;
00558         } else {
00559             $this->_aStdUrls[$iLang] = $sLink;
00560         }
00561     }
00562 
00570     public function getSqlActiveSnippet( $blForceCoreTable = null )
00571     {
00572         $sQ  = parent::getSqlActiveSnippet( $blForceCoreTable );
00573 
00574         $sTable = $this->getViewName($blForceCoreTable);
00575         $sQ .= ( strlen( $sQ )? ' and ' : '' ) . " $sTable.oxhidden = '0' ";
00576 
00577 
00578         return "( $sQ ) ";
00579     }
00580 
00590     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00591     {
00592         if ( isset( $this->oxcategories__oxextlink ) && $this->oxcategories__oxextlink->value ) {
00593             return  $this->oxcategories__oxextlink->value;
00594         }
00595 
00596         $sUrl = '';
00597         if ( $blFull ) {
00598             //always returns shop url, not admin
00599             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
00600         }
00601 
00602         //always returns shop url, not admin
00603         return $sUrl . "index.php?cl=alist" . ( $blAddId ? "&amp;cnid=".$this->getId() : "" );
00604     }
00605 
00614     public function getStdLink( $iLang = null, $aParams = array() )
00615     {
00616         if ( isset( $this->oxcategories__oxextlink ) && $this->oxcategories__oxextlink->value ) {
00617             return  oxUtilsUrl::getInstance()->processUrl( $this->oxcategories__oxextlink->value, false );
00618         }
00619 
00620         if ( $iLang === null ) {
00621             $iLang = $this->getLanguage();
00622         }
00623 
00624         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
00625             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
00626         }
00627 
00628         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
00629     }
00630 
00636     public function getExpanded()
00637     {
00638         if ( !isset( $this->_blExpanded ) ) {
00639             $myConfig = $this->getConfig();
00640             $this->_blExpanded = ( $myConfig->getConfigParam( 'blLoadFullTree' ) && !$myConfig->getConfigParam( 'blTopNaviLayout' ) );
00641         }
00642 
00643         return $this->_blExpanded;
00644     }
00645 
00653     public function setExpanded( $blExpanded )
00654     {
00655         $this->_blExpanded = $blExpanded;
00656     }
00657 
00663     public function getHasSubCats()
00664     {
00665         if ( !isset( $this->_blHasSubCats ) ) {
00666             $this->_blHasSubCats = $this->oxcategories__oxright->value > $this->oxcategories__oxleft->value + 1 ;
00667         }
00668 
00669         return $this->_blHasSubCats;
00670     }
00671 
00677     public function getHasVisibleSubCats()
00678     {
00679         if ( !isset( $this->_blHasVisibleSubCats ) ) {
00680             $this->_blHasVisibleSubCats = false;
00681         }
00682 
00683         return $this->_blHasVisibleSubCats;
00684     }
00685 
00693     public function setHasVisibleSubCats( $blHasVisibleSubcats )
00694     {
00695         if ( $blHasVisibleSubcats && !$this->_blHasVisibleSubCats ) {
00696             unset( $this->_blIsVisible );
00697             if ($this->_oParent instanceof oxCategory) {
00698                 $this->_oParent->setHasVisibleSubCats( true );
00699             }
00700         }
00701         $this->_blHasVisibleSubCats = $blHasVisibleSubcats;
00702     }
00703 
00709     public function getAttributes()
00710     {
00711         $sActCat = $this->getId();
00712 
00713         $sKey = md5( $sActCat . serialize( oxSession::getVar( 'session_attrfilter' ) ) );
00714         if ( !isset( self::$_aCatAttributes[$sKey] ) ) {
00715             $oAttrList = oxNew( "oxAttributeList" );
00716             $oAttrList->getCategoryAttributes( $sActCat, $this->getLanguage() );
00717             self::$_aCatAttributes[$sKey] = $oAttrList;
00718         }
00719 
00720         return self::$_aCatAttributes[$sKey];
00721     }
00722 
00730     public function getCatInLang( $oActCategory = null )
00731     {
00732         $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00733         if ( $this->isPriceCategory() ) {
00734             // get it in base language
00735             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00736             $oCategoryInDefaultLanguage->loadInLang( 0, $this->getId());
00737         } else {
00738             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00739             $oCategoryInDefaultLanguage->loadInLang( 0, $oActCategory->getId());
00740         }
00741         return $oCategoryInDefaultLanguage;
00742     }
00743 
00751     public function setParentCategory( $oCategory )
00752     {
00753         $this->_oParent = $oCategory;
00754     }
00755 
00761     public function getParentCategory()
00762     {
00763         $oCat = null;
00764 
00765         // loading only if parent id is not rootid
00766         if ( $this->oxcategories__oxparentid->value && $this->oxcategories__oxparentid->value != 'oxrootid' ) {
00767 
00768             // checking if object itself has ref to parent
00769             if ( $this->_oParent ) {
00770                 $oCat = $this->_oParent;
00771             } else {
00772                 $oCat = oxNew( 'oxcategory' );
00773                 if ( !$oCat->loadInLang( $this->getLanguage(), $this->oxcategories__oxparentid->value ) ) {
00774                     $oCat = null;
00775                 } else {
00776                     $this->_oParent = $oCat;
00777                 }
00778             }
00779         }
00780         return $oCat;
00781     }
00782 
00790     public static function getRootId($sCategoryId)
00791     {
00792         if ( !isset( $sCategoryId ) ) {
00793             return;
00794         }
00795         $oDb = oxDb::getDb();
00796 
00797         return $oDb->getOne( 'select oxrootid from '.getViewName('oxcategories').' where oxid = ' . $oDb->quote( $sCategoryId ) );
00798     }
00799 
00800 
00808     public function assignViewableRecord($sSelect)
00809     {
00810             if ( $this->assignRecord( $sSelect ) ) {
00811                 return  true;
00812             }
00813 
00814 
00815         return false;
00816     }
00817 
00823     protected function _insert()
00824     {
00825 
00826 
00827         if ( $this->oxcategories__oxparentid->value != "oxrootid") {
00828             // load parent
00829 
00830             $oParent = oxNew( "oxcategory" );
00831             //#M317 check if parent is loaded
00832             if ( !$oParent->load( $this->oxcategories__oxparentid->value) ) {
00833                 return false;
00834             }
00835 
00836             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00837 
00838             // update existing nodes
00839             $oDb = oxDb::getDb();
00840             $oDb->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT + 2
00841                             WHERE  OXROOTID = ".$oDb->quote($oParent->oxcategories__oxrootid->value)."
00842                             AND OXLEFT >   ".((int) $oParent->oxcategories__oxright->value)."
00843                             AND OXRIGHT >= ".((int) $oParent->oxcategories__oxright->value).$sAdd);
00844 
00845 
00846             $oDb->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT + 2
00847                             WHERE  OXROOTID = ".$oDb->quote($oParent->oxcategories__oxrootid->value)."
00848                             AND OXRIGHT >= ".((int) $oParent->oxcategories__oxright->value).$sAdd );
00849 
00850             //if ( !isset( $this->_sOXID) || trim( $this->_sOXID) == "")
00851             //    $this->_sOXID = oxUtilsObject::getInstance()->generateUID();
00852             //$this->oxcategories__oxid->setValue($this->_sOXID);
00853             //refactored to:
00854             if ( !$this->getId() ) {
00855                 $this->setId();
00856             }
00857 
00858             $this->oxcategories__oxrootid = new oxField($oParent->oxcategories__oxrootid->value, oxField::T_RAW);
00859             $this->oxcategories__oxleft = new oxField($oParent->oxcategories__oxright->value, oxField::T_RAW);
00860             $this->oxcategories__oxright = new oxField($oParent->oxcategories__oxright->value + 1, oxField::T_RAW);
00861             return parent::_insert();
00862         } else {
00863             // root entry
00864             if ( !$this->getId() ) {
00865                 $this->setId();
00866             }
00867 
00868             $this->oxcategories__oxrootid = new oxField($this->getId(), oxField::T_RAW);
00869             $this->oxcategories__oxleft = new oxField(1, oxField::T_RAW);
00870             $this->oxcategories__oxright = new oxField(2, oxField::T_RAW);
00871             return parent::_insert();
00872         }
00873     }
00874 
00880     protected function _update()
00881     {
00882 
00883         $oDb = oxDb::getDb();
00884         $sOldParentID = $oDb->getOne( "select oxparentid from oxcategories where oxid = ".$oDb->quote( $this->getId() ), false, false );
00885 
00886         if ( $this->_blIsSeoObject && $this->isAdmin() ) {
00887             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00888         }
00889 
00890         $blRes = parent::_update();
00891 
00892         // #872C - need to update category tree oxleft and oxright values (nested sets),
00893         // then sub trees are moved inside one root, or to another root.
00894         // this is done in 3 basic steps
00895         // 1. increase oxleft and oxright values of target root tree by $iTreeSize, where oxleft>=$iMoveAfter , oxright>=$iMoveAfter
00896         // 2. modify current subtree, we want to move by adding $iDelta to it's oxleft and oxright,  where oxleft>=$sOldParentLeft and oxright<=$sOldParentRight values,
00897         //    in this step we also modify rootid's if they were changed
00898         // 3. decreasing oxleft and oxright values of current root tree, where oxleft >= $sOldParentRight+1 , oxright >= $sOldParentRight+1
00899 
00900         // did we change position in tree ?
00901         if ( $this->oxcategories__oxparentid->value != $sOldParentID) {
00902             $sOldParentLeft = $this->oxcategories__oxleft->value;
00903             $sOldParentRight = $this->oxcategories__oxright->value;
00904 
00905             $iTreeSize = $sOldParentRight-$sOldParentLeft+1;
00906 
00907             $sNewRootID = $oDb->getOne( "select oxrootid from oxcategories where oxid = ".$oDb->quote($this->oxcategories__oxparentid->value), false, false);
00908 
00909             //If empty rootID, we set it to categorys oxid
00910             if ( $sNewRootID == "") {
00911                 //echo "<br>* ) Creating new root tree ( {$this->_sOXID} )";
00912                 $sNewRootID = $this->getId();
00913             }
00914 
00915             $sNewParentLeft = $oDb->getOne( "select oxleft from oxcategories where oxid = ".$oDb->quote($this->oxcategories__oxparentid->value), false, false);
00916 
00917             //if(!$sNewParentLeft){
00918                 //the current node has become root node, (oxrootid == "oxrootid")
00919             //    $sNewParentLeft = 0;
00920             //}
00921 
00922             $iMoveAfter = $sNewParentLeft+1;
00923 
00924 
00925             //New parentid can not be set to it's child
00926             if ($sNewParentLeft > $sOldParentLeft && $sNewParentLeft < $sOldParentRight && $this->oxcategories__oxrootid->value == $sNewRootID) {
00927                 //echo "<br>* ) Can't asign category to it's child";
00928 
00929                 //Restoring old parentid, stoping further actions
00930                 $sRestoreOld = "UPDATE oxcategories SET OXPARENTID = ".$oDb->quote($sOldParentID)." WHERE oxid = ".$oDb->quote($this->getId());
00931                 $oDb->execute( $sRestoreOld );
00932                 return false;
00933             }
00934 
00935             //Old parent will be shifted too, if it is in the same tree
00936             if ($sOldParentLeft > $iMoveAfter && $this->oxcategories__oxrootid->value == $sNewRootID) {
00937                 $sOldParentLeft += $iTreeSize;
00938                 $sOldParentRight += $iTreeSize;
00939             }
00940 
00941             $iDelta = $iMoveAfter-$sOldParentLeft;
00942 
00943             //echo "Size=$iTreeSize, NewStart=$iMoveAfter, delta=$iDelta";
00944 
00945             $sAddOld = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = ".$oDb->quote($this->oxcategories__oxrootid->value).";";
00946             $sAddNew = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = ".$oDb->quote($sNewRootID).";";
00947 
00948             //Updating everything after new position
00949             $oDb->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iTreeSize.") WHERE OXLEFT >= ".$iMoveAfter.$sAddNew );
00950             $oDb->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT + ".$iTreeSize.") WHERE OXRIGHT >= ".$iMoveAfter.$sAddNew );
00951             //echo "<br>1.) + $iTreeSize, >= $iMoveAfter";
00952 
00953             $sChangeRootID = "";
00954             if ($this->oxcategories__oxrootid->value != $sNewRootID) {
00955                 //echo "<br>* ) changing root IDs ( {$this->oxcategories__oxrootid->value} -> {$sNewRootID} )";
00956                 $sChangeRootID = ", OXROOTID=".$oDb->quote($sNewRootID);
00957             }
00958 
00959             //Updating subtree
00960             $oDb->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iDelta."), OXRIGHT = (OXRIGHT + ".$iDelta.") ".$sChangeRootID." WHERE OXLEFT >= ".$sOldParentLeft." AND OXRIGHT <= ".$sOldParentRight.$sAddOld );
00961             //echo "<br>2.) + $iDelta, >= $sOldParentLeft and <= $sOldParentRight";
00962 
00963             //Updating everything after old position
00964             $oDb->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT - ".$iTreeSize.") WHERE OXLEFT >=   ".($sOldParentRight+1).$sAddOld );
00965             $oDb->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT - ".$iTreeSize.") WHERE OXRIGHT >=   ".($sOldParentRight+1).$sAddOld );
00966             //echo "<br>3.) - $iTreeSize, >= ".($sOldParentRight+1);
00967         }
00968 
00969         if ( $blRes && $this->_blIsSeoObject && $this->isAdmin() ) {
00970             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00971         }
00972 
00973         return $blRes;
00974     }
00975 
00985     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00986     {
00987         //preliminar quick check saves 3% of execution time in category lists by avoiding redundant strtolower() call
00988         if ($sFieldName[2] == 'l' || $sFieldName[2] == 'L' || (isset($sFieldName[16]) && ($sFieldName[16] == 'l' || $sFieldName[16] == 'L') ) ) {
00989             if ('oxlongdesc' === strtolower($sFieldName) || 'oxcategories__oxlongdesc' === strtolower($sFieldName)) {
00990                 $iDataType = oxField::T_RAW;
00991             }
00992         }
00993         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00994     }
00995 
00996 
01002     public function getIconUrl()
01003     {
01004         if ( ( $sIcon = $this->oxcategories__oxicon->value ) ) {
01005             $oConfig = $this->getConfig();
01006             $sSize = $oConfig->getConfigParam( 'sCatIconsize' );
01007             if ( !isset( $sSize ) ) {
01008                 $sSize = $oConfig->getConfigParam( 'sIconsize' );
01009             }
01010 
01011             return oxPictureHandler::getInstance()->getPicUrl( "category/icon/", $sIcon, $sSize );
01012         }
01013     }
01014 
01020     public function getThumbUrl()
01021     {
01022         if ( ( $sIcon = $this->oxcategories__oxthumb->value ) ) {
01023             $sSize = $this->getConfig()->getConfigParam( 'sCatThumbnailsize' );
01024             return oxPictureHandler::getInstance()->getPicUrl( "category/thumb/", $sIcon, $sSize );
01025         }
01026     }
01027 
01033     public function getPromotionIconUrl()
01034     {
01035         if ( ( $sIcon = $this->oxcategories__oxpromoicon->value ) ) {
01036             $sSize = $this->getConfig()->getConfigParam( 'sCatPromotionsize' );
01037             return oxPictureHandler::getInstance()->getPicUrl( "category/promo_icon/", $sIcon, $sSize );
01038         }
01039     }
01040 
01049     public function getPictureUrlForType( $sPicName, $sPicType )
01050     {
01051         if ( $sPicName ) {
01052             return $this->getPictureUrl() . $sPicType . '/' . $sPicName;
01053         } else {
01054             return false;
01055         }
01056     }
01057 
01063     public function isTopCategory()
01064     {
01065         if ( $this->_blTopCategory == null ) {
01066             $this->_blTopCategory = $this->oxcategories__oxparentid->value == 'oxrootid';
01067         }
01068         return $this->_blTopCategory;
01069     }
01070 
01076     public function isPriceCategory()
01077     {
01078         return (bool) ( $this->oxcategories__oxpricefrom->value || $this->oxcategories__oxpriceto->value );
01079     }
01080 
01087     public function getLongDesc()
01088     {
01089         if ( isset( $this->oxcategories__oxlongdesc ) && $this->oxcategories__oxlongdesc instanceof oxField ) {
01090            return oxUtilsView::getInstance()->parseThroughSmarty( $this->oxcategories__oxlongdesc->getRawValue(), $this->getId().$this->getLanguage() );
01091         }
01092     }
01093 
01099     public function getTitle()
01100     {
01101         return $this->oxcategories__oxtitle->value;
01102     }
01103 }