_select) { $this->_select = parent::getListSelect(); $this->_select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); if (null !== $this->_categoryId) { $this->_select->where( '`' . $this->_tableAlias . '`.`categoryId` = ?', $this->_categoryId, Qs_Db::INT_TYPE ); } $this->_select->order('sorter ASC'); } return $this->_select; } public function getNotEmptyCategory() { $categories = $this->getNotEmptyCategories(); if (!empty($categories)) { reset($categories); return key($categories); } return null; } public function getNotEmptyCategories() { if (null === $this->_notEmptyCategories) { $select = $this->_db->select(); $select->from($this->_getPair(), array('COUNT(*)'))->where('`categoryId` = 0'); $select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); if (0 != $this->_db->fetchOne($select)) { $this->_notEmptyCategories = array(0 => self::NO_CATEGORY_TITLE); } else { $this->_notEmptyCategories = array(); } $select->reset(); $select->from($this->_getPair('FaqCategory'), array('id', 'title')); $select->where('`FaqCategory`.`enabled` = "y"'); $select->where(new Zend_Db_Expr('(' . $this->_getSelectCountCategoryFaqs() . ') > 0')); $select->order('FaqCategory.sorter'); $categories = $this->_db->fetchPairs($select); if (!empty($categories)) { $this->_notEmptyCategories = Qs_Array::mergeAssoc($this->_notEmptyCategories, $categories); } } return $this->_notEmptyCategories; } protected function _getSelectCountCategoryFaqs() { $select = $this->_db->select(); $select->from($this->_getPair(), 'COUNT(*)'); $select->where('`' . $this->_tableAlias . '`.`categoryId` = `FaqCategory`.`id`'); $select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); return $select; } /** * @param int $categoryId * @return int */ public function getCountCategoryFaqs($categoryId) { $select = $this->_db->select(); $select->from($this->_getPair(), 'COUNT(*)'); $select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); $select->where('`' . $this->_tableAlias . '`.`categoryId` = ?', (string) $categoryId, Qs_Db::INT_TYPE); return (int) $this->_db->fetchOne($select); } /** * @param int $categoryId * @param string $field Optional. Default null * @return mixed */ public function getCategoryData($categoryId, $field = null) { if (null === $this->_categoryData) { $row = $this->_getTable('FaqCategory')->findRow($categoryId); if ($row && 'y' == $row->enabled) { $this->_categoryData = $row->toArray(); $this->_categoryData['faqCount'] = $this->getCountCategoryFaqs($categoryId); } else { return false; } } return Qs_Array::get($this->_categoryData, $field, false); } public function setCategoryId($categoryId) { $this->_categoryId = $categoryId; return $this; } public function getObjectInfo() { if (($info = parent::getObjectInfo())) { $info['itemTitle'] = $info['question']; } if ($this->_categoryId) { $info['categoryTitle'] = $this->getCategoryData($this->_categoryId, 'title'); } else { $info['categoryTitle'] = static::NO_CATEGORY_TITLE; } if (false === strpos($info['categoryTitle'], 'Category')) { $info['categoryTitle'] .= ' Category'; } return $info; } }