| Conditions | 3 |
| Paths | 3 |
| Total Lines | 28 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function run(Request $request, Response $response, array $args) : Response |
||
| 23 | { |
||
| 24 | // get card |
||
| 25 | /* @var Card $card */ |
||
| 26 | $card = Card::query()->findOrFail($args['id']); |
||
| 27 | |||
| 28 | /** @noinspection PhpUndefinedMethodInspection */ |
||
| 29 | $builder = Task::query()->where('cardId', '=', $card->id); |
||
| 30 | |||
| 31 | // sorting |
||
| 32 | if (!is_null($request->getParam('order-by'))) { |
||
| 33 | list($attribute, $direction) = explode(',', $request->getParam('order-by')); |
||
| 34 | $direction = DatabaseUtils::ensureOrderDirection($direction); |
||
| 35 | |||
| 36 | // check if attribute is valid |
||
| 37 | if (!in_array($attribute, ['priority', 'name', 'isDone'])) { |
||
| 38 | $attribute = 'id'; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** @noinspection PhpUndefinedMethodInspection */ |
||
| 42 | $builder->orderBy($attribute, $direction); |
||
| 43 | } else { |
||
| 44 | /** @noinspection PhpUndefinedMethodInspection */ |
||
| 45 | $builder->orderBy('id', 'desc'); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $response->withJson($builder->get()); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |