BxBaseCategory.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. /**
  10. * Category objects representation.
  11. * @see BxDolCategory
  12. */
  13. class BxBaseCategory extends BxDolCategory
  14. {
  15. protected $_oTemplate;
  16. public function __construct ($aObject, $oTemplate = null)
  17. {
  18. parent::__construct ($aObject);
  19. if ($oTemplate)
  20. $this->_oTemplate = $oTemplate;
  21. else
  22. $this->_oTemplate = BxDolTemplate::getInstance();
  23. }
  24. public function getCategoryUrl($sName, $sValue)
  25. {
  26. $sUrl = BX_DOL_URL_ROOT . 'searchKeyword.php?cat=' . rawurlencode($this->getObjectName()) . '&keyword=' . rawurlencode($sValue);
  27. if ($this->_aObject['search_object'])
  28. $sUrl .= '&section[]=' . rawurlencode($this->_aObject['search_object']);
  29. return $sUrl;
  30. }
  31. /**
  32. * Get link to list all items with the same category
  33. * @param $sName category title
  34. * @param $sValue category value
  35. * @return category name wrapped with A tag
  36. */
  37. public function getCategoryLink($sName, $sValue)
  38. {
  39. $sUrl = $this->getCategoryUrl($sName, $sValue);
  40. return '<a class="bx-category-link" href="' . $sUrl . '">' . $sName . '</a>';
  41. }
  42. /**
  43. * Get all categories list
  44. * @param $bDisplayEmptyCats display categories with no items, true by default
  45. * @return categories list html
  46. */
  47. public function getCategoriesList($bDisplayEmptyCats = true)
  48. {
  49. $a = BxDolForm::getDataItems($this->_aObject['list_name']);
  50. if (!$a)
  51. return '';
  52. $aVars = array('bx_repeat:cats' => array());
  53. foreach ($a as $sValue => $sName) {
  54. if (!$sValue)
  55. continue;
  56. $iNum = $this->getItemsNum($sValue);
  57. if (!$bDisplayEmptyCats && !$iNum)
  58. continue;
  59. $aVars['bx_repeat:cats'][] = array(
  60. 'url' => $this->getCategoryUrl($sName, $sValue),
  61. 'name' => $sName,
  62. 'value' => $sValue,
  63. 'num' => $iNum,
  64. );
  65. }
  66. return $this->_oTemplate->parseHtmlByName('category_list.html', $aVars);
  67. }
  68. }
  69. /** @} */