本文整理汇总了PHP中bizley\podium\models\User::find方法的典型用法代码示例。如果您正苦于以下问题:PHP User::find方法的具体用法?PHP User::find怎么用?PHP User::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bizley\podium\models\User
的用法示例。
在下文中一共展示了User::find方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionFieldlist
/**
* Listing the active users for ajax.
* @return string|\yii\web\Response
*/
public function actionFieldlist($q = null)
{
if (Yii::$app->request->isAjax) {
if (!is_null($q) && is_string($q)) {
$cache = Cache::getInstance()->get('members.fieldlist');
if ($cache === false || empty($cache[$q])) {
if ($cache === false) {
$cache = [];
}
$users = User::find()->where(['and', ['status' => User::STATUS_ACTIVE], ['or', ['like', 'username', $q], ['username' => null]]])->orderBy('username, id');
$results = ['results' => []];
foreach ($users->each() as $user) {
$results['results'][] = ['id' => $user->id, 'text' => $user->getPodiumTag(true)];
}
if (!empty($results['results'])) {
$cache[$q] = Json::encode($results);
Cache::getInstance()->set('members.fieldlist', $cache);
} else {
return Json::encode(['results' => []]);
}
}
return $cache[$q];
} else {
return Json::encode(['results' => []]);
}
} else {
return $this->redirect(['default/index']);
}
}
示例2: search
/**
* @inheritdoc
*/
public function search($params, $active = false, $mods = false)
{
$query = User::find();
if ($active) {
$query->andWhere(['!=', 'status', User::STATUS_REGISTERED]);
}
if ($mods) {
$query->andWhere(['role' => [User::ROLE_ADMIN, User::ROLE_MODERATOR]]);
}
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->sort->defaultOrder = ['id' => SORT_ASC];
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id])->andFilterWhere(['status' => $this->status])->andFilterWhere(['role' => $this->role])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'username', $this->username]);
return $dataProvider;
}
示例3: getMods
/**
* Returns list of moderators for this forum.
* @return integer[]
*/
public function getMods()
{
$mods = Cache::getInstance()->getElement('forum.moderators', $this->id);
if ($mods === false) {
$mods = [];
$modteam = User::find()->select(['id', 'role'])->where(['status' => User::STATUS_ACTIVE, 'role' => [User::ROLE_ADMIN, User::ROLE_MODERATOR]])->asArray()->all();
foreach ($modteam as $user) {
if ($user['role'] == User::ROLE_ADMIN) {
$mods[] = $user['id'];
} else {
if ((new Query())->from(Mod::tableName())->where(['forum_id' => $this->id, 'user_id' => $user->id])->exists()) {
$mods[] = $user['id'];
}
}
}
Cache::getInstance()->setElement('forum.moderators', $this->id, $mods);
}
return $mods;
}
示例4: actionFriend
/**
* Adding or removing user as a friend.
* @param integer $id user ID
* @return \yii\web\Response
* @since 0.2
*/
public function actionFriend($id = null)
{
if (Yii::$app->user->isGuest) {
return $this->redirect(['default/index']);
}
$model = User::find()->where(['and', ['id' => $id], ['!=', 'status', User::STATUS_REGISTERED]])->limit(1)->one();
if (empty($model)) {
$this->error(Yii::t('podium/flash', 'Sorry! We can not find Member with this ID.'));
return $this->redirect(['members/index']);
}
if ($model->id == User::loggedId()) {
$this->error(Yii::t('podium/flash', 'Sorry! You can not befriend your own account.'));
return $this->redirect(['members/view', 'id' => $model->id, 'slug' => $model->podiumSlug]);
}
if ($model->updateFriend()) {
if ($model->isBefriendedBy(User::loggedId())) {
$this->success(Yii::t('podium/flash', 'User is your friend now.'));
} else {
$this->success(Yii::t('podium/flash', 'User is not your friend anymore.'));
}
} else {
$this->error(Yii::t('podium/flash', 'Sorry! There was some error while performing this action.'));
}
return $this->redirect(['members/view', 'id' => $model->id, 'slug' => $model->podiumSlug]);
}
示例5: actionMods
/**
* Listing and updating moderation list for the forum of given ID.
* @param integer $id forum ID
* @return string|\yii\web\Response
*/
public function actionMods($id = null)
{
$mod = null;
$moderators = User::find()->where(['role' => User::ROLE_MODERATOR])->indexBy('id')->all();
if (is_numeric($id) && $id > 0) {
if (isset($moderators[$id])) {
$mod = $moderators[$id];
}
} else {
reset($moderators);
$mod = current($moderators);
}
$searchModel = new ForumSearch();
$dataProvider = $searchModel->searchForMods(Yii::$app->request->get());
$postData = Yii::$app->request->post();
if ($postData) {
if (User::can(Rbac::PERM_PROMOTE_USER)) {
$mod_id = !empty($postData['mod_id']) && is_numeric($postData['mod_id']) && $postData['mod_id'] > 0 ? $postData['mod_id'] : 0;
$selection = !empty($postData['selection']) ? $postData['selection'] : [];
$pre = !empty($postData['pre']) ? $postData['pre'] : [];
if ($mod_id != $mod->id) {
$this->error(Yii::t('podium/flash', 'Sorry! There was an error while selecting the moderator ID.'));
} else {
try {
$add = [];
foreach ($selection as $select) {
if (!in_array($select, $pre)) {
if ((new Query())->from(Forum::tableName())->where(['id' => $select])->exists() && (new Query())->from(Mod::tableName())->where(['forum_id' => $select, 'user_id' => $mod->id])->exists() === false) {
$add[] = [$select, $mod->id];
}
}
}
$remove = [];
foreach ($pre as $p) {
if (!in_array($p, $selection)) {
if ((new Query())->from(Mod::tableName())->where(['forum_id' => $p, 'user_id' => $mod->id])->exists()) {
$remove[] = $p;
}
}
}
if (!empty($add)) {
Yii::$app->db->createCommand()->batchInsert(Mod::tableName(), ['forum_id', 'user_id'], $add)->execute();
}
if (!empty($remove)) {
Yii::$app->db->createCommand()->delete(Mod::tableName(), ['forum_id' => $remove, 'user_id' => $mod->id])->execute();
}
Cache::getInstance()->delete('forum.moderators');
Log::info('Moderators updated', null, __METHOD__);
$this->success(Yii::t('podium/flash', 'Moderation list has been saved.'));
} catch (Exception $e) {
Log::error($e->getMessage(), null, __METHOD__);
$this->error(Yii::t('podium/flash', 'Sorry! There was an error while saving the moderatoration list.'));
}
return $this->refresh();
}
} else {
$this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.'));
}
}
return $this->render('mods', ['moderators' => $moderators, 'mod' => $mod, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
示例6: totalMembers
/**
* Counts number of registered users.
* @return integer
*/
public static function totalMembers()
{
$members = Cache::getInstance()->get('forum.memberscount');
if ($members === false) {
$members = User::find()->where(['!=', 'status', User::STATUS_REGISTERED])->count();
Cache::getInstance()->set('forum.memberscount', $members);
}
return $members;
}
示例7: actionView
/**
* Viewing profile of user of given ID and slug.
* @param integer $id
* @param string $slug
* @return string|\yii\web\Response
*/
public function actionView($id = null, $slug = null)
{
$model = User::find()->where(['and', ['id' => (int) $id, 'slug' => [$slug, null, '']], ['!=', 'status', User::STATUS_REGISTERED]])->limit(1)->one();
if (empty($model)) {
$this->error(Yii::t('podium/flash', 'Sorry! We can not find Member with this ID.'));
return $this->redirect(['members/index']);
}
return $this->render('view', ['model' => $model]);
}
示例8: actionView
/**
* Listing the details of user of given ID.
* @param integer $id
* @return string|\yii\web\Response
*/
public function actionView($id = null)
{
$model = User::find()->where(['id' => $id])->limit(1)->one();
if (empty($model)) {
$this->error(Yii::t('podium/flash', 'Sorry! We can not find Member with this ID.'));
return $this->redirect(['admin/members']);
}
return $this->render('view', ['model' => $model]);
}
示例9: actionNew
/**
* Adding a new message.
* @param integer $user message receiver's ID
* @return string|\yii\web\Response
*/
public function actionNew($user = null)
{
$podiumUser = User::findMe();
if (Message::tooMany($podiumUser->id)) {
$this->warning(Yii::t('podium/flash', 'You have reached maximum {max_messages, plural, =1{ message} other{ messages}} per {max_minutes, plural, =1{ minute} other{ minutes}} limit. Wait few minutes before sending a new message.', ['max_messages' => Message::SPAM_MESSAGES, 'max_minutes' => Message::SPAM_WAIT]));
return $this->redirect(['messages/inbox']);
}
$model = new Message();
$to = null;
if (!empty($user) && (int) $user > 0 && (int) $user != $podiumUser->id) {
$member = User::find()->where(['id' => (int) $user, 'status' => User::STATUS_ACTIVE])->limit(1)->one();
if ($member) {
$model->receiversId = [$member->id];
$to = $member;
}
}
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
$validated = [];
$errors = false;
if (!empty($model->friendsId)) {
$model->receiversId = array_merge(is_array($model->receiversId) ? $model->receiversId : [], is_array($model->friendsId) ? $model->friendsId : []);
}
if (empty($model->receiversId)) {
$this->addError('receiver_id', Yii::t('podium/view', 'You have to select at least one message receiver.'));
$errors = true;
} else {
foreach ($model->receiversId as $r) {
if ($r == $podiumUser->id) {
$this->addError('receiver_id', Yii::t('podium/view', 'You can not send message to yourself.'));
$errors = true;
} elseif ($podiumUser->isIgnoredBy($r)) {
$this->addError('receiver_id', Yii::t('podium/view', 'One of the selected members ignores you and has been removed from message receivers.'));
$errors = true;
} else {
$member = User::find()->where(['id' => (int) $r, 'status' => User::STATUS_ACTIVE])->limit(1)->one();
if ($member) {
$validated[] = $member->id;
if (count($validated) > Message::MAX_RECEIVERS) {
$this->addError('receiver_id', Yii::t('podium/view', 'You can send message up to a maximum of 10 receivers at once.'));
$errors = true;
break;
}
}
}
}
$model->receiversId = $validated;
}
if (!$errors) {
if ($model->send()) {
$this->success(Yii::t('podium/flash', 'Message has been sent.'));
return $this->redirect(['messages/inbox']);
} else {
$this->error(Yii::t('podium/flash', 'Sorry! There was some error while sending your message.'));
}
}
}
}
return $this->render('new', ['model' => $model, 'to' => $to, 'friends' => User::friendsList()]);
}