2016-10-03 17:41:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BO Class that stores all parameters used to filter shifts for users.
|
|
|
|
*
|
|
|
|
* @author msquare
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
class ShiftsFilter
|
|
|
|
{
|
2017-01-02 15:43:36 +01:00
|
|
|
/**
|
|
|
|
* Shift is completely full.
|
|
|
|
*/
|
|
|
|
const FILLED_FILLED = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shift has some free slots.
|
|
|
|
*/
|
|
|
|
const FILLED_FREE = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Has the user "user shifts admin" privilege?
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
private $userShiftsAdmin;
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/** @var int[] */
|
2022-06-16 23:00:56 +02:00
|
|
|
private $filled;
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/** @var int[] */
|
2022-06-16 23:00:56 +02:00
|
|
|
private $rooms;
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/** @var int[] */
|
2022-06-16 23:00:56 +02:00
|
|
|
private $types;
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/** @var int unix timestamp */
|
2017-01-02 03:57:23 +01:00
|
|
|
private $startTime = null;
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/** @var int unix timestamp */
|
2017-01-02 03:57:23 +01:00
|
|
|
private $endTime = null;
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* ShiftsFilter constructor.
|
|
|
|
*
|
|
|
|
* @param bool $user_shifts_admin
|
|
|
|
* @param int[] $rooms
|
|
|
|
* @param int[] $types
|
|
|
|
*/
|
2018-08-07 02:38:41 +02:00
|
|
|
public function __construct($user_shifts_admin = false, $rooms = [], $types = [])
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
|
|
|
$this->rooms = $rooms;
|
|
|
|
$this->types = $types;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$this->filled = [
|
2017-01-02 15:43:36 +01:00
|
|
|
ShiftsFilter::FILLED_FREE
|
|
|
|
];
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($user_shifts_admin) {
|
|
|
|
$this->filled[] = ShiftsFilter::FILLED_FILLED;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
}
|
|
|
|
|
2018-08-07 02:38:41 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function sessionExport()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'userShiftsAdmin' => $this->userShiftsAdmin,
|
|
|
|
'filled' => $this->filled,
|
|
|
|
'rooms' => $this->rooms,
|
|
|
|
'types' => $this->types,
|
|
|
|
'startTime' => $this->startTime,
|
|
|
|
'endTime' => $this->endTime,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function sessionImport($data)
|
|
|
|
{
|
|
|
|
$this->userShiftsAdmin = $data['userShiftsAdmin'];
|
|
|
|
$this->filled = $data['filled'];
|
|
|
|
$this->rooms = $data['rooms'];
|
|
|
|
$this->types = $data['types'];
|
|
|
|
$this->startTime = $data['startTime'];
|
|
|
|
$this->endTime = $data['endTime'];
|
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return int unix timestamp
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function getStartTime()
|
|
|
|
{
|
|
|
|
return $this->startTime;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param int $startTime unix timestamp
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function setStartTime($startTime)
|
|
|
|
{
|
|
|
|
$this->startTime = $startTime;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return int unix timestamp
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function getEndTime()
|
|
|
|
{
|
|
|
|
return $this->endTime;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param int $endTime unix timestamp
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function setEndTime($endTime)
|
|
|
|
{
|
2019-12-27 18:58:27 +01:00
|
|
|
$filterMaxDuration = config('filter_max_duration') * 60 * 60;
|
|
|
|
if ($filterMaxDuration && ($endTime - $this->startTime > $filterMaxDuration)) {
|
|
|
|
$endTime = $this->startTime + $filterMaxDuration;
|
|
|
|
}
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$this->endTime = $endTime;
|
2016-12-28 00:11:42 +01:00
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return int[]
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function getTypes()
|
|
|
|
{
|
|
|
|
if (count($this->types) == 0) {
|
2017-01-02 15:43:36 +01:00
|
|
|
return [0];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
return $this->types;
|
2016-10-03 17:41:14 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param int[] $types
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function setTypes($types)
|
|
|
|
{
|
|
|
|
$this->types = $types;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return int[]
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function getRooms()
|
|
|
|
{
|
|
|
|
if (count($this->rooms) == 0) {
|
2017-01-02 15:43:36 +01:00
|
|
|
return [0];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
return $this->rooms;
|
2016-10-03 17:41:14 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param int[] $rooms
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function setRooms($rooms)
|
|
|
|
{
|
|
|
|
$this->rooms = $rooms;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function isUserShiftsAdmin()
|
|
|
|
{
|
|
|
|
return $this->userShiftsAdmin;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param bool $userShiftsAdmin
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function setUserShiftsAdmin($userShiftsAdmin)
|
|
|
|
{
|
|
|
|
$this->userShiftsAdmin = $userShiftsAdmin;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return int[]
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function getFilled()
|
|
|
|
{
|
|
|
|
return $this->filled;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param int[] $filled
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function setFilled($filled)
|
|
|
|
{
|
|
|
|
$this->filled = $filled;
|
|
|
|
}
|
2016-10-03 17:41:14 +02:00
|
|
|
}
|