engelsystem/includes/model/ShiftsFilter.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

196 lines
3.8 KiB
PHP
Raw Normal View History

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.
*/
public const FILLED_FILLED = 1;
2017-01-02 15:43:36 +01:00
/**
* Shift has some free slots.
*/
public const FILLED_FREE = 0;
2017-01-02 15:43:36 +01:00
/**
* 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[] */
private $filled;
2016-10-03 17:41:14 +02:00
2017-01-03 03:22:48 +01:00
/** @var int[] */
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
2022-11-09 00:02:30 +01:00
* @param int[] $angelTypes
2017-01-03 03:22:48 +01:00
*/
public function __construct($user_shifts_admin = false, private $rooms = [], $angelTypes = [])
2017-01-02 03:57:23 +01:00
{
2022-11-09 00:02:30 +01:00
$this->types = $angelTypes;
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
}
/**
* @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)
{
$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-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
}