/** * Display a listing of the resource. * * @param User $user * @param StickerRepository $stickerRepository * * @return Response */ public function index(User $user, StickerRepository $stickerRepository) { $tasks = $user->todoTasks; $stickers = $user->toDoStickers()->with('tasks')->get(); $stickersArray = []; foreach ($stickers as $sticker) { $stickersArray[$sticker->id] = $sticker->toArray(); $pm = new ProgressManager($this->user, $sticker); $stickersArray[$sticker->id]['progress'] = $pm->getTaskProgress(); } foreach ($tasks as $task) { if (empty($stickersArray[$task->stickerId])) { if ($sticker = $stickerRepository->find($task->stickerId)) { $stickersArray[$sticker->id] = $sticker->toArray(); } else { continue; } } if (!array_key_exists('todoTasks', $stickersArray[$task->stickerId])) { $stickersArray[$task->stickerId]['todoTasks'] = []; } $stickersArray[$task->stickerId]['todoTasks'][] = $task->toArray(); } return $this->response(['user' => $user, 'stickers' => array_values($stickersArray)]); }
public function getText() { $usernames = $this->getUsernameText(); $postTitle = null; if ($this->postId) { $post = Post::find($this->postId); $postTitle = $post ? $post->title : ''; } elseif ($this->commentId) { if ($comment = Comment::find($this->commentId)) { $post = Post::find($comment->postId); $postTitle = $post ? $post->title : ''; } } $stickerName = null; if ($this->stickerId) { $stickerRepository = new StickerRepository(); $sticker = $stickerRepository->find($this->stickerId); $stickerName = $sticker ? $sticker->name : ''; } $taskName = null; if ($this->taskId) { $taskRepository = new TaskRepository(); $task = $taskRepository->find($this->taskId); $taskName = $task ? $task->name : ''; } return Lang::get('notifications.types.' . $this->type, ['usernames' => $usernames, 'stickerName' => $stickerName, 'taskName' => $taskName, 'postTitle' => $postTitle]); }