OXID eShop CE  4.9.11
 All Classes Files Functions Variables Pages
alist.php
Go to the documentation of this file.
1 <?php
2 
9 class aList extends oxUBase
10 {
11 
17  protected $_iAllArtCnt = 0;
18 
24  protected $_iCntPages = 0;
25 
31  protected $_sThisTemplate = 'page/list/list.tpl';
32 
38  protected $_sThisMoreTemplate = 'page/list/morecategories.tpl';
39 
45  protected $_sCatPathString = null;
46 
52  protected $_blShowSorting = true;
53 
59  protected $_aAttributes = null;
60 
66  protected $_aCatArtList = null;
67 
73  protected $_blHasVisibleSubCats = null;
74 
80  protected $_aSubCatList = null;
81 
87  protected $_oPageNavigation = null;
88 
94  protected $_blIsCat = null;
95 
101  protected $_oRecommList = null;
102 
108  protected $_sCatTitle = null;
109 
115  protected $_blShowTagCloud = true;
116 
122  protected $_blBargainAction = false;
123 
129  protected $_aSimilarRecommListIds = null;
130 
131 
138  public function getViewId()
139  {
140  if (!isset($this->_sViewId)) {
141  $sCatId = oxRegistry::getConfig()->getRequestParameter('cnid');
142  $iActPage = $this->getActPage();
143  $iArtPerPage = oxRegistry::getSession()->getVariable('_artperpage');
144  $sListDisplayType = $this->_getListDisplayType();
145  $sParentViewId = parent::getViewId();
146 
147  // shorten it
148  $this->_sViewId = md5(
149  $sParentViewId . '|' . $sCatId . '|' . $iActPage . '|' . $iArtPerPage . '|' . $sListDisplayType
150  );
151 
152  }
153 
154  return $this->_sViewId;
155  }
156 
169  public function render()
170  {
171  $myConfig = $this->getConfig();
172 
173  $oCategory = null;
174  $blContinue = true;
175  $this->_blIsCat = false;
176 
177  // A. checking for fake "more" category
178  if ('oxmore' == $myConfig->getRequestParameter('cnid')) {
179  // overriding some standard value and parameters
180  $this->_sThisTemplate = $this->_sThisMoreTemplate;
181  $oCategory = oxNew('oxcategory');
182  $oCategory->oxcategories__oxactive = new oxField(1, oxField::T_RAW);
183  $this->setActiveCategory($oCategory);
184 
185  $this->_blShowTagCloud = true;
186 
187  } elseif (($oCategory = $this->getActiveCategory())) {
188  $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
189  $this->_blIsCat = true;
190  $this->_blBargainAction = true;
191  }
192 
193 
194  // category is inactive ?
195  if (!$blContinue || !$oCategory) {
196  oxRegistry::getUtils()->redirect($myConfig->getShopURL() . 'index.php', true, 302);
197  }
198 
199  $oCat = $this->getActiveCategory();
200  if ($oCat && $myConfig->getConfigParam('bl_rssCategories')) {
201  $oRss = oxNew('oxrssfeed');
202  $this->addRssFeed(
203  $oRss->getCategoryArticlesTitle($oCat),
204  $oRss->getCategoryArticlesUrl($oCat),
205  'activeCategory'
206  );
207  }
208 
209  //checking if actual pages count does not exceed real articles page count
210  $this->getArticleList();
211 
212  if ($this->_blIsCat) {
213  $this->_checkRequestedPage();
214  }
215 
216  parent::render();
217 
218  // processing list articles
219  $this->_processListArticles();
220 
221  return $this->getTemplateName();
222  }
223 
230  protected function _checkRequestedPage()
231  {
232  $iPageCnt = $this->getPageCount();
233  $iCurrentPageNumber = $this->getActPage();
234  if ($iCurrentPageNumber && ($iPageCnt - 1) < $iCurrentPageNumber) {
235  // redirecting to first page in case requested page does not exist
236  if ($iPageCnt) {
237  oxRegistry::getUtils()->redirect($this->getActiveCategory()->getLink(), false);
238  } else {
239  // display error if category has no products, but page number is entered
240  $this->_iActPage = 0;
241  oxRegistry::getUtils()->handlePageNotFoundError($this->getActiveCategory()->getLink());
242  }
243  }
244  }
245 
250  protected function _processListArticles()
251  {
252  if ($aArtList = $this->getArticleList()) {
253  $iLinkType = $this->_getProductLinkType();
254  $sAddDynParams = $this->getAddUrlParams();
255  $sAddSeoParams = $this->getAddSeoUrlParams();
256 
257  foreach ($aArtList as $oArticle) {
258  $oArticle->setLinkType($iLinkType);
259 
260  // appending dynamic urls
261  if ($sAddDynParams) {
262  $oArticle->appendStdLink($sAddDynParams);
263  }
264 
265  // appending seo urls
266  if ($sAddSeoParams) {
267  $oArticle->appendLink($sAddSeoParams);
268  }
269  }
270  }
271  }
272 
273 
279  public function getAddUrlParams()
280  {
281  $sParams = parent::getAddUrlParams();
282  if (!oxRegistry::getUtils()->seoIsActive()) {
283  $iPgNr = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
284  if ($iPgNr > 0) {
285  $sParams .= ($sParams ? '&amp;' : '') . "pgNr={$iPgNr}";
286  }
287  }
288 
289  return $sParams;
290  }
291 
295  public function getAddSeoUrlParams()
296  {
297  }
298 
306  protected function _getProductLinkType()
307  {
308  $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
309  if (($oCat = $this->getActiveCategory()) && $oCat->isPriceCategory()) {
311  }
312 
313  return $iCatType;
314  }
315 
322  public function executefilter()
323  {
324  $iLang = oxRegistry::getLang()->getBaseLanguage();
325  // store this into session
326  $aFilter = oxRegistry::getConfig()->getRequestParameter('attrfilter', true);
327  $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
328 
329  if (!empty($aFilter)) {
330  $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
331  //fix for #2904 - if language will be changed attributes of this category will be deleted from session
332  //and new filters for active language set.
333  $aSessionFilter[$sActCat] = null;
334  $aSessionFilter[$sActCat][$iLang] = $aFilter;
335  oxRegistry::getSession()->setVariable('session_attrfilter', $aSessionFilter);
336  }
337  }
338 
346  protected function _loadArticles($oCategory)
347  {
348  $myConfig = $this->getConfig();
349 
350  $iNrofCatArticles = (int) $myConfig->getConfigParam('iNrofCatArticles');
351  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
352 
353  // load only articles which we show on screen
354  $oArtList = oxNew('oxarticlelist');
355  $oArtList->setSqlLimit($iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles);
356  $oArtList->setCustomSorting($this->getSortingSql($this->getSortIdent()));
357 
358  if ($oCategory->isPriceCategory()) {
359  $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
360  $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
361 
362  $this->_iAllArtCnt = $oArtList->loadPriceArticles($dPriceFrom, $dPriceTo, $oCategory);
363  } else {
364  $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
365 
366  $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
367  $this->_iAllArtCnt = $oArtList->loadCategoryArticles($sActCat, $aSessionFilter);
368  }
369 
370  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
371 
372  return $oArtList;
373  }
374 
380  public function getActPage()
381  {
382  //Fake oxmore category has no subpages so we can set the page number to zero
383  if ('oxmore' == oxRegistry::getConfig()->getRequestParameter('cnid')) {
384  return 0;
385  }
386 
387  return $this->_getRequestPageNr();
388  }
389 
398  protected function _getRequestPageNr()
399  {
400  return parent::getActPage();
401  }
402 
408  protected function _getListDisplayType()
409  {
410  $sListDisplayType = oxRegistry::getSession()->getVariable('ldtype');
411 
412  if (is_null($sListDisplayType)) {
413  $sListDisplayType = oxRegistry::getConfig()->getConfigParam('sDefaultListDisplayType');
414  }
415 
416  return $sListDisplayType;
417  }
418 
424  protected function _getSeoObjectId()
425  {
426  if (($oCategory = $this->getActiveCategory())) {
427  return $oCategory->getId();
428  }
429  }
430 
436  protected function _getCatPathString()
437  {
438  if ($this->_sCatPathString === null) {
439 
440  // marking as already set
441  $this->_sCatPathString = false;
442 
443  //fetching category path
444  if (is_array($aPath = $this->getCatTreePath())) {
445 
446  $oStr = getStr();
447  $this->_sCatPathString = '';
448  foreach ($aPath as $oCat) {
449  if ($this->_sCatPathString) {
450  $this->_sCatPathString .= ', ';
451  }
452  $this->_sCatPathString .= $oStr->strtolower($oCat->oxcategories__oxtitle->value);
453  }
454  }
455  }
456 
457  return $this->_sCatPathString;
458  }
459 
469  protected function _prepareMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
470  {
471  $sDescription = '';
472  // appending parent title
473  if ($oCategory = $this->getActiveCategory()) {
474  if (($oParent = $oCategory->getParentCategory())) {
475  $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
476  }
477 
478  // adding category title
479  $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
480  }
481 
482  // and final component ..
483  //changed for #2776
484  if (($sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value)) {
485  $sDescription .= " {$sSuffix}";
486  }
487 
488  // making safe for output
489  $sDescription = getStr()->html_entity_decode($sDescription);
490  $sDescription = getStr()->strip_tags($sDescription);
491  $sDescription = getStr()->cleanStr($sDescription);
492  $sDescription = getStr()->htmlspecialchars($sDescription);
493 
494  return trim($sDescription);
495  }
496 
502  public function getMetaDescription()
503  {
504  $sMeta = parent::getMetaDescription();
505 
506  if ($sTitlePageSuffix = $this->getTitlePageSuffix()) {
507  if ($sMeta) {
508  $sMeta .= ", ";
509  }
510  $sMeta .= $sTitlePageSuffix;
511  }
512 
513  return $sMeta;
514  }
515 
528  protected function _collectMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
529  {
530  //formatting description tag
531  $oCategory = $this->getActiveCategory();
532 
533  $sAddText = (($oCategory instanceof oxCategory)) ? trim($oCategory->getLongDesc()) : '';
534 
535  $aArticleList = $this->getArticleList();
536  if (!$sAddText && count($aArticleList)) {
537  foreach ($aArticleList as $oArticle) {
538  if ($sAddText) {
539  $sAddText .= ', ';
540  }
541  $sAddText .= $oArticle->oxarticles__oxtitle->value;
542  }
543  }
544 
545  if (!$sMeta) {
546  $sMeta = trim($this->_getCatPathString());
547  }
548 
549  if ($sMeta) {
550  $sMeta = "{$sMeta} - {$sAddText}";
551  } else {
552  $sMeta = $sAddText;
553  }
554 
555  return parent::_prepareMetaDescription($sMeta, $iLength, $blDescTag);
556  }
557 
566  protected function _prepareMetaKeyword($sKeywords, $blRemoveDuplicatedWords = true)
567  {
568  $sKeywords = '';
569  if (($oCategory = $this->getActiveCategory())) {
570  $aKeywords = array();
571 
572  if ($oCatTree = $this->getCategoryTree()) {
573  foreach ($oCatTree->getPath() as $oCat) {
574  $aKeywords[] = trim($oCat->oxcategories__oxtitle->value);
575  }
576  }
577 
578  if (count($aKeywords) > 0) {
579  $sKeywords = implode(", ", $aKeywords);
580  }
581 
582  $aSubCats = $oCategory->getSubCats();
583  if (is_array($aSubCats)) {
584  foreach ($aSubCats as $oSubCat) {
585  $sKeywords .= ', ' . $oSubCat->oxcategories__oxtitle->value;
586  }
587  }
588  }
589 
590  $sKeywords = parent::_prepareMetaDescription($sKeywords, -1, $blRemoveDuplicatedWords);
591 
592  return trim($sKeywords);
593  }
594 
603  protected function _collectMetaKeyword($sKeywords)
604  {
605  $iMaxTextLength = 60;
606  $sText = '';
607 
608  if (count($aArticleList = $this->getArticleList())) {
609  $oStr = getStr();
610  foreach ($aArticleList as $oProduct) {
611  $sDesc = $oStr->strip_tags(trim($oStr->strtolower($oProduct->getLongDescription()->value)));
612 
613  //removing dots from string (they are not cleaned up during general string cleanup)
614  $sDesc = $oStr->preg_replace("/\./", " ", $sDesc);
615 
616  if ($oStr->strlen($sDesc) > $iMaxTextLength) {
617  $sMidText = $oStr->substr($sDesc, 0, $iMaxTextLength);
618  $sDesc = $oStr->substr(
619  $sMidText,
620  0,
621  ($oStr->strlen($sMidText) - $oStr->strpos(strrev($sMidText), ' '))
622  );
623  }
624  if ($sText) {
625  $sText .= ', ';
626  }
627  $sText .= $sDesc;
628  }
629  }
630 
631  if (!$sKeywords) {
632  $sKeywords = $this->_getCatPathString();
633  }
634 
635  if ($sKeywords) {
636  $sText = "{$sKeywords}, {$sText}";
637  }
638 
639  return parent::_prepareMetaKeyword($sText);
640  }
641 
649  public function getTemplateName()
650  {
651  // assign template name
652  if (($sTplName = basename(oxRegistry::getConfig()->getRequestParameter('tpl')))) {
653  $this->_sThisTemplate = 'custom/' . $sTplName;
654  } elseif (($oCategory = $this->getActiveCategory()) && $oCategory->oxcategories__oxtemplate->value) {
655  $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
656  }
657 
658  return $this->_sThisTemplate;
659  }
660 
670  protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
671  {
672  if (oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory())) {
673  if ($iPage) {
674  // only if page number > 0
675  $sUrl = $oCategory->getBaseSeoLink($iLang, $iPage);
676  }
677  } else {
678  $sUrl = parent::_addPageNrParam($sUrl, $iPage, $iLang);
679  }
680 
681  return $sUrl;
682  }
683 
689  protected function _isActCategory()
690  {
691  return $this->_blIsCat;
692  }
693 
699  public function generatePageNavigationUrl()
700  {
701  if ((oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory()))) {
702  return $oCategory->getLink();
703  }
704 
706  }
707 
713  public function getDefaultSorting()
714  {
715  $aSorting = parent::getDefaultSorting();
716 
717  $oCategory = $this->getActiveCategory();
718  if ($oCategory && $oCategory instanceof oxCategory) {
719  if ($sDefaultSorting = $oCategory->getDefaultSorting()) {
720  $sArticleTable = getViewName('oxarticles');
721  $sSortBy = $sArticleTable . '.' . $sDefaultSorting;
722  $sSortDir = ($oCategory->getDefaultSortingMode()) ? "desc" : "asc";
723  $aSorting = array('sortby' => $sSortBy, 'sortdir' => $sSortDir);
724  }
725  }
726 
727  return $aSorting;
728  }
729 
730 
736  public function getTitleSuffix()
737  {
738  if ($this->getActiveCategory()->oxcategories__oxshowsuffix->value) {
739  return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
740  }
741  }
742 
748  public function getTitlePageSuffix()
749  {
750  if (($iPage = $this->getActPage())) {
751  return oxRegistry::getLang()->translateString('PAGE') . " " . ($iPage + 1);
752  }
753  }
754 
763  protected function _getSubject($iLang)
764  {
765  return $this->getActiveCategory();
766  }
767 
774  public function getAttributes()
775  {
776  $this->_aAttributes = false;
777 
778  if (($oCategory = $this->getActiveCategory())) {
779  $aAttributes = $oCategory->getAttributes();
780  if (count($aAttributes)) {
781  $this->_aAttributes = $aAttributes;
782  }
783  }
784 
785  return $this->_aAttributes;
786  }
787 
793  public function getArticleList()
794  {
795  if ($this->_aArticleList === null) {
796  if ($oCategory = $this->getActiveCategory()) {
797  $aArticleList = $this->_loadArticles($oCategory);
798  if (count($aArticleList)) {
799  $this->_aArticleList = $aArticleList;
800  }
801  }
802  }
803 
804  return $this->_aArticleList;
805  }
806 
812  public function getArticleCount()
813  {
814  return $this->_iAllArtCnt;
815  }
816 
822  public function getSimilarRecommListIds()
823  {
824  if ($this->_aSimilarRecommListIds === null) {
825  $this->_aSimilarRecommListIds = false;
826 
827  if ($aCatArtList = $this->getArticleList()) {
828  $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
829  }
830  }
831 
833  }
834 
840  public function getCatTreePath()
841  {
842  if ($this->_sCatTreePath === null) {
843  $this->_sCatTreePath = false;
844  // category path
845  if ($oCatTree = $this->getCategoryTree()) {
846  $this->_sCatTreePath = $oCatTree->getPath();
847  }
848  }
849 
850  return $this->_sCatTreePath;
851  }
852 
858  public function getTreePath()
859  {
860  if ($oCatTree = $this->getCategoryTree()) {
861  return $oCatTree->getPath();
862  }
863  }
864 
870  public function getBreadCrumb()
871  {
872  $aPaths = array();
873 
874  if ('oxmore' == oxRegistry::getConfig()->getRequestParameter('cnid')) {
875  $aPath = array();
876  $aPath['title'] = oxRegistry::getLang()->translateString(
877  'CATEGORY_OVERVIEW',
878  oxRegistry::getLang()->getBaseLanguage(),
879  false
880  );
881  $aPath['link'] = $this->getLink();
882 
883  $aPaths[] = $aPath;
884 
885  return $aPaths;
886  }
887 
888  if (($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath())) {
889  foreach ($oCatPath as $oCat) {
890  $aCatPath = array();
891 
892  $aCatPath['link'] = $oCat->getLink();
893  $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
894 
895  $aPaths[] = $aCatPath;
896  }
897  }
898 
899  return $aPaths;
900  }
901 
908  public function hasVisibleSubCats()
909  {
910  if ($this->_blHasVisibleSubCats === null) {
911  $this->_blHasVisibleSubCats = false;
912  if ($oClickCat = $this->getActiveCategory()) {
913  $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
914  }
915  }
916 
918  }
919 
925  public function getSubCatList()
926  {
927  if ($this->_aSubCatList === null) {
928  $this->_aSubCatList = array();
929  if ($oClickCat = $this->getActiveCategory()) {
930  $this->_aSubCatList = $oClickCat->getSubCats();
931  }
932  }
933 
934  return $this->_aSubCatList;
935  }
936 
942  public function getPageNavigation()
943  {
944  if ($this->_oPageNavigation === null) {
945  $this->_oPageNavigation = $this->generatePageNavigation();
946  }
947 
949  }
950 
956  public function getTitle()
957  {
958  if ($this->_sCatTitle === null) {
959  $this->_sCatTitle = false;
960  if ($this->getCategoryId() == 'oxmore') {
961  $oLang = oxRegistry::getLang();
962  $iBaseLanguage = $oLang->getBaseLanguage();
963 
964  $this->_sCatTitle = $oLang->translateString('CATEGORY_OVERVIEW', $iBaseLanguage, false);
965  } elseif (($oCategory = $this->getActiveCategory())) {
966  $sTitleField = 'oxcategories__oxtitle';
967  $this->_sCatTitle = $oCategory->$sTitleField->value;
968  }
969  }
970 
971  return $this->_sCatTitle;
972  }
973 
979  public function getBargainArticleList()
980  {
981  if ($this->_aBargainArticleList === null) {
982  $this->_aBargainArticleList = array();
983  if ($this->getConfig()->getConfigParam('bl_perfLoadAktion') && $this->_isActCategory()) {
984  $oArtList = oxNew('oxarticlelist');
985  $oArtList->loadActionArticles('OXBARGAIN');
986  if ($oArtList->count()) {
987  $this->_aBargainArticleList = $oArtList;
988  }
989  }
990  }
991 
993  }
994 
1000  public function getActiveCategory()
1001  {
1002  if ($this->_oActCategory === null) {
1003  $this->_oActCategory = false;
1004  $oCategory = oxNew('oxCategory');
1005  if ($oCategory->load($this->getCategoryId())) {
1006  $this->_oActCategory = $oCategory;
1007  }
1008  }
1009 
1010  return $this->_oActCategory;
1011  }
1012 
1018  public function getCanonicalUrl()
1019  {
1020  if (($oCategory = $this->getActiveCategory())) {
1021  $oUtils = oxRegistry::get("oxUtilsUrl");
1022  if (oxRegistry::getUtils()->seoIsActive()) {
1023  $sUrl = $oUtils->prepareCanonicalUrl(
1024  $oCategory->getBaseSeoLink($oCategory->getLanguage(), $this->getActPage())
1025  );
1026  } else {
1027  $sUrl = $oUtils->prepareCanonicalUrl(
1028  $oCategory->getBaseStdLink($oCategory->getLanguage(), $this->getActPage())
1029  );
1030  }
1031 
1032  return $sUrl;
1033  }
1034  }
1035 
1041  public function canSelectDisplayType()
1042  {
1043  return $this->getConfig()->getConfigParam('blShowListDisplayType');
1044  }
1045 
1051  public function getPageCount()
1052  {
1053  return $this->_iCntPages;
1054  }
1055 }