from(Qs_Db::getPair('SponsorshipSubmission'), 'DATE_FORMAT(`added`, "%Y")') ->distinct() ->order('added DESC'); $result = Qs_Db::getInstance()->fetchCol($select); return array_combine($result, $result); } protected function _filter(Zend_Db_Select $select) { if (!$this->hasFilter()) { return $this; } if (!empty($this->_filter['year'])) { $select->where('DATE_FORMAT(`added`, "%Y") = ?', $this->_filter['year']); } return parent::_filter($select); } public function initFromForm(array $data) { if ($data['categoryId']) { $categories = $this->getCategoriesList4Select(); if (!array_key_exists($data['categoryId'], $categories)) { throw new Exception('Category ID is wrong'); } $category = $this->_getCategoryObj()->clearData()->setPrimaryKey($data['categoryId'])->getData(); if (!$category) { throw new Exception('Can\'t fetch category data (Category ID: ' . $data['categoryId'] . ')'); } $data['categoryTitle'] = $category['title']; $data['amount'] = $category['price']; } switch ($data['userType']) { case Entity::USER_TYPE_GUEST: unset($data['userId']); break; case Entity::USER_TYPE_MEMBER: $user = $this->_getUserObj()->clearData()->setPrimaryKey($data['userId'])->getData(); if (!$user) { throw new Exception('Can\'t fetch user data (User ID: ' . $data['userId'] . ')'); } $data['name'] = $user['fullName']; $data['email'] = strval($user['email']); break; default: throw new Exception('Unknown user type: ' . $data['userType']); } return parent::initFromForm($data); } protected function _getUserObj() { if (null === $this->_userObj) { $this->_userObj = new UserObj(); } return $this->_userObj; } protected function _getCategoryObj() { if (null === $this->_categoryObj) { $this->_categoryObj = new CategoryObj(); } return $this->_categoryObj; } public function getCategoriesList4Select() { static $list; if (null === $list) { $list = $this->_getCategoryObj()->getList4Select(); } return $list; } }