BxDolLabel.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 BxDolLabel extends BxDolFactory implements iBxDolSingleton
  10. {
  11. protected $_oDb;
  12. protected $_sForm;
  13. protected $_sFormDisplaySelect;
  14. protected function __construct()
  15. {
  16. parent::__construct();
  17. $this->_oDb = new BxDolLabelQuery();
  18. $this->_sForm= 'sys_labels';
  19. $this->_sFormDisplaySelect = 'sys_labels_select';
  20. }
  21. public function __clone()
  22. {
  23. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  24. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  25. }
  26. public static function getInstance($oTemplate = false)
  27. {
  28. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  29. $GLOBALS['bxDolClasses'][__CLASS__] = new BxTemplLabel($oTemplate);
  30. return $GLOBALS['bxDolClasses'][__CLASS__];
  31. }
  32. public function actionSelectLabels()
  33. {
  34. return echoJson($this->selectLabels(array(
  35. 'name' => bx_process_input(bx_get('name')),
  36. 'list' => bx_process_input(bx_get('value'))
  37. )));
  38. }
  39. public function actionLabelsList()
  40. {
  41. $sTerm = bx_process_input(bx_get('term'));
  42. $aLabels = $this->getLabels(array('type' => 'term', 'term' => $sTerm));
  43. $aResult = array();
  44. foreach($aLabels as $aLabel)
  45. $aResult[] = array (
  46. 'label' => $aLabel['value'],
  47. 'value' => $aLabel['value'],
  48. );
  49. echoJson($aResult);
  50. }
  51. public function getLabels($aParams = array())
  52. {
  53. return $this->_oDb->getLabels($aParams);
  54. }
  55. public function getLabelUrl($sKeyword, $mixedSection = false)
  56. {
  57. $sSectionPart = '';
  58. if(!empty($mixedSection)) {
  59. if (is_array($mixedSection))
  60. $sSectionPart = '&section[]=' . implode('&section[]=', $mixedSection);
  61. elseif (is_string($mixedSection))
  62. $sSectionPart = '&section[]=' . $mixedSection;
  63. }
  64. $sUrl = BX_DOL_URL_ROOT . 'searchKeyword.php?type=keyword&keyword=' . rawurlencode($sKeyword) . $sSectionPart;
  65. bx_alert('meta_keyword', 'url', 0, false, array(
  66. 'url' => &$sUrl,
  67. 'keyword' => $sKeyword,
  68. 'section' => $mixedSection,
  69. ));
  70. return $sUrl;
  71. }
  72. public function getFormFieldId($aInput = array())
  73. {
  74. return !empty($aInput['name']) ? $this->_aHtmlIds['labels_element'] . $aInput['name'] : 'bx-form-element-labels';
  75. }
  76. public function onAdd($iId)
  77. {
  78. $aLabel = $this->_oDb->getLabels(array('type' => 'id', 'id' => $iId));
  79. if(empty($aLabel) || !is_array($aLabel))
  80. return;
  81. bx_alert('label', 'added', $iId, false, array('label' => $aLabel));
  82. }
  83. public function onEdit($iId)
  84. {
  85. $aLabel = $this->_oDb->getLabels(array('type' => 'id', 'id' => $iId));
  86. if(empty($aLabel) || !is_array($aLabel))
  87. return;
  88. bx_alert('label', 'edited', $iId, false, array('label' => $aLabel));
  89. }
  90. public function onDelete($iId)
  91. {
  92. $aLabel = $this->_oDb->getLabels(array('type' => 'id', 'id' => $iId));
  93. if(empty($aLabel) || !is_array($aLabel))
  94. return;
  95. bx_alert('label', 'deleted', $iId, false, array('label' => $aLabel));
  96. }
  97. }
  98. /** @} */