_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 serviceEntityReviews($iContentId = 0) { $CNF = &$this->_oConfig->CNF; if(empty($CNF['OBJECT_REVIEWS'])) return false; return $this->_entityComments($CNF['OBJECT_REVIEWS'], $iContentId); } public function serviceEntityReviewsRating($iContentId = 0) { $CNF = &$this->_oConfig->CNF; if(empty($CNF['OBJECT_REVIEWS'])) return false; if(!$iContentId) $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT); if(!$iContentId) return false; $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_REVIEWS'], $iContentId); if (!$oCmts || !$oCmts->isEnabled()) return false; return $oCmts->getRatingBlock(array('in_designbox' => false)); } public function serviceCategoriesList($aParams = array()) { if(!isset($aParams['show_empty'])) $aParams['show_empty'] = true; return $this->_oTemplate->categoriesList($aParams); } 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_ads_page_block_title_entries_by_category_mask', _t($aCategory['title'])); } return $aBlock; } /** * Common methods. */ public 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]; } /** * 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 _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; } } /** @} */