Example #1
0
 public function toArray()
 {
     $array = parent::toArray();
     $array['bgUrl'] = $this->getBgUrl();
     /** @var User $user */
     if ($user = Auth::user()) {
         $toDoManager = new ToDoManager();
         $array['isOnToDoList'] = $toDoManager->userHasTaskToDo($this, $user);
         $array['hasCompleted'] = $user->hasCompletedTask($this);
     }
     $array['cost'] = $this->cost ? round($this->cost) : null;
     $array['time'] = $this->time ? round($this->time) : null;
     $array['rating'] = $this->rating ? round($this->rating) : null;
     return $array;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param Request $request
  * @param User    $user
  *
  * @return Response
  */
 public function destroy(Request $request, User $user)
 {
     $this->requireUser($user);
     $toDoManager = new ToDoManager();
     if ($request->has('taskId')) {
         $this->validate($request, ['taskId' => 'integer']);
         $taskId = $request->input('taskId');
         /** @var Task $task */
         $task = Task::findOrFail($taskId);
         $success = $toDoManager->removeTaskToDo($task, $user) > 0;
     } elseif ($request->has('stickerId')) {
         $this->validate($request, ['stickerId' => 'integer']);
         $stickerId = $request->input('stickerId');
         /** @var Sticker $sticker */
         $sticker = Sticker::findOrFail($stickerId);
         $success = $toDoManager->removeStickerToDo($sticker, $user) > 0;
     } else {
         throw new HttpException(400, "taskId or stickerId is required");
     }
     return $this->response(['success' => $success]);
 }