-
-
Notifications
You must be signed in to change notification settings - Fork 635
Expand file tree
/
Copy pathCapacityAssignmentRepository.php
More file actions
52 lines (44 loc) · 1.65 KB
/
CapacityAssignmentRepository.php
File metadata and controls
52 lines (44 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace HiEvents\Repository\Eloquent;
use HiEvents\DomainObjects\CapacityAssignmentDomainObject;
use HiEvents\DomainObjects\Generated\CapacityAssignmentDomainObjectAbstract;
use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Models\CapacityAssignment;
use HiEvents\Repository\Interfaces\CapacityAssignmentRepositoryInterface;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
/**
* @extends BaseRepository<CapacityAssignmentDomainObject>
*/
class CapacityAssignmentRepository extends BaseRepository implements CapacityAssignmentRepositoryInterface
{
protected function getModel(): string
{
return CapacityAssignment::class;
}
public function getDomainObject(): string
{
return CapacityAssignmentDomainObject::class;
}
public function findByEventId(int $eventId, QueryParamsDTO $params): LengthAwarePaginator
{
$where = [
[CapacityAssignmentDomainObjectAbstract::EVENT_ID, '=', $eventId]
];
if (!empty($params->query)) {
$where[] = static function (Builder $builder) use ($params) {
$builder
->where(CapacityAssignmentDomainObjectAbstract::NAME, 'ilike', '%' . $params->query . '%');
};
}
$this->model = $this->model->orderBy(
$params->sort_by ?? CapacityAssignmentDomainObject::getDefaultSort(),
$params->sort_direction ?? CapacityAssignmentDomainObject::getDefaultSortDirection(),
);
return $this->paginateWhere(
where: $where,
limit: $params->per_page,
page: $params->page,
);
}
}