예제 #1
0
 /**
  * Execute the job.
  *
  * @param TaskRepository $taskRepository
  * @return void
  */
 public function handle(TaskRepository $taskRepository)
 {
     $task = Task::createTask($this->household_id, $this->name, $this->type, $this->due_date, $this->recurring_date, $this->priority, null, $this->description, $this->coordinates);
     // Save image if any
     if (Input::hasFile('image')) {
         $file = Input::file('image');
         $fileName = $this->uploadImage($file, $this->name, $this->household_id);
         $task->image = $fileName;
     }
     $taskRepository->save($task, $this->task_members);
     foreach ($this->subtasks as $index => $subtask) {
         $subtaskObj = Task::createTask($this->household_id, $subtask['name'], $this->type, $this->due_date, $this->recurring_date, $this->priority, $task->id, $subtask['description']);
         if (!is_null($subtask['image'])) {
             $subtask_tmp = $_FILES['subtasks']['tmp_name'];
             $subtaskImage = Image::make(Input::file("subtasks[{$index}][image]"));
             $stImageFileName = time() . '_' . $this->name . '_subtask.jpg';
             $this->uploadRaw($subtaskImage, $stImageFileName, $this->household_id);
             $subtaskObj->image = $stImageFileName;
         }
         $members = Task::extractMembers($subtask);
         // if members is 0 automatically
         // assign it to all members on parent task
         if (count($members) === 0) {
             $taskRepository->save($subtaskObj, $this->task_members);
         } else {
             $taskRepository->save($task, $members);
         }
     }
 }