Ejemplo n.º 1
0
 public function readnotifyAction()
 {
     $this->view->disable();
     $usersId = $this->auth->getAuth()['id'];
     if ($this->request->isPost()) {
         $id = $this->request->getPost('id');
         $object = $this->request->getPost('object');
         if ($object == ActivityNotifications::TYPE_POSTS) {
             $notify = ActivityNotifications::findFirst(['usersId = ?0 AND postsId = ?1', 'bind' => [$usersId, $id]]);
         } else {
             $notify = ActivityNotifications::findFirst(['usersId = ?0 AND postsReplyId = ?1', 'bind' => [$usersId, $id]]);
         }
         if ($notify) {
             $notify->setWasRead('Y');
             if (!$notify->save()) {
                 $this->saveLoger($notify->getMessages());
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * These is it will save ActivityNotifications when the user have comment,
  * vote, etc to post or post reply, which just display for user
  *
  * @param  object $user   this is session user Phanbook\Models\Users
  * @param  object $object Phanbook\Models\{Posts, PostsReply...}
  * @return mixed
  */
 public function setActivityNotifications($user, $object)
 {
     $activity = new ActivityNotifications();
     //set user recive a notification when it have a post comment or reply
     $activity->setUsersOriginId($user->getId());
     //If is posts, it will use when user vote post
     if (method_exists($object, '_isPost')) {
         $activity->setUsersId($object->getUsersId());
         $activity->setPostsId($object->getId());
         $activity->setPostsReplyId(null);
         $activity->setType(ActivityNotifications::TYPE_POSTS);
     }
     if (method_exists($object, 'isComment')) {
         //@todo
     }
     if (method_exists($object, 'isReply')) {
         $activity->setUsersId($object->post->getUsersId());
         $activity->setPostsId($object->post->getId());
         $activity->setPostsReplyId($object->getId());
         $activity->setType(ActivityNotifications::TYPE_REPLY);
     }
     if (!$activity->save()) {
         error_log('Save fail, I am on here' . __LINE__);
     }
 }
Ejemplo n.º 3
0
 /**
  * Set Notify users that always want notifications just display notification on website
  * @param integer $userId       user want notification
  * @param integer $postId       [description]
  * @param integer $postReplyId  [description]
  * @param string  $type         such as Comment, reply...
  * @param integer $userOriginId the usesr id post question
  */
 public function setActivityNotifications($userId, $postId, $postReplyId, $userOriginId, $type)
 {
     $activity = new ActivityNotifications();
     $activity->setUsersId($userId);
     $activity->setPostsId($postId);
     $activity->setPostsReplyId($postReplyId);
     $activity->setUsersOriginId($userOriginId);
     $activity->setType($type);
     $activity->save();
 }
Ejemplo n.º 4
0
 public function afterCreate()
 {
     $activity = new ActivityNotifications();
     $activity->setUsersId($this->usersId);
     if ($this->getType() == ActivityNotifications::TYPE_POSTS) {
         $activity->setType(ActivityNotifications::TYPE_O);
         $activity->setPostsId($this->code1);
         $activity->setPostsReplyId(0);
     } else {
         if ($this->getType() == ActivityNotifications::TYPE_COMMENTS) {
             $activity->setType(ActivityNotifications::TYPE_V);
             $activity->setPostsId($this->code2);
             $activity->setPostsReplyId($this->code1);
         } else {
             $activity->setType(ActivityNotifications::TYPE_BADGES);
             $activity->setPostsId(1);
             $activity->setPostsReplyId(1);
         }
     }
     $activity->setExtra($this->badge);
     $activity->setUsersOriginId($this->usersId);
     var_dump($activity->save());
 }
Ejemplo n.º 5
0
 public function getNotifications($usersId)
 {
     $notifications = ActivityNotifications::find(array('usersId = ?0 AND wasRead ="N"', 'bind' => array($usersId), 'limit' => 7, 'order' => 'createdAt DESC'));
     return $notifications;
 }