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


PHP Models\Users类代码示例

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


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

示例1: getExpertQuery

 public function getExpertQuery(Users $user)
 {
     if (!$this->query) {
         $this->query = $user->getModelsManager()->createBuilder()->columns(['p.categories_id', 'COUNT(*)'])->from(['r' => 'Phosphorum\\Models\\PostsReplies'])->join('Phosphorum\\Models\\Posts', null, 'p')->where('r.users_id = ?0 AND r.accepted = "Y"')->notInWhere('p.categories_id', $this->getNoBountyCategories())->groupBy('p.categories_id')->having('COUNT(*) >= 10')->getQuery();
     }
     return $this->query;
 }
开发者ID:sitexa,项目名称:forum,代码行数:7,代码来源:Expert.php

示例2: canHave

 /**
  * Check whether the user can have the badge
  *
  * @param Users $user
  * @return boolean
  */
 public function canHave(Users $user)
 {
     $noBountyCategories = $this->getNoBountyCategories();
     $conditions = 'categories_id NOT IN (' . join(', ', $noBountyCategories) . ') AND accepted_answer = "Y"';
     $posts = $user->getPosts(array($conditions, 'order' => 'created_at DESC'));
     foreach ($posts as $post) {
         $ownReply = $post->countReplies(array("accepted = 'Y' AND users_id = ?0", 'bind' => array($user->id)));
         if ($ownReply) {
             return true;
         }
     }
     return false;
 }
开发者ID:Blkc,项目名称:forum,代码行数:19,代码来源:SelfLearner.php

示例3: canHave

 /**
  * Check whether the user can have the badge
  *
  * @param  Users $user
  * @return boolean
  */
 public function canHave(Users $user)
 {
     $ids = [];
     $noBountyCategories = $this->getNoBountyCategories();
     $conditions = 'categories_id NOT IN (' . join(', ', $noBountyCategories) . ') AND number_views >= 10000';
     $posts = $user->getPosts([$conditions, 'columns' => 'id', 'order' => 'created_at DESC']);
     foreach ($posts as $post) {
         $have = UsersBadges::count(['users_id = ?0 AND badge = ?1 AND type = "P" AND code1 = ?2', 'bind' => [$user->id, $this->getName(), $post->id]]);
         if (!$have) {
             $ids[] = $post->id;
         }
     }
     return $ids;
 }
开发者ID:phalcon,项目名称:forum,代码行数:20,代码来源:FamousQuestion.php

示例4: canHave

 /**
  * Check whether the user can have the badge
  *
  * @param  Users $user
  * @return boolean
  */
 public function canHave(Users $user)
 {
     $ids = [];
     $noBountyCategories = $this->getNoBountyCategories();
     $conditions = '(IF(votes_up IS NULL, 0, votes_up) - IF(votes_down IS NULL, 0, votes_down)) >= 5';
     $replies = $user->getReplies([$conditions, 'columns' => 'id, posts_id', 'order' => 'created_at DESC']);
     foreach ($replies as $reply) {
         $have = UsersBadges::count(['users_id = ?0 AND badge = ?1 AND type = "C" AND code1 = ?2', 'bind' => [$user->id, $this->getName(), $reply->id]]);
         if (!$have) {
             $ids[] = [$reply->posts_id, $reply->id];
         }
     }
     return $ids;
 }
开发者ID:phalcon,项目名称:forum,代码行数:20,代码来源:GoodReply.php

示例5: canHave

 /**
  * Check whether the user can have the badge
  *
  * @param  Users $user
  * @return boolean
  */
 public function canHave(Users $user)
 {
     $ids = array();
     $noBountyCategories = $this->getNoBountyCategories();
     $conditions = 'categories_id NOT IN (' . join(', ', $noBountyCategories) . ') AND
     (IF(votes_up IS NULL, 0, votes_up) - IF(votes_down IS NULL, 0, votes_down)) >= 5';
     $posts = $user->getPosts(array($conditions, 'columns' => 'id', 'order' => 'created_at DESC'));
     foreach ($posts as $post) {
         $have = UsersBadges::count(array('users_id = ?0 AND badge = ?1 AND type = "P" AND code1 = ?2', 'bind' => array($user->id, $this->getName(), $post->id)));
         if (!$have) {
             $ids[] = $post->id;
         }
     }
     return $ids;
 }
开发者ID:kjmtrue,项目名称:phalcon-tip,代码行数:21,代码来源:GoodQuestion.php

示例6: process

 /**
  * Process users badges
  */
 public function process()
 {
     $badges = $this->getBadges();
     foreach (Users::find() as $user) {
         $this->processUserBadges($user, $badges);
     }
 }
开发者ID:atsuyim,项目名称:forum,代码行数:10,代码来源:Manager.php

