/** * Handle the event. * * @param NewUser $event * * @return void */ public function handle(NewUser $event) { $user = $event->user; // Give user an avatar $image = AdorableAvatars::getImage($user->id); $user->imageId = $image->id; $user->save(); EventLog::create(['type' => EventLog::TYPE_NEW_USER, 'userId' => $user->id]); }
/** * Handle the event. * * @param StickerEarnt $event * * @return void */ public function handle(StickerEarnt $event) { EventLog::create(['type' => EventLog::TYPE_STICKER_EARNT, 'userId' => $event->user->id, 'stickerId' => $event->sticker->id, 'earntId' => $event->earntId]); $nm = new NotificationManager(); $n = $nm->createNotification($event->user->id, Notification::TYPE_STICKER_EARNT); $n->stickerId = $event->sticker->id; $nm->saveNotification($n); $sticker = $event->sticker; $sticker->earntCount += 1; $sticker->save(); }
/** * - Send notification to the user * - Check if the user has earnt the sticker * * @param SubmissionApproved $event * * @return void */ public function handle(SubmissionApproved $event) { /** @var Post|null $post */ $post = Post::where('submissionId', $event->submission->id)->first(); if ($post) { EventLog::create(['type' => EventLog::TYPE_SUBMISSION_APPROVED, 'userId' => $event->submission->userId, 'taskId' => $event->submission->taskId, 'postId' => $post->id]); } $submission = $event->submission; $nm = new NotificationManager(); $notification = $nm->createNotification($submission->userId, Notification::TYPE_SUBMISSION_APPROVED); $notification->submissionId = $submission->id; $notification->taskId = $submission->taskId; $nm->saveNotification($notification); $task = $submission->task; $task->completedCount += 1; $task->save(); $pm = new ProgressManager($submission->user, $submission->task->sticker); if ($pm->completedSticker()) { $pm->giveSticker(); } $submission->getTask()->updateRating(); }
/** * Handle the event. * * @param NewComment $event * * @return void */ public function handle(NewComment $event) { /** @var Post $post */ $post = Post::find($event->comment->postId); EventLog::create(['type' => EventLog::TYPE_NEW_COMMENT, 'commentId' => $event->comment->id, 'postId' => $event->comment->postId, 'userId' => $event->comment->userId, 'taskId' => $post->taskId]); $nm = new NotificationManager(); // Notify OP of post if ($post = $event->comment->post) { $n = $nm->createNotification($post->userId, Notification::TYPE_COMMENT_ON_POST); $n->postId = $event->comment->postId; $n->newCommentId = $event->comment->id; $n->fromUserId = $event->comment->userId; $nm->saveNotification($n); } // Notify OP of comment if reply if ($parentComment = $event->comment->parentComment) { $n = $nm->createNotification($parentComment->userId, Notification::TYPE_COMMENT_REPLY); $n->postId = $event->comment->postId; $n->commentId = $parentComment->id; $n->newCommentId = $event->comment->id; $n->fromUserId = $event->comment->userId; $nm->saveNotification($n); } }
/** * Handle the event. * * @param NewSticker $event * * @return void */ public function handle(NewSticker $event) { EventLog::create(['type' => EventLog::TYPE_NEW_STICKER, 'stickerId' => $event->sticker->id, 'userId' => $event->sticker->userId]); }
/** * Handle the event. * * @param NewTask $event * * @return void */ public function handle(NewTask $event) { EventLog::create(['type' => EventLog::TYPE_NEW_TASK, 'taskid' => $event->task->id, 'userId' => $event->task->userId]); }
/** * Handle the event. * * @param NewPost $event * * @return void */ public function handle(NewPost $event) { EventLog::create(['type' => EventLog::TYPE_NEW_POST, 'postId' => $event->post->id, 'taskId' => $event->post->taskId, 'userId' => $event->post->userId]); }
/** * Handle the event. * * @param NewToDo $event * * @return void */ public function handle(NewToDo $event) { echo 'OnNewToDo'; print_r($event); EventLog::create(['type' => EventLog::TYPE_NEW_TO_DO, 'userId' => $event->user->id, 'toDoId' => $event->toDoId, 'stickerId' => $event->sticker ? $event->sticker->id : null, 'taskId' => $event->task ? $event->task->id : null]); }