當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::findOne方法代碼示例

本文整理匯總了PHP中humhub\modules\user\models\User::findOne方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::findOne方法的具體用法?PHP User::findOne怎麽用?PHP User::findOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在humhub\modules\user\models\User的用法示例。


在下文中一共展示了User::findOne方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: afterSave

 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($this->scenario == self::SCENARIO_EDIT) {
         $managerGuids = explode(",", $this->managerGuids);
         foreach ($managerGuids as $managerGuid) {
             // Ensure guids valid characters
             $managerGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $managerGuid);
             // Try to load user and get/create the GroupUser relation with isManager
             $user = \humhub\modules\user\models\User::findOne(['guid' => $managerGuid]);
             if ($user != null) {
                 $groupUser = GroupUser::findOne(['group_id' => $this->id, 'user_id' => $user->id]);
                 if ($groupUser != null && !$groupUser->is_group_manager) {
                     $groupUser->is_group_manager = true;
                     $groupUser->save();
                 } else {
                     $this->addUser($user, true);
                 }
             }
         }
         //Remove admins not contained in the selection
         foreach ($this->getManager()->all() as $admin) {
             if (!in_array($admin->guid, $managerGuids)) {
                 $groupUser = GroupUser::findOne(['group_id' => $this->id, 'user_id' => $admin->id]);
                 if ($groupUser != null) {
                     $groupUser->is_group_manager = false;
                     $groupUser->save();
                 }
             }
         }
     }
     parent::afterSave($insert, $changedAttributes);
 }
開發者ID:VasileGabriel,項目名稱:humhub,代碼行數:35,代碼來源:Group.php

示例2: actionEdit

 /** 
  * Edit a karma record
  */
 public function actionEdit()
 {
     $id = (int) Yii::$app->request->get('id');
     $user = User::findOne(['id' => $id]);
     $karma = Karma::findOne(['id' => $id]);
     if ($karma == null) {
         throw new \yii\web\HttpException(404, "Karma record not found!");
     }
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     // Define Form Eleements
     $definition['elements']['Karma'] = array('type' => 'form', 'title' => 'Karma', 'elements' => array('name' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'points' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 10), 'description' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 1000)));
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => 'Save', 'class' => 'btn btn-primary'), 'delete' => array('type' => 'submit', 'label' => 'Delete', 'class' => 'btn btn-danger'));
     $form = new HForm($definition);
     $form->models['Karma'] = $karma;
     if ($form->submitted('save') && $form->validate()) {
         if ($form->save()) {
             return $this->redirect(Url::toRoute(['edit', 'id' => $karma->id]));
         }
     }
     if ($form->submitted('delete')) {
         return $this->redirect(Url::toRoute(['delete', 'id' => $karma->id]));
     }
     return $this->render('edit', array('hForm' => $form));
 }
開發者ID:ConnectedCommunities,項目名稱:humhub-modules-karma,代碼行數:30,代碼來源:AdminController.php

示例3: Get

 /**
  * Gets a user setting
  * 
  * @see \humhub\modules\content\components\ContentContainerSettingsManager::get
  * @param int $userId
  * @param string $name
  * @param string $moduleId
  * @param string $defaultValue
  * @return string the value
  */
 public static function Get($userId, $name, $moduleId = "", $defaultValue = "")
 {
     $user = User::findOne(['id' => $userId]);
     $value = self::getModule($moduleId)->settings->contentContainer($user)->get($name);
     if ($value === null) {
         return $defaultValue;
     }
     return $value;
 }
開發者ID:kreativmind,項目名稱:humhub,代碼行數:19,代碼來源:Setting.php

示例4: actionPopup

 /**
  * Returns an list of all friends of a user
  */
 public function actionPopup()
 {
     $user = User::findOne(['id' => Yii::$app->request->get('userId')]);
     if ($user === null) {
         throw new \yii\web\HttpException(404, 'Could not find user!');
     }
     $query = Friendship::getFriendsQuery($user);
     $title = '<strong>' . Yii::t('FriendshipModule.base', "Friends") . '</strong>';
     return $this->renderAjaxContent(UserListBox::widget(['query' => $query, 'title' => $title]));
 }
開發者ID:VasileGabriel,項目名稱:humhub,代碼行數:13,代碼來源:ListController.php

