| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Directory Directory
- * @ingroup UnaModules
- *
- * @{
- */
- /**
- * Directory module
- */
- class BxDirModule extends BxBaseModTextModule
- {
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- $CNF = &$this->_oConfig->CNF;
- $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
- $CNF['FIELD_CATEGORY_VIEW'],
- $CNF['FIELD_CATEGORY_SELECT']
- ));
- }
- public function serviceUpdateCategoriesStats()
- {
- $aStats = $this->_oDb->getCategories(array('type' => 'collect_stats'));
- if(empty($aStats) || !is_array($aStats))
- return true;
- $iUpdated = 0;
- foreach($aStats as $aStat)
- if($this->_oDb->updateCategory(array('items' => $aStat['count']), array('id' => $aStat['id'])))
- $iUpdated++;
- return count($aStats) == $iUpdated;
- }
- public function serviceGetCategoryOptions($iParentId, $bPleaseSelect = false)
- {
- $aValues = array();
- if($bPleaseSelect)
- $aValues[] = array('key' => '', 'value' => _t('_sys_please_select'));
- $this->_getCategoryOptions($iParentId, $aValues);
- return $aValues;
- }
- public function serviceGetSearchableFields($aInputsAdd = array())
- {
- $aInputsAdd = array_merge($aInputsAdd, $this->_getSearchableFields());
- return parent::serviceGetSearchableFields($aInputsAdd);
- }
- public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
- {
- $CNF = &$this->_oConfig->CNF;
- $aInputsAdd = array_merge($aInputsAdd, $this->_getSearchableFields());
- if(isset($aInputsAdd[$CNF['FIELD_CATEGORY']])) {
- $aInputsAdd[$CNF['FIELD_CATEGORY']]['type'] = 'select';
- $aInputsAdd[$CNF['FIELD_CATEGORY']]['values_src'] = BxDolService::getSerializedService($this->_oConfig->getName(), 'get_category_options', array(0));
- }
- return parent::serviceGetSearchableFieldsExtended($aInputsAdd);
- }
- public function serviceEntityCreate ($sParams = false)
- {
- if(($sDisplay = $this->_getCategoryDisplay('add')) !== false) {
- if(empty($sParams) || !is_array($sParams))
- $sParams = array();
- $sParams['display'] = $sDisplay;
- }
- return parent::serviceEntityCreate($sParams);
- }
- public function serviceCategoriesList($aParams = array())
- {
- return $this->_oTemplate->categoriesList();
- }
- public function serviceBrowseCategory($iCategoryId = 0, $aParams = array())
- {
- $sParamGet = 'category';
- $bEmptyMessage = isset($aParams['empty_message']) ? (bool)$aParams['empty_message'] : true;
- if(!$iCategoryId)
- $iCategoryId = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
- if(!$iCategoryId)
- return $bEmptyMessage ? MsgBox(_t('_Empty')) : '';
- $aBlock = $this->_serviceBrowseWithParam('category', $sParamGet, $iCategoryId, $aParams);
- if(!empty($aBlock['content'])) {
- $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategoryId));
- if(!empty($aCategory['title']))
- $aBlock['title'] = _t('_bx_directory_page_block_title_entries_by_category_mask', _t($aCategory['title']));
- }
- return $aBlock;
- }
- /**
- * Common methods.
- */
- /**
- * Internal methods.
- */
- protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
- {
- $CNF = &$this->_oConfig->CNF;
- $mixedContent = $this->_getContent($iContentId, true);
- if($mixedContent === false)
- return false;
- list($iContentId, $aContentInfo) = $mixedContent;
- $sDisplayType = false;
- switch($sFormMethod) {
- case 'editDataForm':
- $sDisplayType = 'edit';
- break;
- case 'viewDataForm':
- case 'viewDataEntry':
- $sDisplayType = 'view';
- break;
- }
- if($sDisplayType !== false && ($sDisplayNew = $this->_getCategoryDisplay($sDisplayType, $aContentInfo[$CNF['FIELD_CATEGORY']])) !== false)
- $sDisplay = $sDisplayNew;
- return parent::_serviceEntityForm ($sFormMethod, $iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
- }
- protected function _getCategoryDisplay($sDisplayType, $iCategory = 0)
- {
- if(empty($iCategory) && bx_get('category') !== false)
- $iCategory = (int)bx_get('category');
- if(empty($iCategory))
- return false;
- $aCategory = $this->_oDb->getCategories(array('type' => 'id_full', 'id' => $iCategory));
- $sKey = 'type_display_' . $sDisplayType;
- if(empty($aCategory[$sKey]))
- return false;
- return $aCategory[$sKey];
- }
- protected function _getCategoryOptions($iParentId, &$aValues)
- {
- $aCategories = $this->_oDb->getCategories(array('type' => 'parent_id', 'parent_id' => $iParentId));
- foreach($aCategories as $aCategory) {
- $aValues[] = array('key' => $aCategory['id'], 'value' => str_repeat('--', (int)$aCategory['level']) . ' ' . _t($aCategory['title']));
- $this->_getCategoryOptions($aCategory['id'], $aValues);
- }
- }
- protected function _getSearchableFields($mixedDisplayType = '')
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($mixedDisplayType))
- $mixedDisplayType = array('add', 'edit');
- $aResult = array();
- $aDisplays = $this->_oDb->getDisplays($this->_oConfig->getName() . '_entry', $mixedDisplayType);
- foreach($aDisplays as $aDisplay) {
- if($aDisplay['display_name'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])
- continue;
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $aDisplay['display_name'], $this->_oTemplate);
- if(!$oForm)
- continue;
- $aResult = array_merge($aResult, $oForm->aInputs);
- }
- return $aResult;
- }
- }
- /** @} */
|