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         $sUrl = '';
00579         if ( $blFull ) {
00580             //always returns shop url, not admin
00581             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
00582         }
00583 
00584         //always returns shop url, not admin
00585         return $sUrl . "index.php?cl=alist" . ( $blAddId ? "&amp;cnid=".$this->getId() : "" );
00586     }
00587 
00596     public function getStdLink( $iLang = null, $aParams = array() )
00597     {
00598         if ( isset( $this->oxcategories__oxextlink ) && $this->oxcategories__oxextlink->value ) {
00599             return  oxUtilsUrl::getInstance()->processUrl( $this->oxcategories__oxextlink->value, false );
00600         }
00601 
00602         if ( $iLang === null ) {
00603             $iLang = $this->getLanguage();
00604         }
00605 
00606         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
00607             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
00608         }
00609 
00610         return oxUtilsUrl::getInstance()->processStdUrl( $this->_aStdUrls[$iLang], $aParams, $iLang, $iLang != $this->getLanguage() );
00611     }
00612 
00618     public function getExpanded()
00619     {
00620         if ( !isset( $this->_blExpanded ) ) {
00621             $myConfig = $this->getConfig();
00622             $this->_blExpanded = ( $myConfig->getConfigParam( 'blLoadFullTree' ) && !$myConfig->getConfigParam( 'blTopNaviLayout' ) );
00623         }
00624 
00625         return $this->_blExpanded;
00626     }
00627 
00635     public function setExpanded( $blExpanded )
00636     {
00637         $this->_blExpanded = $blExpanded;
00638     }
00639 
00645     public function getHasSubCats()
00646     {
00647         if ( !isset( $this->_blHasSubCats ) ) {
00648             $this->_blHasSubCats = $this->oxcategories__oxright->value > $this->oxcategories__oxleft->value + 1 ;
00649         }
00650 
00651         return $this->_blHasSubCats;
00652     }
00653 
00659     public function getHasVisibleSubCats()
00660     {
00661         if ( !isset( $this->_blHasVisibleSubCats ) ) {
00662             $this->_blHasVisibleSubCats = false;
00663         }
00664 
00665         return $this->_blHasVisibleSubCats;
00666     }
00667 
00675     public function setHasVisibleSubCats( $blHasVisibleSubcats )
00676     {
00677         $this->_blHasVisibleSubCats = $blHasVisibleSubcats;
00678     }
00679 
00685     public function getAttributes()
00686     {
00687         $sActCat        = $this->sOXID;
00688         $aAttributes    = array();
00689         $blActiveFilter = false;
00690 
00691         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00692 
00693         $oArtList = oxNew( "oxarticlelist");
00694         $oArtList->loadCategoryIDs( $sActCat, $aSessionFilter );
00695 
00696         // Only if we have articles
00697         if (count($oArtList) > 0 ) {
00698             $oDb = oxDb::getDb();
00699             $sArtIds = '';
00700             foreach (array_keys($oArtList->getArray()) as $sId ) {
00701                 if ($sArtIds) {
00702                     $sArtIds .= ',';
00703                 }
00704                 $sArtIds .= $oDb->quote($sId);
00705             }
00706             $sActCatQuoted = $oDb->quote($sActCat);
00707             $sAttTbl = getViewName('oxattribute');
00708             $sO2ATbl = getViewName('oxobject2attribute');
00709             $sC2ATbl = getViewName('oxcategory2attribute');
00710             $sLngSuf = oxLang::getInstance()->getLanguageTag($this->getLanguage());
00711 
00712             $sSelect = "SELECT DISTINCT att.oxid, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf} ".
00713                        "FROM $sAttTbl as att, $sO2ATbl as o2a ,$sC2ATbl as c2a ".
00714                        "WHERE att.oxid = o2a.oxattrid AND c2a.oxobjectid = $sActCatQuoted AND c2a.oxattrid = att.oxid AND o2a.oxvalue{$sLngSuf} !='' AND o2a.oxobjectid IN ($sArtIds) ".
00715                        "ORDER BY c2a.oxsort , att.oxpos, att.oxtitle{$sLngSuf}, o2a.oxvalue{$sLngSuf}";
00716 
00717             $rs = $oDb->execute( $sSelect );
00718             if ($rs != false && $rs->recordCount() > 0) {
00719                 $oStr = getStr();
00720                 while ( !$rs->EOF && list($sAttId,$sAttTitle, $sAttValue) = $rs->fields ) {
00721                     if ( !isset( $aAttributes[$sAttId])) {
00722                         $oAttribute           = new stdClass();
00723                         $oAttribute->title    = $sAttTitle;
00724                         $oAttribute->aValues  = array();
00725                         $aAttributes[$sAttId] = $oAttribute;
00726                     }
00727                     $oValue             = new stdClass();
00728                     $oValue->id         = $oStr->htmlspecialchars( $sAttValue );
00729                     $oValue->value      = $oStr->htmlspecialchars( $sAttValue );
00730                     $oValue->blSelected = isset($aSessionFilter[$sActCat][$sAttId]) && $aSessionFilter[$sActCat][$sAttId] == $sAttValue;
00731 
00732                     $sAttValueId = md5( $sAttValue );
00733 
00734                     $blActiveFilter = $blActiveFilter || $oValue->blSelected;
00735                     $aAttributes[$sAttId]->aValues[$sAttValueId] = $oValue;
00736                     $rs->moveNext();
00737                 }
00738             }
00739 
00740         }
00741 
00742         if ( is_array($aSessionFilter[$sActCat]) && !$blActiveFilter ) {
00743             oxSession::setVar( "session_attrfilter", false);
00744         }
00745         return $aAttributes;
00746     }
00747 
00755     public function getCatInLang( $oActCategory = null )
00756     {
00757         $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00758         if ( $this->isPriceCategory() ) {
00759             // get it in base language
00760             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00761             $oCategoryInDefaultLanguage->loadInLang( 0, $this->getId());
00762         } else {
00763             $oCategoryInDefaultLanguage= oxNew( "oxcategory" );
00764             $oCategoryInDefaultLanguage->loadInLang( 0, $oActCategory->getId());
00765         }
00766         return $oCategoryInDefaultLanguage;
00767     }
00768 
00776     public function setParentCategory( $oCategory )
00777     {
00778         $this->_oParent = $oCategory;
00779     }
00780 
00786     public function getParentCategory()
00787     {
00788         $oCat = null;
00789 
00790         // loading only if parent id is not rootid
00791         if ( $this->oxcategories__oxparentid->value && $this->oxcategories__oxparentid->value != 'oxrootid' ) {
00792 
00793             // checking if object itself has ref to parent
00794             if ( $this->_oParent ) {
00795                 $oCat = $this->_oParent;
00796             } else {
00797                 $oCat = oxNew( 'oxcategory' );
00798                 if ( !$oCat->loadInLang( $this->getLanguage(), $this->oxcategories__oxparentid->value ) ) {
00799                     $oCat = null;
00800                 }
00801             }
00802         }
00803         return $oCat;
00804     }
00805 
00813     public static function getRootId($sCategoryId)
00814     {
00815         if ( !isset( $sCategoryId ) ) {
00816             return;
00817         }
00818 
00819         return oxDb::getDb()->getOne( 'select oxrootid from '.getViewName('oxcategories').' where oxid = ?', array( $sCategoryId ) );
00820     }
00821 
00822 
00830     public function assignViewableRecord($sSelect)
00831     {
00832             if ( $this->assignRecord( $sSelect ) ) {
00833                 return  true;
00834             }
00835 
00836 
00837         return false;
00838     }
00839 
00845     protected function _insert()
00846     {
00847 
00848 
00849         if ( $this->oxcategories__oxparentid->value != "oxrootid") {
00850             // load parent
00851 
00852             $oParent = oxNew( "oxcategory" );
00853             //#M317 check if parent is loaded
00854             if ( !$oParent->load( $this->oxcategories__oxparentid->value) ) {
00855                 return false;
00856             }
00857 
00858             $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";
00859 
00860             // update existing nodes
00861             $oDB = oxDb::getDb();
00862             $oDB->execute( "UPDATE oxcategories SET OXLEFT = OXLEFT + 2
00863                             WHERE  OXROOTID = ".$oDB->quote($oParent->oxcategories__oxrootid->value)."
00864                             AND OXLEFT >   ".((int) $oParent->oxcategories__oxright->value)."
00865                             AND OXRIGHT >= ".((int) $oParent->oxcategories__oxright->value).$sAdd);
00866 
00867 
00868             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = OXRIGHT + 2
00869                             WHERE  OXROOTID = ".$oDB->quote($oParent->oxcategories__oxrootid->value)."
00870                             AND OXRIGHT >= ".((int) $oParent->oxcategories__oxright->value).$sAdd );
00871 
00872             //if ( !isset( $this->_sOXID) || trim( $this->_sOXID) == "")
00873             //    $this->_sOXID = oxUtilsObject::getInstance()->generateUID();
00874             //$this->oxcategories__oxid->setValue($this->_sOXID);
00875             //refactored to:
00876             if ( !$this->getId() ) {
00877                 $this->setId();
00878             }
00879 
00880             $this->oxcategories__oxrootid = new oxField($oParent->oxcategories__oxrootid->value, oxField::T_RAW);
00881             $this->oxcategories__oxleft = new oxField($oParent->oxcategories__oxright->value, oxField::T_RAW);
00882             $this->oxcategories__oxright = new oxField($oParent->oxcategories__oxright->value + 1, oxField::T_RAW);
00883             return parent::_insert();
00884         } else {
00885             // root entry
00886             if ( !$this->getId() ) {
00887                 $this->setId();
00888             }
00889 
00890             $this->oxcategories__oxrootid = new oxField($this->getId(), oxField::T_RAW);
00891             $this->oxcategories__oxleft = new oxField(1, oxField::T_RAW);
00892             $this->oxcategories__oxright = new oxField(2, oxField::T_RAW);
00893             return parent::_insert();
00894         }
00895     }
00896 
00902     protected function _update()
00903     {
00904 
00905         $oDB = oxDb::getDb();
00906 
00907         $sOldParentID = $oDB->getOne( "select oxparentid from oxcategories where oxid = '".$this->getId()."'");
00908 
00909         if ( $this->_blIsSeoObject && $this->isAdmin() ) {
00910             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00911         }
00912 
00913         $blRes = parent::_update();
00914 
00915         // #872C - need to update category tree oxleft and oxright values (nested sets),
00916         // then sub trees are moved inside one root, or to another root.
00917         // this is done in 3 basic steps
00918         // 1. increase oxleft and oxright values of target root tree by $iTreeSize, where oxleft>=$iMoveAfter , oxright>=$iMoveAfter
00919         // 2. modify current subtree, we want to move by adding $iDelta to it's oxleft and oxright,  where oxleft>=$sOldParentLeft and oxright<=$sOldParentRight values,
00920         //    in this step we also modify rootid's if they were changed
00921         // 3. decreasing oxleft and oxright values of current root tree, where oxleft >= $sOldParentRight+1 , oxright >= $sOldParentRight+1
00922 
00923         // did we change position in tree ?
00924         if ( $this->oxcategories__oxparentid->value != $sOldParentID) {
00925             $sOldParentLeft = $this->oxcategories__oxleft->value;
00926             $sOldParentRight = $this->oxcategories__oxright->value;
00927 
00928             $iTreeSize = $sOldParentRight-$sOldParentLeft+1;
00929 
00930             $sNewRootID = $oDB->getOne( "select oxrootid from oxcategories where oxid = ".$oDB->quote($this->oxcategories__oxparentid->value));
00931 
00932             //If empty rootID, we set it to categorys oxid
00933             if ( $sNewRootID == "") {
00934                 //echo "<br>* ) Creating new root tree ( {$this->_sOXID} )";
00935                 $sNewRootID = $this->getId();
00936             }
00937 
00938             $sNewParentLeft = $oDB->getOne( "select oxleft from oxcategories where oxid = ".$oDB->quote($this->oxcategories__oxparentid->value));
00939 
00940             //if(!$sNewParentLeft){
00941                 //the current node has become root node, (oxrootid == "oxrootid")
00942             //    $sNewParentLeft = 0;
00943             //}
00944 
00945             $iMoveAfter = $sNewParentLeft+1;
00946 
00947 
00948             //New parentid can not be set to it's child
00949             if ($sNewParentLeft > $sOldParentLeft && $sNewParentLeft < $sOldParentRight && $this->oxcategories__oxrootid->value == $sNewRootID) {
00950                 //echo "<br>* ) Can't asign category to it's child";
00951 
00952                 //Restoring old parentid, stoping further actions
00953                 $sRestoreOld = "UPDATE oxcategories SET OXPARENTID = ".$oDB->quote($sOldParentID)." WHERE oxid = '".$this->getId()."'";
00954                 $oDB->execute( $sRestoreOld );
00955                 return false;
00956             }
00957 
00958             //Old parent will be shifted too, if it is in the same tree
00959             if ($sOldParentLeft > $iMoveAfter && $this->oxcategories__oxrootid->value == $sNewRootID) {
00960                 $sOldParentLeft += $iTreeSize;
00961                 $sOldParentRight += $iTreeSize;
00962             }
00963 
00964             $iDelta = $iMoveAfter-$sOldParentLeft;
00965 
00966             //echo "Size=$iTreeSize, NewStart=$iMoveAfter, delta=$iDelta";
00967 
00968             $sAddOld = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = ".$oDB->quote($this->oxcategories__oxrootid->value).";";
00969             $sAddNew = " and oxshopid = '" . $this->getShopId() . "' and OXROOTID = ".$oDB->quote($sNewRootID).";";
00970 
00971             //Updating everything after new position
00972             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iTreeSize.") WHERE OXLEFT >= ".$iMoveAfter.$sAddNew );
00973             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT + ".$iTreeSize.") WHERE OXRIGHT >= ".$iMoveAfter.$sAddNew );
00974             //echo "<br>1.) + $iTreeSize, >= $iMoveAfter";
00975 
00976             $sChangeRootID = "";
00977             if ($this->oxcategories__oxrootid->value != $sNewRootID) {
00978                 //echo "<br>* ) changing root IDs ( {$this->oxcategories__oxrootid->value} -> {$sNewRootID} )";
00979                 $sChangeRootID = ", OXROOTID=".$oDB->quote($sNewRootID);
00980             }
00981 
00982             //Updating subtree
00983             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT + ".$iDelta."), OXRIGHT = (OXRIGHT + ".$iDelta.") ".$sChangeRootID." WHERE OXLEFT >= ".$sOldParentLeft." AND OXRIGHT <= ".$sOldParentRight.$sAddOld );
00984             //echo "<br>2.) + $iDelta, >= $sOldParentLeft and <= $sOldParentRight";
00985 
00986             //Updating everything after old position
00987             $oDB->execute( "UPDATE oxcategories SET OXLEFT = (OXLEFT - ".$iTreeSize.") WHERE OXLEFT >=   ".($sOldParentRight+1).$sAddOld );
00988             $oDB->execute( "UPDATE oxcategories SET OXRIGHT = (OXRIGHT - ".$iTreeSize.") WHERE OXRIGHT >=   ".($sOldParentRight+1).$sAddOld );
00989             //echo "<br>3.) - $iTreeSize, >= ".($sOldParentRight+1);
00990         }
00991 
00992         if ( $blRes && $this->_blIsSeoObject && $this->isAdmin() ) {
00993             oxSeoEncoderCategory::getInstance()->markRelatedAsExpired($this);
00994         }
00995 
00996         return $blRes;
00997     }
00998 
01008     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
01009     {
01010         //preliminar quick check saves 3% of execution time in category lists by avoiding redundant strtolower() call
01011         if ($sFieldName[2] == 'l' || $sFieldName[2] == 'L' || (isset($sFieldName[16]) && ($sFieldName[16] == 'l' || $sFieldName[16] == 'L') ) ) {
01012             if ('oxlongdesc' === strtolower($sFieldName) || 'oxcategories__oxlongdesc' === strtolower($sFieldName)) {
01013                 $iDataType = oxField::T_RAW;
01014             }
01015         }
01016         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
01017     }
01018 
01019 
01025     public function getIconUrl()
01026     {
01027         return $this->getConfig()->getPictureUrl( 'icon/'.$this->oxcategories__oxicon->value );
01028     }
01029 
01035     public function isTopCategory()
01036     {
01037         if ( $this->_blTopCategory == null ) {
01038             $this->_blTopCategory = $this->oxcategories__oxparentid->value == 'oxrootid';
01039         }
01040         return $this->_blTopCategory;
01041     }
01042 
01048     public function isPriceCategory()
01049     {
01050         return (bool) ( $this->oxcategories__oxpricefrom->value || $this->oxcategories__oxpriceto->value );
01051     }
01052 }

Generated by  doxygen 1.6.2