BxDolCategories.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolCategories extends BxDolFactory implements iBxDolSingleton
  10. {
  11. protected $_bIsApi;
  12. protected $_oDb;
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sBrowseUrl;
  16. protected function __construct()
  17. {
  18. parent::__construct();
  19. $this->_bIsApi = bx_is_api();
  20. $this->_oDb = new BxDolCategoriesQuery();
  21. $this->_sBrowseUrl = bx_append_url_params('searchKeyword.php', [
  22. 'keyword' => '{keyword}',
  23. 'cat' => 'multi',
  24. 'section' => '{section}'
  25. ], true, ['{keyword}', '{section}']) . '{add}';
  26. }
  27. public function __clone()
  28. {
  29. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  30. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  31. }
  32. public static function getInstance()
  33. {
  34. return self::getInstanceWithTemplate(null);
  35. }
  36. public static function getInstanceWithTemplate($oTemplate)
  37. {
  38. $sClassName = __CLASS__;
  39. if($oTemplate)
  40. $sClassName .= get_class($oTemplate);
  41. if(!isset($GLOBALS['bxDolClasses'][$sClassName]))
  42. $GLOBALS['bxDolClasses'][$sClassName] = new BxTemplCategories($oTemplate);
  43. return $GLOBALS['bxDolClasses'][$sClassName];
  44. }
  45. public function setModule($sModule)
  46. {
  47. if(!($this->_sModule = $sModule) || !($this->_oModule = BxDolModule::getInstance($sModule)))
  48. return;
  49. $CNF = &$this->_oModule->_oConfig->CNF;
  50. if(($sKey = 'URL_MULTI_CATEGORY') && !empty($CNF[$sKey]))
  51. $this->_sBrowseUrl = bx_append_url_params(BxDolPermalinks::getInstance()->permalink($CNF[$sKey]), [
  52. 'category' => '{keyword}'
  53. ], true, ['{keyword}']);
  54. }
  55. public function getData($aParams = array())
  56. {
  57. return $this->_oDb->getData($aParams);
  58. }
  59. public function delete($sModule, $iObject)
  60. {
  61. return $this->_oDb->delete($sModule, $iObject);
  62. }
  63. public function add($sModule, $iProfileId, $sValue, $iObject, $bAutoActivation)
  64. {
  65. return $this->_oDb->add($sModule, $iProfileId, $sValue, $iObject, $bAutoActivation);
  66. }
  67. public function getUrl($sModule, $sValue, $sAddParams = '')
  68. {
  69. $s = BX_DOL_URL_ROOT . bx_replace_markers($this->_sBrowseUrl, [
  70. 'keyword' => rawurlencode($sValue),
  71. 'section' => $sModule,
  72. 'add' => $sAddParams
  73. ]);
  74. if($this->_bIsApi)
  75. return bx_api_get_relative_url($s);
  76. return $s;
  77. }
  78. }
  79. /** @} */