Skip to content

Commit

Permalink
Merge pull request #3 from ramartins02/new-features
Browse files Browse the repository at this point in the history
Past Reservations display on dashboard
  • Loading branch information
ramartins02 authored Nov 27, 2023
2 parents 340e514 + 0dc0f87 commit 2affb3c
Show file tree
Hide file tree
Showing 42 changed files with 669 additions and 9 deletions.
98 changes: 98 additions & 0 deletions Controls/Dashboard/PastReservations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

require_once(ROOT_DIR . 'Controls/Dashboard/DashboardItem.php');
require_once(ROOT_DIR . 'Presenters/Dashboard/PastReservationsPresenter.php');
require_once(ROOT_DIR . 'Domain/Access/ReservationViewRepository.php');

class PastReservations extends DashboardItem implements IPastReservationsControl
{
/**
* @var PastReservationsPresenter
*/
protected $presenter;

public function __construct(SmartyPage $smarty)
{
parent::__construct($smarty);
$this->presenter = new PastReservationsPresenter($this, new ReservationViewRepository());
}

public function PageLoad()
{
$this->Set('DefaultTitle', Resources::GetInstance()->GetString('NoTitleLabel'));
$this->presenter->SetSearchCriteria(ServiceLocator::GetServer()->GetUserSession()->UserId, ReservationUserLevel::ALL);
$this->presenter->PageLoad();
$this->Display('past_reservations.tpl');
}

public function SetTimezone($timezone)
{
$this->Set('Timezone', $timezone);
}

public function SetTotal($total)
{
$this->Set('Total', $total);
}

public function SetUserId($userId)
{
$this->Set('UserId', $userId);
}

public function BindToday($reservations)
{
$this->Set('TodaysReservations', $reservations); //TodaysReservations (-)
}

public function BindYesterday($reservations)
{
$this->Set('YesterdayReservations', $reservations); //YesterdayReservations
}

public function BindThisWeek($reservations)
{
$this->Set('ThisWeeksReservations', $reservations); //ThisWeekReservations (-)
}

public function BindPreviousWeek($reservations)
{
$this->Set('PreviousWeekReservations', $reservations); //PreviousWeekReservations
}

public function SetAllowCheckin($allowCheckin)
{
$this->Set('allowCheckin', $allowCheckin);
}

public function SetAllowCheckout($allowCheckout)
{
$this->Set('allowCheckout', $allowCheckout);
}
}

interface IPastReservationsControl
{
public function SetTimezone($timezone);
public function SetTotal($total);
public function SetUserId($userId);

public function SetAllowCheckin($allowCheckin);
public function SetAllowCheckout($allowCheckout);

public function BindToday($reservations);
public function BindYesterday($reservations);
public function BindThisWeek($reservations);
public function BindPreviousWeek($reservations);
}

class AllPastReservations extends PastReservations
{
public function PageLoad()
{
$this->Set('DefaultTitle', Resources::GetInstance()->GetString('NoTitleLabel'));
$this->presenter->SetSearchCriteria(ReservationViewRepository::ALL_USERS, ReservationUserLevel::ALL);
$this->presenter->PageLoad();
$this->Display('admin_upcoming_reservations.tpl');
}
}
92 changes: 92 additions & 0 deletions Presenters/Dashboard/PastReservationsPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

require_once(ROOT_DIR . 'Controls/Dashboard/PastReservations.php');

