diff --git a/CHANGES.md b/CHANGES.md index 4a8ad3edb6700f294bcfd22c8f53f8e7895edff0..194c13457f318dda355c3543ba1c7651bebc3b7d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,11 @@ moodle-theme_boost_campus Changes ------- +### Unreleased + +* 2020-08-05 - Added settings to be able to show a banner with information on selected pages. + PLEASE NOTE: For all scenarios to pass, the Moodle version 3.8.4+ (Build: 2019111804) is needed. + ### Release v3.8-r2 * 2020-06-22 - Improved SCSS settings to be used with admin_setting_scsscode that validates the code before saving. diff --git a/README.md b/README.md index 12157785e70d52763865601001cf181efba14c93..485cea452f41d27bc236bdee24b01fd430f28cfa 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,7 @@ By checking this setting the default homepage link (Dashboard or Site home) will By checking this setting you can enlarge the opened nav drawer menu to the full page width on small screens. This may be wanted because on small screens only very few of the main content area in the background is visible. And a full width menu might serve the users' expectations how menus are displayed on small screens. + ### 6. Tab "Design Settings" #### Login Page @@ -346,6 +347,83 @@ We're using the footer blocks setting and some of the blocks are displaying an i With this setting, the image (e.g. htmlblockimage.png) that should be displayed in the block could be added to this file area and added as a link with the url "/pluginfile.php/1/theme_boost_campus/additionalresources/0/htmlblockimage.png". +### 7. Tab "Info Banner Settings" + +#### Perpetual information banner + +##### Enable perpetual info banner + +With this checkbox you can decide if the perpetual information banner should be shown or hidden on the selected pages. + +##### Perpetual information banner content (dependent on setting "Enable perpetual info banner") + +Enter your information which should be shown within the banner here. + +##### Page layouts to display the info banner on (dependent on setting "Enable perpetual info banner") + +With this setting you can select the pages on which the perpetual information banner should be displayed. + +##### Bootstrap css class for the perpetual info banner (dependent on setting "Enable perpetual info banner") + +With this setting you can select the Bootstrap style with which the perpetual information banner should be displayed. + +##### Perpetual info banner dismissible (dependent on setting "Enable perpetual info banner") + +With this checkbox you can make the banner dismissible permanently. If the user clicks on the x-button a confirmation dialogue will appear and only after the user confirmed this dialogue the banner will be hidden for this user permanently. + +Please note: + +This setting has no effect for the banners shown on the login page. Because banners on the login page cannot be clicked away permanently, we do not offer the possibility to click the banner away at all on the login page. + +##### Confirmation dialogue (dependent on setting "Perpetual info banner dismissible") + +When you enable this setting you can show a confirmation dialogue to a user when he is dismissing the info banner. + +The text is saved in the string with the name "closingperpetualinfobanner": +``` +Are you sure you want to dismiss this information? Once done it will not occur again! +``` +You can override this within your language customization if you need some other text in this dialogue. + +##### Reset visibility for perpetual info banner (dependent on setting "Perpetual info banner dismissible") + +By enabling this checkbox, the visibility of the individually dismissed perpetual info banners will be set to visible again. You can use this setting if you made important content changes and want to show the info to all users again. + +Please note: +After saving this option, the database operations for resetting the visibility will be triggered and this checkbox will be unticked again. The next enabling and saving of this feature will trigger the database operations for resetting the visibility again. + +#### Time controlled information banner + +##### Enable time controlled info banner + +With this checkbox you can decide if the time controlled information banner should be shown or hidden on the selected pages. + +##### Time controlled information banner content (dependent on setting "Enable time controlled info banner") + +Enter your information which should be shown within the time controlled banner here. + +##### Page layouts to display the info banner on (dependent on setting "Enable time controlled info banner") + +With this setting you can select the pages on which the time controlled information banner should be displayed. +If both info banners are active on a selected layout, the time controlled info banner will always appear above the perpetual info banner! + +##### Bootstrap css class for the time controlled info banner (dependent on setting "Enable time controlled info banner") + +With this setting you can select the Bootstrap style with which the time controlled information banner should be displayed. + +##### Start time for the time controlled info banner (dependent on setting "Enable time controlled info banner") + +With this setting you can define when the time controlled information banner should be displayed on the selected pages. +Please enter a valid in this format: YYYY-MM-DD HH:MM:SS. For example: "2020-01-01 08:00:00". The time zone will be the time zone you have defined in the setting "Default timezone". +If you leave this setting empty but entered a date in the for the end, it is the same as if you entered a date far in the past. + +##### End time for the time controlled info banner (dependent on setting "Enable time controlled info banner") + +With this setting you can define when the time controlled information banner should be hidden on the selected pages. +Please enter a valid date in this format: YYYY-MM-DD HH:MM:SS. For example: "2020-01-07 08:00:00. The time zone will be the time zone you have defined in the setting "Default timezone". +If you leave this setting empty but entered a date in the for the start, the banner won't hide after the starting time has been reached. + + Further improvements to Boost core theme ---------------------------------------- diff --git a/amd/build/infobanner.min.js b/amd/build/infobanner.min.js new file mode 100644 index 0000000000000000000000000000000000000000..e5f456c38d80c66895066a2442a231a2a84d8bba --- /dev/null +++ b/amd/build/infobanner.min.js @@ -0,0 +1,2 @@ +define ("theme_boost_campus/infobanner",["jquery","core/str","core/modal_factory","core/modal_events","core/notification"],function(a,b,c,d,e){"use strict";function f(f){var g=b.get_strings([{key:"confirmation",component:"theme_boost_campus"},{key:"closingperpetualinfobanner",component:"theme_boost_campus"},{key:"yes_close",component:"theme_boost_campus"}]),h=c.create({type:c.types.SAVE_CANCEL});a("#themeboostcampusperpinfobanner .close").click(function(b){b.stopPropagation();if("1"==f){a.when(g,h).then(function(b,c){c.setTitle(b[0]);c.setBody(b[1]);c.setSaveButtonText(b[2]);c.getRoot().on(d.save,function(){M.util.set_user_preference("theme_boost_campus_infobanner_dismissed",!0);a("#themeboostcampusperpinfobanner").alert("close")});c.show();return c}).fail(e.exception)}else{M.util.set_user_preference("theme_boost_campus_infobanner_dismissed",!0);a("#themeboostcampusperpinfobanner").alert("close")}})}return{init:function init(a){f(a)}}}); +//# sourceMappingURL=infobanner.min.js.map diff --git a/amd/build/infobanner.min.js.map b/amd/build/infobanner.min.js.map new file mode 100644 index 0000000000000000000000000000000000000000..8eefd53d4c7424bdc16efa9ebf110fb89f9c5498 --- /dev/null +++ b/amd/build/infobanner.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/infobanner.js"],"names":["define","$","str","ModalFactory","ModalEvents","Notification","initInfoBanner","showconfirmationdialogue","stringsPromise","get_strings","key","component","modalPromise","create","type","types","SAVE_CANCEL","click","event","stopPropagation","when","then","strings","modal","setTitle","setBody","setSaveButtonText","getRoot","on","save","M","util","set_user_preference","alert","show","fail","exception","init"],"mappings":"AAuBAA,OAAM,iCAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,oBAAvB,CAA6C,mBAA7C,CAAkE,mBAAlE,CAAD,CACF,SAASC,CAAT,CAAYC,CAAZ,CAAiBC,CAAjB,CAA+BC,CAA/B,CAA4CC,CAA5C,CAA0D,CAC1D,aAKA,QAASC,CAAAA,CAAT,CAAwBC,CAAxB,CAAkD,IAgB1CC,CAAAA,CAAc,CAAGN,CAAG,CAACO,WAAJ,CAdQ,CACzB,CACIC,GAAG,CAAE,cADT,CAEIC,SAAS,CAAE,oBAFf,CADyB,CAItB,CACCD,GAAG,CAAE,4BADN,CAECC,SAAS,CAAE,oBAFZ,CAJsB,CAOrB,CACAD,GAAG,CAAE,WADL,CAEAC,SAAS,CAAE,oBAFX,CAPqB,CAcR,CAhByB,CAiB1CC,CAAY,CAAGT,CAAY,CAACU,MAAb,CAAoB,CAACC,IAAI,CAAEX,CAAY,CAACY,KAAb,CAAmBC,WAA1B,CAApB,CAjB2B,CAoB9Cf,CAAC,CAAC,wCAAD,CAAD,CAA4CgB,KAA5C,CAAkD,SAASC,CAAT,CAAgB,CAE9DA,CAAK,CAACC,eAAN,GAEA,GAAgC,GAA5B,EAAAZ,CAAJ,CAAqC,CACjCN,CAAC,CAACmB,IAAF,CAAOZ,CAAP,CAAuBI,CAAvB,EAAqCS,IAArC,CAA0C,SAAUC,CAAV,CAAmBC,CAAnB,CAA0B,CAChEA,CAAK,CAACC,QAAN,CAAeF,CAAO,CAAC,CAAD,CAAtB,EACAC,CAAK,CAACE,OAAN,CAAcH,CAAO,CAAC,CAAD,CAArB,EACAC,CAAK,CAACG,iBAAN,CAAwBJ,CAAO,CAAC,CAAD,CAA/B,EAEAC,CAAK,CAACI,OAAN,GAAgBC,EAAhB,CAAmBxB,CAAW,CAACyB,IAA/B,CAAqC,UAAY,CAC7CC,CAAC,CAACC,IAAF,CAAOC,mBAAP,CAA2B,yCAA3B,KAEA/B,CAAC,CAAC,iCAAD,CAAD,CAAqCgC,KAArC,CAA2C,OAA3C,CACH,CAJD,EAKAV,CAAK,CAACW,IAAN,GACA,MAAOX,CAAAA,CACV,CAZD,EAYGY,IAZH,CAYQ9B,CAAY,CAAC+B,SAZrB,CAaH,CAdD,IAcO,CACHN,CAAC,CAACC,IAAF,CAAOC,mBAAP,CAA2B,yCAA3B,KAEA/B,CAAC,CAAC,iCAAD,CAAD,CAAqCgC,KAArC,CAA2C,OAA3C,CACH,CACJ,CAvBD,CAwBH,CAED,MAAO,CACHI,IAAI,CAAE,cAAS9B,CAAT,CAAmC,CACrCD,CAAc,CAACC,CAAD,CACjB,CAHE,CAKV,CA1DK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Theme Boost Campus - JS code for feature information banner\n *\n * @package theme_boost_campus\n * @copyright 2020 Kathrin Osswald, Ulm University <kathrin.osswald@uni-ulm.de>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/notification'],\n function($, str, ModalFactory, ModalEvents, Notification) {\n \"use strict\";\n\n /**\n * Initialising.\n */\n function initInfoBanner(showconfirmationdialogue) {\n\n var stringsforInfoBannerJS = [\n {\n key: 'confirmation',\n component: 'theme_boost_campus'\n }, {\n key: 'closingperpetualinfobanner',\n component: 'theme_boost_campus'\n } , {\n key: 'yes_close',\n component: 'theme_boost_campus'\n }\n ];\n\n // Load the strings and modal before clicking on the button so that the confirmation dialogue can pop up faster.\n var stringsPromise = str.get_strings(stringsforInfoBannerJS);\n var modalPromise = ModalFactory.create({type: ModalFactory.types.SAVE_CANCEL});\n\n // With this we store the dismissing of the info banner as a user preference to persist this decision.\n $('#themeboostcampusperpinfobanner .close').click(function(event) {\n // Stop propagation to keep the info banner there until the decision in the confirmation dialogue has been made.\n event.stopPropagation();\n\n if (showconfirmationdialogue == '1') {\n $.when(stringsPromise, modalPromise).then(function (strings, modal) {\n modal.setTitle(strings[0]);\n modal.setBody(strings[1]);\n modal.setSaveButtonText(strings[2]);\n // Saved clicked - the dismissing of the info banner is confirmed.\n modal.getRoot().on(ModalEvents.save, function () {\n M.util.set_user_preference('theme_boost_campus_infobanner_dismissed', true);\n // Now close the alert.\n $('#themeboostcampusperpinfobanner').alert('close');\n });\n modal.show();\n return modal;\n }).fail(Notification.exception);\n } else {\n M.util.set_user_preference('theme_boost_campus_infobanner_dismissed', true);\n // Now close the alert.\n $('#themeboostcampusperpinfobanner').alert('close');\n }\n });\n }\n\n return {\n init: function(showconfirmationdialogue) {\n initInfoBanner(showconfirmationdialogue);\n }\n };\n});\n"],"file":"infobanner.min.js"} \ No newline at end of file diff --git a/amd/src/infobanner.js b/amd/src/infobanner.js new file mode 100644 index 0000000000000000000000000000000000000000..d2b6df89deaf274fd18684ef00b1037903e83bc1 --- /dev/null +++ b/amd/src/infobanner.js @@ -0,0 +1,82 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. + +/** + * Theme Boost Campus - JS code for feature information banner + * + * @package theme_boost_campus + * @copyright 2020 Kathrin Osswald, Ulm University <kathrin.osswald@uni-ulm.de> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/notification'], + function($, str, ModalFactory, ModalEvents, Notification) { + "use strict"; + + /** + * Initialising. + */ + function initInfoBanner(showconfirmationdialogue) { + + var stringsforInfoBannerJS = [ + { + key: 'confirmation', + component: 'theme_boost_campus' + }, { + key: 'closingperpetualinfobanner', + component: 'theme_boost_campus' + } , { + key: 'yes_close', + component: 'theme_boost_campus' + } + ]; + + // Load the strings and modal before clicking on the button so that the confirmation dialogue can pop up faster. + var stringsPromise = str.get_strings(stringsforInfoBannerJS); + var modalPromise = ModalFactory.create({type: ModalFactory.types.SAVE_CANCEL}); + + // With this we store the dismissing of the info banner as a user preference to persist this decision. + $('#themeboostcampusperpinfobanner .close').click(function(event) { + // Stop propagation to keep the info banner there until the decision in the confirmation dialogue has been made. + event.stopPropagation(); + + if (showconfirmationdialogue == '1') { + $.when(stringsPromise, modalPromise).then(function (strings, modal) { + modal.setTitle(strings[0]); + modal.setBody(strings[1]); + modal.setSaveButtonText(strings[2]); + // Saved clicked - the dismissing of the info banner is confirmed. + modal.getRoot().on(ModalEvents.save, function () { + M.util.set_user_preference('theme_boost_campus_infobanner_dismissed', true); + // Now close the alert. + $('#themeboostcampusperpinfobanner').alert('close'); + }); + modal.show(); + return modal; + }).fail(Notification.exception); + } else { + M.util.set_user_preference('theme_boost_campus_infobanner_dismissed', true); + // Now close the alert. + $('#themeboostcampusperpinfobanner').alert('close'); + } + }); + } + + return { + init: function(showconfirmationdialogue) { + initInfoBanner(showconfirmationdialogue); + } + }; +}); diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index c71e5cd7634ab47624a8df92ccc5f28fa83b5a67..1c2fcdb3d4915d250a9a9df62ac2326b562806b8 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -26,22 +26,53 @@ namespace theme_boost_campus\privacy; defined('MOODLE_INTERNAL') || die(); +use \core_privacy\local\metadata\collection; +use core_privacy\local\request\writer; + /** - * Privacy Subsystem implementing null_provider. + * Privacy Subsystem implementing provider. * * @package theme_boost_campus - * @copyright 2018 Alexander Bias, Ulm University <alexander.bias@uni-ulm.de> + * @copyright 2020 Kathrin Osswald, Ulm University <kathrin.osswald@uni-ulm.de> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class provider implements \core_privacy\local\metadata\null_provider { +class provider implements \core_privacy\local\metadata\provider, + \core_privacy\local\request\user_preference_provider { + + /** + * Returns meta data about this system. + * + * @param collection $collection The initialised collection to add items to. + * @return collection A listing of user data stored through this system. + */ + public static function get_metadata(collection $collection) : collection { + $collection->add_user_preference('theme_boost_campus_infobanner_dismissed', + 'privacy:metadata:preference:infobanner_dismissed'); + + return $collection; + } /** - * Get the language string identifier with the component's language - * file to explain why this plugin stores no data. + * Export all user preferences for the plugin. * - * @return string + * @param int $userid The userid of the user whose data is to be exported. */ - public static function get_reason() : string { - return 'privacy:metadata'; + public static function export_user_preferences(int $userid) { + $infobannerpref = get_user_preferences('theme_boost_campus_infobanner_dismissed', null, $userid); + if ($infobannerpref !== null) { + switch ($infobannerpref) { + case 0: + default: + $infobannerprefdesc = get_string('privacy:metadata:request:infobanner_dismissed_no', + 'theme_boost_campus'); + break; + case 1: + $infobannerprefdesc = get_string('privacy:metadata:request:infobanner_dismissed_yes', + 'theme_boost_campus'); + break; + } + writer::export_user_preference('theme_boost_campus', 'theme_boost_campus_infobanner_dismissed', + $infobannerpref, $infobannerprefdesc); + } } } diff --git a/db/uninstall.php b/db/uninstall.php new file mode 100644 index 0000000000000000000000000000000000000000..02c443dd11a0e5411e9a9c623c4f6cbb494c39fc --- /dev/null +++ b/db/uninstall.php @@ -0,0 +1,43 @@ +<?php +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. + +/** + * Theme Boost Campus - Uninstall file. + * + * @package theme_boost_campus + * @copyright 2020 Kathrin Osswald, Ulm University <kathrin.osswald@uni-ulm.de> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plugin uninstall steps. + */ +function xmldb_theme_boost_campus_uninstall() { + global $DB; + + // The plugin uninstall process in Moodle core will take care of removing the plugin configuration, but not of removing the + // user preferences which we have set for the users. We have to remove them ourselves. + // We remove them directly from the DB table and don't use unset_user_preference() as the cache is cleared anyway directly + // after the plugin has been uninstalled. + + $like = $DB->sql_like('name', '?', true, true, false, '|'); + $params = array($DB->sql_like_escape('theme_boost_campus-', '|') . '%'); + $DB->delete_records_select('user_preferences', $like, $params); + + return true; +} diff --git a/lang/en/theme_boost_campus.php b/lang/en/theme_boost_campus.php index c02e8f40e9ce62ede32450072807f84ea4c588e1..d7f33eb21b40639272e8a693ad8ded8483137e8d 100644 --- a/lang/en/theme_boost_campus.php +++ b/lang/en/theme_boost_campus.php @@ -222,14 +222,84 @@ $string['additionalresourcessetting_desc'] = 'With this setting you can upload a The advantage of uploading files to this file area is that those files can be delivered without a check if the user is logged in. This is also why you should only add files that are uncritical and everyone should be allowed to access and don\'t need be protected with a valid login. <br/> An example for a use case can be found in the README.md file.'; +// Info banner settings. +$string['infobannersettings'] = 'Info Banner Settings'; + +// ...Perpetual information banner. +$string['perpetualinfobannerheadingsetting'] = 'Perpetual information banner'; +$string['perpetualinfobannerheadingsetting_desc'] = 'The following settings allow to show some important information within a prominent perpetual banner.'; +$string['perpibenablesetting'] = 'Enable perpetual info banner'; +$string['perpibenablesetting_desc'] = 'With this checkbox you can decide if the perpetual information banner should be shown or hidden on the selected pages.'; +$string['perpibcontent'] = 'Perpetual information banner content'; +$string['perpibcontent_desc'] = 'Enter your information which should be shown within the banner here.'; +$string['perpibshowonpagessetting'] = 'Page layouts to display the info banner on'; +$string['perpibshowonpagessetting_desc'] = 'With this setting you can select the pages on which the perpetual information banner should be displayed.'; +$string['perpibcsssetting'] = 'Bootstrap css class for the perpetual info banner'; +$string['perpibcsssetting_desc'] = 'With this setting you can select the Bootstrap style with which the perpetual information banner should be displayed.'; +$string['perpibdismisssetting'] = 'Perpetual info banner dismissible'; +$string['perpibdismisssetting_desc'] = 'With this checkbox you can make the banner dismissible permanently. If the user clicks on the x-button a confirmation dialogue will appear and only after the user confirmed this dialogue the banner will be hidden for this user permanently. +<br/><br/>Please note: <br/> This setting has no effect for the banners shown on the login page. Because banners on the login page cannot be clicked away permanently, we do not offer the possibility to click the banner away at all on the login page.'; +$string['perpibconfirmsetting'] = 'Confirmation dialogue'; +$string['perpibconfirmsetting_desc'] = 'When you enable this setting you can show a confirmation dialogue to a user when he is dismissing the info banner. +<br/>The text is saved in the string with the name "closingperpetualinfobanner":<br/><br/> +Are you sure you want to dismiss this information? Once done it will not occur again!<br/><br/> +You can override this within your language customization if you need some other text in this dialogue.'; +$string['perpetualinfobannerresetvisiblitysetting'] = 'Reset visibility for perpetual info banner'; +$string['perpetualinfobannerresetvisiblitysetting_desc'] = 'By enabling this checkbox, the visibility of the individually dismissed perpetual info banners will be set to visible again. You can use this setting if you made important content changes and want to show the info to all users again.<br/><br/> +Please note: <br/> +After saving this option, the database operations for resetting the visibility will be triggered and this checkbox will be unticked again. The next enabling and saving of this feature will trigger the database operations for resetting the visibility again.'; + +// ...Time controlled information banner. +$string['timedinfobannerheadingsetting'] = 'Time controlled information banner'; +$string['timedinfobannerheadingsetting_desc'] = 'The following settings allow to show some important information within a prominent time controlled banner.'; +$string['timedibenablesetting'] = 'Enable time controlled info banner'; +$string['timedibenablesetting_desc'] = 'With this checkbox you can decide if the time controlled information banner should be shown or hidden on the selected pages.'; +$string['timedibcontent'] = 'Time controlled information banner content'; +$string['timedibcontent_desc'] = 'Enter your information which should be shown within the time controlled banner here.'; +$string['timedibshowonpagessetting'] = 'Page layouts to display the info banner on'; +$string['timedibshowonpagessetting_desc'] = 'With this setting you can select the pages on which the time controlled information banner should be displayed. +<br/> If both info banners are active on a selected layout, the time controlled info banner will always appear above the perpetual info banner!'; +$string['timedibcsssetting'] = 'Bootstrap css class for the time controlled info banner'; +$string['timedibcsssetting_desc'] = 'With this setting you can select the Bootstrap style with which the time controlled information banner should be displayed.'; +$string['timedibstartsetting'] = 'Start time for the time controlled info banner'; +$string['timedibstartsetting_desc'] = 'With this setting you can define when the time controlled information banner should be displayed on the selected pages. +<br/>Please enter a valid in this format: YYYY-MM-DD HH:MM:SS. For example: "2020-01-01 08:00:00". The time zone will be the time zone you have defined in the setting "Default timezone". +<br/>If you leave this setting empty but entered a date in the for the end, it is the same as if you entered a date far in the past.'; +$string['timedibendsetting'] = 'End time for the time controlled info banner'; +$string['timedibendsetting_desc'] = 'With this setting you can define when the time controlled information banner should be hidden on the selected pages. +<br/>Please enter a valid date in this format: YYYY-MM-DD HH:MM:SS. For example: "2020-01-07 08:00:00. The time zone will be the time zone you have defined in the setting "Default timezone". +<br/>If you leave this setting empty but entered a date in the for the start, the banner won\'t hide after the starting time has been reached.'; + // ADDITIONAL STRINGS (IN ALPHABETICAL ORDER). $string['backtotop'] = 'Back to top'; +$string['bootstrapprimarycolor'] = 'Primary color'; +$string['bootstrapsecondarycolor'] = 'Secondary color'; +$string['bootstrapsuccesscolor'] = 'Success color'; +$string['bootstrapdangercolor'] = 'Danger color'; +$string['bootstrapwarningcolor'] = 'Warning color'; +$string['bootstrapinfocolor'] = 'Info color'; +$string['bootstraplightcolor'] = 'Light color'; +$string['bootstrapdarkcolor'] = 'Dark color'; $string['cachedef_imagearea'] = 'Cache for imagearea items'; +$string['close'] = 'Close'; +$string['confirmation'] = 'Confirmation'; +$string['closingperpetualinfobanner'] = 'Are you sure you want to dismiss this information? Once done it will not occur again!'; +$string['login_page'] = "Login page"; +$string['resetperpetualinfobannervisibilityerror'] = 'Oops... Something went wrong updating the database tables. The user preference "theme_boost_campus_infobanner_dismissed" should have been reset in the table "user_preferences". +<br/>Exception thrown: {$a->message}. +<br/>Stack Trace: +<br/>{$a->stacktrace}. +<br/>The setting "Reset visibility for perpetual info banner" has been reset nevertheless.'; +$string['resetperpetualinfobannersuccess'] = 'Success! All perpetual info banner instances are visible again. +<br/>The setting "Reset visibility for perpetual info banner" has been reset.'; $string['showhintcourseguestaccessgeneral'] = 'You are currently viewing this course as <strong>{$a->role}</strong>.'; $string['showhintcourseguestaccesslink'] = 'To have full access to the course, you can <a href="{$a->url}">self enrol into this course</a>.'; $string['showhintcoursehiddengeneral'] = 'This course is currently <strong>hidden</strong>. Only enrolled teachers can access this course when hidden.'; $string['showhintcoursehiddensettingslink'] = 'You can change the visibility in the <a href="{$a->url}">course settings</a>.'; $string['switchroleto'] = 'Switch role to'; +$string['yes_close'] = "Yes, close!"; // PRIVACY. -$string['privacy:metadata'] = 'The Boost Campus theme does not store any personal data about any user.'; +$string['privacy:metadata:preference:infobanner_dismissed'] = 'The user preference for the status if the perpetual info banner has been dismissed.'; +$string['privacy:metadata:request:infobanner_dismissed_yes'] = 'Perpetual info banner has been dismissed.'; +$string['privacy:metadata:request:infobanner_dismissed_no'] = 'Perpetual info banner has not been dismissed.'; diff --git a/layout/columns2.php b/layout/columns2.php index ba51922ffa048dc1f7b4727d13faa4cc0765ec7c..49743f786bd3ff7ccff6cb55222554d494e98fee 100644 --- a/layout/columns2.php +++ b/layout/columns2.php @@ -29,6 +29,9 @@ global $PAGE; // MODIFICATION END. user_preference_allow_ajax_update('drawer-open-nav', PARAM_ALPHA); +// MODIFICATION START: Allow own user preference to be set via Javascript. +user_preference_allow_ajax_update('theme_boost_campus_infobanner_dismissed', PARAM_BOOL); +// MODIFICATION END. require_once($CFG->libdir . '/behat/lib.php'); // MODIFICATION Start: Require own locallib.php. require_once($CFG->dirroot . '/theme/boost_campus/locallib.php'); @@ -76,6 +79,11 @@ if (get_config('theme_boost_campus', 'darknavbar') == 'yes') { $navdrawerfullwidth = get_config('theme_boost_campus', 'navdrawerfullwidth'); // MODIFICATION END. +// MODIFICATION START: Set these variables in any case as it's needed in the columns2.mustache file. +$perpinfobannershowonselectedpage = false; +$timedinfobannershowonselectedpage = false; +// MODIFICATION END. + $templatecontext = [ 'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]), 'output' => $OUTPUT, @@ -85,13 +93,62 @@ $templatecontext = [ 'navdraweropen' => $navdraweropen, 'regionmainsettingsmenu' => $regionmainsettingsmenu, 'hasregionmainsettingsmenu' => !empty($regionmainsettingsmenu), - // MODIFICATION START: Add Boost Campus realated values to the template context. + // MODIFICATION START: Add Boost Campus related values to the template context. 'catchshortcuts' => json_encode($catchshortcuts), 'navdrawerfullwidth' => $navdrawerfullwidth, - 'darknavbar' => $darknavbar + 'darknavbar' => $darknavbar, + 'perpinfobannershowonselectedpage' => $perpinfobannershowonselectedpage, + 'timedinfobannershowonselectedpage' => $timedinfobannershowonselectedpage // MODIFICATION END. ]; +// MODIFICATION START: Settings for perpetual information banner. +$perpibenable = get_config('theme_boost_campus', 'perpibenable'); + +if ($perpibenable) { + $perpibcontent = format_text(get_config('theme_boost_campus', 'perpibcontent'), FORMAT_HTML); + // Result of multiselect is a string divided by a comma, so exploding into an array. + $perpibshowonpages = explode(",", get_config('theme_boost_campus', 'perpibshowonpages')); + $perpibcss = get_config('theme_boost_campus', 'perpibcss'); + $perpibdismiss = get_config('theme_boost_campus', 'perpibdismiss'); + $perbibconfirmdialogue = get_config('theme_boost_campus', 'perpibconfirm'); + $perbibuserprefdialdismissed = get_user_preferences('theme_boost_campus_infobanner_dismissed'); + + $perpinfobannershowonselectedpage = theme_boost_campus_show_banner_on_selected_page($perpibshowonpages, + $perpibcontent, $PAGE->pagelayout, $perbibuserprefdialdismissed); + + // Add the variables to the templatecontext array. + $templatecontext['perpibcontent'] = $perpibcontent; + $templatecontext['perpibcss'] = $perpibcss; + $templatecontext['perpibdismiss'] = $perpibdismiss; + $templatecontext['perpinfobannershowonselectedpage'] = $perpinfobannershowonselectedpage; + $templatecontext['perbibconfirmdialogue'] = $perbibconfirmdialogue; +} +// MODIFICATION END. + +// MODIFICATION START: Settings for time controlled information banner. +$timedibenable = get_config('theme_boost_campus', 'timedibenable'); + +if ($timedibenable) { + $timedibcontent = format_text(get_config('theme_boost_campus', 'timedibcontent'), FORMAT_HTML); + // Result of multiselect is a string divided by a comma, so exploding into an array. + $timedibshowonpages = explode(",", get_config('theme_boost_campus', 'timedibshowonpages')); + $timedibcss = get_config('theme_boost_campus', 'timedibcss'); + $timedibstartsetting = get_config('theme_boost_campus', 'timedibstart'); + $timedibendsetting = get_config('theme_boost_campus', 'timedibend'); + // Get the current server time. + $now = (new DateTime("now", core_date::get_server_timezone_object()))->getTimestamp(); + + $timedinfobannershowonselectedpage = theme_boost_campus_show_timed_banner_on_selected_page($now, $timedibshowonpages, + $timedibcontent, $timedibstartsetting, $timedibendsetting, $PAGE->pagelayout); + + // Add the variables to the templatecontext array. + $templatecontext['timedibcontent'] = $timedibcontent; + $templatecontext['timedibcss'] = $timedibcss; + $templatecontext['timedinfobannershowonselectedpage'] = $timedinfobannershowonselectedpage; +} +// MODIFICATION END. + $nav = $PAGE->flatnav; // MODIDFICATION START. // Use the returned value from theme_boost_campus_get_modified_flatnav_defaulthomepageontop as the template context. diff --git a/layout/login.php b/layout/login.php index 5b8a1d7131c495998183360d540a5490a064fee2..7989066c6e07c267ce278fc28ce2ba43c60c9063 100644 --- a/layout/login.php +++ b/layout/login.php @@ -30,13 +30,62 @@ require_once($CFG->dirroot . '/theme/boost_campus/locallib.php'); $bodyattributes = $OUTPUT->body_attributes(); $loginbackgroundimagetext = theme_boost_campus_get_loginbackgroundimage_text(); +// MODIFICATION START: Set these variables in any case as it's needed in the columns2.mustache file. +$perpinfobannershowonselectedpage = false; +$timedinfobannershowonselectedpage = false; +// MODIFICATION END. + $templatecontext = [ 'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]), 'output' => $OUTPUT, 'bodyattributes' => $bodyattributes, - 'loginbackgroundimagetext' => $loginbackgroundimagetext + 'loginbackgroundimagetext' => $loginbackgroundimagetext, + 'perpinfobannershowonselectedpage' => $perpinfobannershowonselectedpage, + 'timedinfobannershowonselectedpage' => $timedinfobannershowonselectedpage ]; +// MODIFICATION START: Settings for information banner. +$perpibenable = get_config('theme_boost_campus', 'perpibenable'); + +if ($perpibenable) { + $perpibcontent = format_text(get_config('theme_boost_campus', 'perpibcontent'), FORMAT_HTML); + // Result of multiselect is a string divided by a comma, so exploding into an array. + $perpibshowonpages = explode(",", get_config('theme_boost_campus', 'perpibshowonpages')); + $perpibcss = get_config('theme_boost_campus', 'perpibcss'); + + $perpinfobannershowonselectedpage = theme_boost_campus_show_banner_on_selected_page($perpibshowonpages, + $perpibcontent, $PAGE->pagelayout, false); + + // Add the variables to the templatecontext array. + $templatecontext['perpibcontent'] = $perpibcontent; + $templatecontext['perpibcss'] = $perpibcss; + $templatecontext['perpinfobannershowonselectedpage'] = $perpinfobannershowonselectedpage; +} +// MODIFICATION END. + +// MODIFICATION START: Settings for time controlled information banner. +$timedibenable = get_config('theme_boost_campus', 'timedibenable'); + +if ($timedibenable) { + $timedibcontent = format_text(get_config('theme_boost_campus', 'timedibcontent'), FORMAT_HTML); + // Result of multiselect is a string divided by a comma, so exploding into an array. + $timedibshowonpages = explode(",", get_config('theme_boost_campus', 'timedibshowonpages')); + $timedibcss = get_config('theme_boost_campus', 'timedibcss'); + $timedibstartsetting = get_config('theme_boost_campus', 'timedibstart'); + $timedibendsetting = get_config('theme_boost_campus', 'timedibend'); + // Get the current server time. + $now = (new DateTime("now", core_date::get_server_timezone_object()))->getTimestamp(); + + $timedinfobannershowonselectedpage = theme_boost_campus_show_timed_banner_on_selected_page($now, $timedibshowonpages, + $timedibcontent, $timedibstartsetting, $timedibendsetting, $PAGE->pagelayout); + + // Add the variables to the templatecontext array. + $templatecontext['timedibcontent'] = $timedibcontent; + $templatecontext['timedibcss'] = $timedibcss; + $templatecontext['timedinfobannershowonselectedpage'] = $timedinfobannershowonselectedpage; +} +// MODIFICATION END. + // MODIFICATION START: Handle additional layout elements. // The output buffer is needed to render the additional layout elements now without outputting them to the page directly. ob_start(); diff --git a/lib.php b/lib.php index 0e1b1a85873f3a2d3f357c3275f8294750a3bdd5..0097a738c955a28ec3660cb1a51aecda7772a8e5 100644 --- a/lib.php +++ b/lib.php @@ -200,3 +200,46 @@ function theme_boost_campus_reset_app_cache() { // we also delete the complete theme cache here. theme_reset_all_caches(); } + +/** + * If setting is updated, use this callback to reset the theme_boost_campus_infobanner_dismissed user preferences. + */ +function theme_boost_campus_infobanner_reset_visibility() { + global $DB; + + if (get_config('theme_boost_campus', 'perpibresetvisibility') == 1) { + // Get all users that have dismissed the info banner once and therefore the user preference. + $whereclause = 'name = :name AND value = :value'; + $params = ['name' => 'theme_boost_campus_infobanner_dismissed', 'value' => '1']; + $users = $DB->get_records_select('user_preferences', $whereclause, $params, '', 'userid'); + + // Initialize variable for feedback messages. + $somethingwentwrong = false; + // Store coding exception. + $codingexception[] = array(); + + foreach ($users as $user) { + try { + unset_user_preference('theme_boost_campus_infobanner_dismissed', $user->userid); + } catch (coding_exception $e) { + $somethingwentwrong = true; + $codingexception['message'] = $e->getMessage(); + $codingexception['stacktrace'] = $e->getTraceAsString(); + } + } + + if (!$somethingwentwrong) { + \core\notification::success(get_string('resetperpetualinfobannersuccess', 'theme_boost_campus')); + } else { + \core\notification::error(get_string('resetperpetualinfobannervisibilityerror', + 'theme_boost_campus', $codingexception)); + } + + // Reset the checkbox. + set_config('perpibresetvisibility', 0, 'theme_boost_campus'); + } + + // To be safe and because there can only be one callback function added to a plugin setting, + // we also delete the complete theme cache here. + theme_reset_all_caches(); +} diff --git a/locallib.php b/locallib.php index 19a1639a4f6bfd9926b95979fb0995da7a94871e..a44904601beae111535dd20a8df5655f08c8c5b1 100644 --- a/locallib.php +++ b/locallib.php @@ -448,3 +448,78 @@ function theme_boost_campus_get_course_guest_access_hint($courseid) { return $html; } + +/** + * Return if the info banner should be displayed on current page layout. + * + * @param array $infobannerpagestoshow The list of page layouts on which the info banner should be shown. + * @param string $infobannercontent The content which should be displayed within the info banner. + * @param mixed|moodle_page $thispagelayout The current page layout. + * @param string $perbibuserprefdialdismissed The user preference if the dissmissible banner has been dismissed. + * @return boolean + */ +function theme_boost_campus_show_banner_on_selected_page($infobannerpagestoshow, $infobannercontent, $thispagelayout, + $perbibuserprefdialdismissed) { + + // Initialize variable. + $infobannershowonselectedpage = false; + + // Traverse multiselect setting. + foreach ($infobannerpagestoshow as $page) { + if (empty($infobannercontent)) { + $infobannershowonselectedpage = false; + } else { + // Decide if the info banner should be shown at all. + if (!empty($infobannercontent) && $thispagelayout == $page && !$perbibuserprefdialdismissed) { + $infobannershowonselectedpage = true; + continue; + } + } + } + return $infobannershowonselectedpage; +} + +/** + * Return if the time limited info banner should be displayed on current page layout. + * + * @param int $now The timestamp of the current server time. + * @param array $timedibshowonpages The list of page layouts on which the info banner should be shown. + * @param string $timedibcontent The content which should be displayed within the info banner. + * @param string $timedibstartsetting The value from setting timedibstart. + * @param string $timedibendsetting The value from setting timedibend. + * @param mixed|moodle_page $thispagelayout The current page layout. + * @return boolean + */ +function theme_boost_campus_show_timed_banner_on_selected_page($now, $timedibshowonpages, $timedibcontent, $timedibstartsetting, + $timedibendsetting, $thispagelayout) { + + // Initialize variable. + $timedinfobannershowonselectedpage = false; + + // Check if time settings are empty and try to convert the time string_s_ to a unix timestamp. + if (empty($timedibstartsetting)) { + $timedibstartempty = true; + } else { + $timedibstart = strtotime($timedibstartsetting); + } + if (empty($timedibendsetting)) { + $timedibendempty = true; + } else { + $timedibend = strtotime($timedibendsetting); + } + + // Add the time check: + // Show the banner when now is between start and end time OR + // Show the banner when start is not set but end is not reached yet OR + // Show the banner when end is not set, but start lies in the past OR + // Show the banner if no dates are set, so there's no time restriction. + if (($now >= $timedibstart && $now <= $timedibend || + ($now <= $timedibend && $timedibstartempty) || + ($now >= $timedibstart && $timedibendempty) || + ($timedibstartempty && $timedibendempty))) { + $timedinfobannershowonselectedpage = theme_boost_campus_show_banner_on_selected_page($timedibshowonpages, + $timedibcontent, $thispagelayout, false); + } + + return $timedinfobannershowonselectedpage; +} diff --git a/scss/post.scss b/scss/post.scss index 07e05c96fb110e1ca3735b4e56d993f8d00c6ab3..46491a23bc97ed350e7a076e6c98dee1819e800f 100644 --- a/scss/post.scss +++ b/scss/post.scss @@ -874,6 +874,15 @@ a[href^="mailto"]::before { flex-shrink: 0; } +/* + * Info banner. + */ +/* This is needed because otherwise the top and bottom margin are not equal within the alert box. */ +#themeboostcampusperpinfobanner p, +#themeboostcampustimedinfobanner p { + margin-bottom: 0; +} + /*------------------------------------ Additional Elements diff --git a/settings.php b/settings.php index 79f0a421250c5368236fb4c1ab623c016eb8541a..79d42f24d34e74d4a8346c1117d05ab9a3568db0 100644 --- a/settings.php +++ b/settings.php @@ -529,7 +529,8 @@ if ($ADMIN->fulltree) { // Create design settings tab. - $page = new admin_settingpage('theme_boost_campus_design', get_string('designsettings', 'theme_boost_campus', null, true)); + $page = new admin_settingpage('theme_boost_campus_design', get_string('designsettings', + 'theme_boost_campus', null, true)); // Settings title to group login page related settings together with a common heading. We don't want a description here. $name = 'theme_boost_campus/loginpagedesignheading'; @@ -675,4 +676,200 @@ if ($ADMIN->fulltree) { // Add tab to settings page. $settings->add($page); + + // Create info banner settings tab. + $page = new admin_settingpage('theme_boost_campus_infobanner', get_string('infobannersettings', + 'theme_boost_campus', null, true)); + + // Settings title to group perpetual information banner settings together with a common heading and description. + $name = 'theme_boost_campus/perpetualinfobannerheading'; + $title = get_string('perpetualinfobannerheadingsetting', 'theme_boost_campus', null, true); + $description = get_string('perpetualinfobannerheadingsetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_heading($name, $title, $description); + $page->add($setting); + + // Activate perpetual information banner. + $name = 'theme_boost_campus/perpibenable'; + $title = get_string('perpibenablesetting', 'theme_boost_campus', null, true); + $description = get_string('perpibenablesetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_configcheckbox($name, $title, $description, 0); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + + // Perpetual information banner content. + $name = 'theme_boost_campus/perpibcontent'; + $title = get_string('perpibcontent', 'theme_boost_campus', null, true); + $description = get_string('perpibcontent_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_confightmleditor($name, $title, $description, ''); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/perpibcontent', + 'theme_boost_campus/perpibenable', 'notchecked'); + + // Select pages on which the perpetual information banner should be shown. + $name = 'theme_boost_campus/perpibshowonpages'; + $title = get_string('perpibshowonpagessetting', 'theme_boost_campus', null, true); + $description = get_string('perpibshowonpagessetting_desc', 'theme_boost_campus', null, true); + $perpibshowonpageoptions = [ + // Don't use string lazy loading (= false) because the string will be directly used and would produce a + // PHP warning otherwise. + 'mydashboard' => get_string('myhome', 'core', null, false), + 'course' => get_string('course', 'core', null, false), + 'login' => get_string('login_page', 'theme_boost_campus', null, false) + ]; + $setting = new admin_setting_configmultiselect($name, $title, $description, + array($perpibshowonpageoptions['mydashboard']), $perpibshowonpageoptions); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/perpibshowonpages', + 'theme_boost_campus/perpibenable', 'notchecked'); + + // Select the bootstrap class that should be used for the perpetual info banner. + $name = 'theme_boost_campus/perpibcss'; + $title = get_string('perpibcsssetting', 'theme_boost_campus', null, true); + $description = get_string('perpibcsssetting_desc', 'theme_boost_campus', null, true); + $perpibcssoptions = [ + // Don't use string lazy loading (= false) because the string will be directly used and would produce a + // PHP warning otherwise. + 'primary' => get_string('bootstrapprimarycolor', 'theme_boost_campus', null, false), + 'secondary' => get_string('bootstrapsecondarycolor', 'theme_boost_campus', null, false), + 'success' => get_string('bootstrapsuccesscolor', 'theme_boost_campus', null, false), + 'danger' => get_string('bootstrapdangercolor', 'theme_boost_campus', null, false), + 'warning' => get_string('bootstrapwarningcolor', 'theme_boost_campus', null, false), + 'info' => get_string('bootstrapinfocolor', 'theme_boost_campus', null, false), + 'light' => get_string('bootstraplightcolor', 'theme_boost_campus', null, false), + 'dark' => get_string('bootstrapdarkcolor', 'theme_boost_campus', null, false) + ]; + $setting = new admin_setting_configselect($name, $title, $description, $perpibcssoptions['primary'], + $perpibcssoptions); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/perpibcss', + 'theme_boost_campus/perpibenable', 'notchecked'); + + // Perpetual information banner dismissible. + $name = 'theme_boost_campus/perpibdismiss'; + $title = get_string('perpibdismisssetting', 'theme_boost_campus', null, true); + $description = get_string('perpibdismisssetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_configcheckbox($name, $title, $description, 0); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/perpibdismiss', + 'theme_boost_campus/perpibenable', 'notchecked'); + + // Perpetual information banner show confirmation dialogue when dismissing. + $name = 'theme_boost_campus/perpibconfirm'; + $title = get_string('perpibconfirmsetting', 'theme_boost_campus', null, true); + $description = get_string('perpibconfirmsetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_configcheckbox($name, $title, $description, 0); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/perpibconfirm', + 'theme_boost_campus/perpibenable', 'notchecked'); + $settings->hide_if('theme_boost_campus/perpibconfirm', + 'theme_boost_campus/perpibdismiss', 'notchecked'); + + // Reset the user preference for all users. + $name = 'theme_boost_campus/perpibresetvisibility'; + $title = get_string('perpetualinfobannerresetvisiblitysetting', 'theme_boost_campus', null, true); + $description = get_string('perpetualinfobannerresetvisiblitysetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_configcheckbox($name, $title, $description, 0); + $setting->set_updatedcallback('theme_boost_campus_infobanner_reset_visibility'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/perpibresetvisibility', + 'theme_boost_campus/perpibenable', 'notchecked'); + $settings->hide_if('theme_boost_campus/perpibresetvisibility', + 'theme_boost_campus/perpibdismiss', 'notchecked'); + + // Settings title to group time controlled information banner settings together with a common heading and description. + $name = 'theme_boost_campus/timedinfobannerheading'; + $title = get_string('timedinfobannerheadingsetting', 'theme_boost_campus', null, true); + $description = get_string('timedinfobannerheadingsetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_heading($name, $title, $description); + $page->add($setting); + + // Activate time controlled information banner. + $name = 'theme_boost_campus/timedibenable'; + $title = get_string('timedibenablesetting', 'theme_boost_campus', null, true); + $description = get_string('timedibenablesetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_configcheckbox($name, $title, $description, 0); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + + // Time controlled information banner content. + $name = 'theme_boost_campus/timedibcontent'; + $title = get_string('timedibcontent', 'theme_boost_campus', null, true); + $description = get_string('timedibcontent_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_confightmleditor($name, $title, $description, ''); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/timedibcontent', + 'theme_boost_campus/timedibenable', 'notchecked'); + + // Select pages on which the time controlled information banner should be shown. + $name = 'theme_boost_campus/timedibshowonpages'; + $title = get_string('timedibshowonpagessetting', 'theme_boost_campus', null, true); + $description = get_string('timedibshowonpagessetting_desc', 'theme_boost_campus', null, true); + $timedibpageoptions = [ + // Don't use string lazy loading (= false) because the string will be directly used and would produce a + // PHP warning otherwise. + 'mydashboard' => get_string('myhome', 'core', null, false), + 'course' => get_string('course', 'core', null, false), + 'login' => get_string('login_page', 'theme_boost_campus', null, false) + ]; + $setting = new admin_setting_configmultiselect($name, $title, $description, + array($timedibpageoptions['mydashboard']), $timedibpageoptions); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/timedibshowonpages', + 'theme_boost_campus/timedibenable', 'notchecked'); + + // Select the bootstrap class that should be used for the perpetual info banner. + $name = 'theme_boost_campus/timedibcss'; + $title = get_string('timedibcsssetting', 'theme_boost_campus', null, true); + $description = get_string('timedibcsssetting_desc', 'theme_boost_campus', null, true); + $timedibcssoptions = [ + // Don't use string lazy loading (= false) because the string will be directly used and would produce a + // PHP warning otherwise. + 'primary' => get_string('bootstrapprimarycolor', 'theme_boost_campus', null, false), + 'secondary' => get_string('bootstrapsecondarycolor', 'theme_boost_campus', null, false), + 'success' => get_string('bootstrapsuccesscolor', 'theme_boost_campus', null, false), + 'danger' => get_string('bootstrapdangercolor', 'theme_boost_campus', null, false), + 'warning' => get_string('bootstrapwarningcolor', 'theme_boost_campus', null, false), + 'info' => get_string('bootstrapinfocolor', 'theme_boost_campus', null, false), + 'light' => get_string('bootstraplightcolor', 'theme_boost_campus', null, false), + 'dark' => get_string('bootstrapdarkcolor', 'theme_boost_campus', null, false) + ]; + $setting = new admin_setting_configselect($name, $title, $description, $timedibcssoptions['primary'], + $timedibcssoptions); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/timedibcss', + 'theme_boost_campus/timedibenable', 'notchecked'); + + // This will check for the desired date time format YYYY-MM-DD HH:MM:SS + $timeregex = '/20[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/'; + + // Start time for controlled information banner. + $name = 'theme_boost_campus/timedibstart'; + $title = get_string('timedibstartsetting', 'theme_boost_campus', null, true); + $description = get_string('timedibstartsetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_configtext($name, $title, $description, '', $timeregex); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/timedibstart', + 'theme_boost_campus/timedibenable', 'notchecked'); + + // End time for controlled information banner. + $name = 'theme_boost_campus/timedibend'; + $title = get_string('timedibendsetting', 'theme_boost_campus', null, true); + $description = get_string('timedibendsetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_configtext($name, $title, $description, '', $timeregex); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + $settings->hide_if('theme_boost_campus/timedibend', + 'theme_boost_campus/timedibenable', 'notchecked'); + + // Add tab to settings page. + $settings->add($page); } diff --git a/templates/columns2.mustache b/templates/columns2.mustache index 28c3a5e0d6aca954bfc88b7c15b53bd5194574ba..f1a8aab8d9fdfbf8dac1cf42f8e4e887bb8e8348 100644 --- a/templates/columns2.mustache +++ b/templates/columns2.mustache @@ -31,6 +31,13 @@ * regionmainsettingsmenu - HTML for the region main settings menu * hasregionmainsettingsmenu - There is a region main settings menu on this page. * pagebottomelements - HTML for all additional layout elements below the main content, e.g. the footer. + * timedinfobannershowonselectedpage - true if the time controlled info banner should be displayed. + * timedetualinfobannercontent - The content that should be shown in the time controled information banner. + * timedetualinfobannercssclass - The Bootstrap class that is used for the time controlled info banner. + * perpinfobannershowonselectedpage - true if the perpetual info banner should be displayed. + * perpibcontent - The content that should be shown in the perpetual information banner. + * perpibcss - The Bootstrap class that is used for the perpetual info banner. + * perpibdismiss - true if the setting perpibdismiss is enabled. Example context (json): { @@ -47,7 +54,15 @@ "navdraweropen":true, "regionmainsettingsmenu": "", "hasregionmainsettingsmenu": false, - "pagebottomelements": "" + "pagebottomelements": ""., + "timedinfobannershowonselectedpage":true, + "timedibcontent": "This is a test content for perpetual info banner.", + "timedibcss": danger, + "perpinfobannershowonselectedpage":true, + "perpibcontent": "This is a test content for perpetual info banner.", + "perpibcss": primary, + "perpibdismiss": true, + "infobannerconfirmationdialogue" : true } }} {{! MODIFICATION: @@ -58,6 +73,7 @@ * Call to own navbar mustache template instead of boost/navbar. * Add own additional layout elements: the footer, footnote or image area. * Moved the variable output.standard_end_of_body_html from footer.mustache to solve Javascript issues with behat tests. + * Added the possibility to show information banners. }} {{> theme_boost/head }} @@ -72,6 +88,24 @@ {{> theme_boost/nav-drawer }} <div id="page" class="container-fluid d-print-block"> + + {{#timedinfobannershowonselectedpage}} + <div id="themeboostcampusitimedinfobanner" class="alert alert-{{{ timedibcss }}} mt-3" role="alert"> + {{{ timedibcontent }}} + </div> + {{/timedinfobannershowonselectedpage}} + + {{#perpinfobannershowonselectedpage}} + <div id="themeboostcampusperpinfobanner" class="alert alert-{{{ perpibcss }}} {{#perpibdismiss}}alert-dismissible fade show{{/perpibdismiss}} mt-3" role="alert"> + {{{ perpibcontent }}} + {{#perpibdismiss}} + <button type="button" id="themeboostcampusperpinfobannerclosebutton" class="close" data-dismiss="alert" aria-label="{{#str}}close, theme_boost_campus{{/str}}"> + <span aria-hidden="true">×</span> + </button> + {{/perpibdismiss}} + </div> + {{/perpinfobannershowonselectedpage}} + {{{ output.full_header }}} <div id="page-content" class="row pb-3 d-print-block"> @@ -135,4 +169,9 @@ require(['theme_boost_campus/catchshortcuts'], function(mod) { mod.init(); }); {{/incoursesettings}} +{{#perpinfobannershowonselectedpage}} + require(['theme_boost_campus/infobanner'], function(mod) { + mod.init({{{perbibconfirmdialogue}}}); + }); +{{/perpinfobannershowonselectedpage}} {{/js}} diff --git a/templates/login.mustache b/templates/login.mustache index e150bb02f54b5dde628101ca26377d148e19350d..7fa605e745718365cc83a0f6820b57cf816a14e2 100644 --- a/templates/login.mustache +++ b/templates/login.mustache @@ -25,13 +25,27 @@ "doctype": "<!DOCTYPE html>", "page_title": "Login page", "favicon": "favicon.ico", - "main_content": "<h1>Headers keep HTML validators happy</h1>" + "main_content": "<h1>Headers keep HTML validators happy</h1>", + "timedinfobannershowonselectedpage":true, + "timedibcontent": "This is a test content for perpetual info banner.", + "timedibcss": danger, + "perpinfobannershowonselectedpage": true, + "perpibcontent": "This is a test content.", + "perpibcss": primary, + "perpibdismiss": true } * pagebottomelements - HTML for all additional layout elements: the footnote. + * timedinfobannershowonselectedpage - true if the time controlled info banner should be displayed. + * timedetualinfobannercontent - The content that should be shown in the time controled information banner. + * timedetualinfobannercssclass - The Bootstrap class that is used for the time controlled info banner. + * perpinfobannershowonselectedpage - true if the info banner should be displayed. + * perpibcontent - The content that should be shown in the information banner. + * perpibcss - The Bootstrap class that is used for the info banner. } }} {{! MODIFICATION: * Add own additional layout elements: the footnote. + * Added the possibility to show information banners. }} {{> theme_boost/head }} @@ -42,6 +56,18 @@ {{{ output.standard_top_of_body_html }}} + {{#timedinfobannershowonselectedpage}} + <div id="themeboostcampustimedinfobanner" class="alert alert-{{{ timedibcss }}} m-3" role="alert"> + {{{ timedibcontent }}} + </div> + {{/timedinfobannershowonselectedpage}} + + {{#perpinfobannershowonselectedpage}} + <div id="themeboostcampusperpinfobanner" class="alert alert-{{{ perpibcss }}} m-3" role="alert"> + {{{ perpibcontent }}} + </div> + {{/perpinfobannershowonselectedpage}} + <div id="page" class="container-fluid mt-0"> <div id="page-content" class="row"> <div id="region-main-box" class="col-12"> diff --git a/tests/behat/theme_boost_campus_info_banner_settings.feature b/tests/behat/theme_boost_campus_info_banner_settings.feature new file mode 100644 index 0000000000000000000000000000000000000000..68f8ea4597e71b137bf03a3675cf549e49b1aba0 --- /dev/null +++ b/tests/behat/theme_boost_campus_info_banner_settings.feature @@ -0,0 +1,193 @@ +@theme @theme_boost_campus @theme_boost_campus_info_banner_settings +Feature: Configuring the theme_boost_campus plugin for the "Info banner Settings" tab + In order to use the features + As admin + I need to be able to configure the theme Boost Campus plugin + + Background: + Given the following "users" exist: + | username | + | teacher1 | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + # There is a nasty bug with Behat-testing this theme that the footer is not displayed until the settings + # of the theme are stored manually. It seems not to be sufficient to just rely on the default settings being + # stored during the installation of the theme. Until we find the root of this bug, we circumvent it by setting the + # brand color manually and within this process making sure that all settings are really stored to the database. + And I log in as "admin" + And I navigate to "Appearance > Boost Campus" in site administration + And I click on "General settings" "link" + And I set the field "id_s_theme_boost_campus_brandcolor" to "#7a99ac" + And I press "Save changes" + And I log out + + Scenario: Display perpetual info banner on all available pages + Given the following config values are set as admin: + | config | value | plugin | + | perpibenable | 1 | theme_boost_campus | + | perpibcontent | "This is a test content" | theme_boost_campus | + | perpibshowonpages | mydashboard,course,login | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + When I am on "Course 1" course homepage + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + When I log out + And I click on "Log in" "link" + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + + Scenario: Display perpetual info banner only on one available page + Given the following config values are set as admin: + | config | value | plugin | + | perpibenable | 1 | theme_boost_campus | + | perpibcontent | "This is a test content" | theme_boost_campus | + | perpibshowonpages | mydashboard | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + When I am on "Course 1" course homepage + Then I should not see "This is a test content" + When I log out + And I click on "Log in" "link" + Then I should not see "This is a test content" + + Scenario: Display perpetual info with the different bootstrap color classes + Given the following config values are set as admin: + | config | value | plugin | + | perpibenable | 1 | theme_boost_campus | + | perpibcontent | "This is a test content" | theme_boost_campus | + | perpibshowonpages | mydashboard | theme_boost_campus | + | perpibcss | primary | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + And the "class" attribute of "#themeboostcampusperpinfobanner" "css_element" should contain "primary" + And I log out + Given the following config values are set as admin: + | config | value | plugin | + | perpibcss | secondary | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + And the "class" attribute of "#themeboostcampusperpinfobanner" "css_element" should contain "secondary" + And I log out + Given the following config values are set as admin: + | config | value | plugin | + | perpibcss | success | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + And the "class" attribute of "#themeboostcampusperpinfobanner" "css_element" should contain "success" + And I log out + Given the following config values are set as admin: + | config | value | plugin | + | perpibcss | danger | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + And the "class" attribute of "#themeboostcampusperpinfobanner" "css_element" should contain "danger" + And I log out + Given the following config values are set as admin: + | config | value | plugin | + | perpibcss | warning | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + And the "class" attribute of "#themeboostcampusperpinfobanner" "css_element" should contain "warning" + And I log out + Given the following config values are set as admin: + | config | value | plugin | + | perpibcss | info | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + And the "class" attribute of "#themeboostcampusperpinfobanner" "css_element" should contain "info" + And I log out + Given the following config values are set as admin: + | config | value | plugin | + | perpibcss | light | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + And the "class" attribute of "#themeboostcampusperpinfobanner" "css_element" should contain "light" + And I log out + Given the following config values are set as admin: + | config | value | plugin | + | perpibcss | dark | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + And the "class" attribute of "#themeboostcampusperpinfobanner" "css_element" should contain "dark" + And I log out + + Scenario: Save perpetual content but do not enable the info banner setting at all. + Given the following config values are set as admin: + | config | value | plugin | + | perpibenable | 0 | theme_boost_campus | + | perpibcontent | "This is a test content" | theme_boost_campus | + | perpibshowonpages | mydashboard | theme_boost_campus | + When I log in as "teacher1" + And I follow "Dashboard" in the user menu + Then I should not see "This is a test content" + + @javascript + Scenario: Enable setting "Perpetual info banner dismissible" + Given the following config values are set as admin: + | config | value | plugin | + | perpibenable | 1 | theme_boost_campus | + | perpibcontent | "This is a test content" | theme_boost_campus | + | perpibshowonpages | mydashboard | theme_boost_campus | + | perpibdismiss | 1 | theme_boost_campus | + When I log in as "teacher1" + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + When I click on "#themeboostcampusperpinfobannerclosebutton" "css_element" + Then I should not see "This is a test content" + + # This setting depends on the setting "Info banner dismissible" + @javascript + Scenario: Enable setting "Confirmation dialogue" + Given the following config values are set as admin: + | config | value | plugin | + | perpibenable | 1 | theme_boost_campus | + | perpibcontent | "This is a test content" | theme_boost_campus | + | perpibshowonpages | mydashboard | theme_boost_campus | + | perpibdismiss | 1 | theme_boost_campus | + | perpibconfirm | 1 | theme_boost_campus | + When I log in as "teacher1" + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + When I click on "#themeboostcampusperpinfobannerclosebutton" "css_element" + Then I should see "Confirmation" in the ".modal-title" "css_element" + When I click on "Cancel" "button" in the ".modal-footer" "css_element" + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + When I click on "#themeboostcampusperpinfobannerclosebutton" "css_element" + Then I should see "Confirmation" in the ".modal-title" "css_element" + When I click on "Yes, close!" "button" in the ".modal-footer" "css_element" + Then I should not see "This is a test content" + + # This setting depends on the setting "Info banner dismissible" + @javascript + Scenario: Enable setting "Reset visibility for perpetual info banner" + Given the following config values are set as admin: + | config | value | plugin | + | perpibenable | 1 | theme_boost_campus | + | perpibcontent | "This is a test content" | theme_boost_campus | + | perpibshowonpages | mydashboard | theme_boost_campus | + | perpibdismiss | 1 | theme_boost_campus | + When I log in as "teacher1" + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" + When I click on "#themeboostcampusperpinfobannerclosebutton" "css_element" + Then I should not see "This is a test content" + And I log out + When I log in as "admin" + And I navigate to "Appearance > Boost Campus" in site administration + And I click on "Info Banner Settings" "link" + And I click on "Reset visibility" "checkbox" + And I press "Save changes" + Then I should see "Success! All perpetual info banner instances are visible again." + And I log out + When I log in as "teacher1" + Then I should see "This is a test content" in the "#themeboostcampusperpinfobanner" "css_element" diff --git a/version.php b/version.php index 25d77aa0fc8fa78afd34bdc0d91a4f93aac112d1..5743c80d9f9b73e74235d61908a45abb9f1e1bbd 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'theme_boost_campus'; -$plugin->version = 2020071400; +$plugin->version = 2020080500; $plugin->release = 'v3.8-r2'; -$plugin->requires = 2019111800; +$plugin->requires = 2019111804; $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = array('theme_boost' => 2019111800);