Inheritance: extends Phalcon\Mvc\Model
示例#1
0
 /**
  * Shows the user profile
  *
  * @param int    $id       User id
  * @param string $username User name
  */
 public function viewAction($id, $username)
 {
     $user = $id ? Users::findFirstById($id) : Users::findFirstByLogin($username);
     if (!$user) {
         $user = Users::findFirstByName($username);
     }
     if (!$user) {
         $this->flashSession->error('The user does not exist');
         $this->response->redirect();
         return;
     }
     $this->view->setVar('user', $user);
     $parametersNumberPosts = ['users_id = ?0 AND deleted = 0', 'bind' => [$user->id]];
     $this->view->setVar('numberPosts', Posts::count($parametersNumberPosts));
     $parametersNumberReplies = ['users_id = ?0', 'bind' => [$user->id]];
     $this->view->setVar('numberReplies', PostsReplies::count($parametersNumberReplies));
     $parametersActivities = ['users_id = ?0', 'bind' => [$user->id], 'order' => 'created_at DESC', 'limit' => 15];
     $this->view->setVar('activities', Activities::find($parametersActivities));
     $users = Users::find(['columns' => 'id', 'conditions' => 'karma != 0', 'order' => 'karma DESC']);
     $ranking = count($users);
     foreach ($users as $position => $everyUser) {
         if ($everyUser->id == $user->id) {
             $ranking = $position + 1;
             break;
         }
     }
     $this->gravatar->setSize(220);
     $this->view->setVars(['ranking' => $ranking, 'total_ranking' => count($users), 'avatar' => $this->gravatar->getAvatar($user->email)]);
     $this->tag->setTitle('Profile - ' . $this->escaper->escapeHtml($user->name));
 }
示例#2
0
文件: Users.php 项目: sitexa/forum
 public function afterCreate()
 {
     if ($this->id > 0) {
         $activity = new Activities();
         $activity->users_id = $this->id;
         $activity->type = 'U';
         $activity->save();
     }
 }
示例#3
0
文件: Posts.php 项目: woyifang/forum
 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);
     }
 }
示例#4
0
 public function afterCreate()
 {
     if ($this->id > 0) {
         $activity = new Activities();
         $activity->users_id = $this->users_id;
         $activity->posts_id = $this->posts_id;
         $activity->type = Activities::NEW_REPLY;
         $activity->save();
         $toNotify = array();
         /**
          * Notify users that always want notifications
          */
         foreach (Users::find(array('notifications = "Y"', 'columns' => 'id')) as $user) {
             if ($this->users_id != $user->id) {
                 $notification = new Notifications();
                 $notification->users_id = $user->id;
                 $notification->posts_id = $this->posts_id;
                 $notification->posts_replies_id = $this->id;
                 $notification->type = 'C';
                 $notification->save();
                 $activity = new ActivityNotifications();
                 $activity->users_id = $user->id;
                 $activity->posts_id = $this->posts_id;
                 $activity->posts_replies_id = $this->id;
                 $activity->users_origin_id = $this->users_id;
                 $activity->type = 'C';
                 $activity->save();
                 $toNotify[$user->id] = $notification->id;
             }
         }
         /**
          * Register users subscribed to the post
          */
         foreach (PostsSubscribers::findByPostsId($this->posts_id) as $subscriber) {
             if (!isset($toNotify[$subscriber->users_id])) {
                 $notification = new Notifications();
                 $notification->users_id = $subscriber->users_id;
                 $notification->posts_id = $this->posts_id;
                 $notification->posts_replies_id = $this->id;
                 $notification->type = 'C';
                 $notification->save();
                 $activity = new ActivityNotifications();
                 $activity->users_id = $subscriber->users_id;
                 $activity->posts_id = $this->posts_id;
                 $activity->posts_replies_id = $this->id;
                 $activity->users_origin_id = $this->users_id;
                 $activity->type = 'C';
                 $activity->save();
                 $toNotify[$subscriber->users_id] = $notification->id;
             }
         }
         /**
          * Register the user in the post's notifications
          */
         if (!isset($toNotify[$this->users_id])) {
             $parameters = array('users_id = ?0 AND posts_id = ?1', 'bind' => array($this->users_id, $this->posts_id));
             $hasNotifications = PostsNotifications::count($parameters);
             if (!$hasNotifications) {
                 $notification = new PostsNotifications();
                 $notification->users_id = $this->users_id;
                 $notification->posts_id = $this->posts_id;
                 $notification->save();
             }
         }
         /**
          * Notify users that have commented in the same post
          */
         $postsNotifications = PostsNotifications::findByPostsId($this->posts_id);
         foreach ($postsNotifications as $postNotification) {
             if (!isset($toNotify[$postNotification->users_id])) {
                 if ($postNotification->users_id != $this->users_id) {
                     /**
                      * Generate an e-mail notification
                      */
                     $notification = new Notifications();
                     $notification->users_id = $postNotification->users_id;
                     $notification->posts_id = $this->posts_id;
                     $notification->posts_replies_id = $this->id;
                     $notification->type = 'C';
                     $notification->save();
                     $activity = new ActivityNotifications();
                     $activity->users_id = $postNotification->users_id;
                     $activity->posts_id = $this->posts_id;
                     $activity->posts_replies_id = $this->id;
                     $activity->users_origin_id = $this->users_id;
                     $activity->type = 'C';
                     $activity->save();
                     $toNotify[$postNotification->users_id] = $notification->id;
                 }
             }
         }
         /**
          * Queue notifications to be sent
          */
         $this->getDI()->getQueue()->put($toNotify);
     }
 }
 /**
  * Shows the user profile
  */
 public function userAction($id, $username)
 {
     if ($id) {
         $user = Users::findFirstById($id);
     } else {
         $user = Users::findFirstByLogin($username);
         if (!$user) {
             $user = Users::findFirstByName($username);
         }
     }
     if (!$user) {
         $this->flashSession->error('The user does not exist');
         return $this->response->redirect();
     }
     $this->view->user = $user;
     $parametersNumberPosts = array('users_id = ?0 AND deleted = 0', 'bind' => array($user->id));
     $this->view->numberPosts = Posts::count($parametersNumberPosts);
     $parametersNumberReplies = array('users_id = ?0', 'bind' => array($user->id));
     $this->view->numberReplies = PostsReplies::count($parametersNumberReplies);
     $parametersActivities = array('users_id = ?0', 'bind' => array($user->id), 'order' => 'created_at DESC', 'limit' => 15);
     $this->view->activities = Activities::find($parametersActivities);
     $users = Users::find(array('columns' => 'id', 'conditions' => 'karma != 0', 'order' => 'karma DESC'));
     $ranking = count($users);
     foreach ($users as $position => $everyUser) {
         if ($everyUser->id == $user->id) {
             $ranking = $position + 1;
             break;
         }
     }
     $this->view->ranking = $ranking;
     $this->view->total_ranking = count($users);
     $this->tag->setTitle('Profile - ' . $this->escaper->escapeHtml($user->name));
 }
示例#6
0
 /**
  * Shows the latest activity on the forum
  */
 public function activityAction($offset = 0)
 {
     $parameters = ['order' => 'created_at DESC', 'limit' => ['number' => self::POSTS_IN_PAGE, 'offset' => 0]];
     $this->view->setVars(['total' => Activities::count(), 'activities' => Activities::find($parameters)]);
     $this->tag->setTitle('Recent Activity on the Forum');
 }