From bd54bec595609f3502004163d41c555bfd79672d Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 18 Nov 2016 08:20:17 +0100 Subject: add ValidationResult to namespace --- includes/model/AngelType_model.php | 1 + includes/model/User_model.php | 1 + includes/model/ValidationResult.php | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 includes/model/ValidationResult.php (limited to 'includes/model') diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 86d64504..34da4db7 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -1,4 +1,5 @@ valid = $valid; + $this->value = $value; + } + + /** + * Is the value valid? + */ + public function isValid() { + return $this->valid; + } + + /** + * The parsed/validated value. + */ + public function getValue() { + return $this->value; + } +} +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 9098b8e80d4d790609f0a267b88169a129366b1b Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 18 Nov 2016 08:47:52 +0100 Subject: reduce complexity of user view --- includes/model/User_model.php | 17 ------ includes/view/User_view.php | 121 +++++++++++++++++++++++++----------------- 2 files changed, 73 insertions(+), 65 deletions(-) (limited to 'includes/model') diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 13695821..344a3886 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -274,23 +274,6 @@ function User($user_id) { return null; } -/** - * TODO: Merge into normal user function - * Returns user by id (limit informations. - * - * @param $user_id UID - */ -function mUser_Limit($user_id) { - $user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber` FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1"); - if ($user_source === false) { - return false; - } - if (count($user_source) > 0) { - return $user_source[0]; - } - return null; -} - /** * Returns User by api_key. * diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 09509c3d..65cb36b3 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -223,67 +223,83 @@ function User_shift_state_render($user) { return '' . _("Shift ends %c") . ''; } -function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) { +function User_view_shiftentries($needed_angel_type) { + $shift_info = '
' . $needed_angel_type['name'] . ': '; + + $shift_entries = []; + foreach ($needed_angel_type['users'] as $user_shift) { + $member = User_Nick_render($user_shift); + if ($user_shift['freeloaded']) { + $member = '' . $member . ''; + } + + $shift_entries[] = $member; + } + $shift_info .= join(", ", $shift_entries); + + return $shift_info; +} + +/** + * Helper that renders a shift line for user view + */ +function User_view_myshift($shift, $user_source, $its_me) { global $LETZTES_AUSTRAGEN, $privileges; - $user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']); + $shift_info = '' . $shift['name'] . ''; + if ($shift['title']) { + $shift_info .= '
' . $shift['title'] . ''; + } + foreach ($shift['needed_angeltypes'] as $needed_angel_type) { + $shift_info .= User_view_shiftentries($needed_angel_type); + } + + $myshift = [ + 'date' => date("Y-m-d", $shift['start']), + 'time' => date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']), + 'room' => $shift['Name'], + 'shift_info' => $shift_info, + 'comment' => $shift['Comment'] + ]; + + if ($shift['freeloaded']) { + if (in_array("user_shifts_admin", $privileges)) { + $myshift['comment'] .= '

' . _("Freeloaded") . ': ' . $shift['freeload_comment'] . '

'; + } else { + $myshift['comment'] .= '

' . _("Freeloaded") . '

'; + } + } + + $myshift['actions'] = [ + button(shift_link($shift), glyph('eye-open') . _('view'), 'btn-xs') + ]; + if ($its_me || in_array('user_shifts_admin', $privileges)) { + $myshift['actions'][] = button(page_link_to('user_myshifts') . '&edit=' . $shift['id'] . '&id=' . $user_source['UID'], glyph('edit') . _('edit'), 'btn-xs'); + } + if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) { + $myshift['actions'][] = button(page_link_to('user_myshifts') . ((! $its_me) ? '&id=' . $user_source['UID'] : '') . '&cancel=' . $shift['id'], glyph('trash') . _('sign off'), 'btn-xs'); + } + $myshift['actions'] = table_buttons($myshift['actions']); + return $myshift; +} + +/** + * Helper that prepares the shift table for user view + */ +function User_view_myshifts($shifts, $user_source, $its_me) { $myshifts_table = []; $timesum = 0; foreach ($shifts as $shift) { - $shift_info = '' . $shift['name'] . ''; - if ($shift['title']) { - $shift_info .= '
' . $shift['title'] . ''; - } - foreach ($shift['needed_angeltypes'] as $needed_angel_type) { - $shift_info .= '
' . $needed_angel_type['name'] . ': '; - - $shift_entries = []; - foreach ($needed_angel_type['users'] as $user_shift) { - $member = User_Nick_render($user_shift); - if ($user_shift['freeloaded']) { - $member = '' . $member . ''; - } - - $shift_entries[] = $member; - } - $shift_info .= join(", ", $shift_entries); - } - - $myshift = [ - 'date' => date("Y-m-d", $shift['start']), - 'time' => date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']), - 'room' => $shift['Name'], - 'shift_info' => $shift_info, - 'comment' => $shift['Comment'] - ]; - - if ($shift['freeloaded']) { - if (in_array("user_shifts_admin", $privileges)) { - $myshift['comment'] .= '

' . _("Freeloaded") . ': ' . $shift['freeload_comment'] . '

'; - } else { - $myshift['comment'] .= '

' . _("Freeloaded") . '

'; - } - } - - $myshift['actions'] = [ - button(shift_link($shift), glyph('eye-open') . _('view'), 'btn-xs') - ]; - if ($its_me || in_array('user_shifts_admin', $privileges)) { - $myshift['actions'][] = button(page_link_to('user_myshifts') . '&edit=' . $shift['id'] . '&id=' . $user_source['UID'], glyph('edit') . _('edit'), 'btn-xs'); - } - if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) { - $myshift['actions'][] = button(page_link_to('user_myshifts') . ((! $its_me) ? '&id=' . $user_source['UID'] : '') . '&cancel=' . $shift['id'], glyph('trash') . _('sign off'), 'btn-xs'); - } - $myshift['actions'] = table_buttons($myshift['actions']); + $myshifts_table[] = User_view_myshift($shift, $user_source, $its_me); if ($shift['freeloaded']) { $timesum += (- 2 * ($shift['end'] - $shift['start'])); } else { $timesum += ($shift['end'] - $shift['start']); } - $myshifts_table[] = $myshift; } + if (count($myshifts_table) > 0) { $myshifts_table[] = [ 'date' => '' . _("Sum:") . '', @@ -294,6 +310,15 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel 'actions' => "" ]; } + return $myshifts_table; +} + +/** + * Renders view for a single user + */ +function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) { + $user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']); + $myshifts_table = User_view_myshifts($shifts, $user_source, $its_me); return page_with_title(' ' . htmlspecialchars($user_source['Nick']) . ' ' . $user_name . '', [ msg(), -- cgit v1.2.3-54-g00ecf From bae3ede662426d362a3b9d33d9124253af7e847b Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 25 Nov 2016 13:38:16 +0100 Subject: fixes #279 fix exporting freeload comment in json export --- includes/controller/shifts_controller.php | 23 ++++++----------------- includes/model/Shifts_model.php | 4 +++- includes/model/User_model.php | 2 +- includes/pages/user_atom.php | 3 --- includes/pages/user_ical.php | 3 --- includes/view/ShiftTypes_view.php | 1 + 6 files changed, 11 insertions(+), 25 deletions(-) (limited to 'includes/model') diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 1500b449..1e04c5a8 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -1,6 +1,6 @@ parse($shifttype['description']) ]); } -- cgit v1.2.3-54-g00ecf From 476d1daeb76306faf3ecd70f2afc8e29e98b9553 Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 25 Nov 2016 13:58:43 +0100 Subject: fixes #280 shift entries finished by user returns no freeloaded shifts --- includes/model/ShiftEntry_model.php | 1 + 1 file changed, 1 insertion(+) (limited to 'includes/model') diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 99f67028..dca7e1c1 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -115,6 +115,7 @@ function ShiftEntries_finished_by_user($user) { JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id` WHERE `ShiftEntry`.`UID`=" . sql_escape($user['UID']) . " AND `Shifts`.`end` < " . sql_escape(time()) . " + AND `ShiftEntry`.`freeloaded` = 0 ORDER BY `Shifts`.`end` "); } -- cgit v1.2.3-54-g00ecf From 34248bb20cb3102fbcff76fcd7e059c12d87a6c3 Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 25 Nov 2016 14:27:47 +0100 Subject: show freeload comments to supporters (user shift admin) --- includes/controller/users_controller.php | 2 +- includes/model/Shifts_model.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'includes/model') diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 33abe764..26ca8d00 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -151,7 +151,7 @@ function user_controller() { } } - $shifts = Shifts_by_user($user_source); + $shifts = Shifts_by_user($user_source, in_array("user_shifts_admin", $privileges)); foreach ($shifts as &$shift) { // TODO: Move queries to model $shift['needed_angeltypes'] = sql_select("SELECT DISTINCT `AngelTypes`.* FROM `ShiftEntry` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "' ORDER BY `AngelTypes`.`name`"); diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 67580eee..b1d4ca5e 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -261,10 +261,11 @@ function Shift_create($shift) { /** * Return users shifts. */ -function Shifts_by_user($user) { +function Shifts_by_user($user, $include_freeload_comments = false) { $result = sql_select(" SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`, + " . ($include_freeload_comments ? "`ShiftEntry`.`freeload_comment`, " : "") . " `Shifts`.*, `Room`.* FROM `ShiftEntry` JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) -- cgit v1.2.3-54-g00ecf