示例5: actionDelete

 /**
  * Declines or Deletes Friendship
  */
 public function actionDelete()
 {
     $this->forcePostRequest();
     $friend = User::findOne(['id' => Yii::$app->request->get('userId')]);
     if ($friend === null) {
         throw new \yii\web\HttpException(404, 'User not found!');
     }
     Friendship::cancel(Yii::$app->user->getIdentity(), $friend);
     return $this->redirect($friend->getUrl());
 }
開發者ID:VasileGabriel,項目名稱:humhub,代碼行數:13,代碼來源:RequestController.php

示例6: getUrlByUserGuid

 /**
  * Gets usernameby given guid
  * 
  * @param string $guid
  * @return string|null the username
  */
 public static function getUrlByUserGuid($guid)
 {
     if (isset(static::$userUrlMap[$guid])) {
         return static::$userUrlMap[$guid];
     }
     $user = User::findOne(['guid' => $guid]);
     if ($user !== null) {
         static::$userUrlMap[$user->guid] = $user->username;
         return static::$userUrlMap[$user->guid];
     }
     return null;
 }
開發者ID:VasileGabriel,項目名稱:humhub,代碼行數:18,代碼來源:UrlRule.php

示例7: getUser

 public function getUser()
 {
     if ($this->user != null) {
         return $this->user;
     }
     $guid = Yii::$app->request->getQuery('uguid');
     $this->user = User::findOne(['guid' => $guid]);
     if ($this->user == null) {
         throw new HttpException(404, Yii::t('UserModule.behaviors_ProfileControllerBehavior', 'User not found!'));
     }
     $this->checkAccess();
     return $this->user;
 }
開發者ID:VasileGabriel,項目名稱:humhub,代碼行數:13,代碼來源:ProfileController.php

示例8: getUserByAuthClient

 /**
  * Returns the user object which is linked against given authClient
  * 
  * @param ClientInterface $authClient the authClient
  * @return User the user model or null if not found
  */
 public static function getUserByAuthClient(ClientInterface $authClient)
 {
     $attributes = $authClient->getUserAttributes();
     if ($authClient instanceof interfaces\PrimaryClient) {
         /**
          * @var interfaces\PrimaryClient $authClient
          */
         return User::findOne([$authClient->getUserTableIdAttribute() => $attributes['id'], 'auth_mode' => $authClient->getId()]);
     }
     $auth = Auth::find()->where(['source' => $authClient->getId(), 'source_id' => $attributes['id']])->one();
     if ($auth !== null) {
         return $auth->user;
     }
 }
開發者ID:kreativmind,項目名稱:humhub,代碼行數:20,代碼來源:AuthClientHelpers.php

示例9: recover

 /**
  * Sends this user a new password by E-Mail
  *
  */
 public function recover()
 {
     $user = User::findOne(array('email' => $this->email));
     // Switch to users language - if specified
     if ($user->language !== "") {
         Yii::$app->language = $user->language;
     }
     $token = \humhub\libs\UUID::v4();
     Yii::$app->getModule('user')->settings->contentContainer($user)->set('passwordRecoveryToken', $token . '.' . time());
     $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword', 'text' => '@humhub/modules/user/views/mails/plaintext/RecoverPassword'], ['user' => $user, 'linkPasswordReset' => Url::to(["/user/password-recovery/reset", 'token' => $token, 'guid' => $user->guid], true)]);
     $mail->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')]);
     $mail->setTo($user->email);
     $mail->setSubject(Yii::t('UserModule.forms_AccountRecoverPasswordForm', 'Password Recovery'));
     $mail->send();
     return true;
 }
開發者ID:VasileGabriel,項目名稱:humhub,代碼行數:20,代碼來源:AccountRecoverPassword.php

示例10: checkEmails

 /**
  * Checks a comma separated list of e-mails which should invited.
  * E-Mails needs to be valid and not already registered.
  *
  * @param string $attribute
  * @param array $params
  */
 public function checkEmails($attribute, $params)
 {
     if ($this->{$attribute} != "") {
         foreach ($this->getEmails() as $email) {
             $validator = new \yii\validators\EmailValidator();
             if (!$validator->validate($email)) {
                 $this->addError($attribute, Yii::t('UserModule.invite', '{email} is not valid!', array("{email}" => $email)));
                 continue;
             }
             if (User::findOne(['email' => $email]) != null) {
                 $this->addError($attribute, Yii::t('UserModule.invite', '{email} is already registered!', array("{email}" => $email)));
                 continue;
             }
         }
     }
 }
開發者ID:VasileGabriel,項目名稱:humhub,代碼行數:23,代碼來源:Invite.php

