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


PHP Users::findFirstById方法代码示例

本文整理汇总了PHP中Phosphorum\Models\Users::findFirstById方法的典型用法代码示例。如果您正苦于以下问题:PHP Users::findFirstById方法的具体用法?PHP Users::findFirstById怎么用?PHP Users::findFirstById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phosphorum\Models\Users的用法示例。


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

示例1: voteAction

 /**
  * Votes for a poll option
  *
  * @param int $id     Post ID
  * @param int $option Option ID
  * @return Response
  */
 public function voteAction($id = 0, $option = 0)
 {
     $response = new Response();
     if (!$this->checkTokenGetJson('post-' . $id)) {
         $csrfTokenError = ['status' => 'error', 'message' => 'This post is outdated. Please try to vote again.'];
         return $response->setJsonContent($csrfTokenError);
     }
     if (!($post = Posts::findFirstById($id))) {
         $contentNotExist = ['status' => 'error', 'message' => 'Poll does not exist'];
         return $response->setJsonContent($contentNotExist);
     }
     if (!($user = Users::findFirstById($this->session->get('identity')))) {
         $contentlogIn = ['status' => 'error', 'message' => 'You must log in first to vote'];
         return $response->setJsonContent($contentlogIn);
     }
     if (!($option = PostsPollOptions::findFirstById($option))) {
         $optionNotFound = ['status' => 'error', 'message' => 'Please select one option from the list below'];
         return $response->setJsonContent($optionNotFound);
     }
     if ($post->isParticipatedInPoll($user->id)) {
         $contentAlreadyVote = ['status' => 'error', 'message' => 'You have already voted this post'];
         return $response->setJsonContent($contentAlreadyVote);
     }
     $pollVote = new PostsPollVotes();
     $pollVote->posts_id = $post->id;
     $pollVote->users_id = $user->id;
     $pollVote->options_id = $option->id;
     if (!$pollVote->save()) {
         foreach ($pollVote->getMessages() as $message) {
             /** @var \Phalcon\Mvc\Model\Message $message */
             $contentError = ['status' => 'error', 'message' => $message->getMessage()];
             return $response->setJsonContent($contentError);
         }
     }
     if ($post->users_id != $user->id) {
         $post->user->increaseKarma(Karma::SOMEONE_DID_VOTE_MY_POLL);
         $user->increaseKarma(Karma::VOTE_ON_SOMEONE_ELSE_POLL);
     }
     if (!$post->save()) {
         foreach ($post->getMessages() as $message) {
             /** @var \Phalcon\Mvc\Model\Message $message */
             $contentErrorSave = ['status' => 'error', 'message' => $message->getMessage()];
             return $response->setJsonContent($contentErrorSave);
         }
     }
     $viewCache = $this->getDI()->getShared('viewCache');
     $viewCache->delete('post-' . $post->id);
     $viewCache->delete('poll-votes-' . $post->id);
     $viewCache->delete('poll-options-' . $post->id);
     $contentOk = ['status' => 'OK'];
     return $response->setJsonContent($contentOk);
 }
开发者ID:phalcon,项目名称:forum,代码行数:59,代码来源:PollsController.php

示例2: settingsAction

 /**
  * Allow to change your user settings
  */
 public function settingsAction()
 {
     $usersId = $this->session->get('identity');
     if (!$usersId) {
         $this->flashSession->error('You must be logged first');
         $this->response->redirect();
         return;
     }
     $user = Users::findFirstById($usersId);
     if (!$user) {
         $this->flashSession->error('The user does not exist');
         $this->response->redirect();
         return;
     }
     if ($this->request->isPost()) {
         if (!$this->checkTokenPost()) {
             $this->response->redirect();
             return;
         }
         $user->timezone = $this->request->getPost('timezone');
         $user->notifications = $this->request->getPost('notifications');
         $user->theme = $this->request->getPost('theme');
         $user->digest = $this->request->getPost('digest');
         if ($user->save()) {
             $this->session->set('identity-theme', $user->theme);
             $this->session->get('identity-timezone', $user->timezone);
             $this->flashSession->success('Settings were successfully updated');
             $this->response->redirect();
             return;
         }
     } else {
         $this->tag->displayTo('timezone', $user->timezone);
         $this->tag->displayTo('notifications', $user->notifications);
         $this->tag->displayTo('theme', $user->theme);
         $this->tag->displayTo('digest', $user->digest);
     }
     $this->tag->setTitle('My Settings');
     $this->tag->setAutoEscape(false);
     $this->gravatar->setSize(64);
     $this->view->setVars(['user' => $user, 'timezones' => $this->di->getShared('timezones'), 'numberPosts' => Posts::count(['users_id = ?0 AND deleted = 0', 'bind' => [$user->id]]), 'numberReplies' => PostsReplies::count(['users_id = ?0', 'bind' => [$user->id]])]);
 }
