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