68 public function __construct( $sObjectsInListName =
'oxcategory')
70 $this->_blHideEmpty = $this->
getConfig()->getConfigParam(
'blDontShowEmptyCategories');
83 $this->_blForceFull = $blForceFull;
105 if ( $iForceLevel > 2 ) {
107 } elseif ( $iForceLevel < 1 ) {
110 $this->_iForceLevel = $iForceLevel;
133 if ($aColumns &&
count($aColumns)) {
134 foreach ($aColumns as $key=>$val) {
135 $aColumns[$key].=
' as '.$val;
137 return "$sTable.".implode(
", $sTable.", $aColumns);
140 $sFieldList =
"$sTable.oxid as oxid, $sTable.oxactive as oxactive,"
141 .
" $sTable.oxhidden as oxhidden, $sTable.oxparentid as oxparentid,"
142 .
" $sTable.oxdefsort as oxdefsort, $sTable.oxdefsortmode as oxdefsortmode,"
143 .
" $sTable.oxleft as oxleft, $sTable.oxright as oxright,"
144 .
" $sTable.oxrootid as oxrootid, $sTable.oxsort as oxsort,"
145 .
" $sTable.oxtitle as oxtitle, $sTable.oxdesc as oxdesc,"
146 .
" $sTable.oxpricefrom as oxpricefrom, $sTable.oxpriceto as oxpriceto,"
147 .
" $sTable.oxicon as oxicon, $sTable.oxextlink as oxextlink,"
148 .
" $sTable.oxthumb as oxthumb, $sTable.oxpromoicon as oxpromoicon";
150 $sFieldList.=
",not $sTable.oxactive as oxppremove";
172 $oCat =
oxNew(
'oxCategory' );
173 if (!($this->_sActCat && $oCat->load($this->_sActCat) && $oCat->oxcategories__oxrootid->value)) {
175 $this->_sActCat = null;
186 $sOrdDir = $blReverse?
'desc':
'asc';
187 $sOrder =
"oxrootid $sOrdDir, oxleft $sOrdDir";
190 return "select $sFieldList from $sViewName where $sWhere $sUnion order by $sOrder";
204 $sDepthSnippet =
' ( 0';
209 $sDepthSnippet .=
" or ($sViewName.oxparentid = ".oxDb::getDb()->quote($oCat->oxcategories__oxid->value).
")";
214 $sDepthSnippet .=
" or $sViewName.oxparentid = 'oxrootid'";
219 $sDepthSnippet .=
" or $sViewName.oxrootid = $sViewName.oxparentid or $sViewName.oxid = $sViewName.oxrootid";
222 $sDepthSnippet .=
' ) ';
223 return $sDepthSnippet;
244 return "UNION SELECT ".$this->_getSqlSelectFieldsForTree(
'maincats', $aColumns)
245 .
" FROM oxcategories AS subcats"
246 .
" LEFT JOIN $sViewName AS maincats on maincats.oxparentid = subcats.oxparentid"
247 .
" WHERE subcats.oxrootid = ".
oxDb::getDb()->quote($oCat->oxcategories__oxrootid->value)
248 .
" AND subcats.oxleft <= ". (int)$oCat->oxcategories__oxleft->value
249 .
" AND subcats.oxright >= ".(
int)$oCat->oxcategories__oxright->value;
261 $sSql = $this->
_getSelectString(
false, null,
'oxparentid, oxsort, oxtitle');
292 startProfile(
"buildTree");
294 $this->_sActCat = $sActCat;
316 stopProfile(
"buildTree");
328 if ( isset($this->_aArray[$sId])) {
329 $oNewCat =
oxNew(
'oxCategory' );
330 if ( $oNewCat->load($sId)) {
332 $this->_aArray[$sId] = $oNewCat;
335 $this->_sActCat = null;
346 startProfile(
'buildCategoryList');
357 stopProfile(
'buildCategoryList');
388 $this->_sShopID = $sShopID;
408 if (
count($this->_aPath)) {
409 return end($this->_aPath);
420 if (
count($this->_aPath)) {
421 return array(reset($this->_aPath));
433 $aRemoveList = array();
434 foreach ($this->_aArray as $sId => $oCat) {
435 if ($oCat->oxcategories__oxppremove->value) {
436 if (!isset($aRemoveList[$oCat->oxcategories__oxrootid->value])) {
437 $aRemoveList[$oCat->oxcategories__oxrootid->value] = array();
439 $aRemoveList[$oCat->oxcategories__oxrootid->value][$oCat->oxcategories__oxleft->value] = $oCat->oxcategories__oxright->value;
440 unset( $this->_aArray[$sId] );
442 unset($oCat->oxcategories__oxppremove);
447 foreach ($this->_aArray as $sId => $oCat) {
448 if ( isset( $aRemoveList[$oCat->oxcategories__oxrootid->value] ) &&
449 is_array( $aRemoveList[$oCat->oxcategories__oxrootid->value] ) ) {
450 foreach ( $aRemoveList[$oCat->oxcategories__oxrootid->value] as $iLeft => $iRight ) {
452 ($iLeft <= $oCat->oxcategories__oxleft->value)
453 && ($iRight >= $oCat->oxcategories__oxleft->value)
456 unset( $this->_aArray[$sId] );
471 if (is_null($this->_sActCat)) {
478 while ($sCurrentCat !=
'oxrootid' && isset($this[$sCurrentCat])) {
479 $oCat = $this[$sCurrentCat];
480 $oCat->setExpanded(
true );
481 $aPath[$sCurrentCat] = $oCat;
482 $sCurrentCat = $oCat->oxcategories__oxparentid->value;
485 $this->_aPath = array_reverse($aPath);
496 $oContentList =
oxNew(
"oxContentList" );
497 $oContentList->loadCatMenues();
499 foreach ($oContentList as $sCatId => $aContent) {
500 if (array_key_exists($sCatId, $this->_aArray)) {
501 $this[$sCatId]->setContentCats($aContent);
515 foreach ($this->_aArray as $oCat) {
516 $sParentId = $oCat->oxcategories__oxparentid->value;
517 if ( $sParentId !=
'oxrootid') {
518 if (isset($this->_aArray[$sParentId])) {
519 $this->_aArray[$sParentId]->setSubCat( $oCat, $oCat->getId() );
522 $aTree[$oCat->getId()] = $oCat;
542 foreach ($this->_aArray as $oCat) {
544 $aTree[$oCat->getId()] = $oCat;
545 $aSubCats = $oCat->getSubCats();
546 if (
count($aSubCats) > 0 ) {
547 foreach ($aSubCats as $oSubCat) {
567 $oCat->oxcategories__oxtitle->setValue($sDepth.
' '.$oCat->oxcategories__oxtitle->value);
568 $aTree[$oCat->getId()] = $oCat;
569 $aSubCats = $oCat->getSubCats();
570 if (
count($aSubCats) > 0 ) {
571 foreach ($aSubCats as $oSubCat) {
591 $oDb->execute(
"update oxcategories set oxleft = 0, oxright = 0 where $sWhere");
592 $oDb->execute(
"update oxcategories set oxleft = 1, oxright = 2 where oxparentid = 'oxrootid' and $sWhere");
595 $rs = $oDb->select(
"select oxid, oxtitle from oxcategories where oxparentid = 'oxrootid' and $sWhere order by oxsort",
false,
false );
596 if ($rs !=
false && $rs->recordCount() > 0) {
598 $this->_aUpdateInfo[] =
"<b>Processing : ".$rs->fields[1].
"</b>(".$rs->fields[0].
")<br>";
600 echo
next( $this->_aUpdateInfo );
602 $oxRootId = $rs->fields[0];
634 $thisRoot = $oxRootId;
638 $rs = $oDb->execute(
"update oxcategories set oxrootid = ".$oDb->quote($thisRoot).
" where oxparentid = ".$oDb->quote($oxRootId));
639 $rs = $oDb->select(
"select oxid, oxparentid from oxcategories where oxparentid = ".$oDb->quote($oxRootId).
" order by oxsort",
false,
false);
641 if ($rs !=
false && $rs->recordCount() > 0) {
643 $parentId = $rs->fields[1];
644 $actOxid = $rs->fields[0];
645 $sActOxidQuoted = $oDb->quote($actOxid);
648 $rs3 = $oDb->select(
"select oxrootid, oxright from oxcategories where oxid = ".$oDb->quote($parentId),
false, false );
650 $parentOxRootId = $rs3->fields[0];
651 $parentRight = (int)$rs3->fields[1];
654 $sParentOxRootIdQuoted = $oDb->quote($parentOxRootId);
655 $oDb->execute(
"update oxcategories set oxleft = oxleft + 2 where oxrootid = $sParentOxRootIdQuoted and oxleft > '$parentRight' and oxright >= '$parentRight' and oxid != $sActOxidQuoted");
656 $oDb->execute(
"update oxcategories set oxright = oxright + 2 where oxrootid = $sParentOxRootIdQuoted and oxright >= '$parentRight' and oxid != $sActOxidQuoted");
657 $oDb->execute(
"update oxcategories set oxleft = $parentRight, oxright = ($parentRight + 1) where oxid = $sActOxidQuoted");