diff --git a/Domain/Access/ScheduleRepository.php b/Domain/Access/ScheduleRepository.php index 693b20234..93e14183d 100644 --- a/Domain/Access/ScheduleRepository.php +++ b/Domain/Access/ScheduleRepository.php @@ -240,7 +240,7 @@ public function Update(Schedule $schedule) $schedule->GetAdminGroupId(), $schedule->GetAvailabilityBegin(), $schedule->GetAvailabilityEnd(), - $schedule->GetDefaultStyle(), + $schedule->GetDefaultStyleInt(), $schedule->GetTotalConcurrentReservations(), $schedule->GetMaxResourcesPerReservation() )); diff --git a/Domain/Schedule.php b/Domain/Schedule.php index 5df6e9a71..74b26703c 100644 --- a/Domain/Schedule.php +++ b/Domain/Schedule.php @@ -44,10 +44,7 @@ public function GetAvailability(); */ public function HasAvailability(); - /** - * @return int - */ - public function GetDefaultStyle(); + public function GetDefaultStyle(): ScheduleStyle; } class Schedule implements ISchedule @@ -64,7 +61,7 @@ class Schedule implements ISchedule protected $_adminGroupId; protected $_availabilityBegin; protected $_availabilityEnd; - protected $_defaultStyle; + protected ScheduleStyle $_defaultStyle; protected $_layoutType; protected $_totalConcurrentReservations = 0; protected $_maxResourcesPerReservation = 0; @@ -272,20 +269,24 @@ public function HasAvailability() return $this->GetAvailabilityBegin()->ToString() != '' && $this->GetAvailabilityEnd()->ToString() != ''; } - /** - * @return int|ScheduleStyle - */ - public function GetDefaultStyle() + public function GetDefaultStyle(): ScheduleStyle { return $this->_defaultStyle; } - /** - * @param $defaultDisplay int|ScheduleStyle - */ - public function SetDefaultStyle($defaultDisplay) + public function GetDefaultStyleInt(): int + { + return $this->_defaultStyle->value; + } + + public function SetDefaultStyle(int|ScheduleStyle $defaultDisplay): void { - $this->_defaultStyle = $defaultDisplay; + if ($defaultDisplay instanceof ScheduleStyle) { + $this->_defaultStyle = $defaultDisplay; + return; + } + + $this->_defaultStyle = ScheduleStyle::tryFrom($defaultDisplay) ?? ScheduleStyle::Standard; } /** @@ -434,10 +435,10 @@ public function __construct() } -class ScheduleStyle +enum ScheduleStyle: int { - public const Standard = 0; - public const Wide = 1; - public const Tall = 2; - public const CondensedWeek = 3; + case Standard = 0; + case Wide = 1; + case Tall = 2; + case CondensedWeek = 3; } diff --git a/Pages/Admin/ManageSchedulesPage.php b/Pages/Admin/ManageSchedulesPage.php index 52ce1706f..8fd87ffec 100644 --- a/Pages/Admin/ManageSchedulesPage.php +++ b/Pages/Admin/ManageSchedulesPage.php @@ -288,10 +288,10 @@ public function ProcessPageLoad() $this->Set('Months', Resources::GetInstance()->GetMonths('full')); $this->Set('DayList', range(1, 31)); $this->Set('StyleNames', [ - ScheduleStyle::Standard => $resources->GetString('Standard'), - ScheduleStyle::Wide => $resources->GetString('Wide'), - ScheduleStyle::Tall => $resources->GetString('Tall'), - ScheduleStyle::CondensedWeek => $resources->GetString('Week'), + ScheduleStyle::Standard->value => $resources->GetString('Standard'), + ScheduleStyle::Wide->value => $resources->GetString('Wide'), + ScheduleStyle::Tall->value => $resources->GetString('Tall'), + ScheduleStyle::CondensedWeek->value => $resources->GetString('Week'), ]); $this->Display('Admin/Schedules/manage_schedules.tpl'); } diff --git a/Pages/SchedulePage.php b/Pages/SchedulePage.php index b743294be..24bae900f 100644 --- a/Pages/SchedulePage.php +++ b/Pages/SchedulePage.php @@ -86,14 +86,14 @@ public function GetLayoutDate(); /** * @param int $scheduleId - * @return string|ScheduleStyle + * @return ScheduleStyle|null */ - public function GetScheduleStyle($scheduleId); + public function GetScheduleStyle(int $scheduleId): ?ScheduleStyle; /** - * @param string|ScheduleStyle $direction + * @param ScheduleStyle $direction */ - public function SetScheduleStyle($direction); + public function SetScheduleStyle(ScheduleStyle $direction): void; /** * @return int @@ -237,9 +237,9 @@ class SchedulePage extends ActionPage implements ISchedulePage protected $_presenter; private $_styles = [ - ScheduleStyle::Wide => 'Schedule/schedule-days-horizontal.tpl', - ScheduleStyle::Tall => 'Schedule/schedule-flipped.tpl', - ScheduleStyle::CondensedWeek => 'Schedule/schedule-week-condensed.tpl', + ScheduleStyle::Wide->value => 'Schedule/schedule-days-horizontal.tpl', + ScheduleStyle::Tall->value => 'Schedule/schedule-flipped.tpl', + ScheduleStyle::CondensedWeek->value => 'Schedule/schedule-week-condensed.tpl', ]; /** @@ -259,7 +259,6 @@ public function __construct() $this->Set('CanViewUsers', !Configuration::Instance()->GetKey(ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter())); $this->Set('AllowParticipation', !Configuration::Instance()->GetKey(ConfigKeys::RESERVATION_PREVENT_PARTICIPATION, new BooleanConverter())); $this->Set('AllowCreatePastReservationsButton', ServiceLocator::GetServer()->GetUserSession()->IsAdmin); - $permissionServiceFactory = new PermissionServiceFactory(); $scheduleRepository = new ScheduleRepository(); $userRepository = new UserRepository(); @@ -319,8 +318,9 @@ public function ProcessPageLoad() $this->Display('Schedule/schedule-mobile.tpl'); } } else { - if (array_key_exists($this->ScheduleStyle, $this->_styles)) { - $this->Display($this->_styles[$this->ScheduleStyle]); + $styleValue = $this->ScheduleStyle->value; + if (array_key_exists($styleValue, $this->_styles)) { + $this->Display($this->_styles[$styleValue]); } else { $this->Display('Schedule/schedule.tpl'); } @@ -457,21 +457,21 @@ public function GetLayoutDate() return $this->GetQuerystring(QueryStringKeys::LAYOUT_DATE); } - public function GetScheduleStyle($scheduleId) + public function GetScheduleStyle(int $scheduleId): ?ScheduleStyle { $cookie = $this->server->GetCookie("schedule-style-$scheduleId"); - if ($cookie != null) { - return $cookie; + if ($cookie == null || $cookie === '') { + return null; } - return null; + return ScheduleStyle::tryFrom(intval($cookie)); } - public function SetScheduleStyle($style) + public function SetScheduleStyle(ScheduleStyle $style): void { $this->ScheduleStyle = $style; $this->Set('CookieName', 'schedule-style-' . $this->GetVar('ScheduleId')); - $this->Set('ScheduleStyle', $style); + $this->Set('ScheduleStyle', $style->value); } /** diff --git a/Pages/ScheduleViewerViewSchedulesPage.php b/Pages/ScheduleViewerViewSchedulesPage.php index b1b5e0cec..81adeaf95 100644 --- a/Pages/ScheduleViewerViewSchedulesPage.php +++ b/Pages/ScheduleViewerViewSchedulesPage.php @@ -37,10 +37,10 @@ public function PageLoad() $this->Set('Today', Resources::GetInstance()->GetString('Today')); $this->Set('Months', Resources::GetInstance()->GetMonths('full')); $this->Set('StyleNames', [ - ScheduleStyle::Standard => $resources->GetString('Standard'), - ScheduleStyle::Wide => $resources->GetString('Wide'), - ScheduleStyle::Tall => $resources->GetString('Tall'), - ScheduleStyle::CondensedWeek => $resources->GetString('Week'), + ScheduleStyle::Standard->value => $resources->GetString('Standard'), + ScheduleStyle::Wide->value => $resources->GetString('Wide'), + ScheduleStyle::Tall->value => $resources->GetString('Tall'), + ScheduleStyle::CondensedWeek->value => $resources->GetString('Week'), ]); $this->Display(ROOT_DIR.'tpl/Admin/Schedules/view_schedules.tpl'); diff --git a/Pages/ViewSchedulePage.php b/Pages/ViewSchedulePage.php index 6df7e3812..7035438fa 100644 --- a/Pages/ViewSchedulePage.php +++ b/Pages/ViewSchedulePage.php @@ -9,9 +9,9 @@ class ViewSchedulePage extends SchedulePage private $userRepository; private $_styles = [ - ScheduleStyle::Wide => 'Schedule/schedule-days-horizontal.tpl', - ScheduleStyle::Tall => 'Schedule/schedule-flipped.tpl', - ScheduleStyle::CondensedWeek => 'Schedule/schedule-week-condensed.tpl', + ScheduleStyle::Wide->value => 'Schedule/schedule-days-horizontal.tpl', + ScheduleStyle::Tall->value => 'Schedule/schedule-flipped.tpl', + ScheduleStyle::CondensedWeek->value => 'Schedule/schedule-week-condensed.tpl', ]; public function __construct() @@ -66,8 +66,9 @@ public function ProcessPageLoad() $this->Display('Schedule/schedule-mobile.tpl'); } } else { - if (array_key_exists($this->ScheduleStyle, $this->_styles)) { - $this->Display($this->_styles[$this->ScheduleStyle]); + $styleValue = $this->ScheduleStyle->value; + if (array_key_exists($styleValue, $this->_styles)) { + $this->Display($this->_styles[$styleValue]); } else { $this->Display('Schedule/schedule.tpl'); } diff --git a/Presenters/Schedule/SchedulePageBuilder.php b/Presenters/Schedule/SchedulePageBuilder.php index 7247a7c45..5451f2706 100644 --- a/Presenters/Schedule/SchedulePageBuilder.php +++ b/Presenters/Schedule/SchedulePageBuilder.php @@ -103,7 +103,7 @@ public function BindSchedules(ISchedulePage $page, $schedules, $currentSchedule) $page->SetScheduleName($currentSchedule->GetName()); $page->SetFirstWeekday($currentSchedule->GetWeekdayStart()); $style = $page->GetScheduleStyle($scheduleId); - $page->SetScheduleStyle($style == '' ? $currentSchedule->GetDefaultStyle() : $style); + $page->SetScheduleStyle($style ?? $currentSchedule->GetDefaultStyle()); if ($currentSchedule->GetIsCalendarSubscriptionAllowed()) { $page->SetSubscriptionUrl(new CalendarSubscriptionUrl(null, $currentSchedule->GetPublicId(), null)); } diff --git a/WebServices/SchedulesWebService.php b/WebServices/SchedulesWebService.php index 06bcc6119..3ae99507e 100644 --- a/WebServices/SchedulesWebService.php +++ b/WebServices/SchedulesWebService.php @@ -307,12 +307,12 @@ public function GetLayoutDate() return ''; } - public function GetScheduleStyle($scheduleId) + public function GetScheduleStyle(int $scheduleId): ?ScheduleStyle { return ScheduleStyle::Standard; } - public function SetScheduleStyle($direction) + public function SetScheduleStyle(ScheduleStyle $direction): void { // no op } diff --git a/tests/Domain/Schedule/ScheduleRepositoryTest.php b/tests/Domain/Schedule/ScheduleRepositoryTest.php index eb826355c..454930fe7 100644 --- a/tests/Domain/Schedule/ScheduleRepositoryTest.php +++ b/tests/Domain/Schedule/ScheduleRepositoryTest.php @@ -342,7 +342,7 @@ public function testCanUpdateSchedule() $begin = Date::Now(); $end = Date::Now()->AddDays(1); $allowConcurrent = true; - $style = ScheduleStyle::CondensedWeek; + $style = ScheduleStyle::CondensedWeek->value; $maxConcurrent = 10; $maxResources = 50; diff --git a/tests/Presenters/SchedulePresenterTest.php b/tests/Presenters/SchedulePresenterTest.php index 02e70f2b4..13932a819 100644 --- a/tests/Presenters/SchedulePresenterTest.php +++ b/tests/Presenters/SchedulePresenterTest.php @@ -1061,17 +1061,17 @@ public function GetLayoutDate() /** * @param int $scheduleId - * @return string|ScheduleStyle + * @return ScheduleStyle|null */ - public function GetScheduleStyle($scheduleId) + public function GetScheduleStyle(int $scheduleId): ?ScheduleStyle { - return ''; + return null; } /** - * @param string|ScheduleStyle $direction + * @param ScheduleStyle $direction */ - public function SetScheduleStyle($direction) + public function SetScheduleStyle(ScheduleStyle $direction): void { } diff --git a/tests/fakes/FakeSchedules.php b/tests/fakes/FakeSchedules.php index 943831798..58222c5be 100644 --- a/tests/fakes/FakeSchedules.php +++ b/tests/fakes/FakeSchedules.php @@ -141,7 +141,7 @@ public static function GetRow( ColumnNames::SCHEDULE_ADMIN_GROUP_ID => $adminId, ColumnNames::SCHEDULE_AVAILABLE_START_DATE => $availableStart, ColumnNames::SCHEDULE_AVAILABLE_END_DATE => $availableEnd, - ColumnNames::SCHEDULE_DEFAULT_STYLE => ScheduleStyle::Standard, + ColumnNames::SCHEDULE_DEFAULT_STYLE => ScheduleStyle::Standard->value, ColumnNames::LAYOUT_TYPE => ScheduleLayout::Standard, ColumnNames::TOTAL_CONCURRENT_RESERVATIONS => $totalConcurrentReservations, ColumnNames::MAX_RESOURCES_PER_RESERVATION => $maxResourcesPerReservation, diff --git a/tpl/Admin/Schedules/manage_schedules.tpl b/tpl/Admin/Schedules/manage_schedules.tpl index b11819584..100e43c60 100644 --- a/tpl/Admin/Schedules/manage_schedules.tpl +++ b/tpl/Admin/Schedules/manage_schedules.tpl @@ -132,7 +132,7 @@ class="propertyValue defaultScheduleStyle inlineUpdate fw-bold text-decoration-underline" data-type="select" data-pk="{$id}" data-name="{FormKeys::SCHEDULE_DEFAULT_STYLE}" - data-value="{$schedule->GetDefaultStyle()}">{$StyleNames[$schedule->GetDefaultStyle()]} + data-value="{$schedule->GetDefaultStyle()->value}">{$StyleNames[$schedule->GetDefaultStyle()->value]} {if $CreditsEnabled} diff --git a/tpl/Admin/Schedules/view_schedules.tpl b/tpl/Admin/Schedules/view_schedules.tpl index 76da5c6fa..7f4021b79 100644 --- a/tpl/Admin/Schedules/view_schedules.tpl +++ b/tpl/Admin/Schedules/view_schedules.tpl @@ -76,7 +76,7 @@
-
+
+ schedule-display="{ScheduleStyle::Wide->value}">
+ schedule-display="{ScheduleStyle::CondensedWeek->value}">
@@ -489,4 +489,4 @@ ShowButtonPanel='true'
OnSelect='dpDateChanged'
FirstDay=$FirstWeekday}
-{include file='globalfooter.tpl'}
\ No newline at end of file
+{include file='globalfooter.tpl'}