OXID eShop CE  4.10.1
 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  // redirecting to first page in case requested page does not exist
240  if ($iPageCnt && (($iPageCnt - 1) < $this->getActPage())) {
241  oxRegistry::getUtils()->redirect($this->getActiveCategory()->getLink(), false);
242  }
243  }
244 
249  protected function _processListArticles()
250  {
251  if ($aArtList = $this->getArticleList()) {
252  $iLinkType = $this->_getProductLinkType();
253  $sAddDynParams = $this->getAddUrlParams();
254  $sAddSeoParams = $this->getAddSeoUrlParams();
255 
256  foreach ($aArtList as $oArticle) {
257  $oArticle->setLinkType($iLinkType);
258 
259  // appending dynamic urls
260  if ($sAddDynParams) {
261  $oArticle->appendStdLink($sAddDynParams);
262  }
263 
264  // appending seo urls
265  if ($sAddSeoParams) {
266  $oArticle->appendLink($sAddSeoParams);
267  }
268  }
269  }
270  }
271 
272 
278  public function getAddUrlParams()
279  {
280  $sParams = parent::getAddUrlParams();
281  if (!oxRegistry::getUtils()->seoIsActive()) {
282  $iPgNr = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
283  if ($iPgNr > 0) {
284  $sParams .= ($sParams ? '&amp;' : '') . "pgNr={$iPgNr}";
285  }
286  }
287 
288  return $sParams;
289  }
290 
294  public function getAddSeoUrlParams()
295  {
296  }
297 
305  protected function _getProductLinkType()
306  {
307  $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
308  if (($oCat = $this->getActiveCategory()) && $oCat->isPriceCategory()) {
310  }
311 
312  return $iCatType;
313  }
314 
321  public function executefilter()
322  {
323  $iLang = oxRegistry::getLang()->getBaseLanguage();
324  // store this into session
325  $aFilter = oxRegistry::getConfig()->getRequestParameter('attrfilter', true);
326  $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
327 
328  if (!empty($aFilter)) {
329  $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
330  //fix for #2904 - if language will be changed attributes of this category will be deleted from session
331  //and new filters for active language set.
332  $aSessionFilter[$sActCat] = null;
333  $aSessionFilter[$sActCat][$iLang] = $aFilter;
334  oxRegistry::getSession()->setVariable('session_attrfilter', $aSessionFilter);
335  }
336  }
337 
345  protected function _loadArticles($oCategory)
346  {
347  $myConfig = $this->getConfig();
348 
349  $iNrofCatArticles = (int) $myConfig->getConfigParam('iNrofCatArticles');
350  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
351 
352  // load only articles which we show on screen
353  $oArtList = oxNew('oxarticlelist');
354  $oArtList->setSqlLimit($iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles);
355  $oArtList->setCustomSorting($this->getSortingSql($this->getSortIdent()));
356 
357  if ($oCategory->isPriceCategory()) {
358  $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
359  $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
360 
361  $this->_iAllArtCnt = $oArtList->loadPriceArticles($dPriceFrom, $dPriceTo, $oCategory);
362  } else {
363  $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
364 
365  $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
366  $this->_iAllArtCnt = $oArtList->loadCategoryArticles($sActCat, $aSessionFilter);
367  }
368 
369  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
370 
371  return $oArtList;
372  }
373 
379  public function getActPage()
380  {
381  return $this->_getRequestPageNr();
382  }
383 
392  protected function _getRequestPageNr()
393  {
394  return parent::getActPage();
395  }
396 
402  protected function _getListDisplayType()
403  {
404  $sListDisplayType = oxRegistry::getSession()->getVariable('ldtype');
405 
406  if (is_null($sListDisplayType)) {
407  $sListDisplayType = oxRegistry::getConfig()->getConfigParam('sDefaultListDisplayType');
408  }
409 
410  return $sListDisplayType;
411  }
412 
418  protected function _getSeoObjectId()
419  {
420  if (($oCategory = $this->getActiveCategory())) {
421  return $oCategory->getId();
422  }
423  }
424 
430  protected function _getCatPathString()
431  {
432  if ($this->_sCatPathString === null) {
433 
434  // marking as already set
435  $this->_sCatPathString = false;
436 
437  //fetching category path
438  if (is_array($aPath = $this->getCatTreePath())) {
439 
440  $oStr = getStr();
441  $this->_sCatPathString = '';
442  foreach ($aPath as $oCat) {
443  if ($this->_sCatPathString) {
444  $this->_sCatPathString .= ', ';
445  }
446  $this->_sCatPathString .= $oStr->strtolower($oCat->oxcategories__oxtitle->value);
447  }
448  }
449  }
450 
451  return $this->_sCatPathString;
452  }
453 
463  protected function _prepareMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
464  {
465  $sDescription = '';
466  // appending parent title
467  if ($oCategory = $this->getActiveCategory()) {
468  if (($oParent = $oCategory->getParentCategory())) {
469  $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
470  }
471 
472  // adding category title
473  $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
474  }
475 
476  // and final component ..
477  //changed for #2776
478  if (($sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value)) {
479  $sDescription .= " {$sSuffix}";
480  }
481 
482  // making safe for output
483  $sDescription = getStr()->html_entity_decode($sDescription);
484  $sDescription = getStr()->strip_tags($sDescription);
485  $sDescription = getStr()->cleanStr($sDescription);
486  $sDescription = getStr()->htmlspecialchars($sDescription);
487 
488  return trim($sDescription);
489  }
490 
496  public function getMetaDescription()
497  {
498  $sMeta = parent::getMetaDescription();
499 
500  if ($sTitlePageSuffix = $this->getTitlePageSuffix()) {
501  if ($sMeta) {
502  $sMeta .= ", ";
503  }
504  $sMeta .= $sTitlePageSuffix;
505  }
506 
507  return $sMeta;
508  }
509 
522  protected function _collectMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
523  {
524  //formatting description tag
525  $oCategory = $this->getActiveCategory();
526 
527  $sAddText = (($oCategory instanceof oxCategory)) ? trim($oCategory->getLongDesc()) : '';
528 
529  $aArticleList = $this->getArticleList();
530  if (!$sAddText && count($aArticleList)) {
531  foreach ($aArticleList as $oArticle) {
532  if ($sAddText) {
533  $sAddText .= ', ';
534  }
535  $sAddText .= $oArticle->oxarticles__oxtitle->value;
536  }
537  }
538 
539  if (!$sMeta) {
540  $sMeta = trim($this->_getCatPathString());
541  }
542 
543  if ($sMeta) {
544  $sMeta = "{$sMeta} - {$sAddText}";
545  } else {
546  $sMeta = $sAddText;
547  }
548 
549  return parent::_prepareMetaDescription($sMeta, $iLength, $blDescTag);
550  }
551 
560  protected function _prepareMetaKeyword($sKeywords, $blRemoveDuplicatedWords = true)
561  {
562  $sKeywords = '';
563  if (($oCategory = $this->getActiveCategory())) {
564  $aKeywords = array();
565 
566  if ($oCatTree = $this->getCategoryTree()) {
567  foreach ($oCatTree->getPath() as $oCat) {
568  $aKeywords[] = trim($oCat->oxcategories__oxtitle->value);
569  }
570  }
571 
572  if (count($aKeywords) > 0) {
573  $sKeywords = implode(", ", $aKeywords);
574  }
575 
576  $aSubCats = $oCategory->getSubCats();
577  if (is_array($aSubCats)) {
578  foreach ($aSubCats as $oSubCat) {
579  $sKeywords .= ', ' . $oSubCat->oxcategories__oxtitle->value;
580  }
581  }
582  }
583 
584  $sKeywords = parent::_prepareMetaDescription($sKeywords, -1, $blRemoveDuplicatedWords);
585 
586  return trim($sKeywords);
587  }
588 
597  protected function _collectMetaKeyword($sKeywords)
598  {
599  $iMaxTextLength = 60;
600  $sText = '';
601 
602  if (count($aArticleList = $this->getArticleList())) {
603  $oStr = getStr();
604  foreach ($aArticleList as $oProduct) {
605  $sDesc = $oStr->strip_tags(trim($oStr->strtolower($oProduct->getLongDescription()->value)));
606 
607  //removing dots from string (they are not cleaned up during general string cleanup)
608  $sDesc = $oStr->preg_replace("/\./", " ", $sDesc);
609 
610  if ($oStr->strlen($sDesc) > $iMaxTextLength) {
611  $sMidText = $oStr->substr($sDesc, 0, $iMaxTextLength);
612  $sDesc = $oStr->substr(
613  $sMidText,
614  0,
615  ($oStr->strlen($sMidText) - $oStr->strpos(strrev($sMidText), ' '))
616  );
617  }
618  if ($sText) {
619  $sText .= ', ';
620  }
621  $sText .= $sDesc;
622  }
623  }
624 
625  if (!$sKeywords) {
626  $sKeywords = $this->_getCatPathString();
627  }
628 
629  if ($sKeywords) {
630  $sText = "{$sKeywords}, {$sText}";
631  }
632 
633  return parent::_prepareMetaKeyword($sText);
634  }
635 
643  public function getTemplateName()
644  {
645  // assign template name
646  if (($sTplName = basename(oxRegistry::getConfig()->getRequestParameter('tpl')))) {
647  $this->_sThisTemplate = 'custom/' . $sTplName;
648  } elseif (($oCategory = $this->getActiveCategory()) && $oCategory->oxcategories__oxtemplate->value) {
649  $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
650  }
651 
652  return $this->_sThisTemplate;
653  }
654 
664  protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
665  {
666  if (oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory())) {
667  if ($iPage) {
668  // only if page number > 0
669  $sUrl = $oCategory->getBaseSeoLink($iLang, $iPage);
670  }
671  } else {
672  $sUrl = parent::_addPageNrParam($sUrl, $iPage, $iLang);
673  }
674 
675  return $sUrl;
676  }
677 
683  protected function _isActCategory()
684  {
685  return $this->_blIsCat;
686  }
687 
693  public function generatePageNavigationUrl()
694  {
695  if ((oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory()))) {
696  return $oCategory->getLink();
697  }
698 
700  }
701 
707  public function getDefaultSorting()
708  {
709  $aSorting = parent::getDefaultSorting();
710 
711  $oCategory = $this->getActiveCategory();
712  if ($oCategory && $oCategory instanceof oxCategory) {
713  if ($sDefaultSorting = $oCategory->getDefaultSorting()) {
714  $sArticleTable = getViewName('oxarticles');
715  $sSortBy = $sArticleTable . '.' . $sDefaultSorting;
716  $sSortDir = ($oCategory->getDefaultSortingMode()) ? "desc" : "asc";
717  $aSorting = array('sortby' => $sSortBy, 'sortdir' => $sSortDir);
718  }
719  }
720 
721  return $aSorting;
722  }
723 
724 
730  public function getTitleSuffix()
731  {
732  if ($this->getActiveCategory()->oxcategories__oxshowsuffix->value) {
733  return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
734  }
735  }
736 
742  public function getTitlePageSuffix()
743  {
744  if (($iPage = $this->getActPage())) {
745  return oxRegistry::getLang()->translateString('PAGE') . " " . ($iPage + 1);
746  }
747  }
748 
757  protected function _getSubject($iLang)
758  {
759  return $this->getActiveCategory();
760  }
761 
768  public function getAttributes()
769  {
770  $this->_aAttributes = false;
771 
772  if (($oCategory = $this->getActiveCategory())) {
773  $aAttributes = $oCategory->getAttributes();
774  if (count($aAttributes)) {
775  $this->_aAttributes = $aAttributes;
776  }
777  }
778 
779  return $this->_aAttributes;
780  }
781 
787  public function getArticleList()
788  {
789  if ($this->_aArticleList === null) {
790  if ($oCategory = $this->getActiveCategory()) {
791  $aArticleList = $this->_loadArticles($oCategory);
792  if (count($aArticleList)) {
793  $this->_aArticleList = $aArticleList;
794  }
795  }
796  }
797 
798  return $this->_aArticleList;
799  }
800 
806  public function getArticleCount()
807  {
808  return $this->_iAllArtCnt;
809  }
810 
818  public function getSimilarRecommListIds()
819  {
820  if ($this->_aSimilarRecommListIds === null) {
821  $this->_aSimilarRecommListIds = false;
822 
823  if ($aCatArtList = $this->getArticleList()) {
824  $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
825  }
826  }
827 
829  }
830 
836  public function getCatTreePath()
837  {
838  if ($this->_sCatTreePath === null) {
839  $this->_sCatTreePath = false;
840  // category path
841  if ($oCatTree = $this->getCategoryTree()) {
842  $this->_sCatTreePath = $oCatTree->getPath();
843  }
844  }
845 
846  return $this->_sCatTreePath;
847  }
848 
854  public function getTreePath()
855  {
856  if ($oCatTree = $this->getCategoryTree()) {
857  return $oCatTree->getPath();
858  }
859  }
860 
866  public function getBreadCrumb()
867  {
868  $aPaths = array();
869 
870  if ('oxmore' == oxRegistry::getConfig()->getRequestParameter('cnid')) {
871  $aPath = array();
872  $aPath['title'] = oxRegistry::getLang()->translateString(
873  'CATEGORY_OVERVIEW',
874  oxRegistry::getLang()->getBaseLanguage(),
875  false
876  );
877  $aPath['link'] = $this->getLink();
878 
879  $aPaths[] = $aPath;
880 
881  return $aPaths;
882  }
883 
884  if (($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath())) {
885  foreach ($oCatPath as $oCat) {
886  $aCatPath = array();
887 
888  $aCatPath['link'] = $oCat->getLink();
889  $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
890 
891  $aPaths[] = $aCatPath;
892  }
893  }
894 
895  return $aPaths;
896  }
897 
904  public function hasVisibleSubCats()
905  {
906  if ($this->_blHasVisibleSubCats === null) {
907  $this->_blHasVisibleSubCats = false;
908  if ($oClickCat = $this->getActiveCategory()) {
909  $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
910  }
911  }
912 
914  }
915 
921  public function getSubCatList()
922  {
923  if ($this->_aSubCatList === null) {
924  $this->_aSubCatList = array();
925  if ($oClickCat = $this->getActiveCategory()) {
926  $this->_aSubCatList = $oClickCat->getSubCats();
927  }
928  }
929 
930  return $this->_aSubCatList;
931  }
932 
938  public function getPageNavigation()
939  {
940  if ($this->_oPageNavigation === null) {
941  $this->_oPageNavigation = $this->generatePageNavigation();
942  }
943 
945  }
946 
952  public function getTitle()
953  {
954  if ($this->_sCatTitle === null) {
955  $this->_sCatTitle = false;
956  if ($this->getCategoryId() == 'oxmore') {
957  $oLang = oxRegistry::getLang();
958  $iBaseLanguage = $oLang->getBaseLanguage();
959 
960  $this->_sCatTitle = $oLang->translateString('CATEGORY_OVERVIEW', $iBaseLanguage, false);
961  } elseif (($oCategory = $this->getActiveCategory())) {
962  $sTitleField = 'oxcategories__oxtitle';
963  $this->_sCatTitle = $oCategory->$sTitleField->value;
964  }
965  }
966 
967  return $this->_sCatTitle;
968  }
969 
975  public function getBargainArticleList()
976  {
977  if ($this->_aBargainArticleList === null) {
978  $this->_aBargainArticleList = array();
979  if ($this->getConfig()->getConfigParam('bl_perfLoadAktion') && $this->_isActCategory()) {
980  $oArtList = oxNew('oxarticlelist');
981  $oArtList->loadActionArticles('OXBARGAIN');
982  if ($oArtList->count()) {
983  $this->_aBargainArticleList = $oArtList;
984  }
985  }
986  }
987 
989  }
990 
996  public function getActiveCategory()
997  {
998  if ($this->_oActCategory === null) {
999  $this->_oActCategory = false;
1000  $oCategory = oxNew('oxCategory');
1001  if ($oCategory->load($this->getCategoryId())) {
1002  $this->_oActCategory = $oCategory;
1003  }
1004  }
1005 
1006  return $this->_oActCategory;
1007  }
1008 
1014  public function getCanonicalUrl()
1015  {
1016  if (($oCategory = $this->getActiveCategory())) {
1017  $oUtils = oxRegistry::get("oxUtilsUrl");
1018  if (oxRegistry::getUtils()->seoIsActive()) {
1019  $sUrl = $oUtils->prepareCanonicalUrl(
1020  $oCategory->getBaseSeoLink($oCategory->getLanguage(), $this->getActPage())
1021  );
1022  } else {
1023  $sUrl = $oUtils->prepareCanonicalUrl(
1024  $oCategory->getBaseStdLink($oCategory->getLanguage(), $this->getActPage())
1025  );
1026  }
1027 
1028  return $sUrl;
1029  }
1030  }
1031 
1037  public function canSelectDisplayType()
1038  {
1039  return $this->getConfig()->getConfigParam('blShowListDisplayType');
1040  }
1041 
1047  public function getPageCount()
1048  {
1049  return $this->_iCntPages;
1050  }
1051 }