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, true );
00397         $sKeywords = $this->_removeDuplicatedWords( $sKeywords );
00398 
00399         // removing in admin defined strings
00400         $aSkipTags = $this->getConfig()->getConfigParam( 'aSkipTags' );
00401         if ( is_array( $aSkipTags ) && $sKeywords ) {
00402             foreach ( $aSkipTags as $sSkip ) {
00403                 $aPattern = array( '/\W'.$sSkip.'\W/i', '/^'.$sSkip.'\W/i', '/\"'.$sSkip.'$/i' );
00404                 $sKeywords  = preg_replace( $aPattern, '', $sKeywords );
00405             }
00406         }
00407 
00408         return trim( $sKeywords );
00409     }
00410 
00419     protected function _collectMetaKeyword( $sKeywords )
00420     {
00421         $iMaxTextLenght = 60;
00422         $sText = '';
00423 
00424         if ( count( $aArticleList = $this->getArticleList() ) ) {
00425             $oStr = getStr();
00426             foreach ( $aArticleList as $oProduct ) {
00427                 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00428                 if ( $oStr->strlen( $sDesc ) > $iMaxTextLenght ) {
00429                     $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLenght );
00430                     $sDesc   .= $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00431                 }
00432                 if ( $sText ) {
00433                     $sText .= ', ';
00434                 }
00435                 $sText .= $sDesc;
00436             }
00437         }
00438 
00439         if ( !$sKeywords ) {
00440             $sKeywords = $this->_getCatPathString();
00441         }
00442 
00443         if ( $sKeywords ) {
00444             $sText = "{$sKeywords}, {$sText}";
00445         }
00446 
00447         return parent::_prepareMetaKeyword( $sText );
00448     }
00449 
00457     public function getTemplateName()
00458     {
00459         // assign template name
00460         if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00461             $this->_sThisTemplate = $sTplName;
00462         } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00463             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00464         }
00465 
00466         return $this->_sThisTemplate;
00467     }
00468 
00478     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00479     {
00480         if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00481             if ( $iPage ) { // only if page number > 0
00482                 $sUrl = oxSeoEncoderCategory::getInstance()->getCategoryPageUrl( $oCategory, $iPage, $iLang, $this->_isFixedUrl( $oCategory ) );
00483             }
00484         } else {
00485             $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00486         }
00487         return $sUrl;
00488     }
00489 
00497     protected function _isFixedUrl( $oCategory )
00498     {
00499         if ( $this->_blFixedUrl == null ) {
00500             $sId = $oCategory->getId();
00501             $iLang = $oCategory->getLanguage();
00502             $sShopId = $this->getConfig()->getShopId();
00503             $this->_blFixedUrl = oxDb::getDb()->getOne( "select oxfixed from oxseo where oxobjectid = '{$sId}' and oxshopid = '{$sShopId}' and oxlang = '{$iLang}' and oxparams = '' " );
00504         }
00505         return $this->_blFixedUrl;
00506     }
00507 
00513     protected function _isActCategory()
00514     {
00515         return $this->_blIsCat;
00516     }
00517 
00525     protected function _getCategory()
00526     {
00527         return $this->getActCategory();
00528     }
00529 
00535     public function generatePageNavigationUrl( )
00536     {
00537         if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00538             return $oCategory->getLink();
00539         } else {
00540             return parent::generatePageNavigationUrl( );
00541         }
00542     }
00543 
00551     public function getSorting( $sCnid )
00552     {
00553         // category has own sorting
00554         $aSorting = parent::getSorting( $sCnid );
00555         $oActCat = $this->getActCategory();
00556         if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00557             $sSortBy  = getViewName( 'oxarticles' ).".{$oActCat->oxcategories__oxdefsort->value}";
00558             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? " desc " : null;
00559 
00560             $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00561             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00562         }
00563         return $aSorting;
00564     }
00565 
00571     public function getTitleSuffix()
00572     {
00573         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00574             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00575         }
00576     }
00577 
00584     protected function _getSubject()
00585     {
00586         return $this->getActCategory();
00587     }
00588 
00595     public function getAttributes()
00596     {
00597         // #657 gather all attribute values we do have here in this category
00598         $this->_aAttributes = false;
00599         if ( ( $oCategory = $this->getActCategory() ) ) {
00600             $aAttributes = $oCategory->getAttributes();
00601             if ( count( $aAttributes ) ) {
00602                 $this->_aAttributes = $aAttributes;
00603             }
00604         }
00605         return $this->_aAttributes;
00606     }
00607 
00613     public function getArticleList()
00614     {
00615         if ( $this->_aArticleList === null ) {
00616             if ( $this->_isActCategory() && ( $oCategory = $this->getActCategory() ) ) {
00617                 $aArticleList = $this->_loadArticles( $oCategory );
00618                 if ( count( $aArticleList ) ) {
00619                     $this->_aArticleList = $aArticleList;
00620                 }
00621             }
00622         }
00623         return $this->_aArticleList;
00624     }
00625 
00631     public function getSimilarRecommLists()
00632     {
00633         if ( $this->_oRecommList === null ) {
00634             $this->_oRecommList = false;
00635             if ( $aCatArtList = $this->getArticleList() ) {
00636                 $oRecommList = oxNew('oxrecommlist');
00637                 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00638             }
00639         }
00640         return $this->_oRecommList;
00641     }
00642 
00648     public function getCatTreePath()
00649     {
00650         if ( $this->_sCatTreePath === null ) {
00651              $this->_sCatTreePath = false;
00652             // category path
00653             if ( $oCatTree = $this->getCategoryTree() ) {
00654                 $this->_sCatTreePath = $oCatTree->getPath();
00655             }
00656         }
00657         return $this->_sCatTreePath;
00658     }
00659 
00665     public function getTemplateLocation()
00666     {
00667         if ( $this->_sCatTreeHtmlPath === null ) {
00668              $this->_sCatTreeHtmlPath = false;
00669             // category path
00670             if ( $oCatTree = $this->getCategoryTree() ) {
00671                 $this->_sCatTreeHtmlPath = $oCatTree->getHtmlPath();
00672             }
00673         }
00674         return $this->_sCatTreeHtmlPath;
00675     }
00676 
00683     public function hasVisibleSubCats()
00684     {
00685         if ( $this->_blHasVisibleSubCats === null ) {
00686             $this->_blHasVisibleSubCats = false;
00687             if ( $oClickCat = $this->getActCategory() ) {
00688                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00689             }
00690         }
00691         return $this->_blHasVisibleSubCats;
00692     }
00693 
00699     public function getSubCatList()
00700     {
00701         if ( $this->_aSubCatList === null ) {
00702             $this->_aSubCatList = array();
00703             if ( $oClickCat = $this->getActCategory() ) {
00704                 $this->_aSubCatList = $oClickCat->getSubCats();
00705             }
00706         }
00707         return $this->_aSubCatList;
00708     }
00709 
00715     public function getPageNavigation()
00716     {
00717         if ( $this->_oPageNavigation === null ) {
00718             $this->_oPageNavigation = false;
00719             $this->_oPageNavigation = $this->generatePageNavigation();
00720         }
00721         return $this->_oPageNavigation;
00722     }
00723 
00729     public function getTitle()
00730     {
00731         if ( $this->_sCatTitle === null ) {
00732             $this->_sCatTitle = false;
00733             if ( ( $oCategory = $this->getActCategory() ) ) {
00734                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00735             }
00736         }
00737         return $this->_sCatTitle;
00738     }
00739 
00745     public function getTop5ArticleList()
00746     {
00747         if ( $this->_aTop5ArticleList === null ) {
00748             $this->_aTop5ArticleList = false;
00749             $myConfig = $this->getConfig();
00750             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00751                 // top 5 articles
00752                 $oArtList = oxNew( 'oxarticlelist' );
00753                 $oArtList->loadTop5Articles();
00754                 if ( $oArtList->count() ) {
00755                     $this->_aTop5ArticleList = $oArtList;
00756                 }
00757             }
00758         }
00759         return $this->_aTop5ArticleList;
00760     }
00761 
00767     public function getBargainArticleList()
00768     {
00769         if ( $this->_aBargainArticleList === null ) {
00770             $this->_aBargainArticleList = array();
00771             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00772                 $oArtList = oxNew( 'oxarticlelist' );
00773                 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00774                 if ( $oArtList->count() ) {
00775                     $this->_aBargainArticleList = $oArtList;
00776                 }
00777             }
00778         }
00779         return $this->_aBargainArticleList;
00780     }
00781 
00787     public function getActiveCategory()
00788     {
00789         return $this->getActCategory();
00790     }
00791 
00792 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5