|
|
@ -10,11 +10,7 @@ use Engelsystem\ShiftSignupState;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shifts_by_room($room)
|
|
|
|
function Shifts_by_room($room)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$result = DB::select('SELECT * FROM `Shifts` WHERE `RID`=? ORDER BY `start`', [$room['RID']]);
|
|
|
|
return DB::select('SELECT * FROM `Shifts` WHERE `RID`=? ORDER BY `start`', [$room['RID']]);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
engelsystem_error('Unable to load shifts.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -49,7 +45,8 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
|
|
|
AND NOT `Shifts`.`PSID` IS NULL) AS tmp_shifts
|
|
|
|
AND NOT `Shifts`.`PSID` IS NULL) AS tmp_shifts
|
|
|
|
|
|
|
|
|
|
|
|
ORDER BY `start`';
|
|
|
|
ORDER BY `start`';
|
|
|
|
$result = DB::select(
|
|
|
|
|
|
|
|
|
|
|
|
return DB::select(
|
|
|
|
$sql,
|
|
|
|
$sql,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
$shiftsFilter->getStartTime(),
|
|
|
|
$shiftsFilter->getStartTime(),
|
|
|
@ -58,10 +55,6 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
|
|
|
$shiftsFilter->getEndTime(),
|
|
|
|
$shiftsFilter->getEndTime(),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
engelsystem_error('Unable to load shifts by filter.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -100,7 +93,8 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
|
|
|
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
|
|
|
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
|
|
|
AND `start` BETWEEN ? AND ?
|
|
|
|
AND `start` BETWEEN ? AND ?
|
|
|
|
AND NOT `Shifts`.`PSID` IS NULL';
|
|
|
|
AND NOT `Shifts`.`PSID` IS NULL';
|
|
|
|
$result = DB::select(
|
|
|
|
|
|
|
|
|
|
|
|
return DB::select(
|
|
|
|
$sql,
|
|
|
|
$sql,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
$shiftsFilter->getStartTime(),
|
|
|
|
$shiftsFilter->getStartTime(),
|
|
|
@ -109,10 +103,6 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
|
|
|
$shiftsFilter->getEndTime(),
|
|
|
|
$shiftsFilter->getEndTime(),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
engelsystem_error('Unable to load needed angeltypes by filter.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -122,7 +112,7 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
|
|
|
|
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$result = DB::select('
|
|
|
|
return DB::selectOne('
|
|
|
|
SELECT
|
|
|
|
SELECT
|
|
|
|
`NeededAngelTypes`.*,
|
|
|
|
`NeededAngelTypes`.*,
|
|
|
|
`Shifts`.`SID`,
|
|
|
|
`Shifts`.`SID`,
|
|
|
@ -160,13 +150,6 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
|
|
|
|
$angeltype['id']
|
|
|
|
$angeltype['id']
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
engelsystem_error('Unable to load needed angeltypes by filter.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($result)) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -193,17 +176,13 @@ function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
|
|
|
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
|
|
|
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
|
|
|
|
AND `start` BETWEEN ? AND ?
|
|
|
|
AND `start` BETWEEN ? AND ?
|
|
|
|
ORDER BY `Shifts`.`start`';
|
|
|
|
ORDER BY `Shifts`.`start`';
|
|
|
|
$result = DB::select(
|
|
|
|
return DB::select(
|
|
|
|
$sql,
|
|
|
|
$sql,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
$shiftsFilter->getStartTime(),
|
|
|
|
$shiftsFilter->getStartTime(),
|
|
|
|
$shiftsFilter->getEndTime(),
|
|
|
|
$shiftsFilter->getEndTime(),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
engelsystem_error('Unable to load shift entries by filter.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -402,41 +381,29 @@ function Shift_signup_allowed(
|
|
|
|
* Delete a shift by its external id.
|
|
|
|
* Delete a shift by its external id.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param int $shift_psid
|
|
|
|
* @param int $shift_psid
|
|
|
|
* @return bool
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shift_delete_by_psid($shift_psid)
|
|
|
|
function Shift_delete_by_psid($shift_psid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DB::delete('DELETE FROM `Shifts` WHERE `PSID`=?', [$shift_psid]);
|
|
|
|
DB::delete('DELETE FROM `Shifts` WHERE `PSID`=?', [$shift_psid]);
|
|
|
|
|
|
|
|
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Delete a shift.
|
|
|
|
* Delete a shift.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param int $shift_id
|
|
|
|
* @param int $shift_id
|
|
|
|
* @return bool
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shift_delete($shift_id)
|
|
|
|
function Shift_delete($shift_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mail_shift_delete(Shift($shift_id));
|
|
|
|
mail_shift_delete(Shift($shift_id));
|
|
|
|
|
|
|
|
|
|
|
|
$result = DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]);
|
|
|
|
DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
engelsystem_error('Unable to delete shift.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Update a shift.
|
|
|
|
* Update a shift.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $shift
|
|
|
|
* @param array $shift
|
|
|
|
* @return bool
|
|
|
|
* @return int Updated row count
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shift_update($shift)
|
|
|
|
function Shift_update($shift)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -444,7 +411,7 @@ function Shift_update($shift)
|
|
|
|
$shift['name'] = ShiftType($shift['shifttype_id'])['name'];
|
|
|
|
$shift['name'] = ShiftType($shift['shifttype_id'])['name'];
|
|
|
|
mail_shift_change(Shift($shift['SID']), $shift);
|
|
|
|
mail_shift_change(Shift($shift['SID']), $shift);
|
|
|
|
|
|
|
|
|
|
|
|
return (bool)DB::update('
|
|
|
|
return DB::update('
|
|
|
|
UPDATE `Shifts` SET
|
|
|
|
UPDATE `Shifts` SET
|
|
|
|
`shifttype_id` = ?,
|
|
|
|
`shifttype_id` = ?,
|
|
|
|
`start` = ?,
|
|
|
|
`start` = ?,
|
|
|
@ -480,16 +447,13 @@ function Shift_update($shift)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shift_update_by_psid($shift)
|
|
|
|
function Shift_update_by_psid($shift)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$shift_source = DB::select('SELECT `SID` FROM `Shifts` WHERE `PSID`=?', [$shift['PSID']]);
|
|
|
|
$shift_source = DB::selectOne('SELECT `SID` FROM `Shifts` WHERE `PSID`=?', [$shift['PSID']]);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($shift_source)) {
|
|
|
|
if (empty($shift_source)) {
|
|
|
|
return null;
|
|
|
|
throw new Exception('Shift not found.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$shift['SID'] = $shift_source[0]['SID'];
|
|
|
|
$shift['SID'] = $shift_source['SID'];
|
|
|
|
return Shift_update($shift);
|
|
|
|
return Shift_update($shift);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -497,7 +461,7 @@ function Shift_update_by_psid($shift)
|
|
|
|
* Create a new shift.
|
|
|
|
* Create a new shift.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $shift
|
|
|
|
* @param array $shift
|
|
|
|
* @return int|false shift id or false
|
|
|
|
* @return int ID of the new created shift
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shift_create($shift)
|
|
|
|
function Shift_create($shift)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -528,9 +492,7 @@ function Shift_create($shift)
|
|
|
|
time(),
|
|
|
|
time(),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return DB::getPdo()->lastInsertId();
|
|
|
|
return DB::getPdo()->lastInsertId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -543,7 +505,7 @@ function Shift_create($shift)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shifts_by_user($user, $include_freeload_comments = false)
|
|
|
|
function Shifts_by_user($user, $include_freeload_comments = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$result = DB::select('
|
|
|
|
return DB::select('
|
|
|
|
SELECT `ShiftTypes`.`id` AS `shifttype_id`, `ShiftTypes`.`name`,
|
|
|
|
SELECT `ShiftTypes`.`id` AS `shifttype_id`, `ShiftTypes`.`name`,
|
|
|
|
`ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`,
|
|
|
|
`ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`,
|
|
|
|
' . ($include_freeload_comments ? '`ShiftEntry`.`freeload_comment`, ' : '') . '
|
|
|
|
' . ($include_freeload_comments ? '`ShiftEntry`.`freeload_comment`, ' : '') . '
|
|
|
@ -559,10 +521,6 @@ function Shifts_by_user($user, $include_freeload_comments = false)
|
|
|
|
$user['UID']
|
|
|
|
$user['UID']
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
engelsystem_error('Unable to load users shifts.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -573,22 +531,16 @@ function Shifts_by_user($user, $include_freeload_comments = false)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shift($shift_id)
|
|
|
|
function Shift($shift_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$shifts_source = DB::select('
|
|
|
|
$result = DB::selectOne('
|
|
|
|
SELECT `Shifts`.*, `ShiftTypes`.`name`
|
|
|
|
SELECT `Shifts`.*, `ShiftTypes`.`name`
|
|
|
|
FROM `Shifts`
|
|
|
|
FROM `Shifts`
|
|
|
|
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
|
|
|
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
|
|
|
WHERE `SID`=?', [$shift_id]);
|
|
|
|
WHERE `SID`=?', [$shift_id]);
|
|
|
|
|
|
|
|
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
if (empty($result)) {
|
|
|
|
engelsystem_error('Unable to load shift.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($shifts_source)) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = $shifts_source[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$shiftsEntry_source = DB::select('
|
|
|
|
$shiftsEntry_source = DB::select('
|
|
|
|
SELECT `id`, `TID` , `UID` , `freeloaded`
|
|
|
|
SELECT `id`, `TID` , `UID` , `freeloaded`
|
|
|
|
FROM `ShiftEntry`
|
|
|
|
FROM `ShiftEntry`
|
|
|
@ -613,7 +565,7 @@ function Shift($shift_id)
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Returns all shifts with needed angeltypes and count of subscribed jobs.
|
|
|
|
* Returns all shifts with needed angeltypes and count of subscribed jobs.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return array|false
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function Shifts()
|
|
|
|
function Shifts()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -624,10 +576,6 @@ function Shifts()
|
|
|
|
JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
|
|
|
|
JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
|
|
|
|
');
|
|
|
|
');
|
|
|
|
|
|
|
|
|
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($shifts_source as &$shift) {
|
|
|
|
foreach ($shifts_source as &$shift) {
|
|
|
|
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
|
|
|
|
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
|
|
|
|
$shift['angeltypes'] = $needed_angeltypes;
|
|
|
|
$shift['angeltypes'] = $needed_angeltypes;
|
|
|
|