OXID eShop CE  4.10.6
 All Classes Namespaces 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 
103  protected $_oRecommList = null;
104 
110  protected $_sCatTitle = null;
111 
119  protected $_blShowTagCloud = true;
120 
126  protected $_blBargainAction = false;
127 
135  protected $_aSimilarRecommListIds = null;
136 
137 
144  public function getViewId()
145  {
146  if (!isset($this->_sViewId)) {
147  $sCatId = oxRegistry::getConfig()->getRequestParameter('cnid');
148  $iActPage = $this->getActPage();
149  $iArtPerPage = oxRegistry::getSession()->getVariable('_artperpage');
150  $sListDisplayType = $this->_getListDisplayType();
151  $sParentViewId = parent::getViewId();
152 
153  // shorten it
154  $this->_sViewId = md5(
155  $sParentViewId . '|' . $sCatId . '|' . $iActPage . '|' . $iArtPerPage . '|' . $sListDisplayType
156  );
157 
158  }
159 
160  return $this->_sViewId;
161  }
162 
175  public function render()
176  {
177  $myConfig = $this->getConfig();
178 
179  $oCategory = null;
180  $blContinue = true;
181  $this->_blIsCat = false;
182 
183  // A. checking for fake "more" category
184  if ('oxmore' == $myConfig->getRequestParameter('cnid')) {
185  // overriding some standard value and parameters
186  $this->_sThisTemplate = $this->_sThisMoreTemplate;
187  $oCategory = oxNew('oxcategory');
188  $oCategory->oxcategories__oxactive = new oxField(1, oxField::T_RAW);
189  $this->setActiveCategory($oCategory);
190 
191  $this->_blShowTagCloud = true;
192 
193  } elseif (($oCategory = $this->getActiveCategory())) {
194  $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
195  $this->_blIsCat = true;
196  $this->_blBargainAction = true;
197  }
198 
199 
200  // category is inactive ?
201  if (!$blContinue || !$oCategory) {
202  oxRegistry::getUtils()->redirect($myConfig->getShopURL() . 'index.php', true, 302);
203  }
204 
205  $oCat = $this->getActiveCategory();
206  if ($oCat && $myConfig->getConfigParam('bl_rssCategories')) {
207  $oRss = oxNew('oxrssfeed');
208  $this->addRssFeed(
209  $oRss->getCategoryArticlesTitle($oCat),
210  $oRss->getCategoryArticlesUrl($oCat),
211  'activeCategory'
212  );
213  }
214 
215  //checking if actual pages count does not exceed real articles page count
216  $this->getArticleList();
217 
218  if ($this->_blIsCat) {
219  $this->_checkRequestedPage();
220  }
221 
222  parent::render();
223 
224  // processing list articles
225  $this->_processListArticles();
226 
227  return $this->getTemplateName();
228  }
229 
236  protected function _checkRequestedPage()
237  {
238  $iPageCnt = $this->getPageCount();
239  $iCurrentPageNumber = $this->getActPage();
240  if ($iCurrentPageNumber && ($iPageCnt - 1) < $iCurrentPageNumber) {
241  // redirecting to first page in case requested page does not exist
242  if ($iPageCnt) {
243  oxRegistry::getUtils()->redirect($this->getActiveCategory()->getLink(), false);
244  } else {
245  // display error if category has no products, but page number is entered
246  $this->_iActPage = 0;
247  oxRegistry::getUtils()->handlePageNotFoundError($this->getActiveCategory()->getLink());
248  }
249  }
250  }
251 
256  protected function _processListArticles()
257  {
258  if ($aArtList = $this->getArticleList()) {
259  $iLinkType = $this->_getProductLinkType();
260  $sAddDynParams = $this->getAddUrlParams();
261  $sAddSeoParams = $this->getAddSeoUrlParams();
262 
263  foreach ($aArtList as $oArticle) {
264  $oArticle->setLinkType($iLinkType);
265 
266  // appending dynamic urls
267  if ($sAddDynParams) {
268  $oArticle->appendStdLink($sAddDynParams);
269  }
270 
271  // appending seo urls
272  if ($sAddSeoParams) {
273  $oArticle->appendLink($sAddSeoParams);
274  }
275  }
276  }
277  }
278 
279 
285  public function getAddUrlParams()
286  {
287  $sParams = parent::getAddUrlParams();
288  if (!oxRegistry::getUtils()->seoIsActive()) {
289  $iPgNr = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
290  if ($iPgNr > 0) {
291  $sParams .= ($sParams ? '&amp;' : '') . "pgNr={$iPgNr}";
292  }
293  }
294 
295  return $sParams;
296  }
297 
301  public function getAddSeoUrlParams()
302  {
303  }
304 
312  protected function _getProductLinkType()
313  {
314  $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
315  if (($oCat = $this->getActiveCategory()) && $oCat->isPriceCategory()) {
317  }
318 
319  return $iCatType;
320  }
321 
328  public function executefilter()
329  {
330  $iLang = oxRegistry::getLang()->getBaseLanguage();
331  // store this into session
332  $aFilter = oxRegistry::getConfig()->getRequestParameter('attrfilter', true);
333  $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
334 
335  if (!empty($aFilter)) {
336  $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
337  //fix for #2904 - if language will be changed attributes of this category will be deleted from session
338  //and new filters for active language set.
339  $aSessionFilter[$sActCat] = null;
340  $aSessionFilter[$sActCat][$iLang] = $aFilter;
341  oxRegistry::getSession()->setVariable('session_attrfilter', $aSessionFilter);
342  }
343  }
344 
352  protected function _loadArticles($oCategory)
353  {
354  $myConfig = $this->getConfig();
355 
356  $iNrofCatArticles = (int) $myConfig->getConfigParam('iNrofCatArticles');
357  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
358 
359  // load only articles which we show on screen
360  $oArtList = oxNew('oxarticlelist');
361  $oArtList->setSqlLimit($iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles);
362  $oArtList->setCustomSorting($this->getSortingSql($this->getSortIdent()));
363 
364  if ($oCategory->isPriceCategory()) {
365  $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
366  $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
367 
368  $this->_iAllArtCnt = $oArtList->loadPriceArticles($dPriceFrom, $dPriceTo, $oCategory);
369  } else {
370  $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
371 
372  $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
373  $this->_iAllArtCnt = $oArtList->loadCategoryArticles($sActCat, $aSessionFilter);
374  }
375 
376  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
377 
378  return $oArtList;
379  }
380 
386  public function getActPage()
387  {
388  //Fake oxmore category has no subpages so we can set the page number to zero
389  if ('oxmore' == oxRegistry::getConfig()->getRequestParameter('cnid')) {
390  return 0;
391  }
392 
393  return $this->_getRequestPageNr();
394  }
395 
404  protected function _getRequestPageNr()
405  {
406  return parent::getActPage();
407  }
408 
414  protected function _getListDisplayType()
415  {
416  $sListDisplayType = oxRegistry::getSession()->getVariable('ldtype');
417 
418  if (is_null($sListDisplayType)) {
419  $sListDisplayType = oxRegistry::getConfig()->getConfigParam('sDefaultListDisplayType');
420  }
421 
422  return $sListDisplayType;
423  }
424 
430  protected function _getSeoObjectId()
431  {
432  if (($oCategory = $this->getActiveCategory())) {
433  return $oCategory->getId();
434  }
435  }
436 
442  protected function _getCatPathString()
443  {
444  if ($this->_sCatPathString === null) {
445 
446  // marking as already set
447  $this->_sCatPathString = false;
448 
449  //fetching category path
450  if (is_array($aPath = $this->getCatTreePath())) {
451 
452  $oStr = getStr();
453  $this->_sCatPathString = '';
454  foreach ($aPath as $oCat) {
455  if ($this->_sCatPathString) {
456  $this->_sCatPathString .= ', ';
457  }
458  $this->_sCatPathString .= $oStr->strtolower($oCat->oxcategories__oxtitle->value);
459  }
460  }
461  }
462 
463  return $this->_sCatPathString;
464  }
465 
475  protected function _prepareMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
476  {
477  $sDescription = '';
478  // appending parent title
479  if ($oCategory = $this->getActiveCategory()) {
480  if (($oParent = $oCategory->getParentCategory())) {
481  $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
482  }
483 
484  // adding category title
485  $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
486  }
487 
488  // and final component ..
489  //changed for #2776
490  if (($sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value)) {
491  $sDescription .= " {$sSuffix}";
492  }
493 
494  // making safe for output
495  $sDescription = getStr()->html_entity_decode($sDescription);
496  $sDescription = getStr()->strip_tags($sDescription);
497  $sDescription = getStr()->cleanStr($sDescription);
498  $sDescription = getStr()->htmlspecialchars($sDescription);
499 
500  return trim($sDescription);
501  }
502 
508  public function getMetaDescription()
509  {
510  $sMeta = parent::getMetaDescription();
511 
512  if ($sTitlePageSuffix = $this->getTitlePageSuffix()) {
513  if ($sMeta) {
514  $sMeta .= ", ";
515  }
516  $sMeta .= $sTitlePageSuffix;
517  }
518 
519  return $sMeta;
520  }
521 
534  protected function _collectMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
535  {
536  //formatting description tag
537  $oCategory = $this->getActiveCategory();
538 
539  $sAddText = (($oCategory instanceof oxCategory)) ? trim($oCategory->getLongDesc()) : '';
540 
541  $aArticleList = $this->getArticleList();
542  if (!$sAddText && count($aArticleList)) {
543  foreach ($aArticleList as $oArticle) {
544  if ($sAddText) {
545  $sAddText .= ', ';
546  }
547  $sAddText .= $oArticle->oxarticles__oxtitle->value;
548  }
549  }
550 
551  if (!$sMeta) {
552  $sMeta = trim($this->_getCatPathString());
553  }
554 
555  if ($sMeta) {
556  $sMeta = "{$sMeta} - {$sAddText}";
557  } else {
558  $sMeta = $sAddText;
559  }
560 
561  return parent::_prepareMetaDescription($sMeta, $iLength, $blDescTag);
562  }
563 
572  protected function _prepareMetaKeyword($sKeywords, $blRemoveDuplicatedWords = true)
573  {
574  $sKeywords = '';
575  if (($oCategory = $this->getActiveCategory())) {
576  $aKeywords = array();
577 
578  if ($oCatTree = $this->getCategoryTree()) {
579  foreach ($oCatTree->getPath() as $oCat) {
580  $aKeywords[] = trim($oCat->oxcategories__oxtitle->value);
581  }
582  }
583 
584  if (count($aKeywords) > 0) {
585  $sKeywords = implode(", ", $aKeywords);
586  }
587 
588  $aSubCats = $oCategory->getSubCats();
589  if (is_array($aSubCats)) {
590  foreach ($aSubCats as $oSubCat) {
591  $sKeywords .= ', ' . $oSubCat->oxcategories__oxtitle->value;
592  }
593  }
594  }
595 
596  $sKeywords = parent::_prepareMetaDescription($sKeywords, -1, $blRemoveDuplicatedWords);
597 
598  return trim($sKeywords);
599  }
600 
609  protected function _collectMetaKeyword($sKeywords)
610  {
611  $iMaxTextLength = 60;
612  $sText = '';
613 
614  if (count($aArticleList = $this->getArticleList())) {
615  $oStr = getStr();
616  foreach ($aArticleList as $oProduct) {
617  $sDesc = $oStr->strip_tags(trim($oStr->strtolower($oProduct->getLongDescription()->value)));
618 
619  //removing dots from string (they are not cleaned up during general string cleanup)
620  $sDesc = $oStr->preg_replace("/\./", " ", $sDesc);
621 
622  if ($oStr->strlen($sDesc) > $iMaxTextLength) {
623  $sMidText = $oStr->substr($sDesc, 0, $iMaxTextLength);
624  $sDesc = $oStr->substr(
625  $sMidText,
626  0,
627  ($oStr->strlen($sMidText) - $oStr->strpos(strrev($sMidText), ' '))
628  );
629  }
630  if ($sText) {
631  $sText .= ', ';
632  }
633  $sText .= $sDesc;
634  }
635  }
636 
637  if (!$sKeywords) {
638  $sKeywords = $this->_getCatPathString();
639  }
640 
641  if ($sKeywords) {
642  $sText = "{$sKeywords}, {$sText}";
643  }
644 
645  return parent::_prepareMetaKeyword($sText);
646  }
647 
655  public function getTemplateName()
656  {
657  // assign template name
658  if (($sTplName = basename(oxRegistry::getConfig()->getRequestParameter('tpl')))) {
659  $this->_sThisTemplate = 'custom/' . $sTplName;
660  } elseif (($oCategory = $this->getActiveCategory()) && $oCategory->oxcategories__oxtemplate->value) {
661  $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
662  }
663 
664  return $this->_sThisTemplate;
665  }
666 
676  protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
677  {
678  if (oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory())) {
679  if ($iPage) {
680  // only if page number > 0
681  $sUrl = $oCategory->getBaseSeoLink($iLang, $iPage);
682  }
683  } else {
684  $sUrl = parent::_addPageNrParam($sUrl, $iPage, $iLang);
685  }
686 
687  return $sUrl;
688  }
689 
695  protected function _isActCategory()
696  {
697  return $this->_blIsCat;
698  }
699 
705  public function generatePageNavigationUrl()
706  {
707  if ((oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory()))) {
708  return $oCategory->getLink();
709  }
710 
712  }
713 
719  public function getDefaultSorting()
720  {
721  $aSorting = parent::getDefaultSorting();
722 
723  $oCategory = $this->getActiveCategory();
724  if ($oCategory && $oCategory instanceof oxCategory) {
725  if ($sDefaultSorting = $oCategory->getDefaultSorting()) {
726  $sArticleTable = getViewName('oxarticles');
727  $sSortBy = $sArticleTable . '.' . $sDefaultSorting;
728  $sSortDir = ($oCategory->getDefaultSortingMode()) ? "desc" : "asc";
729  $aSorting = array('sortby' => $sSortBy, 'sortdir' => $sSortDir);
730  }
731  }
732 
733  return $aSorting;
734  }
735 
736 
742  public function getTitleSuffix()
743  {
744  if ($this->getActiveCategory()->oxcategories__oxshowsuffix->value) {
745  return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
746  }
747  }
748 
754  public function getTitlePageSuffix()
755  {
756  if (($iPage = $this->getActPage())) {
757  return oxRegistry::getLang()->translateString('PAGE') . " " . ($iPage + 1);
758  }
759  }
760 
769  protected function _getSubject($iLang)
770  {
771  return $this->getActiveCategory();
772  }
773 
780  public function getAttributes()
781  {
782  $this->_aAttributes = false;
783 
784  if (($oCategory = $this->getActiveCategory())) {
785  $aAttributes = $oCategory->getAttributes();
786  if (count($aAttributes)) {
787  $this->_aAttributes = $aAttributes;
788  }
789  }
790 
791  return $this->_aAttributes;
792  }
793 
799  public function getArticleList()
800  {
801  if ($this->_aArticleList === null) {
802  if ($oCategory = $this->getActiveCategory()) {
803  $aArticleList = $this->_loadArticles($oCategory);
804  if (count($aArticleList)) {
805  $this->_aArticleList = $aArticleList;
806  }
807  }
808  }
809 
810  return $this->_aArticleList;
811  }
812 
818  public function getArticleCount()
819  {
820  return $this->_iAllArtCnt;
821  }
822 
830  public function getSimilarRecommListIds()
831  {
832  if ($this->_aSimilarRecommListIds === null) {
833  $this->_aSimilarRecommListIds = false;
834 
835  if ($aCatArtList = $this->getArticleList()) {
836  $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
837  }
838  }
839 
841  }
842 
848  public function getCatTreePath()
849  {
850  if ($this->_sCatTreePath === null) {
851  $this->_sCatTreePath = false;
852  // category path
853  if ($oCatTree = $this->getCategoryTree()) {
854  $this->_sCatTreePath = $oCatTree->getPath();
855  }
856  }
857 
858  return $this->_sCatTreePath;
859  }
860 
866  public function getTreePath()
867  {
868  if ($oCatTree = $this->getCategoryTree()) {
869  return $oCatTree->getPath();
870  }
871  }
872 
878  public function getBreadCrumb()
879  {
880  $aPaths = array();
881 
882  if ('oxmore' == oxRegistry::getConfig()->getRequestParameter('cnid')) {
883  $aPath = array();
884  $aPath['title'] = oxRegistry::getLang()->translateString(
885  'CATEGORY_OVERVIEW',
886  oxRegistry::getLang()->getBaseLanguage(),
887  false
888  );
889  $aPath['link'] = $this->getLink();
890 
891  $aPaths[] = $aPath;
892 
893  return $aPaths;
894  }
895 
896  if (($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath())) {
897  foreach ($oCatPath as $oCat) {
898  $aCatPath = array();
899 
900  $aCatPath['link'] = $oCat->getLink();
901  $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
902 
903  $aPaths[] = $aCatPath;
904  }
905  }
906 
907  return $aPaths;
908  }
909 
916  public function hasVisibleSubCats()
917  {
918  if ($this->_blHasVisibleSubCats === null) {
919  $this->_blHasVisibleSubCats = false;
920  if ($oClickCat = $this->getActiveCategory()) {
921  $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
922  }
923  }
924 
926  }
927 
933  public function getSubCatList()
934  {
935  if ($this->_aSubCatList === null) {
936  $this->_aSubCatList = array();
937  if ($oClickCat = $this->getActiveCategory()) {
938  $this->_aSubCatList = $oClickCat->getSubCats();
939  }
940  }
941 
942  return $this->_aSubCatList;
943  }
944 
950  public function getPageNavigation()
951  {
952  if ($this->_oPageNavigation === null) {
953  $this->_oPageNavigation = $this->generatePageNavigation();
954  }
955 
957  }
958 
964  public function getTitle()
965  {
966  if ($this->_sCatTitle === null) {
967  $this->_sCatTitle = false;
968  if ($this->getCategoryId() == 'oxmore') {
969  $oLang = oxRegistry::getLang();
970  $iBaseLanguage = $oLang->getBaseLanguage();
971 
972  $this->_sCatTitle = $oLang->translateString('CATEGORY_OVERVIEW', $iBaseLanguage, false);
973  } elseif (($oCategory = $this->getActiveCategory())) {
974  $sTitleField = 'oxcategories__oxtitle';
975  $this->_sCatTitle = $oCategory->$sTitleField->value;
976  }
977  }
978 
979  return $this->_sCatTitle;
980  }
981 
987  public function getBargainArticleList()
988  {
989  if ($this->_aBargainArticleList === null) {
990  $this->_aBargainArticleList = array();
991  if ($this->getConfig()->getConfigParam('bl_perfLoadAktion') && $this->_isActCategory()) {
992  $oArtList = oxNew('oxarticlelist');
993  $oArtList->loadActionArticles('OXBARGAIN');
994  if ($oArtList->count()) {
995  $this->_aBargainArticleList = $oArtList;
996  }
997  }
998  }
999 
1001  }
1002 
1008  public function getActiveCategory()
1009  {
1010  if ($this->_oActCategory === null) {
1011  $this->_oActCategory = false;
1012  $oCategory = oxNew('oxCategory');
1013  if ($oCategory->load($this->getCategoryId())) {
1014  $this->_oActCategory = $oCategory;
1015  }
1016  }
1017 
1018  return $this->_oActCategory;
1019  }
1020 
1026  public function getCanonicalUrl()
1027  {
1028  if (($oCategory = $this->getActiveCategory())) {
1029  $oUtils = oxRegistry::get("oxUtilsUrl");
1030  if (oxRegistry::getUtils()->seoIsActive()) {
1031  $sUrl = $oUtils->prepareCanonicalUrl(
1032  $oCategory->getBaseSeoLink($oCategory->getLanguage(), $this->getActPage())
1033  );
1034  } else {
1035  $sUrl = $oUtils->prepareCanonicalUrl(
1036  $oCategory->getBaseStdLink($oCategory->getLanguage(), $this->getActPage())
1037  );
1038  }
1039 
1040  return $sUrl;
1041  }
1042  }
1043 
1049  public function canSelectDisplayType()
1050  {
1051  return $this->getConfig()->getConfigParam('blShowListDisplayType');
1052  }
1053 
1059  public function getPageCount()
1060  {
1061  return $this->_iCntPages;
1062  }
1063 }