alist.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class aList extends oxUBase
00010 {
00015     protected $_iAllArtCnt = 0;
00016 
00021     protected $_iCntPages = null;
00022 
00027     protected $_sThisTemplate = 'list.tpl';
00028 
00033     protected $_sThisMoreTemplate = 'list_more.tpl';
00034 
00039     protected $_sCatPathString = null;
00040 
00045     protected $_blShowSorting = true;
00046 
00051     protected $_aAttributes = null;
00052 
00057     protected $_aCatArtList = null;
00058 
00063     protected $_sCatTreeHtmlPath = null;
00064 
00069     protected $_blHasVisibleSubCats = null;
00070 
00075     protected $_aSubCatList = null;
00076 
00081     protected $_oPageNavigation = null;
00082 
00087     protected $_blIsCat = null;
00088 
00093     protected $_oRecommList = null;
00094 
00099     protected $_sCatTitle = null;
00100 
00105     protected $_blFixedUrl = null;
00106 
00113     public function getViewId()
00114     {
00115         if ( !isset( $this->_sViewId ) ) {
00116             $sCatId   = oxConfig::getParameter( 'cnid' );
00117             $iActPage = $this->getActPage();
00118             $iArtPerPage = oxConfig::getParameter( '_artperpage' );
00119             $sParentViewId = parent::getViewId();
00120 
00121             // shorten it
00122                 $this->_sViewId = md5( $sParentViewId.'|'.$sCatId.'|'.$iActPage.'|'.$iArtPerPage );
00123 
00124         }
00125 
00126         return $this->_sViewId;
00127     }
00128 
00144     public function render()
00145     {
00146         $myConfig = $this->getConfig();
00147 
00148         $oCategory  = null;
00149         $blContinue = true;
00150         $this->_blIsCat = false;
00151 
00152         // A. checking for fake "more" category
00153         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) && $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00154 
00155             // overriding some standard value and parameters
00156             $this->_sThisTemplate = $this->_sThisMoreTemplate;
00157             $oCategory = oxNew( 'oxcategory' );
00158             $oCategory->oxcategories__oxactive = new oxField( 1, oxField::T_RAW );
00159             $this->setActCategory( $oCategory );
00160         } elseif ( ( $oCategory = $this->getActCategory() ) ) {
00161             $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
00162             $this->_blIsCat = true;
00163         }
00164 
00165 
00166         // category is inactive ?
00167         if ( !$blContinue || !$oCategory ) {
00168             oxUtils::getInstance()->redirect( $myConfig->getShopURL().'index.php' );
00169         }
00170 
00171         $this->_aViewData['filterattributes'] = $this->getAttributes();
00172 
00173         $this->_aViewData['articlelist']       = $this->getArticleList();
00174         $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00175 
00176         // loading actions
00177         $this->_aViewData['articlebargainlist'] = $this->getBargainArticleList();
00178         $this->_aViewData['aTop5Articles']      = $this->getTop5ArticleList();
00179 
00180         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00181 
00182         $this->_aViewData['actCatpath']        = $this->getCatTreePath();
00183         $this->_aViewData['template_location'] = $this->getTemplateLocation();
00184 
00185         // add to the parent view
00186         $this->_aViewData['actCategory'] = $this->getActCategory();
00187 
00188         $oCat = $this->getActCategory();
00189         if ($oCat && is_array($myConfig->getConfigParam( 'aRssSelected' )) && in_array('oxrss_categories', $myConfig->getConfigParam( 'aRssSelected' ))) {
00190             $oRss = oxNew('oxrssfeed');
00191             $this->addRssFeed($oRss->getCategoryArticlesTitle($oCat), $oRss->getCategoryArticlesUrl($oCat), 'activeCategory');
00192         }
00193 
00194         //Gets subcategory tree from category tree
00195         $this->_aViewData['hasVisibleSubCats'] = $this->hasVisibleSubCats();
00196         $this->_aViewData['subcatlist']        = $this->getSubCatList();
00197 
00198         $this->_aViewData['title'] = $this->getTitle();
00199 
00200         parent::render();
00201 
00202         return $this->getTemplateName();
00203     }
00204 
00213     public function executefilter()
00214     {
00215         // store this into session
00216         $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00217         $sActCat = oxConfig::getParameter( 'cnid' );
00218         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00219         $aSessionFilter[$sActCat] = $aFilter;
00220         oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00221     }
00222 
00230     protected function _loadArticles( $oCategory )
00231     {
00232         $myConfig = $this->getConfig();
00233 
00234         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00235         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00236 
00237         // load only articles which we show on screen
00238         $oArtList = oxNew( 'oxarticlelist' );
00239         $oArtList->setSqlLimit( $iNrofCatArticles * $this->getActPage(), $iNrofCatArticles );
00240         $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00241 
00242         if ( $oCategory->oxcategories__oxpricefrom->value || $oCategory->oxcategories__oxpriceto->value ) {
00243             $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00244             $dPriceTo   = $oCategory->oxcategories__oxpriceto->value;
00245 
00246             $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00247         } else {
00248             $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00249 
00250             $sActCat = oxConfig::getParameter( 'cnid' );
00251             $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00252         }
00253 
00254         $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00255 
00256         return $oArtList;
00257     }
00258 
00264     protected function _getSeoObjectId()
00265     {
00266         if ( ( $oCategory = $this->getActCategory() ) ) {
00267             return $oCategory->getId();
00268         }
00269     }
00270 
00276     protected function _getCatPathString()
00277     {
00278         if ( $this->_sCatPathString === null ) {
00279 
00280             // marking as allready set
00281             $this->_sCatPathString = false;
00282 
00283             //fetching category path
00284             if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00285 
00286                 $oStr = getStr();
00287                 $this->_sCatPathString = '';
00288                 foreach ( $aPath as $oCat ) {
00289                     if ( $this->_sCatPathString ) {
00290                         $this->_sCatPathString .= ', ';
00291                     }
00292                     $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00293                 }
00294             }
00295         }
00296         return $this->_sCatPathString;
00297     }
00298 
00308     protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00309     {
00310         // using language constant ..
00311         $sDescription = oxLang::getInstance()->translateString( 'INC_HEADER_YOUAREHERE' );
00312 
00313         // appending parent title
00314         if ( $oCategory = $this->_getCategory() ) {
00315             if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00316                 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00317             }
00318 
00319             // adding cateogry title
00320             $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00321         }
00322 
00323         // and final component ..
00324         if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00325             $sDescription .= " {$sSuffix}";
00326         }
00327 
00328         // making safe for output
00329         $sDescription = getStr()->cleanStr($sDescription);
00330         return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00331     }
00332 
00345     protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00346     {
00347         //formatting description tag
00348         $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->oxcategories__oxlongdesc->value ):'';
00349         $aArticleList = $this->getArticleList();
00350         if ( !$sAddText && count($aArticleList)) {
00351             foreach ( $aArticleList as $oArticle ) {
00352                 if ( $sAddText ) {
00353                     $sAddText .= ', ';
00354                 }
00355                 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00356             }
00357         }
00358 
00359         if ( !$sMeta ) {
00360             $sMeta = trim( $this->_getCatPathString() );
00361         }
00362 
00363         if ( $sMeta ) {
00364             $sMeta = "{$sMeta} - {$sAddText}";
00365         } else {
00366             $sMeta = $sAddText;
00367         }
00368 
00369         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00370     }
00371 
00379     protected function _prepareMetaKeyword( $sKeywords )
00380     {
00381         $sKeywords = '';
00382         if ( ( $oCategory = $this->getActCategory() ) ) {
00383             if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00384                 $sKeywords = $oParent->oxcategories__oxtitle->value;
00385             }
00386 
00387             $sKeywords = ( $sKeywords ? $sKeywords . ', ' : '' ) . $oCategory->oxcategories__oxtitle->value;
00388             $aSubCats  = $oCategory->getSubCats();
00389             if ( is_array( $aSubCats ) ) {
00390                 foreach ( $aSubCats as $oSubCat ) {
00391                     $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00392                 }
00393             }
00394         }
00395 
00396         $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, false );
00397         $aSkipTags = $this->getConfig()->getConfigParam( 'aSkipTags' );
00398         $sKeywords = $this->_removeDuplicatedWords( $sKeywords, $aSkipTags );
00399 
00400         return trim( $sKeywords );
00401     }
00402 
00411     protected function _collectMetaKeyword( $sKeywords )
00412     {
00413         $iMaxTextLenght = 60;
00414         $sText = '';
00415 
00416         if ( count( $aArticleList = $this->getArticleList() ) ) {
00417             $oStr = getStr();
00418             foreach ( $aArticleList as $oProduct ) {
00419                 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00420                 if ( $oStr->strlen( $sDesc ) > $iMaxTextLenght ) {
00421                     $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLenght );
00422                     $sDesc   .= $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00423                 }
00424                 if ( $sText ) {
00425                     $sText .= ', ';
00426                 }
00427                 $sText .= $sDesc;
00428             }
00429         }
00430 
00431         if ( !$sKeywords ) {
00432             $sKeywords = $this->_getCatPathString();
00433         }
00434 
00435         if ( $sKeywords ) {
00436             $sText = "{$sKeywords}, {$sText}";
00437         }
00438 
00439         return parent::_prepareMetaKeyword( $sText );
00440     }
00441 
00449     public function getTemplateName()
00450     {
00451         // assign template name
00452         if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00453             $this->_sThisTemplate = $sTplName;
00454         } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00455             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00456         }
00457 
00458         return $this->_sThisTemplate;
00459     }
00460 
00470     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00471     {
00472         if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00473             if ( $iPage ) { // only if page number > 0
00474                 $sUrl = oxSeoEncoderCategory::getInstance()->getCategoryPageUrl( $oCategory, $iPage, $iLang, $this->_isFixedUrl( $oCategory ) );
00475             }
00476         } else {
00477             $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00478         }
00479         return $sUrl;
00480     }
00481 
00489     protected function _isFixedUrl( $oCategory )
00490     {
00491         if ( $this->_blFixedUrl == null ) {
00492             $sId = $oCategory->getId();
00493             $iLang = $oCategory->getLanguage();
00494             $sShopId = $this->getConfig()->getShopId();
00495             $this->_blFixedUrl = oxDb::getDb()->getOne( "select oxfixed from oxseo where oxobjectid = '{$sId}' and oxshopid = '{$sShopId}' and oxlang = '{$iLang}' and oxparams = '' " );
00496         }
00497         return $this->_blFixedUrl;
00498     }
00499 
00505     protected function _isActCategory()
00506     {
00507         return $this->_blIsCat;
00508     }
00509 
00517     protected function _getCategory()
00518     {
00519         return $this->getActCategory();
00520     }
00521 
00527     public function generatePageNavigationUrl( )
00528     {
00529         if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00530             return $oCategory->getLink();
00531         } else {
00532             return parent::generatePageNavigationUrl( );
00533         }
00534     }
00535 
00543     public function getSorting( $sCnid )
00544     {
00545         // category has own sorting
00546         $aSorting = parent::getSorting( $sCnid );
00547         $oActCat = $this->getActCategory();
00548         if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00549             $sSortBy  = getViewName( 'oxarticles' ).".{$oActCat->oxcategories__oxdefsort->value}";
00550             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? " desc " : null;
00551 
00552             $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00553             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00554         }
00555         return $aSorting;
00556     }
00557 
00563     public function getTitleSuffix()
00564     {
00565         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00566             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00567         }
00568     }
00569 
00576     protected function _getSubject()
00577     {
00578         return $this->getActCategory();
00579     }
00580 
00587     public function getAttributes()
00588     {
00589         // #657 gather all attribute values we do have here in this category
00590         $this->_aAttributes = false;
00591         if ( ( $oCategory = $this->getActCategory() ) ) {
00592             $aAttributes = $oCategory->getAttributes();
00593             if ( count( $aAttributes ) ) {
00594                 $this->_aAttributes = $aAttributes;
00595             }
00596         }
00597         return $this->_aAttributes;
00598     }
00599 
00605     public function getArticleList()
00606     {
00607         if ( $this->_aArticleList === null ) {
00608             if ( $this->_isActCategory() && ( $oCategory = $this->getActCategory() ) ) {
00609                 $aArticleList = $this->_loadArticles( $oCategory );
00610                 if ( count( $aArticleList ) ) {
00611                     $this->_aArticleList = $aArticleList;
00612                 }
00613             }
00614         }
00615         return $this->_aArticleList;
00616     }
00617 
00623     public function getSimilarRecommLists()
00624     {
00625         if ( $this->_oRecommList === null ) {
00626             $this->_oRecommList = false;
00627             if ( $aCatArtList = $this->getArticleList() ) {
00628                 $oRecommList = oxNew('oxrecommlist');
00629                 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00630             }
00631         }
00632         return $this->_oRecommList;
00633     }
00634 
00640     public function getCatTreePath()
00641     {
00642         if ( $this->_sCatTreePath === null ) {
00643              $this->_sCatTreePath = false;
00644             // category path
00645             if ( $oCatTree = $this->getCategoryTree() ) {
00646                 $this->_sCatTreePath = $oCatTree->getPath();
00647             }
00648         }
00649         return $this->_sCatTreePath;
00650     }
00651 
00657     public function getTemplateLocation()
00658     {
00659         if ( $this->_sCatTreeHtmlPath === null ) {
00660              $this->_sCatTreeHtmlPath = false;
00661             // category path
00662             if ( $oCatTree = $this->getCategoryTree() ) {
00663                 $this->_sCatTreeHtmlPath = $oCatTree->getHtmlPath();
00664             }
00665         }
00666         return $this->_sCatTreeHtmlPath;
00667     }
00668 
00675     public function hasVisibleSubCats()
00676     {
00677         if ( $this->_blHasVisibleSubCats === null ) {
00678             $this->_blHasVisibleSubCats = false;
00679             if ( $oClickCat = $this->getActCategory() ) {
00680                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00681             }
00682         }
00683         return $this->_blHasVisibleSubCats;
00684     }
00685 
00691     public function getSubCatList()
00692     {
00693         if ( $this->_aSubCatList === null ) {
00694             $this->_aSubCatList = array();
00695             if ( $oClickCat = $this->getActCategory() ) {
00696                 $this->_aSubCatList = $oClickCat->getSubCats();
00697             }
00698         }
00699         return $this->_aSubCatList;
00700     }
00701 
00707     public function getPageNavigation()
00708     {
00709         if ( $this->_oPageNavigation === null ) {
00710             $this->_oPageNavigation = false;
00711             $this->_oPageNavigation = $this->generatePageNavigation();
00712         }
00713         return $this->_oPageNavigation;
00714     }
00715 
00721     public function getTitle()
00722     {
00723         if ( $this->_sCatTitle === null ) {
00724             $this->_sCatTitle = false;
00725             if ( ( $oCategory = $this->getActCategory() ) ) {
00726                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00727             }
00728         }
00729         return $this->_sCatTitle;
00730     }
00731 
00737     public function getTop5ArticleList()
00738     {
00739         if ( $this->_aTop5ArticleList === null ) {
00740             $this->_aTop5ArticleList = false;
00741             $myConfig = $this->getConfig();
00742             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00743                 // top 5 articles
00744                 $oArtList = oxNew( 'oxarticlelist' );
00745                 $oArtList->loadTop5Articles();
00746                 if ( $oArtList->count() ) {
00747                     $this->_aTop5ArticleList = $oArtList;
00748                 }
00749             }
00750         }
00751         return $this->_aTop5ArticleList;
00752     }
00753 
00759     public function getBargainArticleList()
00760     {
00761         if ( $this->_aBargainArticleList === null ) {
00762             $this->_aBargainArticleList = array();
00763             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00764                 $oArtList = oxNew( 'oxarticlelist' );
00765                 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00766                 if ( $oArtList->count() ) {
00767                     $this->_aBargainArticleList = $oArtList;
00768                 }
00769             }
00770         }
00771         return $this->_aBargainArticleList;
00772     }
00773 
00779     public function getActiveCategory()
00780     {
00781         return $this->getActCategory();
00782     }
00783 
00784 }

Generated on Wed May 13 13:25:55 2009 for OXID eShop CE by  doxygen 1.5.5