oxcmp_categories.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxcmp_categories extends oxView
00008 {
00013     protected $_oMoreCat = null;
00014 
00019     protected $_blIsComponent = true;
00020 
00030     public function init()
00031     {
00032         parent::init();
00033 
00034         // Performance
00035         $myConfig = $this->getConfig();
00036         if ( $myConfig->getConfigParam( 'blDisableNavBars' ) &&
00037              $myConfig->getActiveView()->getIsOrderStep() ) {
00038             return;
00039         }
00040 
00041         $sActCat = $this->_getActCat();
00042 
00043         //@deprecated in v.4.5.7, since 2012-02-15; config option removed bug #0003385
00044         if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00045             // building vendor tree
00046             $this->_loadVendorTree( $sActCat );
00047         }
00048 
00049         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00050             // building Manufacturer tree
00051             $sActManufacturer = oxConfig::getParameter( 'mnid' );
00052             $this->_loadManufacturerTree( $sActManufacturer );
00053         }
00054 
00055         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00056 
00057             // building categorytree for all purposes (nav, search and simple category trees)
00058             $this->_loadCategoryTree( $sActCat );
00059 
00060             if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00061                 if ( ! ( $sActCont = oxConfig::getParameter( 'oxcid' ) ) ) {
00062                     $sActCont = oxConfig::getParameter( 'tpl' );
00063                 }
00064                 $this->_oMoreCat = $this->_getMoreCategory( $sActCat, $sActCont );
00065             }
00066         }
00067     }
00068 
00074     public function getProduct()
00075     {
00076         if ( ( $sActProduct = oxConfig::getParameter( 'anid' ) ) ) {
00077             $oParentView = $this->getParent();
00078             if ( ( $oProduct = $oParentView->getViewProduct() ) ) {
00079                 return $oProduct;
00080             } else {
00081                 $oProduct = oxNew( 'oxarticle' );
00082                 if ( $oProduct->load( $sActProduct ) ) {
00083                     // storing for reuse
00084                     $oParentView->setViewProduct( $oProduct );
00085                     return $oProduct;
00086                 }
00087             }
00088         }
00089     }
00090 
00096     protected function _getActCat()
00097     {
00098         if ( ! ( $sActCont = oxConfig::getParameter( 'oxcid' ) ) ) {
00099             $sActCont = oxConfig::getParameter( 'tpl' );
00100         }
00101         $sActManufacturer = oxConfig::getParameter( 'mnid' );
00102         $sActTag = oxConfig::getParameter( 'searchtag' );
00103         $sActCat = $sActManufacturer ? null : oxConfig::getParameter( 'cnid' );
00104 
00105         // loaded article - then checking additional parameters
00106         $oProduct = $this->getProduct();
00107         if ( $oProduct ) {
00108             $myConfig = $this->getConfig();
00109 
00110             $sActManufacturer = $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ? $sActManufacturer : null;
00111 
00112             //@deprecated in v.4.5.7, since 2012-02-15; config option removed bug #0003385
00113             $sActVendor = ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) && getStr()->preg_match( '/^v_.?/i', $sActCat ) ) ? $sActCat : null;
00114 
00115             $sActCat = $this->_addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActCont, $sActTag, $sActVendor );
00116         }
00117 
00118         // Checking for the default category
00119         if ( $sActCat === null && !$oProduct && !$sActCont && !$sActManufacturer && !$sActTag ) {
00120             // set remote cat
00121             $sActCat = $this->getConfig()->getActiveShop()->oxshops__oxdefcat->value;
00122             if ( $sActCat == 'oxrootid' ) {
00123                 // means none selected
00124                 $sActCat= null;
00125             }
00126         }
00127         return $sActCat;
00128     }
00129 
00137     protected function _loadCategoryTree( $sActCat )
00138     {
00139         $myConfig = $this->getConfig();
00140         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00141             $oCategoryTree = oxNew( 'oxcategorylist' );
00142             $oCategoryTree->buildTree( $sActCat, $myConfig->getConfigParam( 'blLoadFullTree' ), $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ), $myConfig->getConfigParam( 'blTopNaviLayout' ) );
00143 
00144             $oParentView = $this->getParent();
00145 
00146             // setting active category tree
00147             $oParentView->setCategoryTree( $oCategoryTree );
00148 
00149             // setting active category
00150             $oParentView->setActCategory( $oCategoryTree->getClickCat() );
00151         }
00152     }
00153 
00163     protected function _loadVendorTree( $sActVendor )
00164     {
00165         $myConfig = $this->getConfig();
00166         if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00167             $oVendorTree = oxNew( 'oxvendorlist' );
00168             $oVendorTree->buildVendorTree( 'vendorlist', $sActVendor, $myConfig->getShopHomeURL() );
00169 
00170             $oParentView = $this->getParent();
00171 
00172             // setting active vendor list
00173             $oParentView->setVendorTree( $oVendorTree );
00174 
00175             // setting active vendor
00176             if ( ( $oVendor = $oVendorTree->getClickVendor() ) ) {
00177                 $oParentView->setActVendor( $oVendor );
00178             }
00179         }
00180     }
00181 
00189     protected function _loadManufacturerTree( $sActManufacturer )
00190     {
00191         $myConfig = $this->getConfig();
00192         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00193             $oManufacturerTree = oxNew( 'oxmanufacturerlist' );
00194             $oManufacturerTree->buildManufacturerTree( 'manufacturerlist', $sActManufacturer, $myConfig->getShopHomeURL() );
00195 
00196             $oParentView = $this->getParent();
00197 
00198             // setting active Manufacturer list
00199             $oParentView->setManufacturerTree( $oManufacturerTree );
00200 
00201             // setting active Manufacturer
00202             if ( ( $oManufacturer = $oManufacturerTree->getClickManufacturer() ) ) {
00203                 $oParentView->setActManufacturer( $oManufacturer );
00204             }
00205         }
00206     }
00207 
00214     public function render()
00215     {
00216         parent::render();
00217 
00218         // Performance
00219         $myConfig = $this->getConfig();
00220         $oParentView = $this->getParent();
00221 
00222         //@deprecated in v.4.5.7, since 2012-02-15; config option removed bug #0003385
00223         if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) &&
00224              ( $oVendorTree = $oParentView->getVendorTree() )) {
00225             $oParentView->setVendorlist( $oVendorTree );
00226             $oParentView->setRootVendor( $oVendorTree->getRootCat() );
00227         }
00228 
00229         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) &&
00230              ( $oManufacturerTree = $oParentView->getManufacturerTree() ) ) {
00231             $oParentView->setManufacturerlist( $oManufacturerTree );
00232             $oParentView->setRootManufacturer( $oManufacturerTree->getRootCat() );
00233         }
00234 
00235         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) &&
00236              ( $oCategoryTree = $oParentView->getCategoryTree() ) ) {
00237 
00238             // we loaded full category tree ?
00239             if ( $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ) ) {
00240                 $oParentView->setSearchCatTree( $oCategoryTree );
00241             }
00242 
00243             // new navigation ?
00244             if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00245                 $oParentView->setCatMore( $this->_oMoreCat );
00246             }
00247 
00248             return $oCategoryTree;
00249         }
00250     }
00251 
00260     protected function _getMoreCategory( $sActCat, $sActCont )
00261     {
00262         $myConfig = $this->getConfig();
00263         $blExpanded = false;
00264 
00265         if ( $sActCat == 'oxmore' ) {
00266             $blExpanded = true;
00267         } else {
00268             $iTopCount = $myConfig->getConfigParam( 'iTopNaviCatCount' );
00269             $oCategoryTree = $this->getParent()->getCategoryTree();
00270             if ( $oCategoryTree ) {
00271                 $iCnt = 0;
00272                 foreach ( $oCategoryTree as $oCat ) {
00273                     $iCnt++;
00274 
00275                     if ( ( $aContent = $oCat->getContentCats() ) ) {
00276                         foreach ( $aContent as $oContent ) {
00277                             if ( $sActCont == $oContent->getId() && ($iCnt > $iTopCount )) {
00278                                 $blExpanded = true;
00279                                 break 2;
00280                             }
00281                             $iCnt++;
00282                         }
00283                     }
00284 
00285                     if ( $oCat->getExpanded() && ($iCnt > $iTopCount )) {
00286                         $blExpanded = true;
00287                         break;
00288                     }
00289                 }
00290             }
00291         }
00292 
00293         $oMoreCat = new oxStdClass();
00294         $oMoreCat->closelink = $oMoreCat->openlink = $myConfig->getShopHomeURL().'cnid=oxmore';
00295         $oMoreCat->expanded  = $blExpanded;
00296         return $oMoreCat;
00297     }
00298 
00311     protected function _addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActCont, $sActTag, $sActVendor )
00312     {
00313         $sSearchPar = oxConfig::getParameter( 'searchparam' );
00314         $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00315         $sSearchVnd = oxConfig::getParameter( 'searchvendor' );
00316         $sSearchMan = oxConfig::getParameter( 'searchmanufacturer' );
00317         $sListType  = oxConfig::getParameter( 'listtype' );
00318 
00319         // search ?
00320         if ( ( !$sListType || $sListType == 'search' ) && ( $sSearchPar || $sSearchCat || $sSearchVnd || $sSearchMan ) ) {
00321             // setting list type directly
00322             $sListType = 'search';
00323         } else {
00324 
00325             // such Manufacturer is available ?
00326             if ( $sActManufacturer && ( $sActManufacturer == $oProduct->getManufacturerId() ) ) {
00327                 // setting list type directly
00328                 $sListType = 'manufacturer';
00329                 $sActCat   = $sActManufacturer;
00330             } elseif ( $sActVendor && ( substr( $sActVendor, 2 ) == $oProduct->getVendorId() ) ) {
00331                 // such vendor is available ?
00332                 $sListType = 'vendor';
00333                 $sActCat   = $sActVendor;
00334             } elseif ( $sActTag ) {
00335                 // tag ?
00336                 $sListType = 'tag';
00337             } elseif ( $sActCat && $oProduct->isAssignedToCategory( $sActCat ) ) {
00338                 // category ?
00339             } else {
00340                 list( $sListType, $sActCat ) = $this->_getDefaultParams( $oProduct );
00341             }
00342         }
00343 
00344         $oParentView = $this->getParent();
00345         //set list type and category id
00346         $oParentView->setListType( $sListType );
00347         $oParentView->setCategoryId( $sActCat );
00348 
00349         return $sActCat;
00350     }
00351 
00359     protected function _getDefaultParams( $oProduct )
00360     {
00361         $sListType = null;
00362         $aArticleCats = $oProduct->getCategoryIds( true );
00363         if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00364             $sActCat = reset( $aArticleCats );
00365         } elseif ( ( $sActCat = $oProduct->getManufacturerId() ) ) {
00366             // not assigned to any category ? maybe it is assigned to Manufacturer ?
00367             $sListType = 'manufacturer';
00368         } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00369             // not assigned to any category ? maybe it is assigned to vendor ?
00370             $sListType = 'vendor';
00371         } else {
00372             $sActCat = null;
00373         }
00374 
00375         return array( $sListType, $sActCat );
00376     }
00377 }