|
7 | 7 | use HiEvents\DomainObjects\Generated\AttendeeDomainObjectAbstract; |
8 | 8 | use HiEvents\DomainObjects\Status\AttendeeStatus; |
9 | 9 | use HiEvents\DomainObjects\Status\OrderStatus; |
| 10 | +use HiEvents\Http\DTO\FilterFieldDTO; |
10 | 11 | use HiEvents\Http\DTO\QueryParamsDTO; |
11 | 12 | use HiEvents\Models\Attendee; |
12 | 13 | use HiEvents\Repository\Eloquent\Value\Relationship; |
@@ -76,11 +77,22 @@ public function findByEventId(int $eventId, QueryParamsDTO $params): LengthAware |
76 | 77 |
|
77 | 78 | $this->model = $this->model->select('attendees.*') |
78 | 79 | ->join('orders', 'orders.id', '=', 'attendees.order_id') |
79 | | - ->whereIn('orders.status', [OrderStatus::COMPLETED->name, OrderStatus::CANCELLED->name, OrderStatus::AWAITING_OFFLINE_PAYMENT->name]) |
80 | | - ->orderBy( |
81 | | - 'attendees.' . ($params->sort_by ?? AttendeeDomainObject::getDefaultSort()), |
82 | | - $params->sort_direction ?? 'desc', |
83 | | - ); |
| 80 | + ->whereIn('orders.status', [OrderStatus::COMPLETED->name, OrderStatus::CANCELLED->name, OrderStatus::AWAITING_OFFLINE_PAYMENT->name]); |
| 81 | + |
| 82 | + if ($params->filter_fields && $params->filter_fields->isNotEmpty()) { |
| 83 | + $this->applyFilterFields($params, AttendeeDomainObject::getAllowedFilterFields(), prefix: 'attendees'); |
| 84 | + } |
| 85 | + |
| 86 | + $sortBy = $params->sort_by ?? AttendeeDomainObject::getDefaultSort(); |
| 87 | + $sortDirection = $params->sort_direction ?? AttendeeDomainObject::getDefaultSortDirection(); |
| 88 | + |
| 89 | + if ($sortBy === AttendeeDomainObject::TICKET_NAME_SORT_KEY) { |
| 90 | + $this->model = $this->model |
| 91 | + ->leftJoin('products', 'products.id', '=', 'attendees.product_id') |
| 92 | + ->orderBy('products.title', $sortDirection); |
| 93 | + } else { |
| 94 | + $this->model = $this->model->orderBy('attendees.' . $sortBy, $sortDirection); |
| 95 | + } |
84 | 96 |
|
85 | 97 | return $this->paginateWhere( |
86 | 98 | where: $where, |
|
0 commit comments