array('title')); protected $_fileFields = array('image', 'backgroundImage'); public function delete() { $this->_clearErrors(); if (1 >= $this->getListItemsCount()) { $this->_addError(static::MSG_LAST_RECORD); return false; } return parent::delete(); } public function update(array $data = null) { if (null === $data) { $data = $this->_data; } else { $this->_data = $data; } if ($data['show'] != 'y' && !$this->_isLastVisible($this->getPrimaryKey())) { $this->_initWarningLastVisibility(); return false; } return parent::update($data); } public function changeEnumOption($name) { if ($name == 'show' && $this->_data['show'] != 'n' && !$this->_isLastVisible($this->getPrimaryKey())) { $this->_initWarningLastVisibility(); return false; } return parent::changeEnumOption($name); } private function _isLastVisible($id, $isPWX = 'n') { $select = $this->_db->select(); $select->from($this->_tableName, new Zend_Db_Expr('1')); $select->where('`show` = ?', 'y'); $select->where('`isPwx` = ?', $isPWX); $select->where('`id` != ?', (int) $id, Zend_Db::INT_TYPE); $select->limit(1); return '1' === $this->_db->fetchOne($select); } private function _initWarningLastVisibility() { $this->_clearErrors(); $this->_addError(static::MSG_LAST_VISIBLE_RECORD); return $this; } }