/** * @api {delete} /event-logs/:id/likes Unlike A EventLog * @apiGroup Likes * @apiDescription Unlikes the underlying content of an event. (e.g. If it's a new post event, unlikes the post) * @apiUse RequiresAuthentication * * @param EventLog $eventLog * * @return \Illuminate\Http\Response * @throws \Exception */ public function destroyLike(EventLog $eventLog) { $user = $this->requireAuthentication(); $eventLogLikeManager = $eventLog->getLikeManager(); $success = !!$eventLogLikeManager->unlike($user); return $this->response(['success' => $success, 'event' => $eventLog->fresh()]); }
/** * 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(); }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * * @return void */ public function boot(Router $router) { /** * Route model binding */ $router->bind('category', function ($slug) { return app('CategoryRepository')->findBySlugOrFail($slug); }); $router->bind('user', function ($username) { return app('UserRepository')->findBySlugOrFail($username); }); $router->bind('sticker', function ($slug) { return app('StickerRepository')->findBySlugOrFail($slug); }); $router->bind('task', function ($slug) { return app('TaskRepository')->findBySlugOrFail($slug); }); $router->bind('submission', function ($id) { return \Stickable\Models\Submission::findOrFail($id); }); $router->bind('post', function ($id) { return \Stickable\Models\Post::findOrFail($id); }); $router->bind('comment', function ($id) { return \Stickable\Models\Comment::findOrFail($id); }); $router->bind('notification', function ($id) { return \Stickable\Models\Notification::findOrFail($id); }); $router->bind('event', function ($id) { return \Stickable\Models\EventLog::findOrFail($id); }); $router->bind('todo', function ($id) { return \Stickable\Models\ToDo::findOrFail($id); }); parent::boot($router); }
/** * 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]); }