class PastReservationsPresenter
{
/**
* @var IPastReservationsControl
*/
private $control;

/**
* @var IReservationViewRepository
*/
private $repository;

/**
* @var int
*/
private $searchUserId = ReservationViewRepository::ALL_USERS;

/**
* @var int
*/
private $searchUserLevel = ReservationUserLevel::ALL;

public function __construct(IPastReservationsControl $control, IReservationViewRepository $repository)
{
$this->control = $control;
$this->repository = $repository;
}

public function SetSearchCriteria($userId, $userLevel)
{
$this->searchUserId = $userId;
$this->searchUserLevel = $userLevel;
}

public function PageLoad()
{
$user = ServiceLocator::GetServer()->GetUserSession();
$timezone = $user->Timezone;

$now = Date::Now();
$today = $now->ToTimezone($timezone)->GetDate();
$dayOfWeek = $today->Weekday();

$firstDate = $now->AddDays(-(13-$dayOfWeek-1));
$consolidated = $this->repository->GetReservations($firstDate, $now, $this->searchUserId, $this->searchUserLevel, null, null, true);
$yesterday = $today->AddDays(-1);

$startOfPreviousWeek = $today->AddDays(-(7+$dayOfWeek));

$todays = [];
$yesterdays = [];
$thisWeeks = [];
$previousWeeks = [];

/* @var $reservation ReservationItemView */
foreach ($consolidated as $reservation) {
$start = $reservation->EndDate->ToTimezone($timezone);

if ($start->DateEquals($today) && $start->TimeLessThan($now->ToTimezone($timezone)->GetTime())) {
$todays[] = $reservation;
} elseif ($start->DateEquals($yesterday)) {
$yesterdays[] = $reservation;
} elseif ($start->GreaterThan($startOfPreviousWeek->AddDays(7))) {
$thisWeeks[] = $reservation;
} else {
$previousWeeks[] = $reservation;
}
}

$checkinAdminOnly = Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_CHECKIN_ADMIN_ONLY, new BooleanConverter());
$checkoutAdminOnly = Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_CHECKOUT_ADMIN_ONLY, new BooleanConverter());

$allowCheckin = $user->IsAdmin || !$checkinAdminOnly;
$allowCheckout = $user->IsAdmin || !$checkoutAdminOnly;

$this->control->SetTotal(count($consolidated));
$this->control->SetTimezone($timezone);
$this->control->SetUserId($user->UserId);

$this->control->SetAllowCheckin($allowCheckin);
$this->control->SetAllowCheckout($allowCheckout);

$this->control->BindToday($todays);
$this->control->BindYesterday($yesterdays);
$this->control->BindThisWeek($thisWeeks);
$this->control->BindPreviousWeek($previousWeeks);
}
}
3 changes: 3 additions & 0 deletions Presenters/DashboardPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require_once(ROOT_DIR . 'Controls/Dashboard/AnnouncementsControl.php');
require_once(ROOT_DIR . 'Controls/Dashboard/UpcomingReservations.php');
require_once(ROOT_DIR . 'Controls/Dashboard/ResourceAvailabilityControl.php');
require_once(ROOT_DIR . 'Controls/Dashboard/PastReservations.php');

