public function afterCreate() { if ($this->id > 0) { $activity = new Activities(); $activity->setUsersId($this->id); $activity->type = Activities::NEW_USER; $activity->save(); } }
/** * Implement hook beforeUpdate of Model Phalcon * * @return mixed */ public function afterCreate() { if ($this->id > 0) { /** * Register the activity */ $activity = new Activities(); $activity->setUsersId($this->usersId); $activity->setPostsId($this->id); $activity->setType(Activities::NEW_POSTS); $activity->save(); /** * Register the user in the post's notifications */ $notification = new PostsNotifications(); $notification->setUsersId($this->usersId); $notification->setPostsId($this->id); $notification->save(); $toNotify = []; /** * Notify users that always want notifications */ foreach (Users::find(['notifications = "Y"', 'columns' => 'id'])->toArray() as $user) { if ($this->usersId != $user['id']) { $notificationId = $this->setNotification($user['id'], $this->id, null, Notifications::TYPE_POSTS); $toNotify[$user['id']] = $notificationId; } } /** * Queue notifications to be sent */ $this->getDI()->getQueue()->put($toNotify); } }
public function afterCreate() { if ($this->id > 0) { $activity = new Activities(); $activity->setUsersId($this->usersId); $activity->setPostsId($this->postsId); $activity->setType(Activities::NEW_REPLY); $activity->save(); $toNotify = []; /** * Notify users that always want notifications */ foreach (Users::find(['notifications = "Y"', 'columns' => 'id'])->toArray() as $user) { if ($this->usersId != $user['id']) { $notificationId = $this->setNotification($user['id'], $this->postsId, $this->id, Notifications::TYPE_REPLY); $this->setActivityNotifications($user['id'], $this->postsId, $this->id, $this->usersId, ActivityNotifications::TYPE_REPLY); $toNotify[$user['id']] = $notificationId; } } /** * Notify users that always want notifications for comment */ /** * Register users subscribed to the post */ foreach (PostsSubscribers::findByPostsId($this->postsId) as $subscriber) { if (!isset($toNotify[$subscriber->getUsersId()])) { $notificationId = $this->setNotification($subscriber->getUsersId(), $this->postsId, $this->id, Notifications::TYPE_REPLY); $this->setActivityNotifications($subscriber->getUsersId(), $this->postsId, $this->id, $this->usersId, ActivityNotifications::TYPE_REPLY); $toNotify[$subscriber->getUsersId()] = $notificationId; } } /** * Register the user in the post's notifications */ if (!isset($toNotify[$this->usersId])) { $parameters = ['usersId = ?0 AND postsId = ?1', 'bind' => array($this->usersId, $this->postsId)]; $hasNotifications = PostsNotifications::count($parameters); if (!$hasNotifications) { $notification = new PostsNotifications(); $notification->setUsersId($this->usersId); $notification->setPostsId($this->postsId); $notification->save(); } } /** * Queue notifications to be sent */ $this->getDI()->getQueue()->put($toNotify); } }