| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaCore UNA Core
- * @{
- */
- class BxDolLabel extends BxDolFactory implements iBxDolSingleton
- {
- protected $_oDb;
- protected $_sForm;
- protected $_sFormDisplaySelect;
- protected function __construct()
- {
- parent::__construct();
- $this->_oDb = new BxDolLabelQuery();
- $this->_sForm= 'sys_labels';
- $this->_sFormDisplaySelect = 'sys_labels_select';
- }
- public function __clone()
- {
- if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
- trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
- }
- public static function getInstance($oTemplate = false)
- {
- if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
- $GLOBALS['bxDolClasses'][__CLASS__] = new BxTemplLabel($oTemplate);
- return $GLOBALS['bxDolClasses'][__CLASS__];
- }
- public function actionSelectLabels()
- {
- $sName = bx_process_input(bx_get('name'));
- $aValue = bx_process_input(bx_get('value'));
- return echoJson($this->selectLabels([
- 'name' => $sName,
- 'list' => $aValue,
- 'list_context' => $aValue,
- ]));
- }
- public function actionLabelsList()
- {
- $sTerm = bx_process_input(bx_get('term'));
- $aLabels = $this->getLabels(array('type' => 'term', 'term' => $sTerm));
- $aResult = array();
- foreach($aLabels as $aLabel)
- $aResult[] = array (
- 'label' => $aLabel['value'],
- 'value' => $aLabel['value'],
- );
- echoJson($aResult);
- }
- public function getLabels($aParams = [])
- {
- return $this->_oDb->getLabels($aParams);
- }
-
- public function getLabelsSystem($iParentId = 0)
- {
- $iLevel = 0;
- return $this->_getLabelsSystem($iParentId, $iLevel);
- }
-
- public function getLabelsContext($iProfileId = 0)
- {
- if(!$iProfileId)
- $iProfileId = bx_get_logged_profile_id();
- $aModules = bx_srv('system', 'get_modules_by_type', ['context']);
- $aResults = [];
- foreach($aModules as $aModule) {
- if(bx_srv($aModule['name'], 'act_as_profile'))
- continue;
- $aContextPids = bx_srv($aModule['name'], 'get_participating_profiles', [$iProfileId]);
- if(empty($aContextPids) || !is_array($aContextPids))
- continue;
- foreach($aContextPids as $iContextPid) {
- $aContextInfo = bx_srv($aModule['name'], 'get_content_info_by_profile_id', [$iContextPid]);
- if(empty($aContextInfo['hashtag']))
- continue;
- $aResults[] = [
- 'value' => $aContextInfo['hashtag']
- ];
- }
- }
- return $aResults;
- }
- public function getLabelUrl($sKeyword, $mixedSection = false)
- {
- $sSectionPart = '';
- if(!empty($mixedSection)) {
- if (is_array($mixedSection))
- $sSectionPart = '§ion[]=' . implode('§ion[]=', $mixedSection);
- elseif (is_string($mixedSection))
- $sSectionPart = '§ion[]=' . $mixedSection;
- }
- $sUrl = BX_DOL_URL_ROOT . 'searchKeyword.php?type=keyword&keyword=' . rawurlencode($sKeyword) . $sSectionPart;
- bx_alert('meta_keyword', 'url', 0, false, array(
- 'url' => &$sUrl,
- 'keyword' => $sKeyword,
- 'section' => $mixedSection,
- ));
- return $sUrl;
- }
- public function getFormFieldId($aInput = array())
- {
- return !empty($aInput['name']) ? $this->_aHtmlIds['labels_element'] . $aInput['name'] : 'bx-form-element-labels';
- }
- public function onAdd($iId)
- {
- $aLabel = $this->_oDb->getLabels(array('type' => 'id', 'id' => $iId));
- if(empty($aLabel) || !is_array($aLabel))
- return;
- /**
- * @hooks
- * @hookdef hook-label-edited 'label', 'added' - hook on new label added
- * - $unit_name - equals `label`
- * - $action - equals `added`
- * - $object_id - label id
- * - $sender_id - not used
- * - $extra_params - array of additional params with the following array keys:
- * - `label` - [array] array with label info
- * @hook @ref hook-label-added
- */
- bx_alert('label', 'added', $iId, false, array('label' => $aLabel));
- }
- public function onEdit($iId)
- {
- $aLabel = $this->_oDb->getLabels(array('type' => 'id', 'id' => $iId));
- if(empty($aLabel) || !is_array($aLabel))
- return;
- /**
- * @hooks
- * @hookdef hook-label-edited 'label', 'edited' - hook on new label edited
- * - $unit_name - equals `label`
- * - $action - equals `edited`
- * - $object_id - label id
- * - $sender_id - not used
- * - $extra_params - array of additional params with the following array keys:
- * - `label` - [array] array with label info
- * @hook @ref hook-label-edited
- */
- bx_alert('label', 'edited', $iId, false, array('label' => $aLabel));
- }
- public function onDelete($iId)
- {
- $aLabel = $this->_oDb->getLabels(array('type' => 'id', 'id' => $iId));
- if(empty($aLabel) || !is_array($aLabel))
- return;
- /**
- * @hooks
- * @hookdef hook-label-deleted 'label', 'deleted' - hook on new label deleted
- * - $unit_name - equals `label`
- * - $action - equals `deleted`
- * - $object_id - label id
- * - $sender_id - not used
- * - $extra_params - array of additional params with the following array keys:
- * - `label` - [array] array with label info
- * @hook @ref hook-label-deleted
- */
- bx_alert('label', 'deleted', $iId, false, array('label' => $aLabel));
- }
- protected function _getLabelsSystem($iParentId, $iLevel)
- {
- $aLabels = $this->getLabels(['type' => 'parent', 'parent' => $iParentId]);
- if(empty($aLabels) || !is_array($aLabels))
- return [];
- $aResults = [];
- foreach($aLabels as $aLabel) {
- $aResult = [
- 'value' => $aLabel['value']
- ];
- $aSubitems = $this->_getLabelsSystem($aLabel['id'], $iLevel + 1);
- if(!empty($aSubitems) && is_array($aSubitems))
- $aResult['subitems'] = $aSubitems;
-
- $aResults[] = $aResult;
- }
- return $aResults;
- }
- }
- /** @} */
|