From d8476f244dd0ee1bccaab53f123fa12f2a9c9501 Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 24 Nov 2017 10:02:52 +0100 Subject: complete feature contact info for angeltypes, fixes #275 --- db/update.sql | 4 ++ includes/controller/angeltypes_controller.php | 4 ++ includes/model/AngelType_model.php | 69 +++++++-------------------- includes/sys_template.php | 14 ++++++ includes/view/AngelTypes_view.php | 33 +++++++++++-- 5 files changed, 68 insertions(+), 56 deletions(-) diff --git a/db/update.sql b/db/update.sql index 3ed37ceb..c5187675 100644 --- a/db/update.sql +++ b/db/update.sql @@ -31,3 +31,7 @@ INSERT INTO `GroupPrivileges` (group_id, privilege_id) VALUES (-65, 14), (-65, 4 -- Add log level to LogEntries ALTER TABLE `LogEntries` CHANGE COLUMN `nick` `level` VARCHAR(20) NOT NULL; + +-- Angeltype contact update +ALTER TABLE `AngelTypes` DROP FOREIGN KEY angeltypes_ibfk_1; +ALTER TABLE `AngelTypes` DROP `contact_user_id`; \ No newline at end of file diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 3e377fb0..eaaa9c0f 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -143,6 +143,10 @@ function angeltype_edit_controller() $angeltype['description'] = strip_request_item_nl('description', $angeltype['description']); + $angeltype['contact_name'] = strip_request_item('contact_name', $angeltype['contact_name']); + $angeltype['contact_dect'] = strip_request_item('contact_dect', $angeltype['contact_dect']); + $angeltype['contact_email'] = strip_request_item('contact_email', $angeltype['contact_email']); + if ($valid) { if ($angeltype['id'] != null) { AngelType_update($angeltype); diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index b51a6838..1f2c8c63 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -16,7 +16,6 @@ function AngelType_new() 'no_self_signup' => false, 'description' => '', 'requires_driver_license' => false, - 'contact_user_id' => null, 'contact_name' => null, 'contact_dect' => null, 'contact_email' => null @@ -24,53 +23,15 @@ function AngelType_new() } /** - * Validates the contact user - * - * @param array $angeltype The angeltype - * @return ValidationResult + * Checks if the angeltype has any contact information. + * + * @param Angeltype $angeltype + * @return bool */ -function AngelType_validate_contact_user_id($angeltype) -{ - if (!isset($angeltype['contact_user_id'])) { - return new ValidationResult(true, null); - } - if (isset($angeltype['contact_name']) || isset($angeltype['contact_dect']) || isset($angeltype['contact_email'])) { - return new ValidationResult(false, $angeltype['contact_user_id']); - } - if (User($angeltype['contact_user_id']) == null) { - return new ValidationResult(false, $angeltype['contact_user_id']); - } - return new ValidationResult(true, $angeltype['contact_user_id']); -} - -/** - * Returns contact data (name, dect, email) for given angeltype or null - * - * @param array $angeltype The angeltype - * @return array|null - */ -function AngelType_contact_info($angeltype) -{ - if (isset($angeltype['contact_user_id'])) { - $contact_user = User($angeltype['contact_user_id']); - $contact_data = [ - 'contact_name' => $contact_user['Nick'], - 'contact_dect' => $contact_user['DECT'] - ]; - if ($contact_user['email_by_human_allowed']) { - $contact_data['contact_email'] = $contact_user['email']; - } - return $contact_data; - } - if (isset($angeltype['contact_name'])) { - return [ - 'contact_name' => $angeltype['contact_name'], - 'contact_dect' => $angeltype['contact_dect'], - 'contact_email' => $angeltype['contact_email'] - ]; - } - - return null; +function AngelType_has_contact_info($angeltype) { + return !empty($angeltype['contact_name']) + || !empty($angeltype['contact_dect']) + || !empty($angeltype['contact_email']); } /** @@ -102,7 +63,6 @@ function AngelType_update($angeltype) `description` = ?, `requires_driver_license` = ?, `no_self_signup` = ?, - `contact_user_id` = ?, `contact_name` = ?, `contact_dect` = ?, `contact_email` = ? @@ -113,7 +73,6 @@ function AngelType_update($angeltype) $angeltype['description'], (int)$angeltype['requires_driver_license'], (int)$angeltype['no_self_signup'], - $angeltype['contact_user_id'], $angeltype['contact_name'], $angeltype['contact_dect'], $angeltype['contact_email'], @@ -124,7 +83,10 @@ function AngelType_update($angeltype) engelsystem_log( 'Updated angeltype: ' . $angeltype['name'] . ($angeltype['restricted'] ? ', restricted' : '') . ($angeltype['no_self_signup'] ? ', no_self_signup' : '') - . ($angeltype['requires_driver_license'] ? ', requires driver license' : '') + . ($angeltype['requires_driver_license'] ? ', requires driver license' : '') . ', ' + . $angeltype['contact_name'] . ', ' + . $angeltype['contact_dect'] . ', ' + . $angeltype['contact_email'] ); } @@ -143,7 +105,6 @@ function AngelType_create($angeltype) `description`, `requires_driver_license`, `no_self_signup`, - `contact_user_id`, `contact_name`, `contact_dect`, `contact_email` @@ -156,7 +117,6 @@ function AngelType_create($angeltype) $angeltype['description'], (int)$angeltype['requires_driver_license'], (int)$angeltype['no_self_signup'], - $angeltype['contact_user_id'], $angeltype['contact_name'], $angeltype['contact_dect'], $angeltype['contact_email'], @@ -167,7 +127,10 @@ function AngelType_create($angeltype) engelsystem_log( 'Created angeltype: ' . $angeltype['name'] . ($angeltype['restricted'] ? ', restricted' : '') - . ($angeltype['requires_driver_license'] ? ', requires driver license' : '') + . ($angeltype['requires_driver_license'] ? ', requires driver license' : '') . ', ' + . $angeltype['contact_name'] . ', ' + . $angeltype['contact_dect'] . ', ' + . $angeltype['contact_email'] ); return $angeltype; } diff --git a/includes/sys_template.php b/includes/sys_template.php index a659a7f3..662283b1 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -211,6 +211,20 @@ function page_with_title($title, $elements) return '