示例7: send

 /**
  * Sends the digest
  */
 public function send()
 {
     $lastMonths = new \DateTime();
     $lastMonths->modify('-6 month');
     $parameters = array('modified_at >= ?0 AND digest = "Y" AND notifications <> "N"', 'bind' => array($lastMonths->getTimestamp()));
     $users = array();
     foreach (Users::find($parameters) as $user) {
         if ($user->email && strpos($user->email, '@') !== false && strpos($user->email, '@users.noreply.github.com') === false) {
             $users[trim($user->email)] = $user->name;
         }
     }
     $fromName = $this->config->mail->fromName;
     $fromEmail = $this->config->mail->fromEmail;
     $url = $this->config->site->url;
     $subject = 'Top Stories from Phosphorum ' . date('d/m/y');
     $lastWeek = new \DateTime();
     $lastWeek->modify('-1 week');
     $order = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - ' . 'IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies + IF(accepted_answer = "Y", 10, 0) DESC';
     $parameters = array('created_at >= ?0 AND deleted != 1 AND categories_id <> 4', 'bind' => array($lastWeek->getTimestamp()), 'order' => $order, 'limit' => 10);
     $e = $this->escaper;
     $content = '<html><head></head><body><p><h1 style="font-size:22px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;padding:16px 0;border-bottom:1px solid #e2e2e2">Top Stories from Phosphorum</h1></p>';
     foreach (Posts::find($parameters) as $post) {
         $user = $post->user;
         if ($user == false) {
             continue;
         }
         $content .= '<p><a style="text-decoration:none;display:block;font-size:20px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">' . $e->escapeHtml($post->title) . '</a></p>';
         $content .= '<p><table width="100%"><td><table><tr><td>' . '<img src="https://secure.gravatar.com/avatar/' . $user->gravatar_id . '?s=32&amp;r=pg&amp;d=identicon" width="32" height="32" alt="' . $user->name . ' icon">' . '</td><td><a style="text-decoration:none;color:#155fad" href="' . $url . '/user/' . $user->id . '/' . $user->login . '">' . $user->name . '<br><span style="text-decoration:none;color:#999;text-decoration:none">' . $user->getHumanKarma() . '</span></a></td></tr></table></td><td align="right"><table style="border: 1px solid #dadada;" cellspacing=5>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Created</label><br>' . $post->getHumanCreatedAt() . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Replies</label><br>' . $post->number_replies . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Views</label><br>' . $post->number_views . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Votes</label><br>' . ($post->votes_up - $post->votes_down) . '</td>' . '</tr></table></td></tr></table></p>';
         $content .= $this->markdown->render($e->escapeHtml($post->content));
         $content .= '<p><a style="color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">Read more</a></p>';
         $content .= '<hr style="border: 1px solid #dadada">';
     }
     $textContent = strip_tags($content);
     $htmlContent = $content . '<p style="font-size:small;-webkit-text-size-adjust:none;color:#717171;">';
     $htmlContent .= PHP_EOL . 'This email was sent by Phalcon Framework. Change your e-mail preferences <a href="' . $url . '/settings">here</a></p>';
     foreach ($users as $email => $name) {
         try {
             $message = new \Swift_Message('[Phalcon Forum] ' . $subject);
             $message->setTo(array($email => $name));
             $message->setFrom(array($fromEmail => $fromName));
             $bodyMessage = new \Swift_MimePart($htmlContent, 'text/html');
             $bodyMessage->setCharset('UTF-8');
             $message->attach($bodyMessage);
             $bodyMessage = new \Swift_MimePart($textContent, 'text/plain');
             $bodyMessage->setCharset('UTF-8');
             $message->attach($bodyMessage);
             if (!$this->transport) {
                 $this->transport = \Swift_SmtpTransport::newInstance($this->config->smtp->host, $this->config->smtp->port, $this->config->smtp->security);
                 $this->transport->setUsername($this->config->smtp->username);
                 $this->transport->setPassword($this->config->smtp->password);
             }
             if (!$this->mailer) {
                 $this->mailer = \Swift_Mailer::newInstance($this->transport);
             }
             $this->mailer->send($message);
         } catch (\Exception $e) {
             echo $e->getMessage(), PHP_EOL;
         }
     }
 }
开发者ID:woyifang,项目名称:forum,代码行数:63,代码来源:Digest.php

示例8: onConstruct

 public function onConstruct()
 {
     $lastThreads = $this->modelsManager->createBuilder()->from(['p' => 'Phosphorum\\Models\\Posts'])->groupBy("p.id")->join('Phosphorum\\Models\\Categories', "r.id = p.categories_id", 'r')->join('Phosphorum\\Models\\Users', "u.id = p.users_id", 'u')->columns(['p.title as title_post', 'p.id as id_post', 'p.slug as slug_post', 'r.name as name_category', 'u.name as name_user'])->where('p.deleted = 0')->orderBy('p.created_at DESC')->limit(3)->getQuery()->execute();
     /** @var Simple $lastMember */
     $lastMember = Users::find(['order' => 'created_at DESC', 'limit' => 1, 'columns' => 'login']);
     $login = null;
     if ($lastMember->valid()) {
         $login = $lastMember->getFirst()->login;
     }
     $this->view->setVars(['app_name' => $this->config->get('site')->name, 'app_version' => VERSION, 'threads' => Posts::count(), 'last_threads' => $lastThreads, 'users' => Users::count(), 'users_latest' => $login, 'actionName' => $this->dispatcher->getActionName(), 'controllerName' => $this->dispatcher->getControllerName()]);
 }
