@@ 15-43 (lines=29) @@ | ||
12 | ||
13 | use Longman\Platfourm\Repository\Criteria\SearchCriteria; |
|
14 | ||
15 | trait FindEntities |
|
16 | { |
|
17 | ||
18 | public function run($columns = '*', array $options = null, $sortBy = null) |
|
19 | { |
|
20 | $this->checkRepository(); |
|
21 | ||
22 | if (!empty($options['search'])) { |
|
23 | $searchFields = !empty($options['searchFields']) ? $options['searchFields'] : null; |
|
24 | $searchCriteria = new SearchCriteria($options['search'], $searchFields); |
|
25 | $this->repository->pushCriteria($searchCriteria); |
|
26 | } |
|
27 | ||
28 | if (!empty($options['trashed'])) { |
|
29 | $this->repository = $this->repository->withTrashed(); |
|
30 | } |
|
31 | ||
32 | unset($options['search'], $options['searchFields'], $options['trashed']); |
|
33 | ||
34 | $entityCollection = $this->repository->findBy($columns, $options, null, null, $sortBy); |
|
35 | ||
36 | /*if (empty($entityCollection)) { |
|
37 | throw new EntitiesNotFoundException; |
|
38 | }*/ |
|
39 | ||
40 | return $this->parseResult($entityCollection); |
|
41 | } |
|
42 | ||
43 | } |
|
44 |
@@ 15-43 (lines=29) @@ | ||
12 | ||
13 | use Longman\Platfourm\Repository\Criteria\SearchCriteria; |
|
14 | ||
15 | trait SearchAndPaginateEntities |
|
16 | { |
|
17 | ||
18 | public function run($columns = '*', array $options = null, $perPage = null, $page = 1, $sortBy = null) |
|
19 | { |
|
20 | $this->checkRepository(); |
|
21 | ||
22 | if (!empty($options['search'])) { |
|
23 | $searchFields = !empty($options['searchFields']) ? $options['searchFields'] : null; |
|
24 | $searchCriteria = new SearchCriteria($options['search'], $searchFields); |
|
25 | $this->repository->pushCriteria($searchCriteria); |
|
26 | } |
|
27 | ||
28 | if (!empty($options['trashed'])) { |
|
29 | $this->repository = $this->repository->withTrashed(); |
|
30 | } |
|
31 | ||
32 | unset($options['search'], $options['searchFields'], $options['trashed']); |
|
33 | ||
34 | $entityCollection = $this->repository->findBy($columns, $options, $perPage, $page, $sortBy); |
|
35 | ||
36 | /*if (empty($entityCollection)) { |
|
37 | throw new EntitiesNotFoundException; |
|
38 | }*/ |
|
39 | ||
40 | return $this->parseResult($entityCollection); |
|
41 | } |
|
42 | ||
43 | } |
|
44 |