Commit fdfb87cf authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt

add possibility to hide a shift based on the selected task in the shift type and user memberships

parent 97d786a1
......@@ -574,3 +574,6 @@ ALTER TABLE Room
ALTER TABLE Room
ADD COLUMN `color` VARCHAR(7) DEFAULT NULL;
ALTER TABLE `ShiftTypes`
ADD `restrict_visibility` TINYINT(1) NULL DEFAULT '0';
......@@ -40,6 +40,7 @@ function shifttype_edit_controller() {
$name = "";
$angeltype_id = null;
$description = "";
$restrict_visibility = false;
$angeltypes = AngelTypes();
if ($angeltypes === false)
......@@ -57,6 +58,7 @@ function shifttype_edit_controller() {
$name = $shifttype['name'];
$angeltype_id = $shifttype['angeltype_id'];
$description = $shifttype['description'];
$restrict_visibility = !!$shifttype['restrict_visibility'];
}
if (isset($_REQUEST['submit'])) {
......@@ -68,6 +70,10 @@ function shifttype_edit_controller() {
$ok = false;
error(_('Please enter a name.'));
}
if (isset($_REQUEST['restrict_visibility']) && $_REQUEST['restrict_visibility']) {
$restrict_visibility = true;
}
if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id']))
$angeltype_id = $_REQUEST['angeltype_id'];
......@@ -79,13 +85,13 @@ function shifttype_edit_controller() {
if ($ok) {
if ($shifttype_id) {
$result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
$result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description, $restrict_visibility);
if ($result === false)
engelsystem_error('Unable to update shifttype.');
engelsystem_log('Updated shifttype ' . $name);
success(_('Updated shifttype.'));
} else {
$shifttype_id = ShiftType_create($name, $angeltype_id, $description);
$shifttype_id = ShiftType_create($name, $angeltype_id, $description, $restrict_visibility);
if ($shifttype_id === false)
engelsystem_error('Unable to create shifttype.');
engelsystem_log('Created shifttype ' . $name);
......@@ -97,7 +103,7 @@ function shifttype_edit_controller() {
return [
shifttypes_title(),
ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id, $restrict_visibility)
];
}
......@@ -164,4 +170,4 @@ function shifttypes_controller() {
}
}
?>
\ No newline at end of file
?>
......@@ -16,10 +16,11 @@ function ShiftType_delete($shifttype_id) {
* @param int $angeltype_id
* @param string $description
*/
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) {
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description, $restrict_visibility = false) {
return sql_query("UPDATE `ShiftTypes` SET
`name`='" . sql_escape($name) . "',
`angeltype_id`=" . sql_null($angeltype_id) . ",
`restrict_visibility`=" . ($restrict_visibility ? 1 : 0) . ",
`description`='" . sql_escape($description) . "'
WHERE `id`='" . sql_escape($shifttype_id) . "'");
}
......@@ -32,10 +33,11 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) {
* @param string $description
* @return new shifttype id
*/
function ShiftType_create($name, $angeltype_id, $description) {
function ShiftType_create($name, $angeltype_id, $description, $restrict_visibility) {
$result = sql_query("INSERT INTO `ShiftTypes` SET
`name`='" . sql_escape($name) . "',
`angeltype_id`=" . sql_null($angeltype_id) . ",
`restrict_visibility`=" . ($restrict_visibility ? 1 : 0) . ",
`description`='" . sql_escape($description) . "'");
if ($result === false)
return false;
......@@ -63,4 +65,4 @@ function ShiftTypes() {
return sql_select("SELECT * FROM `ShiftTypes` ORDER BY `name`");
}
?>
\ No newline at end of file
?>
......@@ -358,6 +358,7 @@ function user_shifts() {
function view_user_shifts() {
global $user, $privileges;
global $ical_shifts;
$user_angel_times = User_angeltypes($user);
$ical_shifts = array();
$days = sql_select_single_col("
......@@ -575,6 +576,22 @@ function view_user_shifts() {
foreach ($shifts as $shift) {
if ($shift["RID"] == $rid) {
if (floor($shift["start"] / (15 * 60)) == $thistime / (15 * 60)) {
$shift_type = ShiftType($shift['shifttype_id']);
if($shift_type['restrict_visibility']) {
$hasAssignment = false;
foreach($user_angel_times as $assignment) {
if ($shift_type["angeltype_id"] == $assignment["id"]) {
$hasAssignment = $assignment["restricted"] ? !!$assignment["confirm_user_id"] : true;
}
}
if (!$hasAssignment) {
continue;
}
}
$blocks = ($shift["end"] - $shift["start"]) / (15 * 60);
if ($blocks < 1)
$blocks = 1;
......@@ -604,7 +621,7 @@ function view_user_shifts() {
$shifts_row .= " &ndash; ";
$shifts_row .= date('H:i', $shift['end']);
$shifts_row .= "<br /><b>";
$shifts_row .= ShiftType($shift['shifttype_id'])['name'];
$shifts_row .= $shift_type['name'];
$shifts_row .= "</b><br />";
if ($shift['title'] != '') {
$shifts_row .= $shift['title'];
......
......@@ -17,7 +17,7 @@ function ShiftType_delete_view($shifttype) {
));
}
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) {
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id, $restrict_visibility) {
$angeltypes_select = [
'' => _('All')
];
......@@ -32,6 +32,7 @@ function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $s
form([
form_text('name', _('Name'), $name),
form_select('angeltype_id', _('Angeltype'), $angeltypes_select, $angeltype_id),
form_checkbox('restrict_visibility', _('Restrict visibility to people with this Task'), $restrict_visibility, 1),
form_textarea('description', _('Description'), $description),
form_info('', _('Please use markdown for the description.')),
form_submit('submit', _('Save'))
......@@ -77,4 +78,4 @@ function ShiftTypes_list_view($shifttypes) {
]);
}
?>
\ No newline at end of file
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment