Phosphorum\Models\Posts::afterCreate PHP Method

afterCreate() public method

public 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()->getShared('queue')->put($toNotify);
        }
    }