class DashboardPresenter
{
Expand All @@ -21,10 +22,12 @@ public function __construct(IDashboardPage $page)
public function Initialize()
{
$announcement = new AnnouncementsControl(new SmartyPage());
$pastReservations = new PastReservations(new SmartyPage());
$upcomingReservations = new UpcomingReservations(new SmartyPage());
$availability = new ResourceAvailabilityControl(new SmartyPage());

$this->_page->AddItem($announcement);
$this->_page->AddItem($pastReservations);
$this->_page->AddItem($upcomingReservations);
$this->_page->AddItem($availability);

Expand Down
11 changes: 11 additions & 0 deletions lang/ar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,17 @@ protected function _LoadStrings()
$strings['ReservationParticipantJoin'] = '%s Has Joined Your Reservation for %s on %s';
// End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'ليس لديك حجوزات سابقة';
$strings['PastReservations'] = 'الحجوزات السابقة';
$strings['AllNoPastReservations'] = 'لا توجد حجوزات سابقة في الـ %s الأيام السابقة';
$strings['AllPastReservations'] = 'كل الحجوزات السابقة';
$strings['Yesterday'] = 'أمس';
$strings['EarlierThisWeek'] = 'في وقت سابق من هذا الأسبوع';
$strings['PreviousWeek'] = 'الأسبوع السابق';
//End Past Reservations

$this->Strings = $strings;

return $this->Strings;
Expand Down
11 changes: 11 additions & 0 deletions lang/bg_bg.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,17 @@ protected function _LoadStrings()
$strings['ReportSubject'] = 'Вашият заявен отчет (%s)';
// End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'Нямате предходни резервации';
$strings['PastReservations'] = 'Предходни резервации';
$strings['AllNoPastReservations'] = 'Няма предходни резервации в последните %s дни';
$strings['AllPastReservations'] = 'Всички предходни резервации';
$strings['Yesterday'] = 'Вчера';
$strings['EarlierThisWeek'] = 'По-рано този седмица';
$strings['PreviousWeek'] = 'Предходна седмица';
//End Past Reservations

$this->Strings = $strings;

return $this->Strings;
Expand Down
10 changes: 10 additions & 0 deletions lang/ca.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ protected function _LoadStrings()
$strings['ForgotPasswordEmailSent'] = 'S\'ha enviat un email a la direcci&oacute; proporcionada amb instruccions per reiniciar la teva contrasenya';
//

//Past Reservations
$strings['NoPastReservations'] = 'No tens cap reserva anterior';
$strings['PastReservations'] = 'Reserves anteriors';
$strings['AllNoPastReservations'] = 'No hi ha cap reserva anterior en els darrers %s dies';
$strings['AllPastReservations'] = 'Totes les reserves anteriors';
$strings['Yesterday'] = 'Ahir';
$strings['EarlierThisWeek'] = 'Més aviat aquesta setmana';
$strings['PreviousWeek'] = 'Setmana anterior';
//End Past Reservations

$this->Strings = $strings;
}

Expand Down
11 changes: 11 additions & 0 deletions lang/cz.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,17 @@ protected function _LoadStrings()
$strings['ReservationParticipantJoin'] = '%s se přidal k vašemu pozvání k rezervaci %s na %s';
// End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'Nemáte žádné minulé rezervace';
$strings['PastReservations'] = 'Minulé rezervace';
$strings['AllNoPastReservations'] = 'Nejsou žádné minulé rezervace v posledních %s dnech';
$strings['AllPastReservations'] = 'Všechny minulé rezervace';
$strings['Yesterday'] = 'Včera';
$strings['EarlierThisWeek'] = 'Dříve v tomto týdnu';
$strings['PreviousWeek'] = 'Předchozí týden';
//End Past Reservations

$this->Strings = $strings;

return $this->Strings;
Expand Down
11 changes: 11 additions & 0 deletions lang/da_da.php
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,17 @@ protected function _LoadStrings()
$strings['ReservationParticipantJoin'] = '% har tilmeldt sig din reservationen af %s på %s';
// End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'Du har ingen tidligere reservationer';
$strings['PastReservations'] = 'Tidligere reservationer';
$strings['AllNoPastReservations'] = 'Der er ingen tidligere reservationer i de seneste %s dage';
$strings['AllPastReservations'] = 'Alle tidligere reservationer';
$strings['Yesterday'] = 'I går';
$strings['EarlierThisWeek'] = 'Tidligere på ugen';
$strings['PreviousWeek'] = 'Forrige uge';
//End Past Reservations

$this->Strings = $strings;

return $this->Strings;
Expand Down
11 changes: 11 additions & 0 deletions lang/de_de.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,17 @@ protected function _LoadStrings()
$strings['MissedCheckinEmailSubject'] = 'Anmeldung verpasst für %s';
// End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'Sie haben keine vergangenen Reservierungen';
$strings['PastReservations'] = 'Vergangene Reservierungen';
$strings['AllNoPastReservations'] = 'Es gibt keine vergangenen Reservierungen in den letzten %s Tagen';
$strings['AllPastReservations'] = 'Alle vergangenen Reservierungen';
$strings['Yesterday'] = 'Gestern';
$strings['EarlierThisWeek'] = 'Früher in dieser Woche';
$strings['PreviousWeek'] = 'Vorherige Woche';
//End Past Reservations

$this->Strings = $strings;

return $this->Strings;
Expand Down
13 changes: 12 additions & 1 deletion lang/du_be.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,18 @@ protected function _LoadStrings()
$strings['InviteeAddedSubject'] = 'Uitnodiging reservering';
$strings['ResetPassword'] = 'Verzoek om paswoord te resetten';
$strings['ForgotPasswordEmailSent'] = 'Een email werd naar uw account gestuurd met de informatie om uw paswoord te resetten';
//
//End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'U heeft geen vorige reserveringen';
$strings['PastReservations'] = 'Vorige reserveringen';
$strings['AllNoPastReservations'] = 'Er zijn geen vorige reserveringen in de afgelopen %s dagen';
$strings['AllPastReservations'] = 'Alle vorige reserveringen';
$strings['Yesterday'] = 'Gisteren';
$strings['EarlierThisWeek'] = 'Eerder deze week';
$strings['PreviousWeek'] = 'Vorige week';
//End Past Reservations

$this->Strings = $strings;
}
Expand Down
11 changes: 11 additions & 0 deletions lang/du_nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,17 @@ protected function _LoadStrings()
$strings['ResourceStatusChangedSubject'] = 'De beschikbaarheid van %s is gewijzigd';
// End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'U heeft geen eerdere reserveringen';
$strings['PastReservations'] = 'Eerdere reserveringen';
$strings['AllNoPastReservations'] = 'Er zijn geen eerdere reserveringen in de afgelopen %s dagen';
$strings['AllPastReservations'] = 'Alle eerdere reserveringen';
$strings['Yesterday'] = 'Gisteren';
$strings['EarlierThisWeek'] = 'Eerder deze week';
$strings['PreviousWeek'] = 'Vorige week';
//End Past Reservations

