/**
  * Determines if the given user should have the given sticker.
  */
 public function completedSticker()
 {
     $progress = $this->getTaskProgress();
     // If stickers that require specific tasks are implemented, this will be the place to do that check.
     $required = $this->sticker->requiredTasks ? $this->sticker->requiredTasks : $this->sticker->tasks()->count();
     if (count($progress['completed']) >= $required) {
         return true;
     }
     return false;
 }
 /**
  * @api            {get} /stickers/:slug/doers Get Sticker Doers
  * @apiGroup       Stickers
  * @apiDescription Returns a list of users that have a sticker on their to do list.
  *
  * @param Sticker $sticker
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Sticker $sticker)
 {
     $earners = $sticker->doers()->orderBy('pivot_createdAt', 'DESC')->withPivot('id', 'likeCount');
     $paginator = $earners->paginate($this->getResultsPerPage());
     $array = $this->paginatorToArray($paginator, 'users');
     if ($this->user) {
         foreach ($array['users'] as &$user) {
             $user['pivot']['liked'] = $this->user->likesToDo($user['pivot']['id']);
         }
     }
     return $this->response($array);
 }
 protected function getList()
 {
     if ($this->request->has('sticker')) {
         $stickerId = $this->request->input('sticker');
         /** @var Sticker $sticker */
         $sticker = Sticker::findOrFail($stickerId);
         $this->pageTitle = ' Tasks for ' . $sticker->name;
         $this->breadcrumbs = \Breadcrumbs::render('sticker-tasks', $sticker);
         return Task::where('stickerId', $stickerId)->orderBy('name');
     } else {
         return Task::orderBy('name');
     }
 }
 protected function getList()
 {
     if ($this->request->has('sticker')) {
         $stickerId = $this->request->input('sticker');
         $sticker = Sticker::findOrFail($stickerId);
         /** @var Sticker $sticker */
         $this->pageTitle = ' Designs For ' . $sticker->name . ' Sticker';
         $this->breadcrumbs = \Breadcrumbs::render('sticker-designs', $sticker);
         return StickerDesign::where('stickerId', $stickerId)->orderBy('id');
     } else {
         return StickerDesign::orderBy('id');
     }
 }
 /**
  * Returns an array of $id => $name values for every category to display in an HTML select.
  *
  * @return array
  */
 public function getSelectList()
 {
     return Cache::rememberForever('stickerSelectList', function () {
         $list = [];
         $stickers = Sticker::with('category')->orderBy('name')->get();
         /** @var Sticker $sticker */
         foreach ($stickers as $sticker) {
             if ($sticker->category) {
                 $list[$sticker->id] = $sticker->name . ' (' . $sticker->category->name . ') [' . $sticker->id . ']';
             } else {
                 $list[$sticker->id] = $sticker->name . ' [' . $sticker->id . ']';
             }
         }
         return $list;
     });
 }
 /**
  * @api            {post} /tasks Create A Sticker
  * @apiGroup       Stickers
  * @apiDescription Create a new sticker.
  *
  * @param Request $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = $this->requireAuthentication();
     $this->validate($request, ['name' => 'required|unique:stickers,name', 'categoryId' => 'required|exists:categories,id']);
     $data = $request->only(['name', 'categoryId']);
     $sticker = new Sticker($data);
     $sticker->userId = $user->id;
     $sticker->save();
     /** @var Sticker $sticker */
     $sticker = $sticker->fresh();
     $this->user->toDoStickers()->attach($sticker->id);
     return $this->response(['sticker' => $sticker]);
 }
 /**
  * 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]);
 }
 /**
  * Get a query for all the Users that have a Sticker on their To Do List.
  *
  * @param Sticker $sticker
  *
  * @return Builder
  */
 public function getStickerDoers(Sticker $sticker)
 {
     return $sticker->doers()->orderBy('pivot_createdAt', 'DESC')->withPivot('id', 'likeCount');
 }
 protected function getSearchableList()
 {
     return Sticker::query();
 }