示例11: recover

 /**
  * Sends this user a new password by E-Mail
  *
  */
 public function recover()
 {
     $user = User::findOne(array('email' => $this->email));
     // Switch to users language - if specified
     if ($user->language !== "") {
         Yii::$app->language = $user->language;
     }
     $token = \humhub\libs\UUID::v4();
     $user->setSetting('passwordRecoveryToken', $token . '.' . time(), 'user');
     $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword'], ['user' => $user, 'linkPasswordReset' => Url::to(["/user/auth/reset-password", 'token' => $token, 'guid' => $user->guid], true)]);
     $mail->setFrom([\humhub\models\Setting::Get('systemEmailAddress', 'mailing') => \humhub\models\Setting::Get('systemEmailName', 'mailing')]);
     $mail->setTo($user->email);
     $mail->setSubject(Yii::t('UserModule.forms_AccountRecoverPasswordForm', 'Password Recovery'));
     $mail->send();
     return true;
 }
開發者ID:SimonBaeumer,項目名稱:humhub,代碼行數:20,代碼來源:AccountRecoverPassword.php

示例12: actionReset

 /**
  * Resets users password based on given token
  */
 public function actionReset()
 {
     $user = User::findOne(array('guid' => Yii::$app->request->get('guid')));
     if ($user === null || !$this->checkPasswordResetToken($user, Yii::$app->request->get('token'))) {
         throw new HttpException('500', 'It looks like you clicked on an invalid password reset link. Please try again.');
     }
     $model = new Password();
     $model->scenario = 'registration';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->getModule('user')->settings->contentContainer($user)->delete('passwordRecoveryToken');
         $model->user_id = $user->id;
         $model->setPassword($model->newPassword);
         $model->save();
         return $this->render('reset_success');
     }
     return $this->render('reset', array('model' => $model));
 }
開發者ID:kreativmind,項目名稱:humhub,代碼行數:20,代碼來源:PasswordRecoveryController.php

示例13: checkRecipient

 /**
  * Form Validator which checks the recipient field
  *
  * @param type $attribute
  * @param type $params
  */
 public function checkRecipient($attribute, $params)
 {
     // Check if email field is not empty
     if ($this->{$attribute} != "") {
         $recipients = explode(",", $this->{$attribute});
         foreach ($recipients as $userGuid) {
             $userGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $userGuid);
             // Try load user
             $user = User::findOne(['guid' => $userGuid]);
             if ($user != null) {
                 if ($user->id == Yii::$app->user->id) {
                     $this->addError($attribute, Yii::t('MailModule.forms_InviteRecipientForm', "You cannot send a email to yourself!"));
                 } else {
                     $this->recipients[] = $user;
                 }
             }
         }
     }
 }
開發者ID:kinderp,項目名稱:humhub-modules-services,代碼行數:25,代碼來源:InviteRecipient.php

示例14: afterSave

 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($this->scenario == 'edit') {
         \humhub\modules\user\models\GroupAdmin::deleteAll(['group_id' => $this->id]);
         $adminUsers = array();
         foreach (explode(",", $this->adminGuids) as $adminGuid) {
             // Ensure guids valid characters
             $adminGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $adminGuid);
             // Try load user
             $user = \humhub\modules\user\models\User::findOne(['guid' => $adminGuid]);
             if ($user != null) {
                 $groupAdmin = new GroupAdmin();
                 $groupAdmin->user_id = $user->id;
                 $groupAdmin->group_id = $this->id;
                 $groupAdmin->save();
             }
         }
     }
     parent::afterSave($insert, $changedAttributes);
 }
開發者ID:weison-tech,項目名稱:humhub,代碼行數:23,代碼來源:Group.php

示例15: afterSave

 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     foreach (explode(",", $this->assignedUserGuids) as $userGuid) {
         $f = false;
         foreach ($this->assignedUsers as $user) {
             if ($user->guid == trim($userGuid)) {
                 $f = true;
             }
         }
         if ($f == false) {
             $this->assignUser(User::findOne(['guid' => trim($userGuid)]));
         }
     }
     foreach ($this->assignedUsers as $user) {
         if (strpos($this->assignedUserGuids, $user->guid) === false) {
             $this->unassignUser($user);
         }
     }
 }
開發者ID:pkdevboxy,項目名稱:humhub-modules-tasks,代碼行數:20,代碼來源:Task.php


注:本文中的humhub\modules\user\models\User::findOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。