2013-12-09 17:10:07 +01:00
|
|
|
<?php
|
|
|
|
|
2016-11-17 14:35:04 +01:00
|
|
|
/**
|
|
|
|
* Returns an array with the attributes of shift entries.
|
|
|
|
* FIXME! Needs entity object.
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntry_new()
|
|
|
|
{
|
|
|
|
return [
|
2016-11-17 14:35:04 +01:00
|
|
|
'id' => null,
|
|
|
|
'SID' => null,
|
|
|
|
'TID' => null,
|
|
|
|
'UID' => null,
|
|
|
|
'Comment' => null,
|
|
|
|
'freeloaded_comment' => null,
|
2017-01-02 03:57:23 +01:00
|
|
|
'freeloaded' => false
|
2016-11-17 14:35:04 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2014-09-28 15:01:02 +02:00
|
|
|
/**
|
|
|
|
* Counts all freeloaded shifts.
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntries_freeleaded_count()
|
|
|
|
{
|
|
|
|
return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
|
2014-09-28 15:01:02 +02:00
|
|
|
}
|
|
|
|
|
2014-12-07 17:07:19 +01:00
|
|
|
/**
|
|
|
|
* List users subsribed to a given shift.
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntries_by_shift($shift_id)
|
|
|
|
{
|
|
|
|
return sql_select("
|
2016-12-26 14:26:49 +01:00
|
|
|
SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
|
2014-12-07 16:54:00 +01:00
|
|
|
FROM `ShiftEntry`
|
|
|
|
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
|
|
|
|
JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id`
|
2014-12-28 14:56:02 +01:00
|
|
|
WHERE `ShiftEntry`.`SID`='" . sql_escape($shift_id) . "'");
|
2014-12-07 16:54:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 16:45:09 +01:00
|
|
|
/**
|
|
|
|
* Create a new shift entry.
|
2014-12-07 16:54:00 +01:00
|
|
|
*
|
2017-01-02 03:57:23 +01:00
|
|
|
* @param ShiftEntry $shift_entry
|
2014-12-07 16:45:09 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntry_create($shift_entry)
|
|
|
|
{
|
|
|
|
mail_shift_assign(User($shift_entry['UID']), Shift($shift_entry['SID']));
|
|
|
|
return sql_query("INSERT INTO `ShiftEntry` SET
|
2014-12-28 13:44:56 +01:00
|
|
|
`SID`='" . sql_escape($shift_entry['SID']) . "',
|
|
|
|
`TID`='" . sql_escape($shift_entry['TID']) . "',
|
|
|
|
`UID`='" . sql_escape($shift_entry['UID']) . "',
|
2014-12-07 16:45:09 +01:00
|
|
|
`Comment`='" . sql_escape($shift_entry['Comment']) . "',
|
|
|
|
`freeload_comment`='" . sql_escape($shift_entry['freeload_comment']) . "',
|
2014-12-28 13:44:56 +01:00
|
|
|
`freeloaded`=" . sql_bool($shift_entry['freeloaded']));
|
2014-12-07 16:45:09 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 17:13:14 +01:00
|
|
|
/**
|
|
|
|
* Update a shift entry.
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntry_update($shift_entry)
|
|
|
|
{
|
|
|
|
return sql_query("UPDATE `ShiftEntry` SET
|
2014-12-07 17:13:14 +01:00
|
|
|
`Comment`='" . sql_escape($shift_entry['Comment']) . "',
|
|
|
|
`freeload_comment`='" . sql_escape($shift_entry['freeload_comment']) . "',
|
2014-12-28 13:44:56 +01:00
|
|
|
`freeloaded`=" . sql_bool($shift_entry['freeloaded']) . "
|
|
|
|
WHERE `id`='" . sql_escape($shift_entry['id']) . "'");
|
2014-12-07 17:13:14 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 20:29:01 +01:00
|
|
|
/**
|
|
|
|
* Get a shift entry.
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntry($shift_entry_id)
|
|
|
|
{
|
|
|
|
$shift_entry = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'");
|
|
|
|
if ($shift_entry === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (count($shift_entry) == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $shift_entry[0];
|
2014-12-07 20:29:01 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 17:07:19 +01:00
|
|
|
/**
|
|
|
|
* Delete a shift entry.
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntry_delete($shift_entry_id)
|
|
|
|
{
|
|
|
|
$shift_entry = ShiftEntry($shift_entry_id);
|
|
|
|
mail_shift_removed(User($shift_entry['UID']), Shift($shift_entry['SID']));
|
|
|
|
return sql_query("DELETE FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'");
|
2014-12-07 17:07:19 +01:00
|
|
|
}
|
|
|
|
|
2014-08-23 01:55:18 +02:00
|
|
|
/**
|
|
|
|
* Returns next (or current) shifts of given user.
|
2014-12-07 16:45:09 +01:00
|
|
|
*
|
2017-01-02 03:57:23 +01:00
|
|
|
* @param User $user
|
2014-08-23 01:55:18 +02:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntries_upcoming_for_user($user)
|
|
|
|
{
|
|
|
|
return sql_select("
|
2014-08-23 01:55:18 +02:00
|
|
|
SELECT *
|
|
|
|
FROM `ShiftEntry`
|
2014-12-17 17:22:35 +01:00
|
|
|
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)
|
|
|
|
JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
|
2014-08-23 01:55:18 +02:00
|
|
|
WHERE `ShiftEntry`.`UID`=" . sql_escape($user['UID']) . "
|
|
|
|
AND `Shifts`.`end` > " . sql_escape(time()) . "
|
|
|
|
ORDER BY `Shifts`.`end`
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
2016-02-05 22:57:57 +01:00
|
|
|
/**
|
|
|
|
* Returns shifts completed by the given user.
|
|
|
|
*
|
2017-01-02 03:57:23 +01:00
|
|
|
* @param User $user
|
2016-02-05 22:57:57 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntries_finished_by_user($user)
|
|
|
|
{
|
|
|
|
return sql_select("
|
2016-02-05 22:57:57 +01:00
|
|
|
SELECT *
|
|
|
|
FROM `ShiftEntry`
|
|
|
|
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)
|
|
|
|
JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
|
|
|
|
WHERE `ShiftEntry`.`UID`=" . sql_escape($user['UID']) . "
|
|
|
|
AND `Shifts`.`end` < " . sql_escape(time()) . "
|
2016-11-25 13:58:43 +01:00
|
|
|
AND `ShiftEntry`.`freeloaded` = 0
|
2016-02-05 22:57:57 +01:00
|
|
|
ORDER BY `Shifts`.`end`
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:10:07 +01:00
|
|
|
/**
|
|
|
|
* Returns all shift entries in given shift for given angeltype.
|
2014-08-23 01:55:18 +02:00
|
|
|
*
|
2017-01-02 03:57:23 +01:00
|
|
|
* @param int $shift_id
|
|
|
|
* @param int $angeltype_id
|
2013-12-09 17:10:07 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id)
|
|
|
|
{
|
|
|
|
$result = sql_select("
|
2014-12-07 18:01:05 +01:00
|
|
|
SELECT *
|
2013-12-09 17:17:23 +01:00
|
|
|
FROM `ShiftEntry`
|
2013-12-09 17:10:07 +01:00
|
|
|
WHERE `SID`=" . sql_escape($shift_id) . "
|
|
|
|
AND `TID`=" . sql_escape($angeltype_id) . "
|
|
|
|
");
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($result === false) {
|
|
|
|
engelsystem_error("Unable to load shift entries.");
|
|
|
|
}
|
|
|
|
return $result;
|
2013-12-09 17:10:07 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 18:45:27 +01:00
|
|
|
/**
|
|
|
|
* Returns all freeloaded shifts for given user.
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function ShiftEntries_freeloaded_by_user($user)
|
|
|
|
{
|
|
|
|
return sql_select("SELECT *
|
2014-12-07 18:01:05 +01:00
|
|
|
FROM `ShiftEntry`
|
|
|
|
WHERE `freeloaded` = 1
|
2013-12-27 18:45:27 +01:00
|
|
|
AND `UID`=" . sql_escape($user['UID']));
|
|
|
|
}
|