| @@ 103-118 (lines=16) @@ | ||
| 100 | * @return array |
|
| 101 | * @throws \Exception |
|
| 102 | */ |
|
| 103 | public function createTask($input) |
|
| 104 | { |
|
| 105 | if (empty($input['task'])) { |
|
| 106 | throw new \Exception(self::TASK_NAME_REQUIRED, 400); |
|
| 107 | } |
|
| 108 | $status = isset($input['status']) ? $input['status'] : 0; |
|
| 109 | $repository = new TasksRepository; |
|
| 110 | $query = $repository->createTaskQuery(); |
|
| 111 | $statement = $this->database->prepare($query); |
|
| 112 | $statement->bindParam('task', $input['task']); |
|
| 113 | $statement->bindParam('status', $status); |
|
| 114 | $statement->execute(); |
|
| 115 | $task = $this->checkTask($this->database->lastInsertId()); |
|
| 116 | ||
| 117 | return $task; |
|
| 118 | } |
|
| 119 | ||
| 120 | /** |
|
| 121 | * Update a task. |
|
| @@ 102-120 (lines=19) @@ | ||
| 99 | * @return array |
|
| 100 | * @throws \Exception |
|
| 101 | */ |
|
| 102 | public function createUser($input) |
|
| 103 | { |
|
| 104 | if (empty($input['name'])) { |
|
| 105 | throw new \Exception(self::USER_NAME_REQUIRED, 400); |
|
| 106 | } |
|
| 107 | $email = null; |
|
| 108 | if (isset($input['email'])) { |
|
| 109 | $email = $this->validateEmail($input['email']); |
|
| 110 | } |
|
| 111 | $repository = new UsersRepository; |
|
| 112 | $query = $repository->createUserQuery(); |
|
| 113 | $statement = $this->database->prepare($query); |
|
| 114 | $statement->bindParam('name', $input['name']); |
|
| 115 | $statement->bindParam('email', $email); |
|
| 116 | $statement->execute(); |
|
| 117 | $user = $this->checkUser($this->database->lastInsertId()); |
|
| 118 | ||
| 119 | return $user; |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * Update a user. |
|