/** * 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(); }
/** * 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__); } }
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()); }