当前位置: 首页>>代码示例>>PHP>>正文


PHP models\User类代码示例

本文整理汇总了PHP中bizley\podium\models\User的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 /**
  * Creates inherited user account.
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 $new = new User();
                 $new->setScenario('installation');
                 $new->inherited_id = Yii::$app->user->id;
                 $new->status = User::STATUS_ACTIVE;
                 $new->role = User::ROLE_MEMBER;
                 $new->timezone = User::DEFAULT_TIMEZONE;
                 if ($new->save()) {
                     $this->success(Yii::t('podium/flash', Messages::ACCOUNT_INHERITED, ['link' => Html::a(Yii::t('podium/layout', 'Profile'))]));
                     Cache::clearAfterActivate();
                     Log::info('Inherited account created', $new->id, __METHOD__);
                 } else {
                     throw new Exception(Yii::t('podium/view', Messages::ACCOUNT_INHERITED_ERROR));
                 }
             } elseif ($user->status == User::STATUS_BANNED) {
                 return $this->redirect(['default/ban']);
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:34,代码来源:BaseController.php

示例2: getUser

 /**
  * Returns User.
  * @param integer $status
  * @return User
  */
 public function getUser($status = null)
 {
     if ($this->_user === false) {
         $this->_user = User::findByKeyfield($this->username, $status);
     }
     return $this->_user;
 }
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:12,代码来源:ReForm.php

示例3: 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']);
     }
 }
开发者ID:keltstr,项目名称:yii2-podium,代码行数:33,代码来源:MembersController.php

示例4: getUser

 /**
  * Return User.
  * @return User
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByKeyfield($this->username);
     }
     return $this->_user;
 }
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:11,代码来源:LoginForm.php

示例5: blame

 /**
  * Returns ID of user responsible for logged action.
  * @return integer|null
  */
 public static function blame()
 {
     if (Yii::$app instanceof Application && !Yii::$app->user->isGuest) {
         return User::loggedId();
     }
     return null;
 }
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:11,代码来源:Log.php

示例6: search

 /**
  * Searches for subscription
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = self::find()->where(['user_id' => User::loggedId()]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10, 'forcePageParam' => false]]);
     $dataProvider->sort->defaultOrder = ['post_seen' => SORT_ASC, 'id' => SORT_DESC];
     $dataProvider->pagination->pageSize = Yii::$app->session->get('per-page', 20);
     return $dataProvider;
 }
开发者ID:gitter-badger,项目名称:yii2-podium,代码行数:13,代码来源:Subscription.php

示例7: _addAdmin

 /**
  * Adds Administrator account.
  * @return string result message.
  */
 protected function _addAdmin()
 {
     try {
         $podium = PodiumModule::getInstance();
         if ($podium->userComponent == PodiumModule::USER_INHERIT) {
             if (!empty($podium->adminId)) {
                 $this->authManager->assign($this->authManager->getRole('podiumAdmin'), $podium->adminId);
                 return $this->outputSuccess(Yii::t('podium/flash', Messages::ADMINISTRATOR_PRIVILEGES_SET, ['id' => $podium->adminId]));
             } else {
                 return $this->outputWarning(Yii::t('podium/flash', Messages::NO_ADMINISTRATOR_PRIVILEGES_SET));
             }
         } else {
             $admin = new User();
             $admin->setScenario('installation');
             $admin->username = self::DEFAULT_USERNAME;
             $admin->email = self::DEFAULT_USER_EMAIL;
             $admin->status = User::STATUS_ACTIVE;
             $admin->role = User::ROLE_ADMIN;
             $admin->generateAuthKey();
             $admin->setPassword(self::DEFAULT_USERNAME);
             if ($admin->save()) {
                 $this->authManager->assign($this->authManager->getRole('podiumAdmin'), $admin->getId());
                 return $this->outputSuccess(Yii::t('podium/flash', Messages::ADMINISTRATOR_ACCOUNT_CREATED) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Login') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Password') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME));
             } else {
                 $this->setError(true);
                 return $this->outputDanger(Yii::t('podium/flash', Messages::ACCOUNT_CREATING_ERROR) . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
             }
         }
     } catch (Exception $e) {
         Yii::error([$e->getName(), $e->getMessage()], __METHOD__);
         $this->setError(true);
         return $this->outputDanger(Yii::t('podium/flash', Messages::ACCOUNT_CREATING_ERROR) . ': ' . Html::tag('pre', $e->getMessage()));
     }
 }
开发者ID:keltstr,项目名称:yii2-podium,代码行数:38,代码来源:Installation.php