开发者ID:huoybb,项目名称:forum,代码行数:44,代码来源:UsersController.php

示例3: notificationsAction

 /**
  * Shows the latest notifications for the current user
  */
 public function notificationsAction($offset = 0)
 {
     $usersId = $this->session->get('identity');
     if (!$usersId) {
         $this->flashSession->error('You must be logged first');
         return $this->response->redirect();
     }
     $user = Users::findFirstById($usersId);
     if (!$user) {
         $this->flashSession->error('The user does not exist');
         return $this->response->redirect();
     }
     $this->view->user = $user;
     $this->view->notifications = ActivityNotifications::find(['users_id = ?0', 'bind' => [$usersId], 'limit' => 128, 'order' => 'created_at DESC']);
     $this->tag->setTitle('Notifications');
 }
开发者ID:kjmtrue,项目名称:forum,代码行数:19,代码来源:DiscussionsController.php

示例4: acceptAction

 /**
  * Accepts a reply as correct answer
  */
 public function acceptAction($id = 0)
 {
     $response = new Response();
     /**
      * Find the post using get
      */
     $postReply = PostsReplies::findFirstById($id);
     if (!$postReply) {
         $contentNotExist = array('status' => 'error', 'message' => 'Post reply does not exist');
         return $response->setJsonContent($contentNotExist);
     }
     $user = Users::findFirstById($this->session->get('identity'));
     if (!$user) {
         $contentLogIn = array('status' => 'error', 'message' => 'You must log in first to vote');
         return $response->setJsonContent($contentLogIn);
     }
     if ($postReply->accepted == 'Y') {
         $contentAlready = array('status' => 'error', 'message' => 'This reply is already accepted as answer');
         return $response->setJsonContent($contentAlready);
     }
     if ($postReply->post->deleted) {
         $contentDeleted = array('status' => 'error', 'message' => 'Post associated to the reply is deleted');
         return $response->setJsonContent($contentDeleted);
     }
     if ($postReply->post->accepted_answer == 'Y') {
         $contentAlreadyAnswer = array('status' => 'error', 'message' => 'This post already has an accepted answer');
         return $response->setJsonContent($contentAlreadyAnswer);
     }
     if ($postReply->post->users_id != $user->id && $user->moderator != 'Y') {
         $contentCorrect = array('status' => 'error', 'message' => 'You can\'t accept this answer as correct');
         return $response->setJsonContent($contentCorrect);
     }
     if ($postReply->post->users_id != $postReply->users_id) {
         $postReply->post->user->karma += Karma::SOMEONE_ELSE_ACCEPT_YOUR_REPLY;
         $postReply->post->user->votes_points += Karma::SOMEONE_ELSE_ACCEPT_YOUR_REPLY;
         $points = 30 + intval(abs($user->karma - $postReply->user->karma) / 1000);
         $parametersBounty = array('users_id = ?0 AND posts_replies_id = ?1', 'bind' => array($postReply->users_id, $postReply->id));
         $postBounty = PostsBounties::findFirst($parametersBounty);
         if ($postBounty) {
             $points += $postBounty->points;
         }
         $postReply->user->karma += $points;
         $postReply->user->votes_points += $points;
         if ($postReply->users_id != $user->id && $postReply->post->users_id != $user->id) {
             $user->karma += Karma::SOMEONE_ELSE_ACCEPT_YOUR_REPLY;
             $user->votes_points += Karma::SOMEONE_ELSE_ACCEPT_YOUR_REPLY;
         }
     }
     $postReply->accepted = 'Y';
     $postReply->post->accepted_answer = 'Y';
     if ($postReply->save()) {
         if (!$user->save()) {
             foreach ($user->getMessages() as $message) {
                 $contentError = array('status' => 'error', 'message' => $message->getMessage());
                 return $response->setJsonContent($contentError);
             }
         }
     }
     if ($user->id != $postReply->users_id) {
         $activity = new ActivityNotifications();
         $activity->users_id = $postReply->users_id;
         $activity->posts_id = $postReply->post->id;
         $activity->posts_replies_id = $postReply->id;
         $activity->users_origin_id = $user->id;
         $activity->type = 'A';
         $activity->save();
     }
     $contentOk = array('status' => 'OK');
     return $response->setJsonContent($contentOk);
 }
开发者ID:Rudianasaja,项目名称:forum,代码行数:73,代码来源:RepliesController.php


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