Merge pull request #397 from MyIgel/master

Filter angel types based on account settings, closes  #362
main
msquare 7 years ago committed by GitHub
commit e0ce3168e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -226,3 +226,20 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype)
] ]
); );
} }
/**
* Get an UserAngelTypes by user
*
* @param array $user
* @return array[]|null
*/
function UserAngelTypes_by_User($user)
{
return DB::select('
SELECT *
FROM `UserAngelTypes`
WHERE `user_id`=?
',
[$user['UID']]
);
}

@ -186,6 +186,7 @@ function view_user_shifts()
$session->set('ShiftsFilter', $shiftsFilter); $session->set('ShiftsFilter', $shiftsFilter);
} }
/** @var ShiftsFilter $shiftsFilter */
$shiftsFilter = $session->get('ShiftsFilter'); $shiftsFilter = $session->get('ShiftsFilter');
update_ShiftsFilter($shiftsFilter, in_array('user_shifts_admin', $privileges), $days); update_ShiftsFilter($shiftsFilter, in_array('user_shifts_admin', $privileges), $days);
@ -214,6 +215,11 @@ function view_user_shifts()
info(render_user_arrived_hint()); info(render_user_arrived_hint());
} }
$ownTypes = [];
foreach (UserAngelTypes_by_User($user) as $type) {
$ownTypes[] = (int)$type['angeltype_id'];
}
return page([ return page([
div('col-md-12', [ div('col-md-12', [
msg(), msg(),
@ -238,7 +244,13 @@ function view_user_shifts()
$types, $types,
$shiftsFilter->getTypes(), $shiftsFilter->getTypes(),
'types', 'types',
_('Angeltypes') . '<sup>1</sup>' _('Angeltypes') . '<sup>1</sup>',
[
button(
'javascript: checkOwnTypes(\'selection_types\', ' . json_encode($ownTypes) . ')',
_('Own')
),
]
), ),
'filled_select' => make_select($filled, $shiftsFilter->getFilled(), 'filled', _('Occupancy')), 'filled_select' => make_select($filled, $shiftsFilter->getFilled(), 'filled', _('Occupancy')),
'task_notice' => 'task_notice' =>
@ -269,12 +281,12 @@ function view_user_shifts()
/** /**
* Returns a hint for the user how the ical feature works. * Returns a hint for the user how the ical feature works.
*/ */
function ical_hint() { function ical_hint()
{
global $user; global $user;
return heading( return heading(
_('iCal export'), 2) _('iCal export'), 2) . '<p>' . sprintf(
. '<p>' . sprintf(
_('Export of shown shifts. <a href="%s">iCal format</a> or <a href="%s">JSON format</a> available (please keep secret, otherwise <a href="%s">reset the api key</a>).'), _('Export of shown shifts. <a href="%s">iCal format</a> or <a href="%s">JSON format</a> available (please keep secret, otherwise <a href="%s">reset the api key</a>).'),
page_link_to('ical', ['key' => $user['api_key']]), page_link_to('ical', ['key' => $user['api_key']]),
page_link_to('shifts_json_export', ['key' => $user['api_key']]), page_link_to('shifts_json_export', ['key' => $user['api_key']]),
@ -291,15 +303,23 @@ function get_ids_from_array($array)
return $array['id']; return $array['id'];
} }
function make_select($items, $selected, $name, $title = null) /**
* @param array $items
* @param array $selected
* @param string $name
* @param string $title
* @param array $additionalButtons
* @return string
*/
function make_select($items, $selected, $name, $title = null, $additionalButtons = [])
{ {
$html_items = []; $htmlItems = [];
if (isset($title)) { if (isset($title)) {
$html_items[] = '<h4>' . $title . '</h4>' . "\n"; $htmlItems[] = '<h4>' . $title . '</h4>' . "\n";
} }
foreach ($items as $i) { foreach ($items as $i) {
$html_items[] = '<div class="checkbox">' $htmlItems[] = '<div class="checkbox">'
. '<label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '" ' . '<label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '" '
. (in_array($i['id'], $selected) ? ' checked="checked"' : '') . (in_array($i['id'], $selected) ? ' checked="checked"' : '')
. ' > ' . $i['name'] . '</label>' . ' > ' . $i['name'] . '</label>'
@ -307,11 +327,14 @@ function make_select($items, $selected, $name, $title = null)
. '</div><br />'; . '</div><br />';
} }
$html = '<div id="selection_' . $name . '" class="selection ' . $name . '">' . "\n"; $html = '<div id="selection_' . $name . '" class="selection ' . $name . '">' . "\n";
$html .= implode("\n", $html_items); $html .= implode("\n", $htmlItems);
$html .= buttons([
button('javascript: checkAll(\'selection_' . $name . '\', true)', _('All'), ''), $buttons = [];
button('javascript: checkAll(\'selection_' . $name . '\', false)', _('None'), '') $buttons[] = button('javascript: checkAll(\'selection_' . $name . '\', true)', _('All'));
]); $buttons[] = button('javascript: checkAll(\'selection_' . $name . '\', false)', _('None'));
$buttons = array_merge($buttons, $additionalButtons);
$html .= buttons($buttons);
$html .= '</div>' . "\n"; $html .= '</div>' . "\n";
return $html; return $html;
} }

@ -351,8 +351,11 @@ function User_view_myshift($shift, $user_source, $its_me)
} }
$myshift = [ $myshift = [
'date' => glyph('calendar') . date('Y-m-d', $shift['start']) . '<br>' 'date' => glyph('calendar')
. glyph('time') . date('H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']), . date('Y-m-d', $shift['start']) . '<br>'
. glyph('time') . date('H:i', $shift['start'])
. ' - '
. date('H:i', $shift['end']),
'duration' => round(($shift['end'] - $shift['start']) / 3600, 2) . ' h', 'duration' => round(($shift['end'] - $shift['start']) / 3600, 2) . ' h',
'room' => Room_name_render($shift), 'room' => Room_name_render($shift),
'shift_info' => $shift_info, 'shift_info' => $shift_info,
@ -364,7 +367,9 @@ function User_view_myshift($shift, $user_source, $its_me)
} }
if ($shift['freeloaded']) { if ($shift['freeloaded']) {
$myshift['duration'] = '<p class="text-danger">' . round(-($shift['end'] - $shift['start']) / 3600 * 2, 2) . ' h' . '</p>'; $myshift['duration'] = '<p class="text-danger">'
. round(-($shift['end'] - $shift['start']) / 3600 * 2, 2) . ' h'
. '</p>';
if (in_array('user_shifts_admin', $privileges)) { if (in_array('user_shifts_admin', $privileges)) {
$myshift['comment'] .= '<br />' $myshift['comment'] .= '<br />'
. '<p class="text-danger">' . _('Freeloaded') . ': ' . $shift['freeload_comment'] . '</p>'; . '<p class="text-danger">' . _('Freeloaded') . ': ' . $shift['freeload_comment'] . '</p>';
@ -452,8 +457,17 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi
* @param bool $tshirt_admin * @param bool $tshirt_admin
* @return string * @return string
*/ */
function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me, $tshirt_score, $tshirt_admin) function User_view(
{ $user_source,
$admin_user_privilege,
$freeloader,
$user_angeltypes,
$user_groups,
$shifts,
$its_me,
$tshirt_score,
$tshirt_admin
) {
$user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']); $user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']);
$myshifts_table = User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin); $myshifts_table = User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin);

@ -1,8 +1,8 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Engelsystem 2.0\n" "Project-Id-Version: Engelsystem 2.0\n"
"POT-Creation-Date: 2017-12-27 12:17+0100\n" "POT-Creation-Date: 2017-12-27 13:38+0100\n"
"PO-Revision-Date: 2017-12-27 12:17+0100\n" "PO-Revision-Date: 2017-12-27 13:38+0100\n"
"Last-Translator: msquare <msquare@notrademark.de>\n" "Last-Translator: msquare <msquare@notrademark.de>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: de_DE\n" "Language: de_DE\n"
@ -1867,6 +1867,10 @@ msgstr "belegt"
msgid "free" msgid "free"
msgstr "frei" msgstr "frei"
#: /Users/msquare/workspace/projects/engelsystem/includes/pages/user_shifts.php:251
msgid "Own"
msgstr "Eigene"
#: /Users/msquare/workspace/projects/engelsystem/includes/pages/user_shifts.php:243 #: /Users/msquare/workspace/projects/engelsystem/includes/pages/user_shifts.php:243
msgid "Occupancy" msgid "Occupancy"
msgstr "Belegung" msgstr "Belegung"

@ -1,20 +1,25 @@
/** /**
* Runs through the DOM under the element with the given id, finds all * Sets all checkboxes to the wanted state
* checkboxes and sets them to the wanted state.
* *
* @param String * @param {string} id Id of the element containing all the checkboxes
* id Id of the element containing all the checkboxes * @param {bool} checked True if the checkboxes should be checked
* @param Boolean
* checked True if the checkboxes should be checked
*/ */
function checkAll(id, checked) { function checkAll(id, checked) {
var obj = document.getElementById(id); $("#" + id + " input[type='checkbox']").each(function () {
var boxes = obj.getElementsByTagName("input"); this.checked = checked;
for (var i = 0; i < boxes.length; i++) { });
if (boxes[i].type === "checkbox" && !boxes[i].disabled) {
boxes[i].checked = checked;
}
} }
/**
* Sets the checkboxes according to the given type
*
* @param {string} id The elements ID
* @param {list} shifts_list A list of numbers
*/
function checkOwnTypes(id, shifts_list) {
$('#' + id + ' input[type=checkbox]').each(function () {
this.checked = $.inArray(parseInt(this.value), shifts_list);
});
} }
/** /**

Loading…
Cancel
Save