array('firstName', 'lastName', 'email')); /** * Return user list prepared for autocomplete * * @param string $query * @return array */ public function getUser4Autocomplete($query) { $userObj = new App\User\Admin\Obj(); $userObj->getListSelect()->limit(30); Qs_Db_Filter::where($userObj->getListSelect(), array('firstName', 'lastName', 'email'), $query); $list = $userObj->getList(); $data = array(); foreach ($list as $row) { $data[] = array('value' => $row['id'], 'title' => $row['firstName'] . ' ' . $row['lastName'] . ', ' . $row['email']); } return (array) $data; } protected function _filter(Zend_Db_Select $select) { parent::_filter($select); if (!empty($this->_filter['status'])) { $select->where('`' . $this->_tableAlias . '`.`statusId` = ?', $this->_filter['status']); } return $this; } /** * Return data for code * * @param string $code * @return array|bool */ public function getDataByCode($code) { return $this->_getTable()->searchBy(array('cardCode' => $code)); } public function generateCode($iterations = self::CODE_GENERATION_ITERATIONS) { $uniqueValidator = new Qs_Validate_Unique(new Qs_Db_Table('GiftCard'), 'cardCode', $this->getData('id')); $iterations = (int) $iterations; $iterations = ($iterations > 0) ? $iterations : static::CODE_GENERATION_ITERATIONS; $code = ''; $unique = false; while ($unique == false && $iterations > 0) { $code = strtoupper(substr(md5(rand().microtime(true).rand()), 0, static::DEFAULT_CODE_LENGTH)); $code = strtoupper($code); if ($uniqueValidator->isValid($code)) { $unique = true; } else { $code = ''; } $iterations--; } return $code; } }