OXID eShop CE  4.9.9
 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  // redirecting to first page in case requested page does not exist
234  if ($iPageCnt && (($iPageCnt - 1) < $this->getActPage())) {
235  oxRegistry::getUtils()->redirect($this->getActiveCategory()->getLink(), false);
236  }
237  }
238 
243  protected function _processListArticles()
244  {
245  if ($aArtList = $this->getArticleList()) {
246  $iLinkType = $this->_getProductLinkType();
247  $sAddDynParams = $this->getAddUrlParams();
248  $sAddSeoParams = $this->getAddSeoUrlParams();
249 
250  foreach ($aArtList as $oArticle) {
251  $oArticle->setLinkType($iLinkType);
252 
253  // appending dynamic urls
254  if ($sAddDynParams) {
255  $oArticle->appendStdLink($sAddDynParams);
256  }
257 
258  // appending seo urls
259  if ($sAddSeoParams) {
260  $oArticle->appendLink($sAddSeoParams);
261  }
262  }
263  }
264  }
265 
266 
272  public function getAddUrlParams()
273  {
274  $sParams = parent::getAddUrlParams();
275  if (!oxRegistry::getUtils()->seoIsActive()) {
276  $iPgNr = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
277  if ($iPgNr > 0) {
278  $sParams .= ($sParams ? '&amp;' : '') . "pgNr={$iPgNr}";
279  }
280  }
281 
282  return $sParams;
283  }
284 
288  public function getAddSeoUrlParams()
289  {
290  }
291 
299  protected function _getProductLinkType()
300  {
301  $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
302  if (($oCat = $this->getActiveCategory()) && $oCat->isPriceCategory()) {
304  }
305 
306  return $iCatType;
307  }
308 
315  public function executefilter()
316  {
317  $iLang = oxRegistry::getLang()->getBaseLanguage();
318  // store this into session
319  $aFilter = oxRegistry::getConfig()->getRequestParameter('attrfilter', true);
320  $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
321 
322  if (!empty($aFilter)) {
323  $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
324  //fix for #2904 - if language will be changed attributes of this category will be deleted from session
325  //and new filters for active language set.
326  $aSessionFilter[$sActCat] = null;
327  $aSessionFilter[$sActCat][$iLang] = $aFilter;
328  oxRegistry::getSession()->setVariable('session_attrfilter', $aSessionFilter);
329  }
330  }
331 
339  protected function _loadArticles($oCategory)
340  {
341  $myConfig = $this->getConfig();
342 
343  $iNrofCatArticles = (int) $myConfig->getConfigParam('iNrofCatArticles');
344  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
345 
346  // load only articles which we show on screen
347  $oArtList = oxNew('oxarticlelist');
348  $oArtList->setSqlLimit($iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles);
349  $oArtList->setCustomSorting($this->getSortingSql($this->getSortIdent()));
350 
351  if ($oCategory->isPriceCategory()) {
352  $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
353  $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
354 
355  $this->_iAllArtCnt = $oArtList->loadPriceArticles($dPriceFrom, $dPriceTo, $oCategory);
356  } else {
357  $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
358 
359  $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
360  $this->_iAllArtCnt = $oArtList->loadCategoryArticles($sActCat, $aSessionFilter);
361  }
362 
363  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
364 
365  return $oArtList;
366  }
367 
373  public function getActPage()
374  {
375  return $this->_getRequestPageNr();
376  }
377 
386  protected function _getRequestPageNr()
387  {
388  return parent::getActPage();
389  }
390 
396  protected function _getListDisplayType()
397  {
398  $sListDisplayType = oxRegistry::getSession()->getVariable('ldtype');
399 
400  if (is_null($sListDisplayType)) {
401  $sListDisplayType = oxRegistry::getConfig()->getConfigParam('sDefaultListDisplayType');
402  }
403 
404  return $sListDisplayType;
405  }
406 
412  protected function _getSeoObjectId()
413  {
414  if (($oCategory = $this->getActiveCategory())) {
415  return $oCategory->getId();
416  }
417  }
418 
424  protected function _getCatPathString()
425  {
426  if ($this->_sCatPathString === null) {
427 
428  // marking as already set
429  $this->_sCatPathString = false;
430 
431  //fetching category path
432  if (is_array($aPath = $this->getCatTreePath())) {
433 
434  $oStr = getStr();
435  $this->_sCatPathString = '';
436  foreach ($aPath as $oCat) {
437  if ($this->_sCatPathString) {
438  $this->_sCatPathString .= ', ';
439  }
440  $this->_sCatPathString .= $oStr->strtolower($oCat->oxcategories__oxtitle->value);
441  }
442  }
443  }
444 
445  return $this->_sCatPathString;
446  }
447 
457  protected function _prepareMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
458  {
459  $sDescription = '';
460  // appending parent title
461  if ($oCategory = $this->getActiveCategory()) {
462  if (($oParent = $oCategory->getParentCategory())) {
463  $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
464  }
465 
466  // adding category title
467  $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
468  }
469 
470  // and final component ..
471  //changed for #2776
472  if (($sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value)) {
473  $sDescription .= " {$sSuffix}";
474  }
475 
476  // making safe for output
477  $sDescription = getStr()->html_entity_decode($sDescription);
478  $sDescription = getStr()->strip_tags($sDescription);
479  $sDescription = getStr()->cleanStr($sDescription);
480  $sDescription = getStr()->htmlspecialchars($sDescription);
481 
482  return trim($sDescription);
483  }
484 
490  public function getMetaDescription()
491  {
492  $sMeta = parent::getMetaDescription();
493 
494  if ($sTitlePageSuffix = $this->getTitlePageSuffix()) {
495  if ($sMeta) {
496  $sMeta .= ", ";
497  }
498  $sMeta .= $sTitlePageSuffix;
499  }
500 
501  return $sMeta;
502  }
503 
516  protected function _collectMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
517  {
518  //formatting description tag
519  $oCategory = $this->getActiveCategory();
520 
521  $sAddText = (($oCategory instanceof oxCategory)) ? trim($oCategory->getLongDesc()) : '';
522 
523  $aArticleList = $this->getArticleList();
524  if (!$sAddText && count($aArticleList)) {
525  foreach ($aArticleList as $oArticle) {
526  if ($sAddText) {
527  $sAddText .= ', ';
528  }
529  $sAddText .= $oArticle->oxarticles__oxtitle->value;
530  }
531  }
532 
533  if (!$sMeta) {
534  $sMeta = trim($this->_getCatPathString());
535  }
536 
537  if ($sMeta) {
538  $sMeta = "{$sMeta} - {$sAddText}";
539  } else {
540  $sMeta = $sAddText;
541  }
542 
543  return parent::_prepareMetaDescription($sMeta, $iLength, $blDescTag);
544  }
545 
554  protected function _prepareMetaKeyword($sKeywords, $blRemoveDuplicatedWords = true)
555  {
556  $sKeywords = '';
557  if (($oCategory = $this->getActiveCategory())) {
558  $aKeywords = array();
559 
560  if ($oCatTree = $this->getCategoryTree()) {
561  foreach ($oCatTree->getPath() as $oCat) {
562  $aKeywords[] = trim($oCat->oxcategories__oxtitle->value);
563  }
564  }
565 
566  if (count($aKeywords) > 0) {
567  $sKeywords = implode(", ", $aKeywords);
568  }
569 
570  $aSubCats = $oCategory->getSubCats();
571  if (is_array($aSubCats)) {
572  foreach ($aSubCats as $oSubCat) {
573  $sKeywords .= ', ' . $oSubCat->oxcategories__oxtitle->value;
574  }
575  }
576  }
577 
578  $sKeywords = parent::_prepareMetaDescription($sKeywords, -1, $blRemoveDuplicatedWords);
579 
580  return trim($sKeywords);
581  }
582 
591  protected function _collectMetaKeyword($sKeywords)
592  {
593  $iMaxTextLength = 60;
594  $sText = '';
595 
596  if (count($aArticleList = $this->getArticleList())) {
597  $oStr = getStr();
598  foreach ($aArticleList as $oProduct) {
599  $sDesc = $oStr->strip_tags(trim($oStr->strtolower($oProduct->getLongDescription()->value)));
600 
601  //removing dots from string (they are not cleaned up during general string cleanup)
602  $sDesc = $oStr->preg_replace("/\./", " ", $sDesc);
603 
604  if ($oStr->strlen($sDesc) > $iMaxTextLength) {
605  $sMidText = $oStr->substr($sDesc, 0, $iMaxTextLength);
606  $sDesc = $oStr->substr(
607  $sMidText,
608  0,
609  ($oStr->strlen($sMidText) - $oStr->strpos(strrev($sMidText), ' '))
610  );
611  }
612  if ($sText) {
613  $sText .= ', ';
614  }
615  $sText .= $sDesc;
616  }
617  }
618 
619  if (!$sKeywords) {
620  $sKeywords = $this->_getCatPathString();
621  }
622 
623  if ($sKeywords) {
624  $sText = "{$sKeywords}, {$sText}";
625  }
626 
627  return parent::_prepareMetaKeyword($sText);
628  }
629 
637  public function getTemplateName()
638  {
639  // assign template name
640  if (($sTplName = basename(oxRegistry::getConfig()->getRequestParameter('tpl')))) {
641  $this->_sThisTemplate = 'custom/' . $sTplName;
642  } elseif (($oCategory = $this->getActiveCategory()) && $oCategory->oxcategories__oxtemplate->value) {
643  $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
644  }
645 
646  return $this->_sThisTemplate;
647  }
648 
658  protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
659  {
660  if (oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory())) {
661  if ($iPage) {
662  // only if page number > 0
663  $sUrl = $oCategory->getBaseSeoLink($iLang, $iPage);
664  }
665  } else {
666  $sUrl = parent::_addPageNrParam($sUrl, $iPage, $iLang);
667  }
668 
669  return $sUrl;
670  }
671 
677  protected function _isActCategory()
678  {
679  return $this->_blIsCat;
680  }
681 
687  public function generatePageNavigationUrl()
688  {
689  if ((oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory()))) {
690  return $oCategory->getLink();
691  }
692 
694  }
695 
701  public function getDefaultSorting()
702  {
703  $aSorting = parent::getDefaultSorting();
704 
705  $oCategory = $this->getActiveCategory();
706  if ($oCategory && $oCategory instanceof oxCategory) {
707  if ($sDefaultSorting = $oCategory->getDefaultSorting()) {
708  $sArticleTable = getViewName('oxarticles');
709  $sSortBy = $sArticleTable . '.' . $sDefaultSorting;
710  $sSortDir = ($oCategory->getDefaultSortingMode()) ? "desc" : "asc";
711  $aSorting = array('sortby' => $sSortBy, 'sortdir' => $sSortDir);
712  }
713  }
714 
715  return $aSorting;
716  }
717 
718 
724  public function getTitleSuffix()
725  {
726  if ($this->getActiveCategory()->oxcategories__oxshowsuffix->value) {
727  return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
728  }
729  }
730 
736  public function getTitlePageSuffix()
737  {
738  if (($iPage = $this->getActPage())) {
739  return oxRegistry::getLang()->translateString('PAGE') . " " . ($iPage + 1);
740  }
741  }
742 
751  protected function _getSubject($iLang)
752  {
753  return $this->getActiveCategory();
754  }
755 
762  public function getAttributes()
763  {
764  $this->_aAttributes = false;
765 
766  if (($oCategory = $this->getActiveCategory())) {
767  $aAttributes = $oCategory->getAttributes();
768  if (count($aAttributes)) {
769  $this->_aAttributes = $aAttributes;
770  }
771  }
772 
773  return $this->_aAttributes;
774  }
775 
781  public function getArticleList()
782  {
783  if ($this->_aArticleList === null) {
784  if ($oCategory = $this->getActiveCategory()) {
785  $aArticleList = $this->_loadArticles($oCategory);
786  if (count($aArticleList)) {
787  $this->_aArticleList = $aArticleList;
788  }
789  }
790  }
791 
792  return $this->_aArticleList;
793  }
794 
800  public function getArticleCount()
801  {
802  return $this->_iAllArtCnt;
803  }
804 
810  public function getSimilarRecommListIds()
811  {
812  if ($this->_aSimilarRecommListIds === null) {
813  $this->_aSimilarRecommListIds = false;
814 
815  if ($aCatArtList = $this->getArticleList()) {
816  $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
817  }
818  }
819 
821  }
822 
828  public function getCatTreePath()
829  {
830  if ($this->_sCatTreePath === null) {
831  $this->_sCatTreePath = false;
832  // category path
833  if ($oCatTree = $this->getCategoryTree()) {
834  $this->_sCatTreePath = $oCatTree->getPath();
835  }
836  }
837 
838  return $this->_sCatTreePath;
839  }
840 
846  public function getTreePath()
847  {
848  if ($oCatTree = $this->getCategoryTree()) {
849  return $oCatTree->getPath();
850  }
851  }
852 
858  public function getBreadCrumb()
859  {
860  $aPaths = array();
861 
862  if ('oxmore' == oxRegistry::getConfig()->getRequestParameter('cnid')) {
863  $aPath = array();
864  $aPath['title'] = oxRegistry::getLang()->translateString(
865  'CATEGORY_OVERVIEW',
866  oxRegistry::getLang()->getBaseLanguage(),
867  false
868  );
869  $aPath['link'] = $this->getLink();
870 
871  $aPaths[] = $aPath;
872 
873  return $aPaths;
874  }
875 
876  if (($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath())) {
877  foreach ($oCatPath as $oCat) {
878  $aCatPath = array();
879 
880  $aCatPath['link'] = $oCat->getLink();
881  $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
882 
883  $aPaths[] = $aCatPath;
884  }
885  }
886 
887  return $aPaths;
888  }
889 
896  public function hasVisibleSubCats()
897  {
898  if ($this->_blHasVisibleSubCats === null) {
899  $this->_blHasVisibleSubCats = false;
900  if ($oClickCat = $this->getActiveCategory()) {
901  $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
902  }
903  }
904 
906  }
907 
913  public function getSubCatList()
914  {
915  if ($this->_aSubCatList === null) {
916  $this->_aSubCatList = array();
917  if ($oClickCat = $this->getActiveCategory()) {
918  $this->_aSubCatList = $oClickCat->getSubCats();
919  }
920  }
921 
922  return $this->_aSubCatList;
923  }
924 
930  public function getPageNavigation()
931  {
932  if ($this->_oPageNavigation === null) {
933  $this->_oPageNavigation = $this->generatePageNavigation();
934  }
935 
937  }
938 
944  public function getTitle()
945  {
946  if ($this->_sCatTitle === null) {
947  $this->_sCatTitle = false;
948  if ($this->getCategoryId() == 'oxmore') {
949  $oLang = oxRegistry::getLang();
950  $iBaseLanguage = $oLang->getBaseLanguage();
951 
952  $this->_sCatTitle = $oLang->translateString('CATEGORY_OVERVIEW', $iBaseLanguage, false);
953  } elseif (($oCategory = $this->getActiveCategory())) {
954  $sTitleField = 'oxcategories__oxtitle';
955  $this->_sCatTitle = $oCategory->$sTitleField->value;
956  }
957  }
958 
959  return $this->_sCatTitle;
960  }
961 
967  public function getBargainArticleList()
968  {
969  if ($this->_aBargainArticleList === null) {
970  $this->_aBargainArticleList = array();
971  if ($this->getConfig()->getConfigParam('bl_perfLoadAktion') && $this->_isActCategory()) {
972  $oArtList = oxNew('oxarticlelist');
973  $oArtList->loadActionArticles('OXBARGAIN');
974  if ($oArtList->count()) {
975  $this->_aBargainArticleList = $oArtList;
976  }
977  }
978  }
979 
981  }
982 
988  public function getActiveCategory()
989  {
990  if ($this->_oActCategory === null) {
991  $this->_oActCategory = false;
992  $oCategory = oxNew('oxCategory');
993  if ($oCategory->load($this->getCategoryId())) {
994  $this->_oActCategory = $oCategory;
995  }
996  }
997 
998  return $this->_oActCategory;
999  }
1000 
1006  public function getCanonicalUrl()
1007  {
1008  if (($oCategory = $this->getActiveCategory())) {
1009  $oUtils = oxRegistry::get("oxUtilsUrl");
1010  if (oxRegistry::getUtils()->seoIsActive()) {
1011  $sUrl = $oUtils->prepareCanonicalUrl(
1012  $oCategory->getBaseSeoLink($oCategory->getLanguage(), $this->getActPage())
1013  );
1014  } else {
1015  $sUrl = $oUtils->prepareCanonicalUrl(
1016  $oCategory->getBaseStdLink($oCategory->getLanguage(), $this->getActPage())
1017  );
1018  }
1019 
1020  return $sUrl;
1021  }
1022  }
1023 
1029  public function canSelectDisplayType()
1030  {
1031  return $this->getConfig()->getConfigParam('blShowListDisplayType');
1032  }
1033 
1039  public function getPageCount()
1040  {
1041  return $this->_iCntPages;
1042  }
1043 }