$this->Strings = $strings;
}

Expand Down
11 changes: 11 additions & 0 deletions lang/ee_ee.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,17 @@ protected function _LoadStrings()
$strings['InviteeAddedSubjectWithResource'] = '%s Invited You to a Reservation for %s';
// End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'Teil pole varasemaid broneeringuid';
$strings['PastReservations'] = 'Varasemad broneeringud';
$strings['AllNoPastReservations'] = 'Viimase %s päeva jooksul pole varasemaid broneeringuid';
$strings['AllPastReservations'] = 'Kõik varasemad broneeringud';
$strings['Yesterday'] = 'Eile';
$strings['EarlierThisWeek'] = 'Varem sel nädalal';
$strings['PreviousWeek'] = 'Eelmine nädal';
//End Past Reservations

$this->Strings = $strings;

return $this->Strings;
Expand Down
11 changes: 11 additions & 0 deletions lang/el_gr.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,17 @@ protected function _LoadStrings()
$strings['ResourceStatusChangedSubject'] = 'Η διαθεσιμότητα του %s άλλαξε';
// End Email Subjects

//NEEDS CHECKING
//Past Reservations
$strings['NoPastReservations'] = 'Δεν έχετε προηγούμενες κρατήσεις';
$strings['PastReservations'] = 'Προηγούμενες κρατήσεις';
$strings['AllNoPastReservations'] = 'Δεν υπάρχουν προηγούμενες κρατήσεις τις τελευταίες %s ημέρες';
$strings['AllPastReservations'] = 'Όλες οι προηγούμενες κρατήσεις';
$strings['Yesterday'] = 'Χθες';
$strings['EarlierThisWeek'] = 'Νωρίτερα αυτήν την εβδομάδα';
$strings['PreviousWeek'] = 'Προηγούμενη εβδομάδα';
//End Past Reservations

$this->Strings = $strings;

return $this->Strings;
Expand Down
Loading

0 comments on commit 2affb3c

Please sign in to comment.