_select) { $this->_select = parent::getListSelect(); if (null !== $this->_categoryId) { $this->_select->where('`Faq`.`categoryId` = ?', $this->_categoryId, Qs_Db::INT_TYPE); } $this->_select->where('`Faq`.`show` = ?', 'y'); $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')->where( '`Faq`.`show` = ?', 'y' ); if (0 != $this->_db->fetchOne($select)) { $this->_notEmptyCategories = array(0 => self::NO_CATEGORY_TITLE); } $select->reset(); $select->from($this->_getPair('FaqCategory'), array('id', 'title')); $select->order('FaqCategory.sorter'); $select->where("`FaqCategory`.`show` = ?", 'y'); $select->where(new Zend_Db_Expr('(' . $this->_getSelectCountCategoryFaqs() . ') > 0')); $categories = $this->_db->fetchPairs($select); if (!empty($categories)) { if (null === $this->_notEmptyCategories) { $this->_notEmptyCategories = $categories; } else { $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("`Faq`.`categoryId` = `FaqCategory`.`id`"); $select->where("`Faq`.`show` = ?", 'y'); return $select; } public function findCategoryId($categoryId) { if (null === $this->_categoryRow) { $this->_categoryRow = $this->_getTable('FaqCategory')->findRow($categoryId); } return $this->_categoryRow; } 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->findCategoryId($this->_categoryId)->title; } else { $info['categoryTitle'] = static::NO_CATEGORY_TITLE; } if (false === strpos($info['categoryTitle'], 'Category')) { $info['categoryTitle'] .= ' Category'; } return $info; } }