Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 68 additions & 18 deletions Domain/Access/ScheduleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ public function GetList($pageNumber, $pageSize, $sortField = null, $sortDirectio
*/
public function UpdatePeakTimes($scheduleId, ScheduleLayout $layout);

/**
* @param int $scheduleId
* @param PeakTimes $peakTimes
*/
public function AddPeakTimes($scheduleId, PeakTimes $peakTimes);

/**
* @param int $peakTimesId
* @param int $scheduleId
*/
public function DeletePeakTimes($peakTimesId, $scheduleId);

/**
* @param int $scheduleId
*/
public function DeleteAllPeakTimes($scheduleId);

/**
* @param int $scheduleId
* @param Date $start
Expand Down Expand Up @@ -313,8 +330,9 @@ public function GetLayout($scheduleId, ILayoutFactory $layoutFactory)
}

$reader = ServiceLocator::GetDatabase()->Query(new GetPeakTimesCommand($scheduleId));
if ($row = $reader->GetRow()) {
$layout->ChangePeakTimes(PeakTimes::FromRow($row));

while ($row = $reader->GetRow()) {
$layout->AddPeakTimes(PeakTimes::FromRow($row));
}

$reader->Free();
Expand Down Expand Up @@ -414,26 +432,58 @@ public function GetList($pageNumber, $pageSize, $sortField = null, $sortDirectio

public function UpdatePeakTimes($scheduleId, ScheduleLayout $layout)
{
ServiceLocator::GetDatabase()->Execute(new DeletePeakTimesCommand($scheduleId));

if ($layout->HasPeakTimesDefined()) {
$peakTimes = $layout->GetPeakTimes();
ServiceLocator::GetDatabase()->Execute(new AddPeakTimesCommand(
$scheduleId,
$peakTimes->IsAllDay(),
$peakTimes->GetBeginTime(),
$peakTimes->GetEndTime(),
$peakTimes->IsEveryDay(),
implode(',', $peakTimes->GetWeekdays()),
$peakTimes->IsAllYear(),
$peakTimes->GetBeginDay(),
$peakTimes->GetBeginMonth(),
$peakTimes->GetEndDay(),
$peakTimes->GetEndMonth()
));
foreach ($layout->GetPeakTimes() as $peakTimes) {
ServiceLocator::GetDatabase()->Execute(new UpdatePeakTimesCommand(
$peakTimes->getPeakTimesId(),
$scheduleId,
$peakTimes->IsAllDay(),
$peakTimes->GetBeginTime(),
$peakTimes->GetEndTime(),
$peakTimes->IsEveryDay(),
implode(',', $peakTimes->GetWeekdays()),
$peakTimes->IsAllYear(),
$peakTimes->GetBeginDay(),
$peakTimes->GetBeginMonth(),
$peakTimes->GetEndDay(),
$peakTimes->GetEndMonth()
));
}
}
}

public function DeletePeakTimes($peakTimesId, $scheduleId)
{
ServiceLocator::GetDatabase()->Execute(new DeletePeakTimesCommand(
$peakTimesId,
$scheduleId
));
}

public function DeleteAllPeakTimes($scheduleId)
{
ServiceLocator::GetDatabase()->Execute(new DeleteAllPeakTimesCommand(
$scheduleId
));
}

public function AddPeakTimes($scheduleId, PeakTimes $peakTimes)
{
return ServiceLocator::GetDatabase()->ExecuteInsert(new AddPeakTimesCommand(
$scheduleId,
$peakTimes->IsAllDay(),
$peakTimes->GetBeginTime(),
$peakTimes->GetEndTime(),
$peakTimes->IsEveryDay(),
implode(',', $peakTimes->GetWeekdays()),
$peakTimes->IsAllYear(),
$peakTimes->GetBeginDay(),
$peakTimes->GetBeginMonth(),
$peakTimes->GetEndDay(),
$peakTimes->GetEndMonth()
));
}

public function AddCustomLayoutPeriod($scheduleId, Date $start, Date $end)
{
ServiceLocator::GetDatabase()->Execute(new AddCustomLayoutPeriodCommand($scheduleId, $start, $end));
Expand Down
88 changes: 75 additions & 13 deletions Domain/ScheduleLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,27 @@ public function GetPeriod(Date $date);
*/
public function GetSlotCount(Date $startDate, Date $endDate);

/**
* @return array|PeakTimes[]
*/
public function GetPeakTimes();

/**
* @param PeakTimes $peakTimes
*/
public function ChangePeakTimes(PeakTimes $peakTimes);
public function UpdatePeakTimes(PeakTimes $peakTimes);

public function RemovePeakTimes();
/**
* @param PeakTimes $peakTimes
*/
public function AddPeakTimes(PeakTimes $peakTimes);

/**
* @param int $peakTimeId
*/
public function DeletePeakTimes(int $peakTimeId);

public function DeleteAllPeakTimes();

/**
* @return bool
Expand All @@ -97,9 +112,9 @@ class ScheduleLayout implements IScheduleLayout, ILayoutCreation
public const Standard = 0;

/**
* @var PeakTimes
* @var array|PeakTimes[]
*/
protected $peakTimes;
protected $peakTimes = [];

/**
* @var array|LayoutPeriod[]
Expand Down Expand Up @@ -436,7 +451,7 @@ public function Timezone()
}

/**
* @return PeakTimes
* @return array|PeakTimes[]
*/
public function GetPeakTimes()
{
Expand Down Expand Up @@ -610,7 +625,15 @@ public function GetSlotCount(Date $startDate, Date $endDate)
Log::Debug($period->Start);
Log::Debug($period->End);

$isPeak = $this->HasPeakTimesDefined() && $this->peakTimes->IsWithinPeak($testDate->SetTime($period->Start));
$isPeak = false;
if ($this->HasPeakTimesDefined()) {
foreach ($this->peakTimes as $peakTimes) {
$isPeak = $isPeak || $peakTimes->IsWithinPeak($testDate->SetTime($period->Start));
if ($isPeak) {
break;
}
}
}
Comment on lines +628 to +636
if ($isPeak) {
$peakSlots++;
} else {
Expand All @@ -624,18 +647,38 @@ public function GetSlotCount(Date $startDate, Date $endDate)

public function HasPeakTimesDefined()
{
return $this->peakTimes != null;
return !empty($this->peakTimes);
}

public function UpdatePeakTimes(PeakTimes $peakTimes)
{
foreach ($this->peakTimes as $index => $peakTimesTarget) {
if ($peakTimes->GetPeakTimesId() == $peakTimesTarget->GetPeakTimesId()) {
$peakTimes->InTimezone($this->layoutTimezone);
$this->peakTimes[$index] = $peakTimes;
}
}
}

public function ChangePeakTimes(PeakTimes $peakTimes)
public function AddPeakTimes(PeakTimes $peakTimes)
{
$peakTimes->InTimezone($this->layoutTimezone);
$this->peakTimes = $peakTimes;
$this->peakTimes[] = $peakTimes;
}

public function RemovePeakTimes()
public function DeletePeakTimes(int $peakTimeId)
{
$this->peakTimes = null;
foreach ($this->peakTimes as $index => $peakTimes) {
if ($peakTimeId == $peakTimes->GetPeakTimesId()) {
array_splice($this->peakTimes, $index, 1);
break;
}
}
}

public function DeleteAllPeakTimes()
{
$this->peakTimes = [];
}

public function FitsToHours()
Expand Down Expand Up @@ -668,6 +711,20 @@ public function __construct($offPeak, $peak)

class PeakTimes
{
/**
*/
public function SetPeakTimesId(int $peakTimesId)
{
$this->peakTimesId = $peakTimesId;
}

/**
*/
public function GetPeakTimesId()
{
return $this->peakTimesId;
}

/**
* @return bool
*/
Expand Down Expand Up @@ -748,6 +805,7 @@ public function GetEndMonth()
return $this->endMonth;
}

private $peakTimesId = null;
private $allDay = false;
private $beginTime = null;
private $endTime = null;
Expand All @@ -760,6 +818,7 @@ public function GetEndMonth()
private $endMonth = 0;

/**
* @param int $peakTimesId
* @param bool $allDay
* @param string|Time $beginTime
* @param string|Time $endTime
Expand All @@ -771,8 +830,9 @@ public function GetEndMonth()
* @param int $endDay
* @param int $endMonth
*/
public function __construct($allDay, $beginTime, $endTime, $everyDay, $weekdays, $allYear, $beginDay, $beginMonth, $endDay, $endMonth)
public function __construct($peakTimesId, $allDay, $beginTime, $endTime, $everyDay, $weekdays, $allYear, $beginDay, $beginMonth, $endDay, $endMonth)
{
$this->peakTimesId = $peakTimesId;
$this->allDay = $allDay;

$this->beginTime = new NullTime();
Expand All @@ -799,6 +859,8 @@ public function __construct($allDay, $beginTime, $endTime, $everyDay, $weekdays,

public static function FromRow($row)
{
$peakTimesId = intval($row[ColumnNames::PEAK_TIMES_ID]);

$allDay = intval($row[ColumnNames::PEAK_ALL_DAY]);

$beginTime = !empty($row[ColumnNames::PEAK_START_TIME]) ? Time::Parse($row[ColumnNames::PEAK_START_TIME]) : null;
Expand All @@ -816,7 +878,7 @@ public static function FromRow($row)
$endDay = $row[ColumnNames::PEAK_END_DAY];
$endMonth = $row[ColumnNames::PEAK_END_MONTH];

return new PeakTimes($allDay, $beginTime, $endTime, $everyDay, $weekdays, $allYear, $beginDay, $beginMonth, $endDay, $endMonth);
return new PeakTimes($peakTimesId, $allDay, $beginTime, $endTime, $everyDay, $weekdays, $allYear, $beginDay, $beginMonth, $endDay, $endMonth);
}

public function IsWithinPeak(Date $date)
Expand Down
44 changes: 39 additions & 5 deletions Pages/Admin/ManageSchedulesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ interface IUpdateSchedulePage
*/
public function GetScheduleId();

/**
* @return int
*/
public function GetPeakTimesId();

Comment on lines +15 to +19
/**
* @return string
*/
Expand Down Expand Up @@ -171,6 +176,17 @@ public function DisplayPeakTimes(IScheduleLayout $layout);
*/
public function GetDeletePeakTimes();

/**
* @return bool
*/
public function GetAddPeakTimes();


/**
* @return bool
*/
public function GetUpdatePeakTimes();

/**
* @param BookableResource[] $resources
*/
Expand Down Expand Up @@ -281,11 +297,11 @@ public function ProcessPageLoad()
$this->_presenter->PageLoad();

$resources = Resources::GetInstance();
$this->Set('DayNames', $resources->GetDays('full'));
$this->Set('DayNames', $resources->GetDays('abbr'));
$this->Set('Today', Resources::GetInstance()->GetString('Today'));
$this->Set('TimeFormat', Resources::GetInstance()->GetDateFormat('period_time'));
$this->Set('DefaultDate', Date::Now()->SetTimeString('08:00'));
$this->Set('Months', Resources::GetInstance()->GetMonths('full'));
$this->Set('Months', Resources::GetInstance()->GetMonths('abbr'));
$this->Set('DayList', range(1, 31));
$this->Set('StyleNames', [
ScheduleStyle::Standard->value => $resources->GetString('Standard'),
Expand All @@ -299,9 +315,10 @@ public function ProcessPageLoad()
public function DisplayPeakTimes(IScheduleLayout $layout)
{
$this->Set('Layout', $layout);
$this->Set('Months', Resources::GetInstance()->GetMonths('full'));
$this->Set('DayNames', Resources::GetInstance()->GetDays('full'));
$this->Display('Admin/Schedules/manage_peak_times.tpl');
$this->Set('Months', Resources::GetInstance()->GetMonths('abbr'));
$this->Set('DayNames', Resources::GetInstance()->GetDays('abbr'));
$this->Set('PeakTimesArr', $layout->GetPeakTimes());
$this->Display('Admin/Schedules/manage_peak_times_list.tpl');
}

public function ProcessAction()
Expand Down Expand Up @@ -332,6 +349,11 @@ public function GetScheduleId()
return $id;
}

public function GetPeakTimesId()
{
return $this->GetForm(FormKeys::PEAK_TIMES_ID);
}

public function GetScheduleName()
{
return $this->server->GetForm(FormKeys::SCHEDULE_NAME);
Expand Down Expand Up @@ -557,6 +579,18 @@ public function GetDeletePeakTimes()
return $delete == '1';
}

public function GetAddPeakTimes()
{
$add = $this->GetForm(FormKeys::PEAK_ADD);
return $add == '1';
}

public function GetUpdatePeakTimes()
{
$update = $this->GetForm(FormKeys::PEAK_UPDATE);
return $update == '1';
}

public function BindResources($resources)
{
$this->Set('Resources', $resources);
Expand Down
Loading