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 && $myConfig->getConfigParam( 'bl_rssCategories' )) {
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         // processing list articles
00203         $this->_processListArticles();
00204 
00205         return $this->getTemplateName();
00206     }
00207 
00214     protected function _processListArticles()
00215     {
00216         if ( $aArtList = $this->getArticleList() ) {
00217             $iLinkType = $this->_getProductLinkType();
00218             $sAddDynParams = $this->getAddUrlParams();
00219             $sAddSeoParams = $this->getAddSeoUrlParams();
00220 
00221             foreach ( $aArtList as $oArticle ) {
00222                 $oArticle->setLinkType( $iLinkType );
00223 
00224                 // appending dynamic urls
00225                 if ( $sAddDynParams ) {
00226                     $oArticle->appendStdLink( $sAddDynParams );
00227                 }
00228 
00229                 // appending seo urls
00230                 if ( $sAddSeoParams ) {
00231                     $oArticle->appendLink( $sAddSeoParams );
00232                 }
00233             }
00234         }
00235     }
00236 
00237 
00243     public function getAddUrlParams()
00244     {
00245         $sParams = parent::getAddUrlParams();
00246         if ( !oxUtils::getInstance()->seoIsActive() ) {
00247             $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
00248             if ( $iPgNr > 0 ) {
00249                 $sParams .= ($sParams?'&amp;':'') . "pgNr={$iPgNr}";
00250             }
00251         }
00252 
00253         return $sParams;
00254     }
00255 
00261     public function getAddSeoUrlParams()
00262     {
00263     }
00264 
00272     protected function _getProductLinkType()
00273     {
00274         $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00275         if ( ( $oCat = $this->getActCategory() ) && $oCat->isPriceCategory() ) {
00276             $iCatType =  OXARTICLE_LINKTYPE_PRICECATEGORY;
00277         }
00278         return $iCatType;
00279     }
00280 
00289     public function executefilter()
00290     {
00291         // store this into session
00292         $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00293         $sActCat = oxConfig::getParameter( 'cnid' );
00294         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00295         $aSessionFilter[$sActCat] = $aFilter;
00296         oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00297     }
00298 
00306     protected function _loadArticles( $oCategory )
00307     {
00308         $myConfig = $this->getConfig();
00309 
00310         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00311         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00312 
00313         // load only articles which we show on screen
00314         $oArtList = oxNew( 'oxarticlelist' );
00315         $oArtList->setSqlLimit( $iNrofCatArticles * $this->getActPage(), $iNrofCatArticles );
00316         $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00317 
00318         if ( $oCategory->isPriceCategory() ) {
00319             $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00320             $dPriceTo   = $oCategory->oxcategories__oxpriceto->value;
00321 
00322             $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00323         } else {
00324             $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00325 
00326             $sActCat = oxConfig::getParameter( 'cnid' );
00327             $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00328         }
00329 
00330         $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00331 
00332         return $oArtList;
00333     }
00334 
00340     protected function _getSeoObjectId()
00341     {
00342         if ( ( $oCategory = $this->getActCategory() ) ) {
00343             return $oCategory->getId();
00344         }
00345     }
00346 
00352     protected function _getCatPathString()
00353     {
00354         if ( $this->_sCatPathString === null ) {
00355 
00356             // marking as allready set
00357             $this->_sCatPathString = false;
00358 
00359             //fetching category path
00360             if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00361 
00362                 $oStr = getStr();
00363                 $this->_sCatPathString = '';
00364                 foreach ( $aPath as $oCat ) {
00365                     if ( $this->_sCatPathString ) {
00366                         $this->_sCatPathString .= ', ';
00367                     }
00368                     $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00369                 }
00370             }
00371         }
00372         return $this->_sCatPathString;
00373     }
00374 
00384     protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00385     {
00386         // using language constant ..
00387         $sDescription = oxLang::getInstance()->translateString( 'INC_HEADER_YOUAREHERE' );
00388 
00389         // appending parent title
00390         if ( $oCategory = $this->_getCategory() ) {
00391             if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00392                 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00393             }
00394 
00395             // adding cateogry title
00396             $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00397         }
00398 
00399         // and final component ..
00400         if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00401             $sDescription .= " {$sSuffix}";
00402         }
00403 
00404         // making safe for output
00405         $sDescription = getStr()->cleanStr($sDescription);
00406         return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00407     }
00408 
00414     public function getMetaDescription()
00415     {
00416         $sMeta = parent::getMetaDescription();
00417 
00418         if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00419             if ( $sMeta ) {
00420                 $sMeta .= ", ";
00421             }
00422             $sMeta .= $sTitlePageSuffix;
00423         }
00424 
00425         return $sMeta;
00426     }
00427 
00440     protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00441     {
00442         //formatting description tag
00443         $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->oxcategories__oxlongdesc->value ):'';
00444         $aArticleList = $this->getArticleList();
00445         if ( !$sAddText && count($aArticleList)) {
00446             foreach ( $aArticleList as $oArticle ) {
00447                 if ( $sAddText ) {
00448                     $sAddText .= ', ';
00449                 }
00450                 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00451             }
00452         }
00453 
00454         if ( !$sMeta ) {
00455             $sMeta = trim( $this->_getCatPathString() );
00456         }
00457 
00458         if ( $sMeta ) {
00459             $sMeta = "{$sMeta} - {$sAddText}";
00460         } else {
00461             $sMeta = $sAddText;
00462         }
00463 
00464         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00465     }
00466 
00475     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00476     {
00477         $sKeywords = '';
00478         if ( ( $oCategory = $this->getActCategory() ) ) {
00479             $aKeywords = array();
00480 
00481             if ( $oCatTree = $this->getCategoryTree() ) {
00482                 foreach ( $oCatTree->getPath() as $oCat ) {
00483                     $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00484                 }
00485             }
00486 
00487             if ( count( $aKeywords ) > 0 ) {
00488                 $sKeywords = implode( ", ", $aKeywords );
00489             }
00490 
00491             $aSubCats  = $oCategory->getSubCats();
00492             if ( is_array( $aSubCats ) ) {
00493                 foreach ( $aSubCats as $oSubCat ) {
00494                     $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00495                 }
00496             }
00497         }
00498 
00499         $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00500 
00501         return trim( $sKeywords );
00502     }
00503 
00512     protected function _collectMetaKeyword( $sKeywords )
00513     {
00514         $iMaxTextLength = 60;
00515         $sText = '';
00516 
00517         if ( count( $aArticleList = $this->getArticleList() ) ) {
00518             $oStr = getStr();
00519             foreach ( $aArticleList as $oProduct ) {
00520                 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00521 
00522                 //removing dots from string (they are not cleaned up during general string cleanup)
00523                 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00524 
00525                 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00526                     $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00527                     $sDesc    = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00528                 }
00529                 if ( $sText ) {
00530                     $sText .= ', ';
00531                 }
00532                 $sText .= $sDesc;
00533             }
00534         }
00535 
00536         if ( !$sKeywords ) {
00537             $sKeywords = $this->_getCatPathString();
00538         }
00539 
00540         if ( $sKeywords ) {
00541             $sText = "{$sKeywords}, {$sText}";
00542         }
00543 
00544         return parent::_prepareMetaKeyword( $sText );
00545     }
00546 
00554     public function getTemplateName()
00555     {
00556         // assign template name
00557         if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00558             $this->_sThisTemplate = $sTplName;
00559         } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00560             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00561         }
00562 
00563         return $this->_sThisTemplate;
00564     }
00565 
00575     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00576     {
00577         if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00578             if ( $iPage ) {
00579                 // only if page number > 0
00580                 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00581             }
00582         } else {
00583             $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00584         }
00585         return $sUrl;
00586     }
00587 
00597     protected function _isFixedUrl( $oCategory )
00598     {
00599         if ( $this->_blFixedUrl == null ) {
00600             $oDb = oxDb::getDb();
00601             $sIdQuoted = $oDb->quote( $oCategory->getId() );
00602             $iLang = $oCategory->getLanguage();
00603             $sShopId = $this->getConfig()->getShopId();
00604             $this->_blFixedUrl = $oDb->getOne( "select oxfixed from oxseo where oxobjectid = {$sIdQuoted} and oxshopid = '{$sShopId}' and oxlang = '{$iLang}' and oxparams = '' " );
00605         }
00606         return $this->_blFixedUrl;
00607     }
00608 
00614     protected function _isActCategory()
00615     {
00616         return $this->_blIsCat;
00617     }
00618 
00626     protected function _getCategory()
00627     {
00628         return $this->getActCategory();
00629     }
00630 
00636     public function generatePageNavigationUrl( )
00637     {
00638         if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00639             return $oCategory->getLink();
00640         }
00641         return parent::generatePageNavigationUrl( );
00642     }
00643 
00651     public function getSorting( $sCnid )
00652     {
00653         // category has own sorting
00654         $aSorting = parent::getSorting( $sCnid );
00655         $oActCat = $this->getActCategory();
00656         if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00657             $sSortBy  = getViewName( 'oxarticles' ).".{$oActCat->oxcategories__oxdefsort->value}";
00658             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : null;
00659 
00660             $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00661             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00662         }
00663         return $aSorting;
00664     }
00665 
00671     public function getTitleSuffix()
00672     {
00673         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00674             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00675         }
00676     }
00677 
00683     public function getTitlePageSuffix()
00684     {
00685         if ( ( $iPage = $this->getActPage() ) ) {
00686             return oxLang::getInstance()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00687         }
00688     }
00689 
00698     protected function _getSubject( $iLang )
00699     {
00700         return $this->getActCategory();
00701     }
00702 
00709     public function getAttributes()
00710     {
00711         // #657 gather all attribute values we do have here in this category
00712         $this->_aAttributes = false;
00713         if ( ( $oCategory = $this->getActCategory() ) ) {
00714             $aAttributes = $oCategory->getAttributes();
00715             if ( count( $aAttributes ) ) {
00716                 $this->_aAttributes = $aAttributes;
00717             }
00718         }
00719         return $this->_aAttributes;
00720     }
00721 
00727     public function getArticleList()
00728     {
00729         if ( $this->_aArticleList === null ) {
00730             if ( $this->_isActCategory() && ( $oCategory = $this->getActCategory() ) ) {
00731                 $aArticleList = $this->_loadArticles( $oCategory );
00732                 if ( count( $aArticleList ) ) {
00733                     $this->_aArticleList = $aArticleList;
00734                 }
00735             }
00736         }
00737         return $this->_aArticleList;
00738     }
00739 
00745     public function getSimilarRecommLists()
00746     {
00747         if (!$this->getViewConfig()->getShowListmania()) {
00748             return false;
00749         }
00750 
00751         if ( $this->_oRecommList === null ) {
00752             $this->_oRecommList = false;
00753             if ( $aCatArtList = $this->getArticleList() ) {
00754                 $oRecommList = oxNew('oxrecommlist');
00755                 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00756             }
00757         }
00758         return $this->_oRecommList;
00759     }
00760 
00766     public function getCatTreePath()
00767     {
00768         if ( $this->_sCatTreePath === null ) {
00769              $this->_sCatTreePath = false;
00770             // category path
00771             if ( $oCatTree = $this->getCategoryTree() ) {
00772                 $this->_sCatTreePath = $oCatTree->getPath();
00773             }
00774         }
00775         return $this->_sCatTreePath;
00776     }
00777 
00785     public function getTemplateLocation()
00786     {
00787         if ( $this->_sCatTreeHtmlPath === null ) {
00788              $this->_sCatTreeHtmlPath = false;
00789             // category path
00790             if ( $oCatTree = $this->getCategoryTree() ) {
00791                 $this->_sCatTreeHtmlPath = $oCatTree->getHtmlPath();
00792             }
00793         }
00794         return $this->_sCatTreeHtmlPath;
00795     }
00796 
00802     public function getTreePath()
00803     {
00804         if ( $oCatTree = $this->getCategoryTree() ) {
00805             return $oCatTree->getPath();
00806         }
00807     }
00808 
00815     public function hasVisibleSubCats()
00816     {
00817         if ( $this->_blHasVisibleSubCats === null ) {
00818             $this->_blHasVisibleSubCats = false;
00819             if ( $oClickCat = $this->getActCategory() ) {
00820                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00821             }
00822         }
00823         return $this->_blHasVisibleSubCats;
00824     }
00825 
00831     public function getSubCatList()
00832     {
00833         if ( $this->_aSubCatList === null ) {
00834             $this->_aSubCatList = array();
00835             if ( $oClickCat = $this->getActCategory() ) {
00836                 $this->_aSubCatList = $oClickCat->getSubCats();
00837             }
00838         }
00839         return $this->_aSubCatList;
00840     }
00841 
00847     public function getPageNavigation()
00848     {
00849         if ( $this->_oPageNavigation === null ) {
00850             $this->_oPageNavigation = $this->generatePageNavigation();
00851         }
00852         return $this->_oPageNavigation;
00853     }
00854 
00860     public function getTitle()
00861     {
00862         if ( $this->_sCatTitle === null ) {
00863             $this->_sCatTitle = false;
00864             if ( ( $oCategory = $this->getActCategory() ) ) {
00865                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00866             }
00867         }
00868         return $this->_sCatTitle;
00869     }
00870 
00876     public function getTop5ArticleList()
00877     {
00878         if ( $this->_aTop5ArticleList === null ) {
00879             $this->_aTop5ArticleList = false;
00880             $myConfig = $this->getConfig();
00881             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00882                 // top 5 articles
00883                 $oArtList = oxNew( 'oxarticlelist' );
00884                 $oArtList->loadTop5Articles();
00885                 if ( $oArtList->count() ) {
00886                     $this->_aTop5ArticleList = $oArtList;
00887                 }
00888             }
00889         }
00890         return $this->_aTop5ArticleList;
00891     }
00892 
00898     public function getBargainArticleList()
00899     {
00900         if ( $this->_aBargainArticleList === null ) {
00901             $this->_aBargainArticleList = array();
00902             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00903                 $oArtList = oxNew( 'oxarticlelist' );
00904                 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00905                 if ( $oArtList->count() ) {
00906                     $this->_aBargainArticleList = $oArtList;
00907                 }
00908             }
00909         }
00910         return $this->_aBargainArticleList;
00911     }
00912 
00918     public function getActiveCategory()
00919     {
00920         return $this->getActCategory();
00921     }
00922 
00928     public function getCanonicalUrl()
00929     {
00930         if ( ( $oCategory = $this->getActiveCategory() ) ) {
00931             $oUtils = oxUtilsUrl::getInstance();
00932             if ( oxUtils::getInstance()->seoIsActive() ) {
00933                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00934             } else {
00935                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00936             }
00937             return $sUrl;
00938         }
00939     }
00940 }