/** * Check if user with given login exists * * @param string $login * @param integer $cacheMinutes * @throws InvalidArgumentException * @return boolean */ public function isLoginExists($login, $cacheMinutes = 0, $cacheTag = null) { if (empty($login)) { throw new InvalidArgumentException("\$login have to be non empty string"); } $filter = new UsersFilter(); $filter->setLogin($login); $usersCount = $this->getUsersListCount($filter, $cacheMinutes, $cacheTag); if ($usersCount > 0) { return true; } return false; }
protected function prepareFilter() { if (isset($_GET['post'])) { $get = $this->removeMark(); $this->filters = UsersFilter::model()->setFilter(Yii::app()->user->id, $get); Yii::app()->cache->set('filter_' . Yii::app()->user->id, $this->filters); $this->redirect(Yii::app()->createUrl('manage/profiles/index') . '?' . http_build_query($get)); } else { $content = Yii::app()->cache->get('filter_' . Yii::app()->user->id); if ($content === false) { $content = UsersFilter::model()->getFilter(Yii::app()->user->id); Yii::app()->cache->set('filter_' . Yii::app()->user->id, $content); } if (!sizeof($_GET) && sizeof($content)) { $this->redirect(Yii::app()->createUrl('manage/profiles/index') . '?' . http_build_query($content)); } $this->filters = $content; } }
/** * Get user list * * @param UsersFilter $filter * @param MysqlPager $pager * @return array[User] */ public function getUsersList(UsersFilter $filter = null, MysqlPager $pager = null, $cacheMinutes = 0) { $users = array(); if ($filter == null) { $filter = new UsersFilter(); } $sqlQuery = $filter->getSQL(); if ($pager !== null) { $this->query = $pager->executePagedSQL($sqlQuery, $cacheMinutes); } else { $this->query->exec($sqlQuery, $cacheMinutes); } if ($this->query->countRecords()) { foreach ($this->query->fetchFields('id') as $user_id) { array_push($users, $this->getObjectById($user_id, $cacheMinutes)); } } return $users; }