78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Enumerations\UserRole;
|
|
use App\Models\CostUnit;
|
|
use App\Models\Event;
|
|
use App\Resources\CostUnitResource;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Psy\Readline\Hoa\EventBucket;
|
|
|
|
class EventRepository {
|
|
public function listAll() : array {
|
|
return $this->getEventsByCriteria([
|
|
'archived' => false
|
|
]);
|
|
|
|
}
|
|
|
|
public function getAvailable(bool $accessCheck = true) : array {
|
|
return $this->getEventsByCriteria([
|
|
'archived' => false,
|
|
'registration_allowed' => true
|
|
],$accessCheck);
|
|
}
|
|
|
|
public function getForRegistration(int $id) : ?Event {
|
|
$events = self::getEventsByCriteria(['id' => $id, 'registration_allowed' => true]);
|
|
}
|
|
|
|
public function getById(int $id, bool $accessCheck = true) : ?Event {
|
|
$events = self::getEventsByCriteria(['id' => $id], $accessCheck);
|
|
return $events[0] ?? null;
|
|
}
|
|
|
|
public function getByIdentifier(string $identifier, bool $accessCheck = true) : ?Event {
|
|
$events = self::getEventsByCriteria(['identifier' => $identifier], $accessCheck);
|
|
return $events[0] ?? null;
|
|
}
|
|
|
|
public function getEventsByCriteria(array $criteria, $accessCheck = true) : array {
|
|
$tenant = app('tenant');
|
|
|
|
$canSeeAll = false;
|
|
$user = Auth()->user();
|
|
|
|
if (!$accessCheck) {
|
|
$canSeeAll = true;
|
|
} else {
|
|
if ($tenant->slug !== 'lv') {
|
|
if (
|
|
$user->user_role_main === UserRole::USER_ROLE_ADMIN ||
|
|
in_array($user->user_role_local_group, [UserRole::USER_ROLE_GROUP_LEADER, UserRole::USER_ROLE_ADMIN])
|
|
) {
|
|
$canSeeAll = true;
|
|
}
|
|
} else {
|
|
if (
|
|
in_array($user->user_role_main, [UserRole::USER_ROLE_GROUP_LEADER, UserRole::USER_ROLE_ADMIN])
|
|
) {
|
|
$canSeeAll = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
$visibleEvents = [];
|
|
/** @var Event $event */
|
|
foreach (Event::where($criteria)->get() as $event) {
|
|
|
|
if ($canSeeAll || !$accessCheck || $event->eventManagers()->where('user_id', $user->id)->exists()) {
|
|
$visibleEvents[] = $event;
|
|
}
|
|
}
|
|
|
|
return $visibleEvents;
|
|
}
|
|
}
|