diff --git a/bin/migrate b/bin/migrate
index 7a70e527..2aa71548 100755
--- a/bin/migrate
+++ b/bin/migrate
@@ -4,7 +4,9 @@
use Composer\Autoload\ClassLoader;
use Engelsystem\Application;
use Engelsystem\Database\Migration\Migrate;
+use Engelsystem\Database\Migration\Direction;
use Engelsystem\Database\Migration\MigrationServiceProvider;
+use Engelsystem\Environment;
use Engelsystem\Exceptions\Handler;
use Engelsystem\Exceptions\Handlers\NullHandler;
@@ -19,7 +21,7 @@ $app->register(MigrationServiceProvider::class);
/** @var Handler $errorHandler */
$errorHandler = $app->get(Handler::class);
-$errorHandler->setHandler(Handler::ENV_PRODUCTION, new NullHandler());
+$errorHandler->setHandler(Environment::PRODUCTION, new NullHandler());
/** @var Migrate $migration */
$migration = $app->get('db.migration');
@@ -32,10 +34,10 @@ if (in_array('help', $argv) || in_array('--help', $argv) || in_array('-h', $argv
exit;
}
-$method = Migrate::UP;
+$direction = Direction::UP;
if (in_array('down', $argv)) {
$argv = array_values($argv);
- $method = Migrate::DOWN;
+ $direction = Direction::DOWN;
}
$oneStep = false;
@@ -48,4 +50,4 @@ if (in_array('force', $argv) || in_array('--force', $argv) || in_array('-f', $ar
$force = true;
}
-$migration->run($baseDir, $method, $oneStep, $force);
+$migration->run($baseDir, $direction, $oneStep, $force);
diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php
index 7cd7b352..b8c904b6 100644
--- a/includes/controller/shift_entries_controller.php
+++ b/includes/controller/shift_entries_controller.php
@@ -3,6 +3,7 @@
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftEntry;
+use Engelsystem\Models\Shifts\ShiftSignupStatus;
use Engelsystem\Models\User\User;
use Engelsystem\Models\UserAngelType;
use Engelsystem\ShiftSignupState;
@@ -180,21 +181,16 @@ function shift_entry_create_controller_supporter(Shift $shift, AngelType $angelt
*/
function shift_entry_error_message(ShiftSignupState $shift_signup_state)
{
- if ($shift_signup_state->getState() == ShiftSignupState::ANGELTYPE) {
- error(__('You need be accepted member of the angeltype.'));
- } elseif ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) {
- error(__('This shift collides with one of your shifts.'));
- } elseif ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) {
- error(__('This shift is already occupied.'));
- } elseif ($shift_signup_state->getState() == ShiftSignupState::SHIFT_ENDED) {
- error(__('This shift ended already.'));
- } elseif ($shift_signup_state->getState() == ShiftSignupState::NOT_ARRIVED) {
- error(__('You are not marked as arrived.'));
- } elseif ($shift_signup_state->getState() == ShiftSignupState::NOT_YET) {
- error(__('You are not allowed to sign up yet.'));
- } elseif ($shift_signup_state->getState() == ShiftSignupState::SIGNED_UP) {
- error(__('You are signed up for this shift.'));
- }
+ match ($shift_signup_state->getState()) {
+ ShiftSignupStatus::ANGELTYPE => error(__('You need be accepted member of the angeltype.')),
+ ShiftSignupStatus::COLLIDES => error(__('This shift collides with one of your shifts.')),
+ ShiftSignupStatus::OCCUPIED => error(__('This shift is already occupied.')),
+ ShiftSignupStatus::SHIFT_ENDED => error(__('This shift ended already.')),
+ ShiftSignupStatus::NOT_ARRIVED => error(__('You are not marked as arrived.')),
+ ShiftSignupStatus::NOT_YET => error(__('You are not allowed to sign up yet.')),
+ ShiftSignupStatus::SIGNED_UP => error(__('You are signed up for this shift.')),
+ default => null, // ShiftSignupStatus::FREE|ShiftSignupStatus::ADMIN
+ };
}
/**
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index bfae83c1..157485c2 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -7,6 +7,7 @@ use Engelsystem\Models\Shifts\NeededAngelType;
use Engelsystem\Models\Shifts\ScheduleShift;
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftType;
+use Engelsystem\Models\Shifts\ShiftSignupStatus;
use Engelsystem\ShiftSignupState;
use Illuminate\Support\Collection;
@@ -313,7 +314,7 @@ function shift_controller()
$angeltypes = AngelType::all();
$user_shifts = Shifts_by_user($user->id);
- $shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
+ $shift_signup_state = new ShiftSignupState(ShiftSignupStatus::OCCUPIED, 0);
foreach ($angeltypes as $angeltype) {
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
if (empty($needed_angeltype)) {
diff --git a/includes/model/ShiftSignupState.php b/includes/model/ShiftSignupState.php
index 9bbde7bb..54539cfc 100644
--- a/includes/model/ShiftSignupState.php
+++ b/includes/model/ShiftSignupState.php
@@ -2,67 +2,24 @@
namespace Engelsystem;
+use Engelsystem\Models\Shifts\ShiftSignupStatus;
+
/**
* BO to represent if there are free slots on a shift for a given angeltype
* and if signup for a given user is possible (or not, because of collisions, etc.)
*/
class ShiftSignupState
{
- /**
- * Shift has free places
- */
- public const FREE = 'FREE';
-
- /**
- * Shift collides with users shifts
- */
- public const COLLIDES = 'COLLIDES';
-
- /**
- * User cannot join because of a restricted angeltype or user is not in the angeltype
- */
- public const ANGELTYPE = 'ANGELTYPE';
-
- /**
- * Shift is full
- */
- public const OCCUPIED = 'OCCUPIED';
-
- /**
- * User is admin and can do what he wants.
- */
- public const ADMIN = 'ADMIN';
-
- /**
- * Shift has already ended, no signup
- */
- public const SHIFT_ENDED = 'SHIFT_ENDED';
-
- /**
- * Shift is not available yet
- */
- public const NOT_YET = 'NOT_YET';
-
- /**
- * User is already signed up
- */
- public const SIGNED_UP = 'SIGNED_UP';
-
- /**
- * User has to be arrived
- */
- public const NOT_ARRIVED = 'NOT_ARRIVED';
-
/** @var int */
private $freeEntries;
/**
* ShiftSignupState constructor.
*
- * @param string $state
- * @param int $free_entries
+ * @param ShiftSignupStatus $state
+ * @param int $free_entries
*/
- public function __construct(private $state, $free_entries)
+ public function __construct(private ShiftSignupStatus $state, $free_entries)
{
$this->freeEntries = $free_entries;
}
@@ -82,17 +39,17 @@ class ShiftSignupState
}
/**
- * @param string $state
+ * @param ShiftSignupStatus $state
* @return int
*/
- private function valueForState($state)
+ private function valueForState(ShiftSignupStatus $state)
{
return match ($state) {
- ShiftSignupState::NOT_ARRIVED, ShiftSignupState::NOT_YET, ShiftSignupState::SHIFT_ENDED => 100,
- ShiftSignupState::SIGNED_UP => 90,
- ShiftSignupState::FREE => 80,
- ShiftSignupState::ANGELTYPE, ShiftSignupState::COLLIDES => 70,
- ShiftSignupState::OCCUPIED, ShiftSignupState::ADMIN => 60,
+ ShiftSignupStatus::NOT_ARRIVED, ShiftSignupStatus::NOT_YET, ShiftSignupStatus::SHIFT_ENDED => 100,
+ ShiftSignupStatus::SIGNED_UP => 90,
+ ShiftSignupStatus::FREE => 80,
+ ShiftSignupStatus::ANGELTYPE, ShiftSignupStatus::COLLIDES => 70,
+ ShiftSignupStatus::OCCUPIED, ShiftSignupStatus::ADMIN => 60,
default => 0,
};
}
@@ -105,7 +62,7 @@ class ShiftSignupState
public function isSignupAllowed()
{
return match ($this->state) {
- ShiftSignupState::FREE, ShiftSignupState::ADMIN => true,
+ ShiftSignupStatus::FREE, ShiftSignupStatus::ADMIN => true,
default => false,
};
}
@@ -113,9 +70,9 @@ class ShiftSignupState
/**
* Return the shift signup state
*
- * @return string
+ * @return ShiftSignupStatus
*/
- public function getState()
+ public function getState(): ShiftSignupStatus
{
return $this->state;
}
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 397cd184..e00fff91 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -5,6 +5,7 @@ use Engelsystem\Helpers\Carbon;
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftEntry;
+use Engelsystem\Models\Shifts\ShiftSignupStatus;
use Engelsystem\Models\User\User;
use Engelsystem\Models\UserAngelType;
use Engelsystem\ShiftsFilter;
@@ -323,11 +324,11 @@ function Shift_signup_allowed_angel(
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
if (config('signup_requires_arrival') && !$user->state->arrived) {
- return new ShiftSignupState(ShiftSignupState::NOT_ARRIVED, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::NOT_ARRIVED, $free_entries);
}
if (config('signup_advance_hours') && $shift->start->timestamp > time() + config('signup_advance_hours') * 3600) {
- return new ShiftSignupState(ShiftSignupState::NOT_YET, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::NOT_YET, $free_entries);
}
if (empty($user_shifts)) {
@@ -344,7 +345,7 @@ function Shift_signup_allowed_angel(
if ($signed_up) {
// you cannot join if you already signed up for this shift
- return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::SIGNED_UP, $free_entries);
}
$shift_post_signup_total_allowed_seconds =
@@ -353,11 +354,11 @@ function Shift_signup_allowed_angel(
if (time() > $shift->start->timestamp + $shift_post_signup_total_allowed_seconds) {
// you can only join if the shift is in future
- return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::SHIFT_ENDED, $free_entries);
}
if ($free_entries == 0) {
// you cannot join if shift is full
- return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::OCCUPIED, $free_entries);
}
if (empty($user_angeltype)) {
@@ -373,16 +374,16 @@ function Shift_signup_allowed_angel(
// you cannot join if you are not confirmed
// you cannot join if angeltype has no self signup
- return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::ANGELTYPE, $free_entries);
}
if (Shift_collides($shift, $user_shifts)) {
// you cannot join if user already joined a parallel of this shift
- return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::COLLIDES, $free_entries);
}
// Hooray, shift is free for you!
- return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::FREE, $free_entries);
}
/**
@@ -396,10 +397,10 @@ function Shift_signup_allowed_angeltype_supporter(AngelType $needed_angeltype, $
{
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
if ($free_entries == 0) {
- return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::OCCUPIED, $free_entries);
}
- return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::FREE, $free_entries);
}
/**
@@ -415,10 +416,10 @@ function Shift_signup_allowed_admin(AngelType $needed_angeltype, $shift_entries)
if ($free_entries == 0) {
// User shift admins may join anybody in every shift
- return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::ADMIN, $free_entries);
}
- return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
+ return new ShiftSignupState(ShiftSignupStatus::FREE, $free_entries);
}
/**
diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php
index 9e5bfb1c..e1f104bb 100644
--- a/includes/view/ShiftCalendarShiftRenderer.php
+++ b/includes/view/ShiftCalendarShiftRenderer.php
@@ -5,6 +5,7 @@ namespace Engelsystem;
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftEntry;
+use Engelsystem\Models\Shifts\ShiftSignupStatus;
use Engelsystem\Models\User\User;
use Illuminate\Support\Collection;
@@ -72,11 +73,11 @@ class ShiftCalendarShiftRenderer
private function classForSignupState(ShiftSignupState $shiftSignupState)
{
return match ($shiftSignupState->getState()) {
- ShiftSignupState::ADMIN, ShiftSignupState::OCCUPIED => 'success',
- ShiftSignupState::SIGNED_UP => 'primary',
- ShiftSignupState::NOT_ARRIVED, ShiftSignupState::NOT_YET, ShiftSignupState::SHIFT_ENDED => 'secondary',
- ShiftSignupState::ANGELTYPE, ShiftSignupState::COLLIDES => 'warning',
- ShiftSignupState::FREE => 'danger',
+ ShiftSignupStatus::ADMIN, ShiftSignupStatus::OCCUPIED => 'success',
+ ShiftSignupStatus::SIGNED_UP => 'primary',
+ ShiftSignupStatus::NOT_ARRIVED, ShiftSignupStatus::NOT_YET, ShiftSignupStatus::SHIFT_ENDED => 'secondary',
+ ShiftSignupStatus::ANGELTYPE, ShiftSignupStatus::COLLIDES => 'warning',
+ ShiftSignupStatus::FREE => 'danger',
default => 'light',
};
}
@@ -118,7 +119,7 @@ class ShiftCalendarShiftRenderer
}
}
if (is_null($shift_signup_state)) {
- $shift_signup_state = new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, 0);
+ $shift_signup_state = new ShiftSignupState(ShiftSignupStatus::SHIFT_ENDED, 0);
}
if (auth()->can('user_shifts_admin')) {
@@ -173,63 +174,42 @@ class ShiftCalendarShiftRenderer
$freeEntriesCount = $shift_signup_state->getFreeEntries();
$inner_text = _e('%d helper needed', '%d helpers needed', $freeEntriesCount, [$freeEntriesCount]);
- switch ($shift_signup_state->getState()) {
- case ShiftSignupState::ADMIN:
- case ShiftSignupState::FREE:
- // When admin or free display a link + button for sign up
- $entry_list[] = ''
- . $inner_text
- . ' '
+ $entry = match ($shift_signup_state->getState()) {
+ // When admin or free display a link + button for sign up
+ ShiftSignupStatus::ADMIN, ShiftSignupStatus::FREE =>
+ ''
+ . $inner_text
+ . ' '
+ . button(
+ shift_entry_create_link($shift, $angeltype),
+ __('Sign up'),
+ 'btn-sm btn-primary text-nowrap d-print-none'
+ ),
+ // No link and add a text hint, when the shift ended
+ ShiftSignupStatus::SHIFT_ENDED => $inner_text . ' (' . __('ended') . ')',
+ // No link and add a text hint, when the shift ended
+ ShiftSignupStatus::NOT_ARRIVED => $inner_text . ' (' . __('please arrive for signup') . ')',
+ ShiftSignupStatus::NOT_YET => $inner_text . ' (' . __('not yet') . ')',
+ ShiftSignupStatus::ANGELTYPE => $angeltype->restricted
+ // User has to be confirmed on the angeltype first
+ ? $inner_text . icon('mortarboard-fill')
+ // Add link to join the angeltype first
+ : $inner_text . '
'
. button(
- shift_entry_create_link($shift, $angeltype),
- __('Sign up'),
- 'btn-sm btn-primary text-nowrap d-print-none'
- );
- break;
-
- case ShiftSignupState::SHIFT_ENDED:
- // No link and add a text hint, when the shift ended
- $entry_list[] = $inner_text . ' (' . __('ended') . ')';
- break;
-
- case ShiftSignupState::NOT_ARRIVED:
- // No link and add a text hint, when the shift ended
- $entry_list[] = $inner_text . ' (' . __('please arrive for signup') . ')';
- break;
-
- case ShiftSignupState::NOT_YET:
- $entry_list[] = $inner_text . ' (' . __('not yet') . ')';
- break;
-
- case ShiftSignupState::ANGELTYPE:
- if ($angeltype->restricted) {
- // User has to be confirmed on the angeltype first
- $entry_list[] = $inner_text . icon('mortarboard-fill');
- } else {
- // Add link to join the angeltype first
- $entry_list[] = $inner_text . '
'
- . button(
- page_link_to(
- 'user_angeltypes',
- ['action' => 'add', 'angeltype_id' => $angeltype->id]
- ),
- sprintf(__('Become %s'), $angeltype->name),
- 'btn-sm'
- );
- }
- break;
-
- case ShiftSignupState::COLLIDES:
- case ShiftSignupState::SIGNED_UP:
- // Shift collides or user is already signed up: No signup allowed
- $entry_list[] = $inner_text;
- break;
-
- case ShiftSignupState::OCCUPIED:
- // Shift is full
- break;
+ page_link_to('user_angeltypes', ['action' => 'add', 'angeltype_id' => $angeltype->id]),
+ sprintf(__('Become %s'), $angeltype->name),
+ 'btn-sm'
+ ),
+ // Shift collides or user is already signed up: No signup allowed
+ ShiftSignupStatus::COLLIDES, ShiftSignupStatus::SIGNED_UP => $inner_text,
+ // Shift is full
+ ShiftSignupStatus::OCCUPIED => null,
+ default => null,
+ };
+ if (!is_null($entry)) {
+ $entry_list[] = $entry;
}
$shifts_row = '