engelsystem/includes/model/ShiftsFilter.php

206 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2016-10-03 17:41:14 +02:00
<?php
namespace Engelsystem;
2023-01-03 22:19:03 +01:00
use Engelsystem\Helpers\Carbon;
2016-10-03 17:41:14 +02:00
/**
* 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
2023-10-15 19:25:55 +02:00
* @param int[] $locations
2022-11-09 00:02:30 +01:00
* @param int[] $angelTypes
2017-01-03 03:22:48 +01:00
*/
2023-10-15 19:25:55 +02:00
public function __construct($user_shifts_admin = false, private $locations = [], $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 = [
ShiftsFilter::FILLED_FREE,
2017-01-02 15:43:36 +01:00
];
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,
2023-10-15 19:25:55 +02:00
'locations' => $this->locations,
'types' => $this->types,
'startTime' => $this->startTime,
'endTime' => $this->endTime,
];
}
/**
* @param array $data
*/
public function sessionImport($data)
{
2023-10-15 19:25:55 +02:00
$this->userShiftsAdmin = $data['userShiftsAdmin'] ?? false;
$this->filled = $data['filled'] ?? [];
$this->locations = $data['locations'] ?? [];
$this->types = $data['types'] ?? [];
$this->startTime = $data['startTime'] ?? null;
$this->endTime = $data['endTime'] ?? null;
}
2023-01-03 22:19:03 +01:00
/**
* @return Carbon
*/
public function getStart()
{
return Carbon::createFromTimestamp($this->startTime);
}
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
2023-01-03 22:19:03 +01:00
/**
* @return Carbon
*/
public function getEnd()
{
return Carbon::createFromTimestamp($this->endTime);
}
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[]
*/
2023-10-15 19:25:55 +02:00
public function getLocations()
2017-01-02 03:57:23 +01:00
{
2023-10-15 19:25:55 +02:00
if (count($this->locations) == 0) {
2017-01-02 15:43:36 +01:00
return [0];
2017-01-02 03:57:23 +01:00
}
2023-10-15 19:25:55 +02:00
return $this->locations;
2016-10-03 17:41:14 +02:00
}
2017-01-03 03:22:48 +01:00
/**
2023-10-15 19:25:55 +02:00
* @param int[] $locations
2017-01-03 03:22:48 +01:00
*/
2023-10-15 19:25:55 +02:00
public function setLocations($locations)
2017-01-02 03:57:23 +01:00
{
2023-10-15 19:25:55 +02:00
$this->locations = $locations;
2017-01-02 03:57:23 +01:00
}
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
}