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         // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
00166         $this->oxcategories__oxlongdesc = new oxField( str_replace( '&lang=', '&amp;lang=', $this->oxcategories__oxlongdesc->value ), oxField::T_RAW);
00167 
00168         startProfile("parseThroughSmarty");
00169         // #1030C run through smarty
00170         $myConfig = $this->getConfig();
00171         if (!$this->_isInList() && !$this->isAdmin() && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00172             $this->oxcategories__oxlongdesc = new oxField( oxUtilsView::getInstance()->parseThroughSmarty( $this->oxcategories__oxlongdesc->value, $this->getId() ), oxField::T_RAW );
00173         }
00174 
00175         if ( !$this->isAdmin() && ( $myConfig->getConfigParam( 'bl_perfShowActionCatArticleCnt' ) || $myConfig->getConfigParam('blDontShowEmptyCategories')  ) ) {
00176             if ( $this->isPriceCategory() ) {
00177                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getPriceCatArticleCount( $this->getId(), $this->oxcategories__oxpricefrom->value, $this->oxcategories__oxpriceto->value );
00178             } else {
00179                 $this->_iNrOfArticles = oxUtilsCount::getInstance()->getCatArticleCount( $this->getId() );
00180             }
00181         }
00182 
00183         stopProfile("parseThroughSmarty");
00184     }
00185 
00193     public function delete( $sOXID = null)
00194     {
00195         if ( !$this->getId() ) {
00196             $this->load( $sOXID);
00197         }
00198 
00199 
00200         $myConfig = $this->getConfig();
00201         $oDB      = oxDb::getDb();
00202         $blRet    = false;
00203 
00204         if ( $this->oxcategories__oxright->value == ($this->oxcategories__oxleft->value+1) ) {
00205             $myUtilsPic = oxUtilsPic::getInstance();
00206 
00207             // only delete empty categories
00208             // #1173M - not all pic are deleted, after article is removed
00209             $myUtilsPic->safePictureDelete($this->oxcategories__oxthumb->value, $myConfig->getAbsDynImageDir().'/0', 'oxcategories', 'oxthumb' );
00210 
00211             $myUtilsPic->safePictureDelete($this->oxcategories__oxicon->value, $myConfig->getAbsDynImageDir().'/icon', 'oxcategories', 'oxicon' );
00212 
00213             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00214 
00215             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT - 2
00216                             WHERE  OXROOTID = ".$oDB->quote($this->oxcategories__oxrootid->value)."
00217                             AND OXLEFT >   ".((int)$this->oxcategories__oxleft->value).$sAdd );
00218 
00219             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT - 2
00220                             WHERE  OXROOTID = ".$oDB->quote($this->oxcategories__oxrootid->value)."
00221                             AND OXRIGHT >   ".((int)$this->oxcategories__oxright->value).$sAdd );
00222 
00223             // delete entry
00224             $blRet = parent::delete();
00225 
00226             $sOxidQuoted = $oDB->quote($this->oxcategories__oxid->value);
00227             // delete links to articles
00228             $oDB->execute( "delete from oxobject2category where oxobject2category.oxcatnid=$sOxidQuoted ");
00229 
00230             // #657 ADDITIONAL delete links to attributes
00231             $oDB->execute( "delete from oxcategory2attribute where oxcategory2attribute.oxobjectid=$sOxidQuoted ");
00232 
00233             // A. removing assigned:
00234             // - deliveries
00235             $oDB->execute( "delete from oxobject2delivery where oxobject2delivery.oxobjectid=$sOxidQuoted ");
00236             // - discounts
00237             $oDB->execute( "delete from oxobject2discount where oxobject2discount.oxobjectid=$sOxidQuoted ");
00238 
00239             oxSeoEncoderCategory::getInstance()->onDeleteCategory($this);
00240         }
00241         return $blRet;
00242     }
00243 
00249     public function getSubCats()
00250     {
00251         return $this->_aSubCats;
00252     }
00253 
00261     public function getSubCat($sKey)
00262     {
00263         return $this->_aSubCats[$sKey];
00264     }
00265 
00273     public function setSubCats( $aCats )
00274     {
00275         $this->_aSubCats = $aCats;
00276 
00277         foreach ( $aCats as $oCat ) {
00278             if ( $oCat->getIsVisible() ) {
00279                 $this->setHasVisibleSubCats( true );
00280             }
00281         }
00282 
00283         $this->sortSubCats();
00284     }
00285 
00295     public function setSubCat($oCat, $sKey=null, $blSkipSorting = false)
00296     {
00297         if ( $sKey ) {
00298             $this->_aSubCats[$sKey] = $oCat;
00299         } else {
00300             $this->_aSubCats[] = $oCat;
00301         }
00302 
00303         // keeping ref. to parent
00304         $oCat->setParentCategory( $this );
00305 
00306         if ( $oCat->getIsVisible() ) {
00307             $this->setHasVisibleSubCats( true );
00308         }
00309 
00310         if (!$blSkipSorting) {
00311             $this->sortSubCats();
00312         }
00313     }
00314 
00320     public function sortSubCats()
00321     {
00322         if ( count( $this->_aIds ) > 0 ) {
00323             uasort($this->_aSubCats, array( $this, 'cmpCat' ) );
00324         }
00325     }
00326 
00336     public function cmpCat( $a,$b )
00337     {
00338         if ( count( $this->_aIds ) == 0 ) {
00339             return;
00340         }
00341 
00342         $sNumA = $this->_aIds[$a->oxcategories__oxid->value];
00343         $sNumB = $this->_aIds[$b->oxcategories__oxid->value];
00344 
00345         if ($sNumA  < $sNumB ) {
00346             return -1;
00347         } if ( $sNumA == $sNumB) {
00348             return 0;
00349         }
00350         return 1;
00351     }
00352 
00360     public function setSortingIds( $aSorIds )
00361     {
00362         $this->_aIds = $aSorIds;
00363     }
00364 
00370     public function getContentCats()
00371     {
00372         return $this->_aContentCats;
00373     }
00374 
00382     public function setContentCats( $aContent )
00383     {
00384         $this->_aContentCats = $aContent;
00385     }
00386 
00395     public function setContentCat( $oContent, $sKey=null )
00396     {
00397         if ( $sKey ) {
00398             $this->_aContentCats[$sKey] = $oContent;
00399         } else {
00400             $this->_aContentCats[] = $oContent;
00401         }
00402     }
00403 
00409     public function getNrOfArticles()
00410     {
00411         if ( !$this->getConfig()->getConfigParam( 'bl_perfShowActionCatArticleCnt' ) && $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00412             return 0;
00413         }
00414 
00415         return $this->_iNrOfArticles;
00416     }
00417 
00425     public function setNrOfArticles( $iNum )
00426     {
00427         $this->_iNrOfArticles = $iNum;
00428     }
00429 
00435     public function getIsVisible()
00436     {
00437         if (!isset( $this->_blIsVisible ) ) {
00438 
00439             if ( $this->getConfig()->getConfigParam( 'blDontShowEmptyCategories' ) ) {
00440                 $blEmpty = ($this->_iNrOfArticles < 1) && !$this->getHasVisibleSubCats();
00441             } else {
00442                 $blEmpty = false;
00443             }
00444 
00445             $this->_blIsVisible = !($blEmpty || $this->oxcategories__oxhidden->value);
00446         }
00447 
00448         return $this->_blIsVisible;
00449     }
00450 
00458     public function setIsVisible( $blVisible )
00459     {
00460         $this->_blIsVisible = $blVisible;
00461     }
00462 
00468     public function getPictureUrl()
00469     {
00470         if ( $this->_sDynImageDir === null ) {
00471             $sThisShop = $this->oxcategories__oxshopid->value;
00472             $this->_sDynImageDir = $this->getConfig()->getPictureUrl( null, false, null, null, $sThisShop);
00473         }
00474         return $this->_sDynImageDir;
00475     }
00476 
00484     public function getLink($iLang = null)
00485     {
00486         if (isset($iLang)) {
00487             $iLang = (int) $iLang;
00488             if ($iLang == (int) $this->getLanguage()) {
00489                 $iLang = null;
00490             }
00491         }
00492         if ( ($this->link === null ) || isset($iLang)) {
00493             if ( (!isset( $this->oxcategories__oxextlink->value ) || !$this->oxcategories__oxextlink->value ) &&
00494                  oxUtils::getInstance()->seoIsActive() ) {
00495                 $link = oxSeoEncoderCategory::getInstance()->getCategoryUrl( $this, $iLang );
00496             } else {
00497                 $link = $this->getStdLink($iLang);
00498             }
00499 
00500             if (isset($iLang)) {
00501                 return $link;
00502             } else {
00503                 $this->link = $link;
00504             }
00505         }
00506 
00507         return $this->link;
00508     }
00509 
00517     public function setLink( $sLink )
00518     {
00519         $this->link = $sLink;
00520     }
00521 
00529     public function getSqlActiveSnippet( $blForceCoreTable = false )
00530     {
00531             $sTable = $this->getCoreTableName();
00532 
00533         $sQ  = parent::getSqlActiveSnippet( $blForceCoreTable );
00534         $sQ .= ( strlen( $sQ )? ' and ' : '' ) . " $sTable.oxhidden = '0' ";
00535 
00536 
00537         return "( $sQ ) ";
00538     }
00539 
00547     public function getStdLink($iLang = null)
00548     {
00549         $sLink = '';
00550         if ( $this->oxcategories__oxextlink->value ) {
00551             return $this->getSession()->url( $this->oxcategories__oxextlink->value );
00552         } else {
00553             $sLink = $this->getConfig()->getShopHomeURL(). "cl=alist&amp;cnid=" . $this->getId();
00554         }
00555 
00556         if ( isset($iLang) && !oxUtils::getInstance()->seoIsActive() ) {
00557             $iLang = (int) $iLang;
00558             if ($iLang != (int) $this->getLanguage()) {
00559                 $sLink .= "&amp;lang={$iLang}";
00560             }
00561         }
00562 
00563         return $sLink;
00564     }
00565 
00571     public function getExpanded()
00572     {
00573         if ( !isset( $this->_blExpanded ) ) {
00574             $myConfig = $this->getConfig();
00575             $this->_blExpanded = ( $myConfig->getConfigParam( 'blLoadFullTree' ) && !$myConfig->getConfigParam( 'blTopNaviLayout' ) );
00576         }
00577 
00578         return $this->_blExpanded;
00579     }
00580 
00588     public function setExpanded( $blExpanded )
00589     {
00590         $this->_blExpanded = $blExpanded;
00591     }
00592 
00598     public function getHasSubCats()
00599     {
00600         if ( !isset( $this->_blHasSubCats ) ) {
00601             $this->_blHasSubCats = $this->oxcategories__oxright->value > $this->oxcategories__oxleft->value + 1 ;
00602         }
00603 
00604         return $this->_blHasSubCats;
00605     }
00606 
00612     public function getHasVisibleSubCats()
00613     {
00614         if ( !isset( $this->_blHasVisibleSubCats ) ) {
00615             $this->_blHasVisibleSubCats = false;
00616         }
00617 
00618         return $this->_blHasVisibleSubCats;
00619     }
00620 
00628     public function setHasVisibleSubCats( $blHasVisibleSubcats )
00629     {
00630         $this->_blHasVisibleSubCats = $blHasVisibleSubcats;
00631     }
00632 
00638     public function getAttributes()
00639     {
00640         $sActCat        = $this->sOXID;
00641         $aAttributes    = array();
00642         $blActiveFilter = false;
00643 
00644         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00645 
00646         $oArtList = oxNew( "oxarticlelist");
00647         $oArtList->loadCategoryIDs( $sActCat, $aSessionFilter );
00648 
00649         // Only if we have articles
00650         if (count($oArtList) > 0 ) {
00651             $oDb = oxDb::getDb();
00652             $sArtIds = '';
00653             foreach (array_keys($oArtList->getArray()) as $sId ) {
00654                 if ($sArtIds) {
00655                     $sArtIds .= ',';
00656                 }
00657                 $sArtIds .= $oDb->quote($sId);
00658             }
00659             $sActCatQuoted = $oDb->quote($sActCat);
00660             $sAttTbl = getViewName('oxattribute');
00661             $sO2ATbl = getViewName('oxobject2attribute');
00662             $sC2ATbl = getViewName('oxcategory2attribute');
00663             $sLngSuf = oxLang::getInstance()->getLanguageTag($this->getLanguage());
00664 
00665             $sSelect = "SELECT DISTINCT att.oxid, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf} ".
00666                        "FROM $sAttTbl as att, $sO2ATbl as o2a ,$sC2ATbl as c2a ".
00667                        "WHERE att.oxid = o2a.oxattrid AND c2a.oxobjectid = $sActCatQuoted AND c2a.oxattrid = att.oxid AND o2a.oxvalue{$sLngSuf} !='' AND o2a.oxobjectid IN ($sArtIds) ".
00668                        "ORDER BY c2a.oxsort , att.oxpos, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf}";
00669 
00670             $rs = $oDb->Execute( $sSelect);
00671             if ($rs != false && $rs->recordCount() > 0) {
00672                 $oStr = getStr();
00673                 while ( !$rs->EOF && list($sAttId,$sAttTitle, $sAttValue) = $rs->fields ) {
00674                     if ( !isset( $aAttributes[$sAttId])) {
00675                         $oAttribute           = new stdClass();
00676                         $oAttribute->title    = $sAttTitle;
00677                         $oAttribute->aValues  = array();
00678                         $aAttributes[$sAttId] = $oAttribute;
00679                     }
00680                     $oValue             = new stdClass();
00681                     $oValue->id         = $oStr->htmlspecialchars( $sAttValue );
00682                     $oValue->value      = $oStr->htmlspecialchars( $sAttValue );
00683                     $oValue->blSelected = isset($aSessionFilter[$sActCat][$sAttId]) && $aSessionFilter[$sActCat][$sAttId] == $sAttValue;
00684 
00685                     $sAttValueId = md5( $sAttValue );
00686 
00687                     $blActiveFilter = $blActiveFilter || $oValue->blSelected;
00688                     $aAttributes[$sAttId]->aValues[$sAttValueId] = $oValue;
00689                     $rs->moveNext();
00690                 }
00691             }
00692 
00693         }
00694 
00695         if ( is_array($aSessionFilter[$sActCat]) && !$blActiveFilter ) {
00696             oxSession::setVar( "session_attrfilter", false);
00697         }
00698         return $aAttributes;
00699     }
00700 
00708     public function getCatInLang( $oActCategory = null )
00709     {
00710         $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00711         if ( $this->isPriceCategory() ) {
00712             // get it in base language
00713             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00714             $oCategoryInDefaultLanguage->loadInLang( 0, $this->getId());
00715         } else {
00716             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00717             $oCategoryInDefaultLanguage->loadInLang( 0, $oActCategory->getId());
00718         }
00719         return $oCategoryInDefaultLanguage;
00720     }
00721 
00729     public function setParentCategory( $oCategory )
00730     {
00731         $this->_oParent = $oCategory;
00732     }
00733 
00739     public function getParentCategory()
00740     {
00741         $oCat = null;
00742 
00743         // loading only if parent id is not rootid
00744         if ( $this->oxcategories__oxparentid->value && $this->oxcategories__oxparentid->value != 'oxrootid' ) {
00745 
00746             // checking if object itself has ref to parent
00747             if ( $this->_oParent ) {
00748                 $oCat = $this->_oParent;
00749             } else {
00750                 $oCat = oxNew( 'oxcategory' );
00751                 if ( !$oCat->loadInLang( $this->getLanguage(), $this->oxcategories__oxparentid->value ) ) {
00752                     $oCat = null;
00753                 }
00754             }
00755         }
00756         return $oCat;
00757     }
00758 
00766     public static function getRootId($sCategoryId)
00767     {
00768         if ( !isset( $sCategoryId ) ) {
00769             return;
00770         }
00771 
00772         return oxDb::getDb()->getOne( 'select oxrootid from '.getViewName('oxcategories').' where oxid = ?', array( $sCategoryId ) );
00773     }
00774 
00775 
00783     public function assignViewableRecord($sSelect)
00784     {
00785             if ( $this->assignRecord( $sSelect ) ) {
00786                 return  true;
00787             }
00788 
00789 
00790         return false;
00791     }
00792 
00798     protected function _insert()
00799     {
00800 
00801 
00802         if ( $this->oxcategories__oxparentid->value != "oxrootid") {
00803             // load parent
00804 
00805             $oParent = oxNew( "oxcategory" );
00806             //#M317 check if parent is loaded
00807             if ( !$oParent->load( $this->oxcategories__oxparentid->value) ) {
00808                 return false;
00809             }
00810 
00811             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00812 
00813             // update existing nodes
00814             $oDB = oxDb::getDb();
00815             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT + 2
00816                             WHERE  OXROOTID = ".$oDB->quote($oParent->oxcategories__oxrootid->value)."
00817                             AND OXLEFT >   ".((int)$oParent->oxcategories__oxright->value)."
00818                             AND OXRIGHT >= ".((int)$oParent->oxcategories__oxright->value).$sAdd);
00819 
00820 
00821             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT + 2
00822                             WHERE  OXROOTID = ".$oDB->quote($oParent->oxcategories__oxrootid->value)."
00823                             AND OXRIGHT >= ".((int)$oParent->oxcategories__oxright->value).$sAdd );
00824 
00825             //if ( !isset( $this->_sOXID) || trim( $this->_sOXID) == "")
00826             //    $this->_sOXID = oxUtilsObject::getInstance()->generateUID();
00827             //$this->oxcategories__oxid->setValue($this->_sOXID);
00828             //refactored to:
00829             if ( !$this->getId() ) {
00830                 $this->setId();
00831             }
00832 
00833             $this->oxcategories__oxrootid = new oxField($oParent->oxcategories__oxrootid->value, oxField::T_RAW);
00834             $this->oxcategories__oxleft = new oxField($oParent->oxcategories__oxright->value, oxField::T_RAW);
00835             $this->oxcategories__oxright = new oxField($oParent->oxcategories__oxright->value + 1, oxField::T_RAW);
00836             return parent::_insert();
00837         } else {
00838             // root entry
00839             if ( !$this->getId() ) {
00840                 $this->setId();
00841             }
00842 
00843             $this->oxcategories__oxrootid = new oxField($this->getId(), oxField::T_RAW);
00844             $this->oxcategories__oxleft = new oxField(1, oxField::T_RAW);
00845             $this->oxcategories__oxright = new oxField(2, oxField::T_RAW);
00846             return parent::_insert();
00847         }
00848     }
00849 
00855     protected function _update()
00856     {
00857 
00858         $oDB = oxDb::getDb();
00859 
00860         $sOldParentID = $oDB->getOne( "select oxparentid from oxcategories where oxid = '".$this->getId()."'");
00861 
00862         if ( $this->_blIsSeoObject && $this->isAdmin() ) {
00863             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00864         }
00865 
00866         $blRes = parent::_update();
00867 
00868         // #872C - need to update category tree oxleft and oxright values (nested sets),
00869         // then sub trees are moved inside one root, or to another root.
00870         // this is done in 3 basic steps
00871         // 1. increase oxleft and oxright values of target root tree by $iTreeSize, where oxleft>=$iMoveAfter , oxright>=$iMoveAfter
00872         // 2. modify current subtree, we want to move by adding $iDelta to it's oxleft and oxright,  where oxleft>=$sOldParentLeft and oxright<=$sOldParentRight values,
00873         //    in this step we also modify rootid's if they were changed
00874         // 3. decreasing oxleft and oxright values of current root tree, where oxleft >= $sOldParentRight+1 , oxright >= $sOldParentRight+1
00875 
00876         // did we change position in tree ?
00877         if ( $this->oxcategories__oxparentid->value != $sOldParentID) {
00878             $sOldParentLeft = $this->oxcategories__oxleft->value;
00879             $sOldParentRight = $this->oxcategories__oxright->value;
00880 
00881             $iTreeSize = $sOldParentRight-$sOldParentLeft+1;
00882 
00883             $sNewRootID = $oDB->getOne( "select oxrootid from oxcategories where oxid = ".$oDB->quote($this->oxcategories__oxparentid->value));
00884 
00885             //If empty rootID, we set it to categorys oxid
00886             if ( $sNewRootID == "") {
00887                 //echo "<br>* ) Creating new root tree ( {$this->_sOXID} )";
00888                 $sNewRootID = $this->getId();
00889             }
00890 
00891             $sNewParentLeft = $oDB->getOne( "select oxleft from oxcategories where oxid = ".$oDB->quote($this->oxcategories__oxparentid->value));
00892 
00893             //if(!$sNewParentLeft){
00894                 //the current node has become root node, (oxrootid == "oxrootid")
00895             //    $sNewParentLeft = 0;
00896             //}
00897 
00898             $iMoveAfter = $sNewParentLeft+1;
00899 
00900 
00901             //New parentid can not be set to it's child
00902             if ($sNewParentLeft > $sOldParentLeft && $sNewParentLeft < $sOldParentRight && $this->oxcategories__oxrootid->value == $sNewRootID) {
00903                 //echo "<br>* ) Can't asign category to it's child";
00904 
00905                 //Restoring old parentid, stoping further actions
00906                 $sRestoreOld = "UPDATE oxcategories SET OXPARENTID = ".$oDB->quote($sOldParentID)." WHERE oxid = '".$this->getId()."'";
00907                 $oDB->execute( $sRestoreOld );
00908                 return false;
00909             }
00910 
00911             //Old parent will be shifted too, if it is in the same tree
00912             if ($sOldParentLeft > $iMoveAfter && $this->oxcategories__oxrootid->value == $sNewRootID) {
00913                 $sOldParentLeft += $iTreeSize;
00914                 $sOldParentRight += $iTreeSize;
00915             }
00916 
00917             $iDelta = $iMoveAfter-$sOldParentLeft;
00918 
00919             //echo "Size=$iTreeSize, NewStart=$iMoveAfter, delta=$iDelta";
00920 
00921             $sAddOld = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = ".$oDB->quote($this->oxcategories__oxrootid->value).";";
00922             $sAddNew = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = ".$oDB->quote($sNewRootID).";";
00923 
00924             //Updating everything after new position
00925             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iTreeSize.") WHERE OXLEFT >= ".$iMoveAfter.$sAddNew );
00926             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT + ".$iTreeSize.") WHERE OXRIGHT >= ".$iMoveAfter.$sAddNew );
00927             //echo "<br>1.) + $iTreeSize, >= $iMoveAfter";
00928 
00929             $sChangeRootID = "";
00930             if ($this->oxcategories__oxrootid->value != $sNewRootID) {
00931                 //echo "<br>* ) changing root IDs ( {$this->oxcategories__oxrootid->value} -> {$sNewRootID} )";
00932                 $sChangeRootID = ", OXROOTID=".$oDB->quote($sNewRootID);
00933             }
00934 
00935             //Updating subtree
00936             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iDelta."), OXRIGHT = (OXRIGHT + ".$iDelta.") ".$sChangeRootID." WHERE OXLEFT >= ".$sOldParentLeft." AND OXRIGHT <= ".$sOldParentRight.$sAddOld );
00937             //echo "<br>2.) + $iDelta, >= $sOldParentLeft and <= $sOldParentRight";
00938 
00939             //Updating everything after old position
00940             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT - ".$iTreeSize.") WHERE OXLEFT >=   ".($sOldParentRight+1).$sAddOld );
00941             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT - ".$iTreeSize.") WHERE OXRIGHT >=   ".($sOldParentRight+1).$sAddOld );
00942             //echo "<br>3.) - $iTreeSize, >= ".($sOldParentRight+1);
00943         }
00944 
00945         if ( $blRes && $this->_blIsSeoObject && $this->isAdmin() ) {
00946             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00947         }
00948 
00949         return $blRes;
00950     }
00951 
00961     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00962     {
00963         //preliminar quick check saves 3% of execution time in category lists by avoiding redundant strtolower() call
00964         if ($sFieldName[2] == 'l' || $sFieldName[2] == 'L' || (isset($sFieldName[16]) && ($sFieldName[16] == 'l' || $sFieldName[16] == 'L') ) ) {
00965             if ('oxlongdesc' === strtolower($sFieldName) || 'oxcategories__oxlongdesc' === strtolower($sFieldName)) {
00966                 $iDataType = oxField::T_RAW;
00967             }
00968         }
00969         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00970     }
00971 
00972 
00978     public function getIconUrl()
00979     {
00980         return $this->getConfig()->getPictureUrl( 'icon/'.$this->oxcategories__oxicon->value );
00981     }
00982 
00988     public function isTopCategory()
00989     {
00990         if ( $this->_blTopCategory == null ) {
00991             $this->_blTopCategory = $this->oxcategories__oxparentid->value == 'oxrootid';
00992         }
00993         return $this->_blTopCategory;
00994     }
00995 
01001     public function isPriceCategory()
01002     {
01003         return (bool) ( $this->oxcategories__oxpricefrom->value || $this->oxcategories__oxpriceto->value );
01004     }
01005 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5