_maxAmount; } public function getMinAmount() { return $this->_minAmount; } public function getAmounts() { $result = array(); for ($i = $this->_maxAmount; $i >= $this->_minAmount; $i--) { $result[] = $i; } return $result; } public function getAmount4Select() { $amounts = array_fill_keys($this->getAmounts(), ''); foreach ($amounts as $value => &$title) { $title = '$' . number_format($value, 0, '.', ','); } return $amounts; } function _getWhat4Grid($opt = array()) { $sql = parent::_getWhat4Grid($opt); $sql .= ', `bda`.`amount`'; return $sql; } function getFromDbSql($id) { $sql = 'SELECT `' . $this->tableName . '`.* ' . ', (' . $this->_getSelectTotalAmount() . ') AS `total_amount` ' . 'FROM `' . $this->tableNameDB . '` AS `' . $this->tableName . '` ' . 'WHERE `' . $this->tableName . '`.`id` = ' . $this->db->quote($id, 'integer') . ' '; return $sql; } protected function _getSelectTotalAmount() { $sql = 'SELECT SUM(`bda`.`amount`) ' . 'FROM `' . $this->tableNameDB . 'Amount` AS `bda` ' . 'WHERE `bda`.`idBattleDonation` = `' . $this->tableName . '`.`id`'; return $sql; } function _getJoin4Grid() { $sql = 'JOIN `' . $this->tableNameDB . 'Amount` AS `bda` ' . 'ON `bda`.`idBattleDonation` = `' . $this->tableName . '`.`id`'; return $sql; } function getList($opt = array()) { $res = $this->_getRes4Grid($this->_getWhat4Grid(), $opt); $this->isDBError($res); $list = $res->fetchAll(); return $this->_getPreparedList($list); } function _getPreparedList($list) { $result = array_fill_keys($this->getAmounts(), ''); foreach ($list as $row) { $result[$row['amount']] = $row; } return $result; } function getTotalAmount() { $sql = 'SELECT SUM(`amount`) ' . 'FROM `' . $this->tableNameDB . 'Amount` ' . 'WHERE 1'; $res = $this->db->queryOne($sql); $this->isDBError($res); return $res; } function getDisabledAmounts() { $sql = 'SELECT `amount` ' . 'FROM `' . $this->tableNameDB . 'Amount` ' . 'WHERE 1'; $res = $this->db->queryCol($sql); $this->isDBError($res); return $res; } function getActiveAmounts() { return array_diff($this->getAmounts(), $this->getDisabledAmounts()); } protected function _getAmount($idBattleDonation) { $sql = 'SELECT `amount` ' . 'FROM `' . $this->tableNameDB . 'Amount` ' . 'WHERE `idBattleDonation` = ' . $this->db->quote($idBattleDonation, 'integer') . ' ' . 'ORDER BY `amount` DESC'; $res = $this->db->queryCol($sql); $this->isDBError($res); return $res; } function _addDependenciesFromDb(&$data) { $data['amount'] = $this->_getAmount($data['id']); return $this; } }