示例8: search

 /**
  * Searches for threads with unread posts.
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search()
 {
     $loggedId = User::loggedId();
     $query = Thread::find()->joinWith('threadView')->where(['or', ['and', ['user_id' => $loggedId], new Expression('`new_last_seen` < `new_post_at`')], ['and', ['user_id' => $loggedId], new Expression('`edited_last_seen` < `edited_post_at`')], ['user_id' => null]]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10, 'forcePageParam' => false]]);
     $dataProvider->sort->defaultOrder = ['edited_post_at' => SORT_ASC, 'id' => SORT_ASC];
     $dataProvider->pagination->pageSize = Yii::$app->session->get('per-page', 20);
     return $dataProvider;
 }
开发者ID:gitter-badger,项目名称:yii2-podium,代码行数:14,代码来源:ThreadView.php

示例9: validateCurrentPassword

 public function validateCurrentPassword($attribute)
 {
     if (!empty($this->user_id)) {
         $user = User::findOne($this->user_id);
         if (!$user->validatePassword($this->current_password)) {
             $this->addError($attribute, Yii::t('podium/view', 'Current password is incorrect.'));
         }
     }
 }
开发者ID:keltstr,项目名称:yii2-podium,代码行数:9,代码来源:Meta.php

示例10: search

 /**
  * Searches for subscription
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = self::find()->where(['user_id' => User::loggedId()]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10, 'forcePageParam' => false]]);
     $dataProvider->sort->defaultOrder = ['post_seen' => SORT_ASC, 'id' => SORT_DESC];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     return $dataProvider;
 }
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:15,代码来源:Subscription.php

示例11: run

 /**
  * Renders the list of users reading current section.
  * @return string
  */
 public function run()
 {
     $url = Yii::$app->request->getUrl();
     $out = '';
     switch ($this->what) {
         case 'forum':
             $out .= Yii::t('podium/view', 'Browsing this forum') . ': ';
             break;
         case 'topic':
             $out .= Yii::t('podium/view', 'Reading this thread') . ': ';
             break;
         case 'unread':
             $out .= Yii::t('podium/view', 'Browsing unread threads') . ': ';
             break;
         case 'members':
             $out .= Yii::t('podium/view', 'Browsing the members') . ': ';
             break;
     }
     $conditions = ['and', [Activity::tableName() . '.anonymous' => 0], ['is not', 'user_id', null], new Expression('`url` LIKE :url'), ['>=', Activity::tableName() . '.updated_at', time() - 5 * 60]];
     $guest = true;
     $anon = false;
     if (!Yii::$app->user->isGuest) {
         $guest = false;
         $me = User::findMe();
         $conditions[] = ['not in', 'user_id', $me->id];
         if ($me->anonymous == 0) {
             $out .= $me->podiumTag . ' ';
         } else {
             $anon = true;
         }
     }
     $users = Activity::find()->joinWith(['user'])->where($conditions)->params([':url' => $url . '%']);
     foreach ($users->each() as $user) {
         $out .= $user->user->podiumTag . ' ';
     }
     $conditions = ['and', ['anonymous' => 1], new Expression('`url` LIKE :url'), ['>=', 'updated_at', time() - 5 * 60]];
     $anonymous = Activity::find()->where($conditions)->params([':url' => $url . '%'])->count('id');
     if ($anon) {
         $anonymous += 1;
     }
     $conditions = ['and', ['user_id' => null], new Expression('`url` LIKE :url'), ['>=', 'updated_at', time() - 5 * 60]];
     $guests = Activity::find()->where($conditions)->params([':url' => $url . '%'])->count('id');
     if ($guest) {
         $guests += 1;
     }
     if ($anonymous) {
         $out .= Html::button(Yii::t('podium/view', '{n, plural, =1{# anonymous user} other{# anonymous users}}', ['n' => $anonymous]), ['class' => 'btn btn-xs btn-default disabled']) . ' ';
     }
     if ($guests) {
         $out .= Html::button(Yii::t('podium/view', '{n, plural, =1{# guest} other{# guests}}', ['n' => $guests]), ['class' => 'btn btn-xs btn-default disabled']);
     }
     return $out;
 }
开发者ID:gitter-badger,项目名称:yii2-podium,代码行数:57,代码来源:Readers.php

示例12: 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;
 }
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:20,代码来源:UserSearch.php

