-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ramartins02/new-features
Past Reservations display on dashboard
- Loading branch information
Showing
42 changed files
with
669 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.