开发者ID:phalcon,项目名称:forum,代码行数:11,代码来源:ControllerBase.php

示例9: statsAction

 public function statsAction()
 {
     $this->view->threads = Posts::count();
     $this->view->replies = Posts::sum(array('column' => 'number_replies'));
     $this->view->votes = Posts::sum(array('column' => 'votes_up + votes_down'));
     $this->view->users = Users::count();
     $this->view->karma = Users::sum(array('column' => 'karma'));
     $this->view->notifications = Notifications::count();
     $this->view->unotifications = ActivityNotifications::count();
     $this->view->views = Posts::sum(array('column' => 'number_views'));
     $this->view->irc = IrcLog::count();
 }
开发者ID:atsuyim,项目名称:forum,代码行数:12,代码来源:HelpController.php

示例10: 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

示例11: karmaAction

 public function karmaAction()
 {
     foreach (Users::find() as $user) {
         if ($user->karma === null) {
             $parametersNumbersPost = array('users_id = ?0', 'bind' => array($user->id));
             $numberPosts = Posts::count($parametersNumbersPost);
             $parametersNumberReplies = array('users_id = ?0', 'bind' => array($user->id));
             $numberReplies = PostsReplies::count($parametersNumberReplies);
             $user->karma = $numberReplies * 10 + $numberPosts * 5;
             $user->votes = intval($user->karma / 50);
             $user->save();
         }
     }
 }
开发者ID:kjmtrue,项目名称:phalcon-tip,代码行数:14,代码来源:UtilsController.php

示例12: 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

示例13: canHave

 /**
  * Check whether the user can have the badge
  *
  * @param Users $user
  * @return boolean
  */
 public function canHave(Users $user)
 {
     return $user->countPosts('accepted_answer = "Y"') >= 1;
 }
开发者ID:kjmtrue,项目名称:phalcon-tip,代码行数:10,代码来源:Scholar.php

示例14: Categories

    $title = $faker->company;
    $category = new Categories();
    $category->name = $title;
    $category->description = $faker->sentence;
    $category->slug = Tag::friendlyTitle($title);
    $category->number_posts = 0;
    $category->no_bounty = 'N';
    $category->no_digest = 'N';
    if (!$category->save()) {
        $database->rollback();
        die(join(PHP_EOL, $category->getMessages()));
    }
    $log->info('Category: ' . $category->name);
}
for ($i = 0; $i <= 50; $i++) {
    $user = new Users();
    $user->name = $faker->name;
    $user->login = $faker->userName;
    $user->email = $faker->email;
    $user->timezone = $faker->timezone;
    if (!$user->save()) {
        $database->rollback();
        die(join(PHP_EOL, $user->getMessages()));
    }
    $log->info('User: ' . $user->name);
}
$database->commit();
$categoryIds = Categories::find(['columns' => 'id'])->toArray();
$userIds = Users::find(['columns' => 'id'])->toArray();
$database->begin();
for ($i = 0; $i <= 500; $i++) {
开发者ID:foxman209,项目名称:forum,代码行数:31,代码来源:random-entries.php

示例15: afterCreate

 public function afterCreate()
 {
     /**
      * Register a new activity
      */
     if ($this->id > 0) {
         /**
          * Register the activity
          */
         $activity = new Activities();
         $activity->users_id = $this->users_id;
         $activity->posts_id = $this->id;
         $activity->type = Activities::NEW_POST;
         $activity->save();
         /**
          * Notify users that always want notifications
          */
         $notification = new PostsNotifications();
         $notification->users_id = $this->users_id;
         $notification->posts_id = $this->id;
         $notification->save();
         /**
          * Notify users that always want notifications
          */
         $toNotify = [];
         foreach (Users::find(['notifications = "Y"', 'columns' => 'id']) as $user) {
             if ($this->users_id != $user->id) {
                 $notification = new Notifications();
                 $notification->users_id = $user->id;
                 $notification->posts_id = $this->id;
                 $notification->type = 'P';
                 $notification->save();
                 $toNotify[$user->id] = $notification->id;
             }
         }
         /**
          * Update the total of posts related to a category
          */
         $this->category->number_posts++;
         $this->category->save();
         /**
          * Queue notifications to be sent
          */
         $this->getDI()->getQueue()->put($toNotify);
     }
 }
开发者ID:woyifang,项目名称:forum,代码行数:46,代码来源:Posts.php


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