_select) { $this->_select = parent::getListSelect(); $this->_select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); Qs_Db::filter($this->_select, ['categoryId' => $this->_categoryId], $this->_tableAlias); $this->_select->order('sorter ASC'); } return $this->_select; } public function getNotEmptyCategoryAlias() { $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('FaqCategory'), ['alias', 'title']); $select->where('`FaqCategory`.`enabled` = "y"'); $select->where(new Zend_Db_Expr('(' . $this->_getSelectCountCategoryFaqs() . ') > 0')); $select->order('FaqCategory.sorter'); $this->_notEmptyCategories = $this->_db->fetchPairs($select); $select = $this->_db->select(); $select->from($this->_getPair(), ['COUNT(*)'])->where('`categoryId` IS NULL'); $select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); if (0 != $this->_db->fetchOne($select)) { $this->_notEmptyCategories = [self::NO_CATEGORY_ALIAS => self::NO_CATEGORY_TITLE] + $this->_notEmptyCategories; } } return $this->_notEmptyCategories; } protected function _getSelectCountCategoryFaqs($alias = 'FaqCategory') { $select = $this->_db->select(); $select->from($this->_getPair(), 'COUNT(*)'); $select->where('`' . $this->_tableAlias . "`.`categoryId` = `{$alias}`.`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 array $key * @param string $field Optional. Default null * @internal param int $categoryId * @return mixed */ public function getCategoryData(array $key, $field = null) { if (null === $this->_categoryData) { $row = $this->_getTable('FaqCategory')->searchBy($key); if ($row && 'y' == $row['enabled']) { $this->_categoryData = $row; $this->_categoryData['faqCount'] = $this->getCountCategoryFaqs($row['id']); } 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(['id' => $this->_categoryId], 'title'); } else { $info['categoryTitle'] = static::NO_CATEGORY_TITLE; } if (false === strpos($info['categoryTitle'], 'Category')) { $info['categoryTitle'] .= ' Category'; } return $info; } public function getListStatement4XmlSitemap($columns = ['alias']) { $select = $this->_db->select(); $select->from($this->_getPair('FaqCategory', 'fc'), $columns); $select->where('`fc`.`enabled` = "y"'); $select->where(new Zend_Db_Expr('(' . $this->_getSelectCountCategoryFaqs('fc') . ') > 0')); $select->order('fc.sorter'); return $select->query(); } }