示例13: _addAdmin

 /**
  * Adds Administrator account.
  * @return string result message.
  */
 protected function _addAdmin()
 {
     try {
         $podium = PodiumModule::getInstance();
         if ($podium->userComponent == PodiumModule::USER_INHERIT) {
             if (!empty($podium->adminId)) {
                 $admin = new User();
                 $admin->setScenario('installation');
                 $admin->inherited_id = $podium->adminId;
                 $admin->username = self::DEFAULT_USERNAME;
                 $admin->status = User::STATUS_ACTIVE;
                 $admin->role = User::ROLE_ADMIN;
                 $admin->timezone = User::DEFAULT_TIMEZONE;
                 if ($admin->save()) {
                     $this->authManager->assign($this->authManager->getRole(Rbac::ROLE_ADMIN), $podium->adminId);
                     return $this->outputSuccess(Yii::t('podium/flash', 'Administrator privileges have been set for the user of ID {id}.', ['id' => $podium->adminId]));
                 } else {
                     $this->setError(true);
                     return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
                 }
             } else {
                 return $this->outputWarning(Yii::t('podium/flash', 'No administrator privileges have been set.'));
             }
         } else {
             $admin = new User();
             $admin->setScenario('installation');
             $admin->username = self::DEFAULT_USERNAME;
             $admin->status = User::STATUS_ACTIVE;
             $admin->role = User::ROLE_ADMIN;
             $admin->timezone = User::DEFAULT_TIMEZONE;
             $admin->generateAuthKey();
             $admin->setPassword(self::DEFAULT_USERNAME);
             if ($admin->save()) {
                 $this->authManager->assign($this->authManager->getRole(Rbac::ROLE_ADMIN), $admin->getId());
                 return $this->outputSuccess(Yii::t('podium/flash', 'Administrator account has been created.') . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Login') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Password') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME));
             } else {
                 $this->setError(true);
                 return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
             }
         }
     } catch (Exception $e) {
         Yii::error([$e->getName(), $e->getMessage()], __METHOD__);
         $this->setError(true);
         return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', $e->getMessage()));
     }
 }
开发者ID:aekkapun,项目名称:yii2-podium,代码行数:50,代码来源:Installation.php

示例14: searchDeleted

 public function searchDeleted($params)
 {
     $dataProvider = $this->search();
     $dataProvider->query->where(['or', ['and', ['sender_id' => Yii::$app->user->id], ['sender_status' => Message::getDeletedStatuses()]], ['and', ['receiver_id' => Yii::$app->user->id], ['receiver_status' => Message::getDeletedStatuses()]]]);
     if (!($this->load($params) && $this->validate())) {
         $dataProvider->query->joinWith(['receiverUser' => function ($q) {
             $q->from(User::tableName() . ' pdu_receiver');
         }, 'senderUser' => function ($q) {
             $q->from(User::tableName() . ' pdu_sender');
         }]);
         return $dataProvider;
     }
     $dataProvider->query->andFilterWhere(['like', 'topic', $this->topic]);
     $dataProvider->query->joinWith(['receiverUser' => function ($q) {
         $q->from(User::tableName() . ' pdu_receiver')->where(['like', 'pdu_receiver.username', $this->receiverName]);
     }, 'senderUser' => function ($q) {
         $q->from(User::tableName() . ' pdu_sender')->where(['like', 'pdu_sender.username', $this->senderName]);
     }]);
     return $dataProvider;
 }
开发者ID:keltstr,项目名称:yii2-podium,代码行数:20,代码来源:MessageSearch.php

示例15: search

 /**
  * Searches for sent messages.
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     // not very proud of this query - slow for sure
     // let me know if it can be done better.
     $subquery = (new Query())->select(['m2.replyto'])->from(['m1' => Message::tableName()])->leftJoin(['m2' => Message::tableName()], '`m1`.`replyto` = `m2`.`id`')->where(['is not', 'm2.replyto', null]);
     $query = self::find()->where(['and', ['sender_id' => User::loggedId(), 'sender_status' => Message::getSentStatuses()], ['not in', Message::tableName() . '.id', $subquery]]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => ['id', 'topic', 'created_at']]]);
     $dataProvider->sort->defaultOrder = ['id' => SORT_DESC];
     $dataProvider->pagination->pageSize = Yii::$app->session->get('per-page', 20);
     if (!($this->load($params) && $this->validate())) {
         $dataProvider->query->joinWith(['messageReceivers' => function ($q) {
             $q->joinWith(['receiver']);
         }]);
         return $dataProvider;
     }
     $dataProvider->query->andFilterWhere(['like', 'topic', $this->topic]);
     if (preg_match('/^(forum|orum|rum|um|m)?#([0-9]+)$/', strtolower($this->receiverName), $matches)) {
         $dataProvider->query->joinWith(['messageReceivers' => function ($q) use($matches) {
             $q->joinWith(['receiver' => function ($q) use($matches) {
                 $q->andFilterWhere(['username' => ['', null], User::tableName() . '.id' => $matches[2]]);
             }]);
         }]);
     } elseif (preg_match('/^([0-9]+)$/', $this->receiverName, $matches)) {
         $dataProvider->query->joinWith(['messageReceivers' => function ($q) use($matches) {
             $q->joinWith(['receiver' => function ($q) use($matches) {
                 $q->andFilterWhere(['or', ['like', 'username', $this->receiverName], ['username' => ['', null], 'id' => $matches[1]]]);
             }]);
         }]);
     } else {
         $dataProvider->query->joinWith(['messageReceivers' => function ($q) {
             $q->joinWith(['receiver' => function ($q) {
                 $q->andFilterWhere(['like', User::tableName() . '.username', $this->receiverName]);
             }]);
         }]);
     }
     return $dataProvider;
 }
开发者ID:gitter-badger,项目名称:yii2-podium,代码行数:42,代码来源:MessageSearch.php


注:本文中的bizley\podium\models\User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。