' . $title . '

' . join($elements) . '
'; } +/** + * Renders a description based on the data arrays key and values as label an description. + * @param array $data + */ +function description($data) { + $elements = []; + foreach($data as $label => $description) { + if(!empty($label) && !empty($description)) { + $elements[] = '
' . $label . '
' . $description . '
'; + } + } + return '
' . join($elements) . '
'; +} + /** * Rendert eine Datentabelle * diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php index baf0e04a..6e70b3be 100644 --- a/includes/view/AngelTypes_view.php +++ b/includes/view/AngelTypes_view.php @@ -92,15 +92,20 @@ function AngelType_edit_view($angeltype, $supporter_mode) _('Requires driver license'), $angeltype['requires_driver_license'] ), - //form_text('contact_name', _('Name'), $angeltype['contact_name']), - //form_text('contact_dect', _('DECT'), $angeltype['contact_dect']), - //form_text('contact_email', _('E-Mail'), $angeltype['contact_email']), form_info( '', _('Restricted angel types can only be used by an angel if enabled by a supporter (double opt-in).') ), form_textarea('description', _('Description'), $angeltype['description']), form_info('', _('Please use markdown for the description.')), + heading(_('Contact'), 3), + form_info( + '', + _('Primary contact person/desk for user questions.') + ), + form_text('contact_name', _('Name'), $angeltype['contact_name']), + form_text('contact_dect', _('DECT'), $angeltype['contact_dect']), + form_text('contact_email', _('E-Mail'), $angeltype['contact_email']), form_submit('submit', _('Save')) ]) ]); @@ -322,6 +327,10 @@ function AngelType_view( msg() ]; + if(AngelType_has_contact_info($angeltype)) { + $page[] = AngelTypes_render_contact_info($angeltype); + } + $page[] = '

' . _('Description') . '

'; $parsedown = new Parsedown(); if ($angeltype['description'] != '') { @@ -392,6 +401,20 @@ function AngelType_view( return page_with_title(sprintf(_('Team %s'), $angeltype['name']), $page); } +/** + * Renders the contact info + * + * @param Anteltype $angeltype + * @return string HTML + */ +function AngelTypes_render_contact_info($angeltype) { + return heading(_('Contact'), 3) . description([ + _('Name') => $angeltype['contact_name'], + _('DECT') => $angeltype['contact_dect'], + _('E-Mail') => $angeltype['contact_email'] + ]); +} + /** * Display the list of angeltypes. * @@ -431,6 +454,10 @@ function AngelTypes_about_view_angeltype($angeltype) $html = '

' . $angeltype['name'] . '

'; + if(AngelType_has_contact_info($angeltype)) { + $html .= AngelTypes_render_contact_info($angeltype); + } + if (isset($angeltype['user_angeltype_id'])) { $buttons = []; if ($angeltype['user_angeltype_id'] != null) { -- cgit v1.2.3-54-g00ecf