_cleanCache(); return $this; } protected function _updateDependency() { $this->_cleanCache(); return $this; } public function updateOrder(array $order) { $this->_cleanCache(); return parent::updateOrder($order); } protected function _hasPosts() { $select = $this->_db->select(); $select->from($this->_getPair('Post'), 'id'); $select->where('`Post`.`categoryId` = ?', $this->getPrimaryKey(), \Zend_Db::INT_TYPE); $select->limit(1); return (bool) $this->_db->fetchOne($select); } public function delete() { $this->_clearErrors(); if (null === $this->getData()) { $this->_addError(static::MSG_INVALID_RECORD_ID); return false; } else if ($this->_hasPosts()) { $this->_addError(static::MSG_HAS_POSTS); return false; } $this->_deleteDependency(); $this->_deleteFiles(); return $this->_getTable()->deleteByKey($this->_primaryKey); } public function changeEnumOption($name) { Blog\AbstractObj::cleanCache(); return parent::changeEnumOption($name); } /** * @param null|bool $enabled * @return \Zend_Db_Select */ protected function _getPostCountSelect($enabled = null) { $select = $this->_db->select(); $select->from($this->_getPair('Post'), 'COUNT(`Post`.`id`)'); $select->where('`Post`.`categoryId` = `' . $this->_tableAlias . '`.`id`'); if (null !== $enabled) { $value = ($enabled) ? 'y' : 'n'; $select->where('`Post`.`enabled` = "' . $value . '"'); } return $select; } protected function _getFromColumns() { $columns = [ $this->_tableAlias . '.*', 'postsCount' => new \Zend_Db_Expr('(' . $this->_getPostCountSelect() . ')'), 'postsEnabledCount' => new \Zend_Db_Expr('(' . $this->_getPostCountSelect(true) . ')'), ]; return $columns; } }