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 
00097     protected $_aIds = array();
00098 
00104     protected $_aStdUrls = array();
00105 
00111     protected $_aSeoUrls = array();
00112 
00116     public function __construct()
00117     {
00118         parent::__construct();
00119         $this->init( 'oxcategories' );
00120     }
00121 
00129     public function __get( $sName )
00130     {
00131         switch ( $sName ) {
00132             case 'aSubCats':
00133                 return $this->_aSubCats;
00134                 break;
00135             case 'aContent':
00136                 return $this->_aContentCats;
00137                 break;
00138             case 'iArtCnt':
00139                 return $this->getNrOfArticles();
00140                 break;
00141             case 'isVisible':
00142                 return $this->getIsVisible();
00143                 break;
00144             case 'expanded':
00145                 return $this->getExpanded();
00146                 break;
00147             case 'hasSubCats':
00148                 return $this->getHasSubCats();
00149                 break;
00150             case 'hasVisibleSubCats':
00151                 return $this->getHasVisibleSubCats();
00152                 break;
00153             case 'openlink':
00154             case 'closelink':
00155             case 'link':
00156                 //case 'toListLink':
00157                 //case 'noparamlink':
00158                 return $this->getLink();
00159                 break;
00160             case 'dimagedir':
00161                 return $this->getPictureUrl();
00162                 break;
00163         }
00164         return parent::__get($sName);
00165     }
00166 
00174     public function assign( $dbRecord )
00175     {
00176 
00177         parent::assign( $dbRecord );
00178 
00179         // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
00180         $this->oxcategories__oxlongdesc = new oxField( str_replace( '&lang=', '&amp;lang=', $this->oxcategories__oxlongdesc->value ), oxField::T_RAW);
00181 
00182         startProfile("parseThroughSmarty");
00183         // #1030C run through smarty
00184         $myConfig = $this->getConfig();
00185         if (!$this->_isInList() && !$this->isAdmin() && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00186             $this->oxcategories__oxlongdesc = new oxField( oxUtilsView::getInstance()->parseThroughSmarty( $this->oxcategories__oxlongdesc->value, $this->getId() ), oxField::T_RAW );
00187         }
00188 
00189         if ( !$this->isAdmin() && ( $myConfig->getConfigParam( 'bl_perfShowActionCatArticleCnt' ) || $myConfig->getConfigParam('blDontShowEmptyCategories')  ) ) {
00190             if ( $this->isPriceCategory() ) {
00191                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getPriceCatArticleCount( $this->getId(), $this->oxcategories__oxpricefrom->value, $this->oxcategories__oxpriceto->value );
00192             } else {
00193                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getCatArticleCount( $this->getId() );
00194             }
00195         }
00196 
00197         stopProfile("parseThroughSmarty");
00198     }
00199 
00207     public function delete( $sOXID = null)
00208     {
00209         if ( !$this->getId() ) {
00210             $this->load( $sOXID);
00211         }
00212 
00213 
00214         $myConfig = $this->getConfig();
00215         $oDB      = oxDb::getDb();
00216         $blRet    = false;
00217 
00218         if ( $this->oxcategories__oxright->value == ($this->oxcategories__oxleft->value+1) ) {
00219             $myUtilsPic = oxUtilsPic::getInstance();
00220 
00221             // only delete empty categories
00222             // #1173M - not all pic are deleted, after article is removed
00223             $myUtilsPic->safePictureDelete($this->oxcategories__oxthumb->value, $myConfig->getAbsDynImageDir().'/0', 'oxcategories', 'oxthumb' );
00224 
00225             $myUtilsPic->safePictureDelete($this->oxcategories__oxicon->value, $myConfig->getAbsDynImageDir().'/icon', 'oxcategories', 'oxicon' );
00226 
00227             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00228 
00229             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT - 2
00230                             WHERE  OXROOTID = ".$oDB->quote($this->oxcategories__oxrootid->value)."
00231                             AND OXLEFT >   ".((int) $this->oxcategories__oxleft->value).$sAdd );
00232 
00233             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT - 2
00234                             WHERE  OXROOTID = ".$oDB->quote($this->oxcategories__oxrootid->value)."
00235                             AND OXRIGHT >   ".((int) $this->oxcategories__oxright->value).$sAdd );
00236 
00237             // delete entry
00238             $blRet = parent::delete();
00239 
00240             $sOxidQuoted = $oDB->quote($this->oxcategories__oxid->value);
00241             // delete links to articles
00242             $oDB->execute( "delete from oxobject2category where oxobject2category.oxcatnid=$sOxidQuoted ");
00243 
00244             // #657 ADDITIONAL delete links to attributes
00245             $oDB->execute( "delete from oxcategory2attribute where oxcategory2attribute.oxobjectid=$sOxidQuoted ");
00246 
00247             // A. removing assigned:
00248             // - deliveries
00249             $oDB->execute( "delete from oxobject2delivery where oxobject2delivery.oxobjectid=$sOxidQuoted ");
00250             // - discounts
00251             $oDB->execute( "delete from oxobject2discount where oxobject2discount.oxobjectid=$sOxidQuoted ");
00252 
00253             oxSeoEncoderCategory::getInstance()->onDeleteCategory($this);
00254         }
00255         return $blRet;
00256     }
00257 
00263     public function getSubCats()
00264     {
00265         return $this->_aSubCats;
00266     }
00267 
00275     public function getSubCat($sKey)
00276     {
00277         return $this->_aSubCats[$sKey];
00278     }
00279 
00287     public function setSubCats( $aCats )
00288     {
00289         $this->_aSubCats = $aCats;
00290 
00291         foreach ( $aCats as $oCat ) {
00292             if ( $oCat->getIsVisible() ) {
00293                 $this->setHasVisibleSubCats( true );
00294             }
00295         }
00296 
00297         $this->sortSubCats();
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         if (!$blSkipSorting) {
00325             $this->sortSubCats();
00326         }
00327     }
00328 
00334     public function sortSubCats()
00335     {
00336         if ( count( $this->_aIds ) > 0 ) {
00337             uasort($this->_aSubCats, array( $this, 'cmpCat' ) );
00338         }
00339     }
00340 
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 
00374     public function setSortingIds( $aSorIds )
00375     {
00376         $this->_aIds = $aSorIds;
00377     }
00378 
00384     public function getContentCats()
00385     {
00386         return $this->_aContentCats;
00387     }
00388 
00396     public function setContentCats( $aContent )
00397     {
00398         $this->_aContentCats = $aContent;
00399     }
00400 
00409     public function setContentCat( $oContent, $sKey=null )
00410     {
00411         if ( $sKey ) {
00412             $this->_aContentCats[$sKey] = $oContent;
00413         } else {
00414             $this->_aContentCats[] = $oContent;
00415         }
00416     }
00417 
00423     public function getNrOfArticles()
00424     {
00425         if ( !$this->getConfig()->getConfigParam( 'bl_perfShowActionCatArticleCnt' ) && $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00426             return 0;
00427         }
00428 
00429         return $this->_iNrOfArticles;
00430     }
00431 
00439     public function setNrOfArticles( $iNum )
00440     {
00441         $this->_iNrOfArticles = $iNum;
00442     }
00443 
00449     public function getIsVisible()
00450     {
00451         if (!isset( $this->_blIsVisible ) ) {
00452 
00453             if ( $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00454                 $blEmpty = ($this->_iNrOfArticles < 1) && !$this->getHasVisibleSubCats();
00455             } else {
00456                 $blEmpty = false;
00457             }
00458 
00459             $this->_blIsVisible = !($blEmpty || $this->oxcategories__oxhidden->value);
00460         }
00461 
00462         return $this->_blIsVisible;
00463     }
00464 
00472     public function setIsVisible( $blVisible )
00473     {
00474         $this->_blIsVisible = $blVisible;
00475     }
00476 
00482     public function getPictureUrl()
00483     {
00484         if ( $this->_sDynImageDir === null ) {
00485             $sThisShop = $this->oxcategories__oxshopid->value;
00486             $this->_sDynImageDir = $this->getConfig()->getPictureUrl( null, false, null, null, $sThisShop);
00487         }
00488         return $this->_sDynImageDir;
00489     }
00490 
00499     public function getBaseSeoLink( $iLang, $iPage = 0 )
00500     {
00501         $oEncoder = oxSeoEncoderCategory::getInstance();
00502         if ( !$iPage ) {
00503             return $oEncoder->getCategoryUrl( $this, $iLang );
00504         }
00505         return $oEncoder->getCategoryPageUrl( $this, $iPage, $iLang );
00506     }
00507 
00515     public function getLink( $iLang = null )
00516     {
00517         if ( !oxUtils::getInstance()->seoIsActive() ||
00518              ( isset( $this->oxcategories__oxextlink ) && $this->oxcategories__oxextlink->value ) ) {
00519             return $this->getStdLink( $iLang );
00520         }
00521 
00522         if ( $iLang === null ) {
00523             $iLang = $this->getLanguage();
00524         }
00525 
00526         if ( !isset( $this->_aSeoUrls[$iLang] ) ) {
00527             $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink( $iLang );
00528         }
00529         return $this->_aSeoUrls[$iLang];
00530     }
00531 
00539     public function setLink( $sLink )
00540     {
00541         $iLang = $this->getLanguage();
00542         if ( oxUtils::getInstance()->seoIsActive() ) {
00543             $this->_aSeoUrls[$iLang] = $sLink;
00544         } else {
00545             $this->_aStdUrls[$iLang] = $sLink;
00546         }
00547     }
00548 
00556     public function getSqlActiveSnippet( $blForceCoreTable = false )
00557     {
00558             $sTable = $this->getCoreTableName();
00559 
00560         $sQ  = parent::getSqlActiveSnippet( $blForceCoreTable );
00561         $sQ .= ( strlen( $sQ )? ' and ' : '' ) . " $sTable.oxhidden = '0' ";
00562 
00563 
00564         return "( $sQ ) ";
00565     }
00566 
00576     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00577     {
00578         if ( isset( $this->oxcategories__oxextlink ) && $this->oxcategories__oxextlink->value ) {
00579             return  $this->oxcategories__oxextlink->value;
00580         }
00581 
00582         $sUrl = '';
00583         if ( $blFull ) {
00584             //always returns shop url, not admin
00585             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
00586         }
00587 
00588         //always returns shop url, not admin
00589         return $sUrl . "index.php?cl=alist" . ( $blAddId ? "&amp;cnid=".$this->getId() : "" );
00590     }
00591 
00600     public function getStdLink( $iLang = null, $aParams = array() )
00601     {
00602         if ( isset( $this->oxcategories__oxextlink ) && $this->oxcategories__oxextlink->value ) {
00603             return  oxUtilsUrl::getInstance()->processUrl( $this->oxcategories__oxextlink->value, false );
00604         }
00605 
00606         if ( $iLang === null ) {
00607             $iLang = $this->getLanguage();
00608         }
00609 
00610         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
00611             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
00612         }
00613 
00614         return oxUtilsUrl::getInstance()->processStdUrl( $this->_aStdUrls[$iLang], $aParams, $iLang, $iLang != $this->getLanguage() );
00615     }
00616 
00622     public function getExpanded()
00623     {
00624         if ( !isset( $this->_blExpanded ) ) {
00625             $myConfig = $this->getConfig();
00626             $this->_blExpanded = ( $myConfig->getConfigParam( 'blLoadFullTree' ) && !$myConfig->getConfigParam( 'blTopNaviLayout' ) );
00627         }
00628 
00629         return $this->_blExpanded;
00630     }
00631 
00639     public function setExpanded( $blExpanded )
00640     {
00641         $this->_blExpanded = $blExpanded;
00642     }
00643 
00649     public function getHasSubCats()
00650     {
00651         if ( !isset( $this->_blHasSubCats ) ) {
00652             $this->_blHasSubCats = $this->oxcategories__oxright->value > $this->oxcategories__oxleft->value + 1 ;
00653         }
00654 
00655         return $this->_blHasSubCats;
00656     }
00657 
00663     public function getHasVisibleSubCats()
00664     {
00665         if ( !isset( $this->_blHasVisibleSubCats ) ) {
00666             $this->_blHasVisibleSubCats = false;
00667         }
00668 
00669         return $this->_blHasVisibleSubCats;
00670     }
00671 
00679     public function setHasVisibleSubCats( $blHasVisibleSubcats )
00680     {
00681         $this->_blHasVisibleSubCats = $blHasVisibleSubcats;
00682     }
00683 
00689     public function getAttributes()
00690     {
00691         $sActCat        = $this->sOXID;
00692         $aAttributes    = array();
00693         $blActiveFilter = false;
00694 
00695         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00696 
00697         $oArtList = oxNew( "oxarticlelist");
00698         $oArtList->loadCategoryIDs( $sActCat, $aSessionFilter );
00699 
00700         // Only if we have articles
00701         if (count($oArtList) > 0 ) {
00702             $oDb = oxDb::getDb();
00703             $sArtIds = '';
00704             foreach (array_keys($oArtList->getArray()) as $sId ) {
00705                 if ($sArtIds) {
00706                     $sArtIds .= ',';
00707                 }
00708                 $sArtIds .= $oDb->quote($sId);
00709             }
00710             $sActCatQuoted = $oDb->quote($sActCat);
00711             $sAttTbl = getViewName('oxattribute');
00712             $sO2ATbl = getViewName('oxobject2attribute');
00713             $sC2ATbl = getViewName('oxcategory2attribute');
00714             $sLngSuf = oxLang::getInstance()->getLanguageTag($this->getLanguage());
00715 
00716             $sSelect = "SELECT DISTINCT att.oxid, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf} ".
00717                        "FROM $sAttTbl as att, $sO2ATbl as o2a ,$sC2ATbl as c2a ".
00718                        "WHERE att.oxid = o2a.oxattrid AND c2a.oxobjectid = $sActCatQuoted AND c2a.oxattrid = att.oxid AND o2a.oxvalue{$sLngSuf} !='' AND o2a.oxobjectid IN ($sArtIds) ".
00719                        "ORDER BY c2a.oxsort , att.oxpos, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf}";
00720 
00721             $rs = $oDb->execute( $sSelect );
00722             if ($rs != false && $rs->recordCount() > 0) {
00723                 $oStr = getStr();
00724                 while ( !$rs->EOF && list($sAttId,$sAttTitle, $sAttValue) = $rs->fields ) {
00725                     if ( !isset( $aAttributes[$sAttId])) {
00726                         $oAttribute           = new stdClass();
00727                         $oAttribute->title    = $sAttTitle;
00728                         $oAttribute->aValues  = array();
00729                         $aAttributes[$sAttId] = $oAttribute;
00730                     }
00731                     $oValue             = new stdClass();
00732                     $oValue->id         = $oStr->htmlspecialchars( $sAttValue );
00733                     $oValue->value      = $oStr->htmlspecialchars( $sAttValue );
00734                     $oValue->blSelected = isset($aSessionFilter[$sActCat][$sAttId]) && $aSessionFilter[$sActCat][$sAttId] == $sAttValue;
00735 
00736                     $sAttValueId = md5( $sAttValue );
00737 
00738                     $blActiveFilter = $blActiveFilter || $oValue->blSelected;
00739                     $aAttributes[$sAttId]->aValues[$sAttValueId] = $oValue;
00740                     $rs->moveNext();
00741                 }
00742             }
00743 
00744         }
00745 
00746         if ( is_array($aSessionFilter[$sActCat]) && !$blActiveFilter ) {
00747             oxSession::setVar( "session_attrfilter", false);
00748         }
00749         return $aAttributes;
00750     }
00751 
00759     public function getCatInLang( $oActCategory = null )
00760     {
00761         $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00762         if ( $this->isPriceCategory() ) {
00763             // get it in base language
00764             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00765             $oCategoryInDefaultLanguage->loadInLang( 0, $this->getId());
00766         } else {
00767             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00768             $oCategoryInDefaultLanguage->loadInLang( 0, $oActCategory->getId());
00769         }
00770         return $oCategoryInDefaultLanguage;
00771     }
00772 
00780     public function setParentCategory( $oCategory )
00781     {
00782         $this->_oParent = $oCategory;
00783     }
00784 
00790     public function getParentCategory()
00791     {
00792         $oCat = null;
00793 
00794         // loading only if parent id is not rootid
00795         if ( $this->oxcategories__oxparentid->value && $this->oxcategories__oxparentid->value != 'oxrootid' ) {
00796 
00797             // checking if object itself has ref to parent
00798             if ( $this->_oParent ) {
00799                 $oCat = $this->_oParent;
00800             } else {
00801                 $oCat = oxNew( 'oxcategory' );
00802                 if ( !$oCat->loadInLang( $this->getLanguage(), $this->oxcategories__oxparentid->value ) ) {
00803                     $oCat = null;
00804                 }
00805             }
00806         }
00807         return $oCat;
00808     }
00809 
00817     public static function getRootId($sCategoryId)
00818     {
00819         if ( !isset( $sCategoryId ) ) {
00820             return;
00821         }
00822 
00823         return oxDb::getDb()->getOne( 'select oxrootid from '.getViewName('oxcategories').' where oxid = ?', array( $sCategoryId ) );
00824     }
00825 
00826 
00834     public function assignViewableRecord($sSelect)
00835     {
00836             if ( $this->assignRecord( $sSelect ) ) {
00837                 return  true;
00838             }
00839 
00840 
00841         return false;
00842     }
00843 
00849     protected function _insert()
00850     {
00851 
00852 
00853         if ( $this->oxcategories__oxparentid->value != "oxrootid") {
00854             // load parent
00855 
00856             $oParent = oxNew( "oxcategory" );
00857             //#M317 check if parent is loaded
00858             if ( !$oParent->load( $this->oxcategories__oxparentid->value) ) {
00859                 return false;
00860             }
00861 
00862             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00863 
00864             // update existing nodes
00865             $oDB = oxDb::getDb();
00866             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT + 2
00867                             WHERE  OXROOTID = ".$oDB->quote($oParent->oxcategories__oxrootid->value)."
00868                             AND OXLEFT >   ".((int) $oParent->oxcategories__oxright->value)."
00869                             AND OXRIGHT >= ".((int) $oParent->oxcategories__oxright->value).$sAdd);
00870 
00871 
00872             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT + 2
00873                             WHERE  OXROOTID = ".$oDB->quote($oParent->oxcategories__oxrootid->value)."
00874                             AND OXRIGHT >= ".((int) $oParent->oxcategories__oxright->value).$sAdd );
00875 
00876             //if ( !isset( $this->_sOXID) || trim( $this->_sOXID) == "")
00877             //    $this->_sOXID = oxUtilsObject::getInstance()->generateUID();
00878             //$this->oxcategories__oxid->setValue($this->_sOXID);
00879             //refactored to:
00880             if ( !$this->getId() ) {
00881                 $this->setId();
00882             }
00883 
00884             $this->oxcategories__oxrootid = new oxField($oParent->oxcategories__oxrootid->value, oxField::T_RAW);
00885             $this->oxcategories__oxleft = new oxField($oParent->oxcategories__oxright->value, oxField::T_RAW);
00886             $this->oxcategories__oxright = new oxField($oParent->oxcategories__oxright->value + 1, oxField::T_RAW);
00887             return parent::_insert();
00888         } else {
00889             // root entry
00890             if ( !$this->getId() ) {
00891                 $this->setId();
00892             }
00893 
00894             $this->oxcategories__oxrootid = new oxField($this->getId(), oxField::T_RAW);
00895             $this->oxcategories__oxleft = new oxField(1, oxField::T_RAW);
00896             $this->oxcategories__oxright = new oxField(2, oxField::T_RAW);
00897             return parent::_insert();
00898         }
00899     }
00900 
00906     protected function _update()
00907     {
00908 
00909         $oDB = oxDb::getDb();
00910 
00911         $sOldParentID = $oDB->getOne( "select oxparentid from oxcategories where oxid = '".$this->getId()."'");
00912 
00913         if ( $this->_blIsSeoObject && $this->isAdmin() ) {
00914             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00915         }
00916 
00917         $blRes = parent::_update();
00918 
00919         // #872C - need to update category tree oxleft and oxright values (nested sets),
00920         // then sub trees are moved inside one root, or to another root.
00921         // this is done in 3 basic steps
00922         // 1. increase oxleft and oxright values of target root tree by $iTreeSize, where oxleft>=$iMoveAfter , oxright>=$iMoveAfter
00923         // 2. modify current subtree, we want to move by adding $iDelta to it's oxleft and oxright,  where oxleft>=$sOldParentLeft and oxright<=$sOldParentRight values,
00924         //    in this step we also modify rootid's if they were changed
00925         // 3. decreasing oxleft and oxright values of current root tree, where oxleft >= $sOldParentRight+1 , oxright >= $sOldParentRight+1
00926 
00927         // did we change position in tree ?
00928         if ( $this->oxcategories__oxparentid->value != $sOldParentID) {
00929             $sOldParentLeft = $this->oxcategories__oxleft->value;
00930             $sOldParentRight = $this->oxcategories__oxright->value;
00931 
00932             $iTreeSize = $sOldParentRight-$sOldParentLeft+1;
00933 
00934             $sNewRootID = $oDB->getOne( "select oxrootid from oxcategories where oxid = ".$oDB->quote($this->oxcategories__oxparentid->value));
00935 
00936             //If empty rootID, we set it to categorys oxid
00937             if ( $sNewRootID == "") {
00938                 //echo "<br>* ) Creating new root tree ( {$this->_sOXID} )";
00939                 $sNewRootID = $this->getId();
00940             }
00941 
00942             $sNewParentLeft = $oDB->getOne( "select oxleft from oxcategories where oxid = ".$oDB->quote($this->oxcategories__oxparentid->value));
00943 
00944             //if(!$sNewParentLeft){
00945                 //the current node has become root node, (oxrootid == "oxrootid")
00946             //    $sNewParentLeft = 0;
00947             //}
00948 
00949             $iMoveAfter = $sNewParentLeft+1;
00950 
00951 
00952             //New parentid can not be set to it's child
00953             if ($sNewParentLeft > $sOldParentLeft && $sNewParentLeft < $sOldParentRight && $this->oxcategories__oxrootid->value == $sNewRootID) {
00954                 //echo "<br>* ) Can't asign category to it's child";
00955 
00956                 //Restoring old parentid, stoping further actions
00957                 $sRestoreOld = "UPDATE oxcategories SET OXPARENTID = ".$oDB->quote($sOldParentID)." WHERE oxid = '".$this->getId()."'";
00958                 $oDB->execute( $sRestoreOld );
00959                 return false;
00960             }
00961 
00962             //Old parent will be shifted too, if it is in the same tree
00963             if ($sOldParentLeft > $iMoveAfter && $this->oxcategories__oxrootid->value == $sNewRootID) {
00964                 $sOldParentLeft += $iTreeSize;
00965                 $sOldParentRight += $iTreeSize;
00966             }
00967 
00968             $iDelta = $iMoveAfter-$sOldParentLeft;
00969 
00970             //echo "Size=$iTreeSize, NewStart=$iMoveAfter, delta=$iDelta";
00971 
00972             $sAddOld = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = ".$oDB->quote($this->oxcategories__oxrootid->value).";";
00973             $sAddNew = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = ".$oDB->quote($sNewRootID).";";
00974 
00975             //Updating everything after new position
00976             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iTreeSize.") WHERE OXLEFT >= ".$iMoveAfter.$sAddNew );
00977             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT + ".$iTreeSize.") WHERE OXRIGHT >= ".$iMoveAfter.$sAddNew );
00978             //echo "<br>1.) + $iTreeSize, >= $iMoveAfter";
00979 
00980             $sChangeRootID = "";
00981             if ($this->oxcategories__oxrootid->value != $sNewRootID) {
00982                 //echo "<br>* ) changing root IDs ( {$this->oxcategories__oxrootid->value} -> {$sNewRootID} )";
00983                 $sChangeRootID = ", OXROOTID=".$oDB->quote($sNewRootID);
00984             }
00985 
00986             //Updating subtree
00987             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iDelta."), OXRIGHT = (OXRIGHT + ".$iDelta.") ".$sChangeRootID." WHERE OXLEFT >= ".$sOldParentLeft." AND OXRIGHT <= ".$sOldParentRight.$sAddOld );
00988             //echo "<br>2.) + $iDelta, >= $sOldParentLeft and <= $sOldParentRight";
00989 
00990             //Updating everything after old position
00991             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT - ".$iTreeSize.") WHERE OXLEFT >=   ".($sOldParentRight+1).$sAddOld );
00992             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT - ".$iTreeSize.") WHERE OXRIGHT >=   ".($sOldParentRight+1).$sAddOld );
00993             //echo "<br>3.) - $iTreeSize, >= ".($sOldParentRight+1);
00994         }
00995 
00996         if ( $blRes && $this->_blIsSeoObject && $this->isAdmin() ) {
00997             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00998         }
00999 
01000         return $blRes;
01001     }
01002 
01012     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
01013     {
01014         //preliminar quick check saves 3% of execution time in category lists by avoiding redundant strtolower() call
01015         if ($sFieldName[2] == 'l' || $sFieldName[2] == 'L' || (isset($sFieldName[16]) && ($sFieldName[16] == 'l' || $sFieldName[16] == 'L') ) ) {
01016             if ('oxlongdesc' === strtolower($sFieldName) || 'oxcategories__oxlongdesc' === strtolower($sFieldName)) {
01017                 $iDataType = oxField::T_RAW;
01018             }
01019         }
01020         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
01021     }
01022 
01023 
01029     public function getIconUrl()
01030     {
01031         return $this->getConfig()->getIconUrl( 'icon/'.$this->oxcategories__oxicon->value );
01032     }
01033 
01039     public function isTopCategory()
01040     {
01041         if ( $this->_blTopCategory == null ) {
01042             $this->_blTopCategory = $this->oxcategories__oxparentid->value == 'oxrootid';
01043         }
01044         return $this->_blTopCategory;
01045     }
01046 
01052     public function isPriceCategory()
01053     {
01054         return (bool) ( $this->oxcategories__oxpricefrom->value || $this->oxcategories__oxpriceto->value );
01055     }
01056 }