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                 break;
00121             case 'aContent':
00122                 return $this->_aContentCats;
00123                 break;
00124             case 'iArtCnt':
00125                 return $this->getNrOfArticles();
00126                 break;
00127             case 'isVisible':
00128                 return $this->getIsVisible();
00129                 break;
00130             case 'expanded':
00131                 return $this->getExpanded();
00132                 break;
00133             case 'hasSubCats':
00134                 return $this->getHasSubCats();
00135                 break;
00136             case 'hasVisibleSubCats':
00137                 return $this->getHasVisibleSubCats();
00138                 break;
00139             case 'openlink':
00140             case 'closelink':
00141             case 'link':
00142                 //case 'toListLink':
00143                 //case 'noparamlink':
00144                 return $this->getLink();
00145                 break;
00146             case 'dimagedir':
00147                 return $this->getPictureUrl();
00148                 break;
00149         }
00150         return parent::__get($sName);
00151     }
00152 
00160     public function assign( $dbRecord )
00161     {
00162 
00163         parent::assign( $dbRecord );
00164 
00165         startProfile("parseThroughSmarty");
00166         // #1030C run through smarty
00167         $myConfig = $this->getConfig();
00168         if (!$this->_isInList() && !$this->isAdmin() && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00169             $this->oxcategories__oxlongdesc = new oxField( oxUtilsView::getInstance()->parseThroughSmarty( $this->oxcategories__oxlongdesc->value, $this->getId() ), oxField::T_RAW );
00170         }
00171 
00172         if ( !$this->isAdmin() && ( $myConfig->getConfigParam( 'bl_perfShowActionCatArticleCnt' ) || $myConfig->getConfigParam('blDontShowEmptyCategories')  ) ) {
00173             if ( $this->isPriceCategory() ) {
00174                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getPriceCatArticleCount( $this->getId(), $this->oxcategories__oxpricefrom->value, $this->oxcategories__oxpriceto->value );
00175             } else {
00176                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getCatArticleCount( $this->getId() );
00177             }
00178         }
00179 
00180         stopProfile("parseThroughSmarty");
00181     }
00182 
00190     public function delete( $sOXID = null)
00191     {
00192         if ( !$this->getId() ) {
00193             $this->load( $sOXID);
00194         }
00195 
00196 
00197         $myConfig = $this->getConfig();
00198         $oDB      = oxDb::getDb();
00199         $blRet    = false;
00200 
00201         if ( $this->oxcategories__oxright->value == ($this->oxcategories__oxleft->value+1) ) {
00202             $myUtilsPic = oxUtilsPic::getInstance();
00203 
00204             // only delete empty categories
00205             // #1173M - not all pic are deleted, after article is removed
00206             $myUtilsPic->safePictureDelete($this->oxcategories__oxthumb->value, $myConfig->getAbsDynImageDir().'/0', 'oxcategories', 'oxthumb' );
00207 
00208             $myUtilsPic->safePictureDelete($this->oxcategories__oxicon->value, $myConfig->getAbsDynImageDir().'/icon', 'oxcategories', 'oxicon' );
00209 
00210             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00211 
00212             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT - 2
00213                             WHERE  OXROOTID = '".$this->oxcategories__oxrootid->value."'
00214                             AND OXLEFT >   ".$this->oxcategories__oxleft->value.$sAdd );
00215 
00216             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT - 2
00217                             WHERE  OXROOTID = '".$this->oxcategories__oxrootid->value."'
00218                             AND OXRIGHT >   ".$this->oxcategories__oxright->value.$sAdd );
00219 
00220             // delete entry
00221             $blRet = parent::delete();
00222 
00223             // delete links to articles
00224             $oDB->execute( "delete from oxobject2category where oxobject2category.oxcatnid='".$this->oxcategories__oxid->value."' ");
00225 
00226             // #657 ADDITIONAL delete links to attributes
00227             $oDB->execute( "delete from oxcategory2attribute where oxcategory2attribute.oxobjectid='".$this->oxcategories__oxid->value."' ");
00228 
00229             // A. removing assigned:
00230             // - deliveries
00231             $oDB->execute( "delete from oxobject2delivery where oxobject2delivery.oxobjectid='".$this->oxcategories__oxid->value."' ");
00232             // - discounts
00233             $oDB->execute( "delete from oxobject2discount where oxobject2discount.oxobjectid='".$this->oxcategories__oxid->value."' ");
00234 
00235             oxSeoEncoderCategory::getInstance()->onDeleteCategory($this);
00236         }
00237         return $blRet;
00238     }
00239 
00245     public function getSubCats()
00246     {
00247         return $this->_aSubCats;
00248     }
00249 
00257     public function getSubCat($sKey)
00258     {
00259         return $this->_aSubCats[$sKey];
00260     }
00261 
00269     public function setSubCats( $aCats )
00270     {
00271         $this->_aSubCats = $aCats;
00272 
00273         foreach ( $aCats as $oCat ) {
00274             if ( $oCat->getIsVisible() ) {
00275                 $this->setHasVisibleSubCats( true );
00276             }
00277         }
00278 
00279         $this->sortSubCats();
00280     }
00281 
00290     public function setSubCat($oCat, $sKey=null)
00291     {
00292         if ( $sKey ) {
00293             $this->_aSubCats[$sKey] = $oCat;
00294         } else {
00295             $this->_aSubCats[] = $oCat;
00296         }
00297 
00298         // keeping ref. to parent
00299         $oCat->setParentCategory( $this );
00300 
00301         if ( $oCat->getIsVisible() ) {
00302             $this->setHasVisibleSubCats( true );
00303         }
00304 
00305         $this->sortSubCats();
00306     }
00307 
00313     public function sortSubCats()
00314     {
00315         if ( count( $this->_aIds ) > 0 ) {
00316             uasort($this->_aSubCats, array( $this, 'cmpCat' ) );
00317         }
00318     }
00319 
00329     public function cmpCat( $a,$b )
00330     {
00331         if ( count( $this->_aIds ) == 0 ) {
00332             return;
00333         }
00334 
00335         $sNumA = $this->_aIds[$a->oxcategories__oxid->value];
00336         $sNumB = $this->_aIds[$b->oxcategories__oxid->value];
00337 
00338         if ($sNumA  < $sNumB ) {
00339             return -1;
00340         } if ( $sNumA == $sNumB) {
00341             return 0;
00342         }
00343         return 1;
00344     }
00345 
00353     public function setSortingIds( $aSorIds )
00354     {
00355         $this->_aIds = $aSorIds;
00356     }
00357 
00363     public function getContentCats()
00364     {
00365         return $this->_aContentCats;
00366     }
00367 
00375     public function setContentCats( $aContent )
00376     {
00377         $this->_aContentCats = $aContent;
00378     }
00379 
00388     public function setContentCat( $oContent, $sKey=null )
00389     {
00390         if ( $sKey ) {
00391             $this->_aContentCats[$sKey] = $oContent;
00392         } else {
00393             $this->_aContentCats[] = $oContent;
00394         }
00395     }
00396 
00402     public function getNrOfArticles()
00403     {
00404         if ( !$this->getConfig()->getConfigParam( 'bl_perfShowActionCatArticleCnt' ) && $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00405             return 0;
00406         }
00407 
00408         return $this->_iNrOfArticles;
00409     }
00410 
00418     public function setNrOfArticles( $iNum )
00419     {
00420         $this->_iNrOfArticles = $iNum;
00421     }
00422 
00428     public function getIsVisible()
00429     {
00430         if (!isset( $this->_blIsVisible ) ) {
00431 
00432             if ( $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00433                 $blEmpty = ($this->_iNrOfArticles < 1) && !$this->getHasVisibleSubCats();
00434             } else {
00435                 $blEmpty = false;
00436             }
00437 
00438             $this->_blIsVisible = !($blEmpty || $this->oxcategories__oxhidden->value);
00439         }
00440 
00441         return $this->_blIsVisible;
00442     }
00443 
00451     public function setIsVisible( $blVisible )
00452     {
00453         $this->_blIsVisible = $blVisible;
00454     }
00455 
00461     public function getPictureUrl()
00462     {
00463         if ( $this->_sDynImageDir === null ) {
00464             $sThisShop = $this->oxcategories__oxshopid->value;
00465             $this->_sDynImageDir = $this->getConfig()->getPictureUrl( null, false, null, null, $sThisShop);
00466         }
00467         return $this->_sDynImageDir;
00468     }
00469 
00477     public function getLink($iLang = null)
00478     {
00479         if (isset($iLang)) {
00480             $iLang = (int) $iLang;
00481             if ($iLang == (int) $this->getLanguage()) {
00482                 $iLang = null;
00483             }
00484         }
00485         if ( ($this->link === null ) || isset($iLang)) {
00486             if ( (!isset( $this->oxcategories__oxextlink->value ) || !$this->oxcategories__oxextlink->value ) &&
00487                  oxUtils::getInstance()->seoIsActive() ) {
00488                 $link = oxSeoEncoderCategory::getInstance()->getCategoryUrl( $this, $iLang );
00489             } else {
00490                 $link = $this->getStdLink($iLang);
00491             }
00492 
00493             if (isset($iLang)) {
00494                 return $link;
00495             } else {
00496                 $this->link = $link;
00497             }
00498         }
00499 
00500         return $this->link;
00501     }
00502 
00510     public function setLink( $sLink )
00511     {
00512         $this->link = $sLink;
00513     }
00514 
00522     public function getSqlActiveSnippet( $blForceCoreTable = false )
00523     {
00524             $sTable = $this->getCoreTableName();
00525 
00526         $sQ  = parent::getSqlActiveSnippet( $blForceCoreTable );
00527         $sQ .= ( strlen( $sQ )? ' and ' : '' ) . " $sTable.oxhidden = '0' ";
00528 
00529 
00530         return "( $sQ ) ";
00531     }
00532 
00540     public function getStdLink($iLang = null)
00541     {
00542         $sLink = '';
00543         if ( $this->oxcategories__oxextlink->value ) {
00544             return $this->getSession()->url( $this->oxcategories__oxextlink->value );
00545         } else {
00546             $sLink = $this->getConfig()->getShopHomeURL(). "cl=alist&amp;cnid=" . $this->getId();
00547         }
00548 
00549         if ( isset($iLang) && !oxUtils::getInstance()->seoIsActive() ) {
00550             $iLang = (int) $iLang;
00551             if ($iLang != (int) $this->getLanguage()) {
00552                 $sLink .= "&amp;lang={$iLang}";
00553             }
00554         }
00555 
00556         return $sLink;
00557     }
00558 
00564     public function getExpanded()
00565     {
00566         if ( !isset( $this->_blExpanded ) ) {
00567             $myConfig = $this->getConfig();
00568             $this->_blExpanded = ( $myConfig->getConfigParam( 'blLoadFullTree' ) && !$myConfig->getConfigParam( 'blTopNaviLayout' ) );
00569         }
00570 
00571         return $this->_blExpanded;
00572     }
00573 
00581     public function setExpanded( $blExpanded )
00582     {
00583         $this->_blExpanded = $blExpanded;
00584     }
00585 
00591     public function getHasSubCats()
00592     {
00593         if ( !isset( $this->_blHasSubCats ) ) {
00594             $this->_blHasSubCats = $this->oxcategories__oxright->value > $this->oxcategories__oxleft->value + 1 ;
00595         }
00596 
00597         return $this->_blHasSubCats;
00598     }
00599 
00605     public function getHasVisibleSubCats()
00606     {
00607         if ( !isset( $this->_blHasVisibleSubCats ) ) {
00608             $this->_blHasVisibleSubCats = false;
00609         }
00610 
00611         return $this->_blHasVisibleSubCats;
00612     }
00613 
00621     public function setHasVisibleSubCats( $blHasVisibleSubcats )
00622     {
00623         $this->_blHasVisibleSubCats = $blHasVisibleSubcats;
00624     }
00625 
00631     public function getAttributes()
00632     {
00633         $sActCat        = $this->sOXID;
00634         $aAttributes    = array();
00635         $blActiveFilter = false;
00636 
00637         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00638 
00639         $oArtList = oxNew( "oxarticlelist");
00640         $oArtList->loadCategoryIDs( $sActCat, $aSessionFilter );
00641 
00642         // Only if we have articles
00643         if (count($oArtList) > 0 ) {
00644             $sArtIds = implode("','", array_keys($oArtList->getArray()) );
00645             $sAttTbl = getViewName('oxattribute');
00646             $sO2ATbl = getViewName('oxobject2attribute');
00647             $sC2ATbl = getViewName('oxcategory2attribute');
00648             $sLngSuf = oxLang::getInstance()->getLanguageTag($this->getLanguage());
00649 
00650             $sSelect = "SELECT DISTINCT att.oxid, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf} ".
00651                        "FROM $sAttTbl as att, $sO2ATbl as o2a ,$sC2ATbl as c2a ".
00652                        "WHERE att.oxid = o2a.oxattrid AND c2a.oxobjectid = '{$sActCat}' AND c2a.oxattrid = att.oxid AND o2a.oxvalue{$sLngSuf} !='' AND o2a.oxobjectid IN ('$sArtIds') ".
00653                        "ORDER BY c2a.oxsort , att.oxpos, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf}";
00654 
00655             $rs = oxDb::getDb()->Execute( $sSelect);
00656             if ($rs != false && $rs->recordCount() > 0) {
00657                 $oStr = getStr();
00658                 while ( !$rs->EOF && list($sAttId,$sAttTitle, $sAttValue) = $rs->fields ) {
00659                     if ( !isset( $aAttributes[$sAttId])) {
00660                         $oAttribute           = new stdClass();
00661                         $oAttribute->title    = $sAttTitle;
00662                         $oAttribute->aValues  = array();
00663                         $aAttributes[$sAttId] = $oAttribute;
00664                     }
00665                     $oValue             = new stdClass();
00666                     $oValue->id         = $oStr->htmlspecialchars( $sAttValue );
00667                     $oValue->value      = $oStr->htmlspecialchars( $sAttValue );
00668                     $oValue->blSelected = isset($aSessionFilter[$sActCat][$sAttId]) && $aSessionFilter[$sActCat][$sAttId] == $sAttValue;
00669 
00670                     $sAttValueId = md5( $sAttValue );
00671 
00672                     $blActiveFilter = $blActiveFilter || $oValue->blSelected;
00673                     $aAttributes[$sAttId]->aValues[$sAttValueId] = $oValue;
00674                     $rs->moveNext();
00675                 }
00676             }
00677 
00678         }
00679 
00680         if ( is_array($aSessionFilter[$sActCat]) && !$blActiveFilter ) {
00681             oxSession::setVar( "session_attrfilter", false);
00682         }
00683         return $aAttributes;
00684     }
00685 
00693     public function getCatInLang( $oActCategory = null )
00694     {
00695         $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00696         if ( $this->isPriceCategory() ) {
00697             // get it in base language
00698             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00699             $oCategoryInDefaultLanguage->loadInLang( 0, $this->getId());
00700         } else {
00701             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00702             $oCategoryInDefaultLanguage->loadInLang( 0, $oActCategory->getId());
00703         }
00704         return $oCategoryInDefaultLanguage;
00705     }
00706 
00714     public function setParentCategory( $oCategory )
00715     {
00716         $this->_oParent = $oCategory;
00717     }
00718 
00724     public function getParentCategory()
00725     {
00726         $oCat = null;
00727 
00728         // loading only if parent id is not rootid
00729         if ( $this->oxcategories__oxparentid->value && $this->oxcategories__oxparentid->value != 'oxrootid' ) {
00730 
00731             // checking if object itself has ref to parent
00732             if ( $this->_oParent ) {
00733                 $oCat = $this->_oParent;
00734             } else {
00735                 $oCat = oxNew( 'oxcategory' );
00736                 if ( !$oCat->loadInLang( $this->getLanguage(), $this->oxcategories__oxparentid->value ) ) {
00737                     $oCat = null;
00738                 }
00739             }
00740         }
00741         return $oCat;
00742     }
00743 
00751     public static function getRootId($sCategoryId)
00752     {
00753         if ( !isset( $sCategoryId ) ) {
00754             return;
00755         }
00756 
00757         return oxDb::getDb()->getOne( 'select oxrootid from '.getViewName('oxcategories').' where oxid = ?', array( $sCategoryId ) );
00758     }
00759 
00760 
00768     public function assignViewableRecord($sSelect)
00769     {
00770             if ( $this->assignRecord( $sSelect ) ) {
00771                 return  true;
00772             }
00773 
00774 
00775         return false;
00776     }
00777 
00783     protected function _insert()
00784     {
00785 
00786 
00787         if ( $this->oxcategories__oxparentid->value != "oxrootid") {
00788             // load parent
00789 
00790             $oParent = oxNew( "oxcategory" );
00791             //#M317 check if parent is loaded
00792             if ( !$oParent->load( $this->oxcategories__oxparentid->value) ) {
00793                 return false;
00794             }
00795 
00796             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00797 
00798             // update existing nodes
00799             $oDB = oxDb::getDb();
00800             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT + 2
00801                             WHERE  OXROOTID = '".$oParent->oxcategories__oxrootid->value."'
00802                             AND OXLEFT >   ".$oParent->oxcategories__oxright->value."
00803                             AND OXRIGHT >= ".$oParent->oxcategories__oxright->value.$sAdd);
00804 
00805 
00806             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT + 2
00807                             WHERE  OXROOTID = '".$oParent->oxcategories__oxrootid->value."'
00808                             AND OXRIGHT >= ".$oParent->oxcategories__oxright->value.$sAdd );
00809 
00810             //if ( !isset( $this->_sOXID) || trim( $this->_sOXID) == "")
00811             //    $this->_sOXID = oxUtilsObject::getInstance()->generateUID();
00812             //$this->oxcategories__oxid->setValue($this->_sOXID);
00813             //refactored to:
00814             if ( !$this->getId() ) {
00815                 $this->setId();
00816             }
00817 
00818             $this->oxcategories__oxrootid = new oxField($oParent->oxcategories__oxrootid->value, oxField::T_RAW);
00819             $this->oxcategories__oxleft = new oxField($oParent->oxcategories__oxright->value, oxField::T_RAW);
00820             $this->oxcategories__oxright = new oxField($oParent->oxcategories__oxright->value + 1, oxField::T_RAW);
00821             return parent::_insert();
00822         } else {
00823             // root entry
00824             if ( !$this->getId() ) {
00825                 $this->setId();
00826             }
00827 
00828             $this->oxcategories__oxrootid = new oxField($this->getId(), oxField::T_RAW);
00829             $this->oxcategories__oxleft = new oxField(1, oxField::T_RAW);
00830             $this->oxcategories__oxright = new oxField(2, oxField::T_RAW);
00831             return parent::_insert();
00832         }
00833     }
00834 
00840     protected function _update()
00841     {
00842 
00843         $oDB = oxDb::getDb();
00844 
00845         $sOldParentID = $oDB->getOne( "select oxparentid from oxcategories where oxid = '".$this->getId()."'");
00846 
00847         if ( $this->_blIsSeoObject && $this->isAdmin() ) {
00848             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00849         }
00850 
00851         $blRes = parent::_update();
00852 
00853         // #872C - need to update category tree oxleft and oxright values (nested sets),
00854         // then sub trees are moved inside one root, or to another root.
00855         // this is done in 3 basic steps
00856         // 1. increase oxleft and oxright values of target root tree by $iTreeSize, where oxleft>=$iMoveAfter , oxright>=$iMoveAfter
00857         // 2. modify current subtree, we want to move by adding $iDelta to it's oxleft and oxright,  where oxleft>=$sOldParentLeft and oxright<=$sOldParentRight values,
00858         //    in this step we also modify rootid's if they were changed
00859         // 3. decreasing oxleft and oxright values of current root tree, where oxleft >= $sOldParentRight+1 , oxright >= $sOldParentRight+1
00860 
00861         // did we change position in tree ?
00862         if ( $this->oxcategories__oxparentid->value != $sOldParentID) {
00863             $sOldParentLeft = $this->oxcategories__oxleft->value;
00864             $sOldParentRight = $this->oxcategories__oxright->value;
00865 
00866             $iTreeSize = $sOldParentRight-$sOldParentLeft+1;
00867 
00868             $sNewRootID = $oDB->getOne( "select oxrootid from oxcategories where oxid = '".$this->oxcategories__oxparentid->value."'");
00869 
00870             //If empty rootID, we set it to categorys oxid
00871             if ( $sNewRootID == "") {
00872                 //echo "<br>* ) Creating new root tree ( {$this->_sOXID} )";
00873                 $sNewRootID = $this->getId();
00874             }
00875 
00876             $sNewParentLeft = $oDB->getOne( "select oxleft from oxcategories where oxid = '".$this->oxcategories__oxparentid->value."'");
00877 
00878             //if(!$sNewParentLeft){
00879                 //the current node has become root node, (oxrootid == "oxrootid")
00880             //    $sNewParentLeft = 0;
00881             //}
00882 
00883             $iMoveAfter = $sNewParentLeft+1;
00884 
00885 
00886             //New parentid can not be set to it's child
00887             if ($sNewParentLeft > $sOldParentLeft && $sNewParentLeft < $sOldParentRight && $this->oxcategories__oxrootid->value == $sNewRootID) {
00888                 //echo "<br>* ) Can't asign category to it's child";
00889 
00890                 //Restoring old parentid, stoping further actions
00891                 $sRestoreOld = "UPDATE oxcategories SET OXPARENTID = '".$sOldParentID."' WHERE oxid = '".$this->getId()."'";
00892                 $oDB->execute( $sRestoreOld );
00893                 return false;
00894             }
00895 
00896             //Old parent will be shifted too, if it is in the same tree
00897             if ($sOldParentLeft > $iMoveAfter && $this->oxcategories__oxrootid->value == $sNewRootID) {
00898                 $sOldParentLeft += $iTreeSize;
00899                 $sOldParentRight += $iTreeSize;
00900             }
00901 
00902             $iDelta = $iMoveAfter-$sOldParentLeft;
00903 
00904             //echo "Size=$iTreeSize, NewStart=$iMoveAfter, delta=$iDelta";
00905 
00906             $sAddOld = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = '".$this->oxcategories__oxrootid->value."';";
00907             $sAddNew = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = '".$sNewRootID."';";
00908 
00909             //Updating everything after new position
00910             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iTreeSize.") WHERE OXLEFT >= ".$iMoveAfter.$sAddNew );
00911             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT + ".$iTreeSize.") WHERE OXRIGHT >= ".$iMoveAfter.$sAddNew );
00912             //echo "<br>1.) + $iTreeSize, >= $iMoveAfter";
00913 
00914             $sChangeRootID = "";
00915             if ($this->oxcategories__oxrootid->value != $sNewRootID) {
00916                 //echo "<br>* ) changing root IDs ( {$this->oxcategories__oxrootid->value} -> {$sNewRootID} )";
00917                 $sChangeRootID = ", OXROOTID='$sNewRootID'";
00918             }
00919 
00920             //Updating subtree
00921             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iDelta."), OXRIGHT = (OXRIGHT + ".$iDelta.") ".$sChangeRootID." WHERE OXLEFT >= ".$sOldParentLeft." AND OXRIGHT <= ".$sOldParentRight.$sAddOld );
00922             //echo "<br>2.) + $iDelta, >= $sOldParentLeft and <= $sOldParentRight";
00923 
00924             //Updating everything after old position
00925             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT - ".$iTreeSize.") WHERE OXLEFT >=   ".($sOldParentRight+1).$sAddOld );
00926             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT - ".$iTreeSize.") WHERE OXRIGHT >=   ".($sOldParentRight+1).$sAddOld );
00927             //echo "<br>3.) - $iTreeSize, >= ".($sOldParentRight+1);
00928         }
00929 
00930         if ( $blRes && $this->_blIsSeoObject && $this->isAdmin() ) {
00931             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00932         }
00933 
00934         return $blRes;
00935     }
00936 
00946     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00947     {
00948         //preliminar quick check saves 3% of execution time in category lists by avoiding redundant strtolower() call
00949         if ($sFieldName[2] == 'l' || $sFieldName[2] == 'L' || (isset($sFieldName[16]) && ($sFieldName[16] == 'l' || $sFieldName[16] == 'L') ) ) {
00950             if ('oxlongdesc' === strtolower($sFieldName) || 'oxcategories__oxlongdesc' === strtolower($sFieldName)) {
00951                 $iDataType = oxField::T_RAW;
00952             }
00953         }
00954         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00955     }
00956 
00957 
00963     public function getIconUrl()
00964     {
00965         return $this->getConfig()->getPictureUrl( 'icon/'.$this->oxcategories__oxicon->value );
00966     }
00967 
00973     public function isTopCategory()
00974     {
00975         if ( $this->_blTopCategory == null ) {
00976             $this->_blTopCategory = $this->oxcategories__oxparentid->value == 'oxrootid';
00977         }
00978         return $this->_blTopCategory;
00979     }
00980 
00986     public function isPriceCategory()
00987     {
00988         return (bool) ( $this->oxcategories__oxpricefrom->value || $this->oxcategories__oxpriceto->value );
00989     }
00990 }

Generated on Tue Aug 4 09:09:57 2009 for OXID eShop CE by  doxygen 1.5.5