From 7b55aaa12eef2d5550e8465140d869b3276529d8 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 20 Sep 2016 17:23:22 +0800 Subject: [PATCH] MDL-55942 core: obey the mighty CiBoT --- blocks/online_users/block_online_users.php | 3 +- lib/amd/src/auto_rows.js | 4 +- lib/amd/src/custom_interaction_events.js | 4 +- lib/amd/src/popover_region_controller.js | 15 +++--- lib/outputrenderers.php | 14 +++--- message/amd/src/message_area.js | 6 +-- message/amd/src/message_area_contacts.js | 31 ++++++------ message/amd/src/message_area_messages.js | 48 +++++++++--------- message/amd/src/message_area_profile.js | 14 +++--- message/amd/src/message_area_search.js | 14 +++--- message/amd/src/message_area_tabs.js | 4 +- .../src/message_notification_preference.js | 14 +++--- message/amd/src/message_popover_controller.js | 32 ++++++------ message/amd/src/message_preferences.js | 7 ++- message/amd/src/message_repository.js | 7 ++- .../src/notification_popover_controller.js | 47 ++++++++++-------- message/amd/src/notification_preference.js | 29 +++++------ message/amd/src/notification_processor.js | 10 ++-- .../src/notification_processor_settings.js | 7 ++- message/amd/src/notification_repository.js | 3 +- ...eferences_notifications_list_controller.js | 12 +++-- message/amd/src/preferences_processor_form.js | 18 +++---- message/amd/src/toggle_contact_button.js | 49 +++++++++---------- message/classes/api.php | 28 ++++++----- message/classes/helper.php | 5 +- .../classes/output/messagearea/contact.php | 2 + .../classes/output/messagearea/contacts.php | 2 + .../classes/output/messagearea/message.php | 2 + .../output/messagearea/message_area.php | 2 + .../messagearea/message_search_results.php | 2 + .../classes/output/messagearea/messages.php | 2 + .../messagearea/people_search_results.php | 2 + .../classes/output/messagearea/profile.php | 2 + message/classes/output/popup_notification.php | 20 ++++---- .../preferences/message_notification_list.php | 17 ++++--- .../message_notification_list_component.php | 9 ++-- .../output/preferences/notification_list.php | 31 ++++++------ .../notification_list_component.php | 27 +++++----- .../notification_list_processor.php | 41 +++++++--------- .../classes/output/preferences/processor.php | 23 ++++----- message/classes/output/processor.php | 6 ++- message/externallib.php | 35 ++++++++----- message/lib.php | 8 +-- message/notificationpreferences.php | 14 +++--- message/output/popup/db/events.php | 4 +- message/renderer.php | 11 +++-- message/tests/externallib_test.php | 4 +- message/tests/messagelib_test.php | 4 +- theme/bootstrapbase/less/moodle/message.less | 2 +- .../less/moodle/popover_region.less | 1 - theme/bootstrapbase/style/moodle.css | 3 +- 51 files changed, 371 insertions(+), 330 deletions(-) diff --git a/blocks/online_users/block_online_users.php b/blocks/online_users/block_online_users.php index ec32a5ae589..9b2e19e3749 100644 --- a/blocks/online_users/block_online_users.php +++ b/blocks/online_users/block_online_users.php @@ -125,7 +125,8 @@ class block_online_users extends block_base { if ($canshowicon and ($USER->id != $user->id) and !isguestuser($user)) { // Only when logged in and messaging active etc $anchortagcontents = ''. get_string('messageselectadd') .''; $anchorurl = new moodle_url('/message/index.php', array('id' => $user->id)); - $anchortag = html_writer::link($anchorurl, $anchortagcontents, array('title' => get_string('messageselectadd'))); + $anchortag = html_writer::link($anchorurl, $anchortagcontents, + array('title' => get_string('messageselectadd'))); $this->content->text .= '
'.$anchortag.'
'; } diff --git a/lib/amd/src/auto_rows.js b/lib/amd/src/auto_rows.js index 73302bd2f4e..634fb34e829 100644 --- a/lib/amd/src/auto_rows.js +++ b/lib/amd/src/auto_rows.js @@ -36,7 +36,7 @@ define(['jquery'], function($) { * Determine how many rows should be set for the given element. * * @method calculateRows - * @param {jQuery object} element The textarea element + * @param {jQuery} element The textarea element * @return {int} The number of rows for the element * @private */ @@ -69,7 +69,7 @@ define(['jquery'], function($) { * Add the event listeners for all text areas within the given element. * * @method init - * @param {jQuery object|selector} root The container element of all enhanced text areas + * @param {jQuery|selector} root The container element of all enhanced text areas * @public */ var init = function(root) { diff --git a/lib/amd/src/custom_interaction_events.js b/lib/amd/src/custom_interaction_events.js index e464ff6db48..d0fbb6cc0c0 100644 --- a/lib/amd/src/custom_interaction_events.js +++ b/lib/amd/src/custom_interaction_events.js @@ -281,7 +281,7 @@ define(['jquery', 'core/key_codes'], function($, keyCodes) { * * @method addScrollLockListener * @private - * @param {jQuery object} element jQuery object to add event listeners to + * @param {jQuery} element jQuery object to add event listeners to */ var addScrollLockListener = function(element) { // Lock mousewheel scrolling within the element to stop the annoying window scroll. @@ -316,6 +316,8 @@ define(['jquery', 'core/key_codes'], function($, keyCodes) { return false; } + + return true; }); }; diff --git a/lib/amd/src/popover_region_controller.js b/lib/amd/src/popover_region_controller.js index fd4ba310fe1..d2e5f3568e0 100644 --- a/lib/amd/src/popover_region_controller.js +++ b/lib/amd/src/popover_region_controller.js @@ -38,8 +38,7 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'], /** * Constructor for the PopoverRegionController. * - * @param element jQuery object root element of the popover - * @return object PopoverRegionController + * @param {jQuery} element object root element of the popover */ var PopoverRegionController = function(element) { this.root = $(element); @@ -52,6 +51,8 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'], /** * The collection of events triggered by this controller. + * + * @returns {object} */ PopoverRegionController.prototype.events = function() { return { @@ -66,7 +67,7 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'], * Return the container element for the content element. * * @method getContentContainer - * @return jQuery object + * @return {jQuery} object */ PopoverRegionController.prototype.getContentContainer = function() { return this.contentContainer; @@ -76,7 +77,7 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'], * Return the content element. * * @method getContent - * @return jQuery object + * @return {jQuery} object */ PopoverRegionController.prototype.getContent = function() { return this.content; @@ -86,7 +87,7 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'], * Checks if the popover is displayed. * * @method isMenuOpen - * @return bool + * @return {bool} */ PopoverRegionController.prototype.isMenuOpen = function() { return !this.root.hasClass('collapsed'); @@ -203,7 +204,7 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'], * Check if a content item has focus. * * @method contentItemHasFocus - * @return bool + * @return {bool} */ PopoverRegionController.prototype.contentItemHasFocus = function() { return this.getContentItemWithFocus().length > 0; @@ -213,7 +214,7 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'], * Return the currently focused content item. * * @method getContentItemWithFocus - * @return jQuery object + * @return {jQuery} object */ PopoverRegionController.prototype.getContentItemWithFocus = function() { var currentFocus = $(document.activeElement); diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 8363a562180..32dbc5c9ac9 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -147,10 +147,10 @@ class renderer_base { try { // Grab a copy of the existing helper to be restored later. - $uniqidHelper = $mustache->getHelper('uniqid'); + $uniqidhelper = $mustache->getHelper('uniqid'); } catch (Mustache_Exception_UnknownHelperException $e) { // Helper doesn't exist. - $uniqidHelper = null; + $uniqidhelper = null; } // Provide 1 random value that will not change within a template @@ -169,15 +169,15 @@ class renderer_base { } } - $renderedTemplate = trim($template->render($context)); + $renderedtemplate = trim($template->render($context)); // If we had an existing uniqid helper then we need to restore it to allow // handle nested calls of render_from_template. - if ($uniqidHelper) { - $mustache->addHelper('uniqid', $uniqidHelper); + if ($uniqidhelper) { + $mustache->addHelper('uniqid', $uniqidhelper); } - return $renderedTemplate; + return $renderedtemplate; } @@ -3193,7 +3193,7 @@ EOD; } /** - * Returns the noticication menu + * Returns the notification menu * * @return string HTML for the notification menu */ diff --git a/message/amd/src/message_area.js b/message/amd/src/message_area.js index fb242a2d550..671afaf5ee4 100644 --- a/message/amd/src/message_area.js +++ b/message/amd/src/message_area.js @@ -74,7 +74,7 @@ define(['jquery', 'core_message/message_area_contacts', 'core_message/message_ar SEARCHBOX: "[data-region='search-box']", SEARCHFILTER: "[data-region='search-filter']", SEARCHFILTERAREA: "[data-region='search-filter-area']", - SEARCHPEOPLEINCOURSE : "[data-action='search-people-in-course']", + SEARCHPEOPLEINCOURSE: "[data-action='search-people-in-course']", SEARCHRESULTSAREA: "[data-region='search-results-area']", SEARCHTEXTAREA: "[data-region='search-text-area']", SELECTEDVIEWPROFILE: "[data-action='view-contact-profile'].selected", @@ -162,7 +162,7 @@ define(['jquery', 'core_message/message_area_contacts', 'core_message/message_ar * Handles finding a node in the messaging area. * * @param {String} selector The selector for the node we are looking for - * @returns {jQuery} The node + * @return {jQuery} The node */ Messagearea.prototype.find = function(selector) { return this.node.find(selector); @@ -171,7 +171,7 @@ define(['jquery', 'core_message/message_area_contacts', 'core_message/message_ar /** * Returns the ID of the user whose message area we are viewing. * - * @returns {int} The user id + * @return {int} The user id */ Messagearea.prototype.getCurrentUserId = function() { return this.node.data('userid'); diff --git a/message/amd/src/message_area_contacts.js b/message/amd/src/message_area_contacts.js index 3d12820fb21..7cda7338445 100644 --- a/message/amd/src/message_area_contacts.js +++ b/message/amd/src/message_area_contacts.js @@ -230,16 +230,16 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles loading conversations. * - * @returns {Promise} The promise resolved when the contact area has been rendered, + * @return {Promise|boolean} The promise resolved when the contact area has been rendered, * @private */ Contacts.prototype._loadConversations = function() { if (this._isDeleting) { - return; + return false; } if (this._isLoadingConversations) { - return; + return false; } // Tell the user we are loading items. @@ -284,16 +284,16 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles loading contacts. * - * @returns {Promise} The promise resolved when the contact area has been rendered + * @return {Promise|boolean} The promise resolved when the contact area has been rendered * @private */ Contacts.prototype._loadContacts = function() { if (this._isDeleting) { - return; + return false; } if (this._isLoadingContacts) { - return; + return false; } // Tell the user we are loading items. @@ -384,7 +384,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * @param {String} webservice The web service to call * @param {int} limitfrom * @param {int} limitnum - * @returns {Promise} The promise resolved when the contact area has been rendered + * @return {Promise} The promise resolved when the contact area has been rendered * @private */ Contacts.prototype._getItems = function(webservice, limitfrom, limitnum) { @@ -404,8 +404,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles deleting a conversation. * - * @params {Event} event - * @params {int} The user id belonging to the messages we are deleting. + * @param {Event} event + * @param {int} userid The user id belonging to the messages we are deleting. * @private */ Contacts.prototype._deleteConversation = function(event, userid) { @@ -420,9 +420,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles updating the last message in the contact. * - * @params {Event} event - * @params {int} The user id belonging to the messages we are deleting - * @params {jQuery|null} The message we need to update the contact panel with + * @param {Event} event + * @param {int} userid The user id belonging to the messages we are deleting + * @param {jQuery|null} updatemessage The message we need to update the contact panel with * @private */ Contacts.prototype._updateLastMessage = function(event, userid, updatemessage) { @@ -446,7 +446,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles adding a contact to the list. * - * @param {int} userid * @private */ Contacts.prototype._addContact = function() { @@ -506,6 +505,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * * @param {String} selector * @param {int} userid + * @return {jQuery} The user node * @private */ Contacts.prototype._getUserNode = function(selector, userid) { @@ -530,6 +530,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * Converts a text message into the text that should be stored in the contact list * * @param {String} text + * @return {String} The altered text */ Contacts.prototype._getContactText = function(text) { if (text.length > this._messageLength) { @@ -552,10 +553,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // Get the text we will display on the contact panel. text = this._getContactText(text); if (sentbyuser) { - Str.get_string('you', 'message').done(function (string) { + Str.get_string('you', 'message').done(function(string) { // Ensure we display that the message is from this user. user.find(this.messageArea.SELECTORS.LASTMESSAGEUSER).empty().append(string); - }.bind(this)).always(function () { + }.bind(this)).always(function() { user.find(this.messageArea.SELECTORS.LASTMESSAGETEXT).empty().append(text); }.bind(this)); } else { diff --git a/message/amd/src/message_area_messages.js b/message/amd/src/message_area_messages.js index 7175a01e463..05e9faa0395 100644 --- a/message/amd/src/message_area_messages.js +++ b/message/amd/src/message_area_messages.js @@ -115,7 +115,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * * @param {Event} event * @param {int} userid - * @returns {Promise} The promise resolved when the messages have been loaded. + * @return {Promise} The promise resolved when the messages have been loaded. * @private */ Messages.prototype._viewMessages = function(event, userid) { @@ -160,12 +160,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Loads messages while scrolling. * - * @returns {Promise} The promise resolved when the messages have been loaded. + * @return {Promise|boolean} The promise resolved when the messages have been loaded. * @private */ Messages.prototype._loadMessages = function() { if (this._isLoadingMessages) { - return; + return false; } this._isLoadingMessages = true; @@ -215,7 +215,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * Handles returning a list of messages to display. * * @param {int} userid - * @returns {Promise} The promise resolved when the contact area has been rendered + * @return {Promise} The promise resolved when the contact area has been rendered * @private */ Messages.prototype._getMessages = function(userid) { @@ -238,7 +238,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles sending a message. * - * @returns {Promise} The promise resolved once the message has been sent. + * @return {Promise|boolean} The promise resolved once the message has been sent. * @private */ Messages.prototype._sendMessage = function() { @@ -247,12 +247,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // Do not do anything if it is empty. if (text.trim() === '') { - return; + return false; } // If we are sending a message, don't do anything, be patient! if (this._isSendingMessage) { - return; + return false; } // Ok, mark that we are sending a message. @@ -297,7 +297,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles selecting messages to delete. * - * @returns {Promise} The promise resolved when the messages to delete have been selected. * @private */ Messages.prototype._chooseMessagesToDelete = function() { @@ -332,7 +331,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust read: isread } }); - }.bind(this)); + }); if (requests.length > 0) { ajax.call(requests)[requests.length - 1].then(function() { @@ -382,7 +381,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles adding a scrolling event listener. * - * @params {int} The number of messages received + * @param {int} numberreceived The number of messages received * @private */ Messages.prototype._addScrollEventListener = function(numberreceived) { @@ -446,7 +445,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handles hiding the delete checkboxes and replacing the response area. * - * @return {Promise} JQuery promise object resolved when the template has been rendered. * @private */ Messages.prototype._hideDeleteAction = function() { @@ -462,14 +460,14 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * @private */ Messages.prototype._triggerCancelMessagesToDelete = function() { - // Trigger event letting other modules know message deletion was canceled. + // Trigger event letting other modules know message deletion was canceled. this.messageArea.trigger(this.messageArea.EVENTS.CANCELDELETEMESSAGES); }; /** * Handles adding messages to the DOM. * - * @returns {Promise} The promise resolved when the message has been added to the DOM. + * @return {Promise} The promise resolved when the message has been added to the DOM. * @private */ Messages.prototype._addMessageToDom = function() { @@ -497,7 +495,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Returns the ID of the other user in the conversation. * - * @returns {int} The user id + * @return {int} The user id * @private */ Messages.prototype._getUserId = function() { @@ -520,8 +518,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Select the previous message in the list. * - * @params {event} e The jquery event - * @params {object} data Extra event data + * @param {event} e The jquery event + * @param {object} data Extra event data * @private */ Messages.prototype._selectPreviousMessage = function(e, data) { @@ -540,8 +538,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Select the next message in the list. * - * @params {event} e The jquery event - * @params {object} data Extra event data + * @param {event} e The jquery event + * @param {object} data Extra event data * @private */ Messages.prototype._selectNextMessage = function(e, data) { @@ -560,7 +558,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Flag the response area as messaging. * - * @params {event} e The jquery event + * @param {event} e The jquery event * @private */ Messages.prototype._setMessaging = function(e) { @@ -570,7 +568,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Clear the response area as messaging flag. * - * @params {event} e The jquery event + * @param {event} e The jquery event * @private */ Messages.prototype._clearMessaging = function(e) { @@ -580,7 +578,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Turn on delete message mode. * - * @params {event} e The jquery event + * @param {event} e The jquery event * @private */ Messages.prototype._startDeleting = function(e) { @@ -603,7 +601,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Check or uncheck the message if the message area is in editing mode. * - * @params {event} e The jquery event + * @param {event} e The jquery event * @private */ Messages.prototype._toggleMessage = function(e) { @@ -624,7 +622,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * Adjust the height of the messages area to match the changed height of * the response area. * - * @params {event} e The jquery event + * @param {event} e The jquery event * @private */ Messages.prototype._adjustMessagesAreaHeight = function(e) { @@ -641,8 +639,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust /** * Handle the event that triggers sending a message from the messages area. * - * @params {event} e The jquery event - * @params {object} data Additional event data + * @param {event} e The jquery event + * @param {object} data Additional event data * @private */ Messages.prototype._sendMessageHandler = function(e, data) { diff --git a/message/amd/src/message_area_profile.js b/message/amd/src/message_area_profile.js index 9c105dd527d..0aca7f81ab5 100644 --- a/message/amd/src/message_area_profile.js +++ b/message/amd/src/message_area_profile.js @@ -70,7 +70,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' * * @param {Event} event * @param {int} userid - * @returns {Promise} The promise resolved when the profile has been rendered + * @return {Promise} The promise resolved when the profile has been rendered * @private */ Profile.prototype._viewProfile = function(event, userid) { @@ -117,7 +117,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' /** * Handles blocking the contact. * - * @returns {Promise} The promise resolved when the contact has been blocked + * @return {Promise} The promise resolved when the contact has been blocked * @private */ Profile.prototype._blockContact = function() { @@ -131,7 +131,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' /** * Handles unblocking the contact. * - * @returns {Promise} The promise resolved when the contact has been unblocked + * @return {Promise} The promise resolved when the contact has been unblocked * @private */ Profile.prototype._unblockContact = function() { @@ -145,7 +145,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' /** * Handles adding the contact. * - * @returns {Promise} The promise resolved when the contact has been added + * @return {Promise} The promise resolved when the contact has been added * @private */ Profile.prototype._addContact = function() { @@ -159,7 +159,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' /** * Handles removing the contact. * - * @returns {Promise} The promise resolved when the contact has been removed + * @return {Promise} The promise resolved when the contact has been removed * @private */ Profile.prototype._removeContact = function() { @@ -178,7 +178,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' * @param {String} oldaction The data-action of the button * @param {string} newaction The data-action to change the button to * @param {String} newclass The CSS class we want to add - * @returns {Promise} The promise resolved when the action has been performed + * @return {Promise} The promise resolved when the action has been performed * @private */ Profile.prototype._performAction = function(service, string, oldaction, newaction, newclass) { @@ -225,7 +225,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' /** * Returns the ID of the user whos profile we are viewing. * - * @returns {int} The user ID + * @return {int} The user ID * @private */ Profile.prototype._getUserId = function() { diff --git a/message/amd/src/message_area_search.js b/message/amd/src/message_area_search.js index 4c0c55c5f8c..6933a103b4f 100644 --- a/message/amd/src/message_area_search.js +++ b/message/amd/src/message_area_search.js @@ -177,13 +177,13 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA).show(); if (this._searchArea == this._searchAreas.MESSAGES) { - this._requestTimeout = setTimeout(function () { + this._requestTimeout = setTimeout(function() { this._clearSearchArea(); this._numMessagesDisplayed = 0; this._searchMessages(); }.bind(this), 300); } else if (this._searchArea == this._searchAreas.PEOPLEINCOURSE) { - this._requestTimeout = setTimeout(function () { + this._requestTimeout = setTimeout(function() { this._clearSearchArea(); this._numPeopleDisplayed = 0; this._searchPeopleInCourse(); @@ -201,11 +201,11 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' * Handles searching for messages. * * @private - * @returns {Promise} The promise resolved when the search area has been rendered + * @return {Promise|boolean} The promise resolved when the search area has been rendered */ Search.prototype._searchMessages = function() { if (this._isLoading) { - return; + return false; } var str = this.messageArea.find(this.messageArea.SELECTORS.SEARCHBOX).val(); @@ -257,7 +257,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' * Handles searching for people. * * @private - * @returns {Promise} The promise resolved when the search area has been rendered + * @return {Promise} The promise resolved when the search area has been rendered */ Search.prototype._searchPeople = function() { var str = this.messageArea.find(this.messageArea.SELECTORS.SEARCHBOX).val(); @@ -288,11 +288,11 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' * Handles searching for people in a course. * * @private - * @returns {Promise} The promise resolved when the search area has been rendered + * @return {Promise|boolean} The promise resolved when the search area has been rendered */ Search.prototype._searchPeopleInCourse = function() { if (this._isLoading) { - return; + return false; } var str = this.messageArea.find(this.messageArea.SELECTORS.SEARCHBOX).val(); diff --git a/message/amd/src/message_area_tabs.js b/message/amd/src/message_area_tabs.js index 973da6120b1..6f7317d76ab 100644 --- a/message/amd/src/message_area_tabs.js +++ b/message/amd/src/message_area_tabs.js @@ -134,12 +134,12 @@ define(['core/custom_interaction_events'], function(CustomEvents) { * @private */ Tabs.prototype._selectTab = function(tabselect, tabdeselect) { - var tabdeselect = this.messageArea.find(tabdeselect); + tabdeselect = this.messageArea.find(tabdeselect); tabdeselect.removeClass('selected'); tabdeselect.attr('aria-selected', 'false'); tabdeselect.attr('tabindex', '-1'); - var tabselect = this.messageArea.find(tabselect); + tabselect = this.messageArea.find(tabselect); tabselect.addClass('selected'); tabselect.attr('aria-selected', 'true'); tabselect.attr('tabindex', '0'); diff --git a/message/amd/src/message_notification_preference.js b/message/amd/src/message_notification_preference.js index e817d9c920a..1248f88a4f5 100644 --- a/message/amd/src/message_notification_preference.js +++ b/message/amd/src/message_notification_preference.js @@ -22,10 +22,9 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ -define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_preference'], - function($, ajax, notification, NotificationPreference) { +define(['jquery', 'core_message/notification_preference'], + function($, NotificationPreference) { var SELECTORS = { PREFERENCE_KEY: '[data-preference-key]', @@ -34,9 +33,8 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p /** * Constructor for the Preference. * - * @param element jQuery object root element of the preference - * @param int the current user id - * @return object Preference + * @param {object} element jQuery object root element of the preference + * @param {int} userId The current user id */ var MessageNotificationPreference = function(element, userId) { NotificationPreference.call(this, element, userId); @@ -50,13 +48,13 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p /** * Set constructor. */ - MessageNotificationPreference.prototype.constructor = NotificationPreference; + MessageNotificationPreference.prototype.constructor = MessageNotificationPreference; /** * Get the unique prefix key that identifies this user preference. * * @method getPreferenceKey - * @return string + * @return {string} */ MessageNotificationPreference.prototype.getPreferenceKey = function() { return this.root.find(SELECTORS.PREFERENCE_KEY).attr('data-preference-key'); diff --git a/message/amd/src/message_popover_controller.js b/message/amd/src/message_popover_controller.js index af712d93fb3..6cb239a07cf 100644 --- a/message/amd/src/message_popover_controller.js +++ b/message/amd/src/message_popover_controller.js @@ -23,7 +23,6 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates', 'core/str', 'core/notification', 'core/custom_interaction_events', 'core/popover_region_controller', @@ -43,15 +42,13 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * Constructor for the MessagePopoverController. * Extends PopoverRegionController. * - * @param element jQuery object root element of the popover - * @return object MessagePopoverController + * @param {object} element jQuery object root element of the popover */ var MessagePopoverController = function(element) { // Initialise base class. PopoverController.call(this, element); this.markAllReadButton = this.root.find(SELECTORS.MARK_ALL_READ_BUTTON); - this.blockNonContactsButton = this.root.find(SELECTORS.BLOCK_NON_CONTACTS_BUTTON); this.content = this.root.find(SELECTORS.CONTENT); this.userId = this.root.attr('data-userid'); this.limit = 20; @@ -78,7 +75,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * Get the element holding the messages. * * @method getContent - * @return jQuery element + * @return {object} jQuery element */ MessagePopoverController.prototype.getContent = function() { return this.content; @@ -162,9 +159,9 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * Render the message data with the appropriate template and add it to the DOM. * * @method renderMessages - * @param messages array message data - * @param container jQuery object the container to append the rendered messages - * @return jQuery promise that is resolved when all messages have been + * @param {array} messages Message data + * @param {object} container jQuery object the container to append the rendered messages + * @return {object} jQuery promise that is resolved when all messages have been * rendered and added to the DOM */ MessagePopoverController.prototype.renderMessages = function(messages, container) { @@ -189,7 +186,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' promise.then(function(html, js) { allhtml[index] = html; alljs[index] = js; - }.bind(this)); + }); }.bind(this)); } @@ -208,7 +205,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * loading some and haven't already loaded all of them. * * @method loadMoreMessages - * @return jQuery promise that is resolved when messages have been + * @return {object} jQuery promise that is resolved when messages have been * retrieved and added to the DOM */ MessagePopoverController.prototype.loadMoreMessages = function() { @@ -224,7 +221,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' }; var container = this.getContent(); - var promise = MessageRepo.query(request).then(function(result) { + return MessageRepo.query(request).then(function(result) { var messages = result.contacts; this.loadedAll = !messages.length || messages.length < this.limit; this.initialLoad = true; @@ -234,10 +231,12 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' this.incrementOffset(); return this.renderMessages(messages, container); } - }.bind(this)) - .always(function() { this.stopLoading(); }.bind(this)); - return promise; + return false; + }.bind(this)) + .always(function() { + this.stopLoading(); + }.bind(this)); }; /** @@ -245,6 +244,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * the unread count and unread messages elements appropriately. * * @method markAllAsRead + * @return {Promise} */ MessagePopoverController.prototype.markAllAsRead = function() { if (this.markAllReadButton.hasClass('loading')) { @@ -259,7 +259,9 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' this.hideUnreadCount(); this.getContent().find(SELECTORS.CONTENT_ITEM_CONTAINER).removeClass('unread'); }.bind(this)) - .always(function() { this.markAllReadButton.removeClass('loading'); }.bind(this)); + .always(function() { + this.markAllReadButton.removeClass('loading'); + }.bind(this)); }; /** diff --git a/message/amd/src/message_preferences.js b/message/amd/src/message_preferences.js index 087c3671c41..d3c3ef16171 100644 --- a/message/amd/src/message_preferences.js +++ b/message/amd/src/message_preferences.js @@ -21,7 +21,6 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'core/ajax', 'core/notification', 'core_message/message_notification_preference', 'core/custom_interaction_events'], @@ -37,8 +36,7 @@ define(['jquery', 'core/ajax', 'core/notification', /** * Constructor for the MessagePreferences. * - * @param {jQuery object} element The root element for the message preferences - * @return object MessagePreferences + * @param {object} element The root element for the message preferences */ var MessagePreferences = function(element) { this.root = $(element); @@ -50,7 +48,7 @@ define(['jquery', 'core/ajax', 'core/notification', * Check if the preferences have been disabled on this page. * * @method preferencesDisabled - * @return bool + * @return {bool} */ MessagePreferences.prototype.preferencesDisabled = function() { return this.root.find(SELECTORS.PREFERENCES_CONTAINER).hasClass('disabled'); @@ -60,6 +58,7 @@ define(['jquery', 'core/ajax', 'core/notification', * Update the block messages from non-contacts user preference in the DOM and * send a request to update on the server. * + * @return {Promise} * @method saveBlockNonContactsStatus */ MessagePreferences.prototype.saveBlockNonContactsStatus = function() { diff --git a/message/amd/src/message_repository.js b/message/amd/src/message_repository.js index 9729b88bb7c..6c0ee94f039 100644 --- a/message/amd/src/message_repository.js +++ b/message/amd/src/message_repository.js @@ -21,14 +21,13 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notification) { /** * Retrieve a list of messages from the server. * * @param {object} args The request arguments: - * @return {jQuery promise} + * @return {object} jQuery promise */ var query = function(args) { // Normalise the arguments to use limit/offset rather than limitnum/limitfrom. @@ -63,7 +62,7 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat * for a given user. * * @param {object} args The request arguments: - * @return {jQuery promise} + * @return {object} jQuery promise */ var countUnreadConversations = function(args) { var request = { @@ -82,7 +81,7 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat * Mark all of unread messages for a user as read. * * @param {object} args The request arguments: - * @return {jQuery promise} + * @return {object} jQuery promise */ var markAllAsRead = function(args) { var request = { diff --git a/message/amd/src/notification_popover_controller.js b/message/amd/src/notification_popover_controller.js index 5cd337849b6..19f48a3cca3 100644 --- a/message/amd/src/notification_popover_controller.js +++ b/message/amd/src/notification_popover_controller.js @@ -23,7 +23,6 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates', 'core/str', 'core/notification', 'core/custom_interaction_events', 'core/popover_region_controller', @@ -45,8 +44,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * Constructor for the NotificationPopoverController. * Extends PopoverRegionController. * - * @param element jQuery object root element of the popover - * @return object NotificationPopoverController + * @param {object} element jQuery object root element of the popover */ var NotificationPopoverController = function(element) { // Initialise base class. @@ -106,7 +104,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * depending on which is currently visible. * * @method getContent - * @return jQuery object currently visible content contianer + * @return {object} jQuery object currently visible content contianer */ NotificationPopoverController.prototype.getContent = function() { return this.container; @@ -117,7 +115,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * to sent to the backend to correctly paginate the notifications. * * @method getOffset - * @return int current offset + * @return {int} current offset */ NotificationPopoverController.prototype.getOffset = function() { return this.offset; @@ -137,7 +135,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * state of the popover. * * @method hasDoneInitialLoad - * @return bool true if first notification loaded, false otherwise + * @return {bool} true if first notification loaded, false otherwise */ NotificationPopoverController.prototype.hasDoneInitialLoad = function() { return this.initialLoad; @@ -148,7 +146,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * state. * * @method hasLoadedAllContent - * @return bool true if all notifications loaded, false otherwise + * @return {bool} true if all notifications loaded, false otherwise */ NotificationPopoverController.prototype.hasLoadedAllContent = function() { return this.loadedAll; @@ -159,7 +157,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * of the popover. * * @method setLoadedAllContent - * @param bool true if all content is loaded, false otherwise + * @param {bool} val True if all content is loaded, false otherwise */ NotificationPopoverController.prototype.setLoadedAllContent = function(val) { this.loadedAll = val; @@ -210,10 +208,10 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * Render the notification data with the appropriate template and add it to the DOM. * * @method renderNotifications - * @param notifications array notification data - * @param container jQuery object the container to append the rendered notifications - * @return jQuery promise that is resolved when all notifications have been - * rendered and added to the DOM + * @param {array} notifications Notification data + * @param {object} container jQuery object the container to append the rendered notifications + * @return {object} jQuery promise that is resolved when all notifications have been + * rendered and added to the DOM */ NotificationPopoverController.prototype.renderNotifications = function(notifications, container) { var promises = []; @@ -228,9 +226,9 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' promise.then(function(html, js) { allhtml[index] = html; alljs[index] = js; - }.bind(this)) + }) .fail(DebugNotification.exception); - }.bind(this)); + }); } return $.when.apply($.when, promises).then(function() { @@ -253,7 +251,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' * All notifications are marked as read by the server when they are returned. * * @method loadMoreNotifications - * @return jQuery promise that is resolved when notifications have been + * @return {object} jQuery promise that is resolved when notifications have been * retrieved and added to the DOM */ NotificationPopoverController.prototype.loadMoreNotifications = function() { @@ -272,7 +270,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' }; var container = this.getContent(); - var promise = NotificationRepo.query(request).then(function(result) { + return NotificationRepo.query(request).then(function(result) { var notifications = result.notifications; this.unreadCount = result.unreadcount; this.setLoadedAllContent(!notifications.length || notifications.length < this.limit); @@ -283,16 +281,19 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' this.incrementOffset(); return this.renderNotifications(notifications, container); } - }.bind(this)) - .always(function() { this.stopLoading(); }.bind(this)); - return promise; + return false; + }.bind(this)) + .always(function() { + this.stopLoading(); + }.bind(this)); }; /** * Send a request to the server to mark all unread notifications as read and update * the unread count and unread notification elements appropriately. * + * @return {Promise} * @method markAllAsRead */ NotificationPopoverController.prototype.markAllAsRead = function() { @@ -303,18 +304,22 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates' this.unreadCount = 0; this.root.find(SELECTORS.UNREAD_NOTIFICATION).removeClass('unread'); }.bind(this)) - .always(function() { this.markAllReadButton.removeClass('loading'); }.bind(this)); + .always(function() { + this.markAllReadButton.removeClass('loading'); + }.bind(this)); }; /** * Send a request to the server to mark a single notification as read and update * the unread count and unread notification elements appropriately. * + * @param {jQuery} element + * @return {Promise|boolean} * @method markAllAsRead */ NotificationPopoverController.prototype.markNotificationAsRead = function(element) { if (!element.hasClass('unread')) { - return; + return false; } return NotificationRepo.markAsRead(element.attr('data-id')) diff --git a/message/amd/src/notification_preference.js b/message/amd/src/notification_preference.js index a260007a019..86c36d6230a 100644 --- a/message/amd/src/notification_preference.js +++ b/message/amd/src/notification_preference.js @@ -22,10 +22,9 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_processor'], - function($, ajax, notification, NotificationProcessor) { + function($, Ajax, Notification, NotificationProcessor) { var SELECTORS = { PROCESSOR: '[data-processor-name]', @@ -35,9 +34,8 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p /** * Constructor for the Preference. * - * @param element jQuery object root element of the preference - * @param int the current user id - * @return object Preference + * @param {object} element jQuery object root element of the preference + * @param {int} userId The current user id */ var NotificationPreference = function(element, userId) { this.root = $(element); @@ -48,7 +46,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p * Get the unique prefix key that identifies this user preference. * * @method getPreferenceKey - * @return string + * @return {string} */ NotificationPreference.prototype.getPreferenceKey = function() { return this.root.attr('data-preference-key'); @@ -58,7 +56,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p * Get the unique key for the logged in preference. * * @method getLoggedInPreferenceKey - * @return string + * @return {string} */ NotificationPreference.prototype.getLoggedInPreferenceKey = function() { return this.getPreferenceKey() + '_loggedin'; @@ -68,7 +66,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p * Get the unique key for the logged off preference. * * @method getLoggedOffPreferenceKey - * @return string + * @return {string} */ NotificationPreference.prototype.getLoggedOffPreferenceKey = function() { return this.getPreferenceKey() + '_loggedoff'; @@ -78,7 +76,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p * Get the list of Processors available for this preference. * * @method getProcessors - * @return array + * @return {array} */ NotificationPreference.prototype.getProcessors = function() { return this.root.find(SELECTORS.PROCESSOR).map(function(index, element) { @@ -110,6 +108,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p * Check if the preference is loading. * * @method isLoading + * @return {Boolean} */ NotificationPreference.prototype.isLoading = function() { return this.root.hasClass('loading'); @@ -119,7 +118,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p * Persist the current state of the processors for this preference. * * @method save - * @return promise + * @return {object} jQuery promise */ NotificationPreference.prototype.save = function() { if (this.isLoading()) { @@ -158,7 +157,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p } var args = { - userid : this.userId, + userid: this.userId, preferences: [ { type: this.getLoggedInPreferenceKey(), @@ -176,9 +175,11 @@ define(['jquery', 'core/ajax', 'core/notification', 'core_message/notification_p args: args, }; - return ajax.call([request])[0] - .fail(notification.exception) - .always(function() { this.stopLoading(); }.bind(this)); + return Ajax.call([request])[0] + .fail(Notification.exception) + .always(function() { + this.stopLoading(); + }.bind(this)); }; return NotificationPreference; diff --git a/message/amd/src/notification_processor.js b/message/amd/src/notification_processor.js index 16774afc7d5..9d95c0d112b 100644 --- a/message/amd/src/notification_processor.js +++ b/message/amd/src/notification_processor.js @@ -21,7 +21,6 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery'], function($) { var SELECTORS = { @@ -34,8 +33,7 @@ define(['jquery'], function($) { /** * Constructor for the notification processor. * - * @param element jQuery object root element of the processor - * @return object NotificationProcessor + * @param {object} element jQuery object root element of the processor */ var NotificationProcessor = function(element) { this.root = $(element); @@ -45,7 +43,7 @@ define(['jquery'], function($) { * Get the processor name. * * @method getName - * @return string + * @return {string} */ NotificationProcessor.prototype.getName = function() { return this.root.attr('data-processor-name'); @@ -55,7 +53,7 @@ define(['jquery'], function($) { * Check if the processor is enabled when the user is logged in. * * @method isLoggedInEnabled - * @return bool + * @return {bool} */ NotificationProcessor.prototype.isLoggedInEnabled = function() { var none = this.root.find(SELECTORS.STATE_NONE).find('input'); @@ -74,7 +72,7 @@ define(['jquery'], function($) { * Check if the processor is enabled when the user is logged out. * * @method isLoggedOffEnabled - * @return bool + * @return {bool} */ NotificationProcessor.prototype.isLoggedOffEnabled = function() { var none = this.root.find(SELECTORS.STATE_NONE).find('input'); diff --git a/message/amd/src/notification_processor_settings.js b/message/amd/src/notification_processor_settings.js index ea835fe3c83..bb3763b05c1 100644 --- a/message/amd/src/notification_processor_settings.js +++ b/message/amd/src/notification_processor_settings.js @@ -21,7 +21,6 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'core/ajax', 'core/notification', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialogue'], function($, Ajax, Notification, Fragment, Templates, Str, Dialogue) { @@ -34,8 +33,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/fragment', 'core/templ /** * Constructor for the notification processor settings. * - * @param element jQuery object root element of the processor - * @return object NotificationProcessorSettings + * @param {object} element jQuery object root element of the processor */ var NotificationProcessorSettings = function(element) { this.root = $(element); @@ -85,12 +83,13 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/fragment', 'core/templ * status from the interface. * * @method updateConfiguredStatus + * @return {Promise|boolean} */ NotificationProcessorSettings.prototype.updateConfiguredStatus = function() { var processorHeader = this.root.closest(SELECTORS.PROCESSOR); if (!processorHeader.hasClass('unconfigured')) { - return; + return false; } var processorName = processorHeader.attr('data-processor-name'); diff --git a/message/amd/src/notification_repository.js b/message/amd/src/notification_repository.js index 3d2dd15bc99..35fde95b071 100644 --- a/message/amd/src/notification_repository.js +++ b/message/amd/src/notification_repository.js @@ -21,7 +21,6 @@ * @package message * @copyright 2015 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['core/ajax', 'core/notification'], function(ajax, notification) { /** @@ -90,7 +89,7 @@ define(['core/ajax', 'core/notification'], function(ajax, notification) { }; /** - * Mark all notifications for the given user as read. + * Mark a specific notification as read. * * @param {int} id The notification id * @param {int} timeread The read timestamp (optional) diff --git a/message/amd/src/preferences_notifications_list_controller.js b/message/amd/src/preferences_notifications_list_controller.js index 1bbed33d6b4..a2f3b8ae0fe 100644 --- a/message/amd/src/preferences_notifications_list_controller.js +++ b/message/amd/src/preferences_notifications_list_controller.js @@ -22,7 +22,6 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_events', 'core_message/notification_preference', 'core_message/notification_processor_settings'], @@ -40,8 +39,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve /** * Constructor for the PreferencesController. * - * @param element jQuery object root element of the preference - * @return object PreferencesController + * @param {object} element jQuery object root element of the preference */ var PreferencesController = function(element) { this.root = $(element); @@ -54,7 +52,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve * Check if the preferences are all disabled. * * @method isDisabled - * @return bool + * @return {bool} */ PreferencesController.prototype.isDisabled = function() { return this.root.hasClass('disabled'); @@ -85,6 +83,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve * send a request to update on the server. * * @method toggleDisableAllStatus + * @return {Promise} */ PreferencesController.prototype.toggleDisableAllStatus = function() { var checkbox = $(SELECTORS.DISABLE_NOTIFICATIONS); @@ -119,6 +118,11 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve .fail(Notification.exception); }; + /** + * Set up all of the event listeners for the PreferencesController. + * + * @method registerEventListeners + */ PreferencesController.prototype.registerEventListeners = function() { var disabledNotificationsElement = $(SELECTORS.DISABLE_NOTIFICATIONS); diff --git a/message/amd/src/preferences_processor_form.js b/message/amd/src/preferences_processor_form.js index 3cbef6071c3..53b3766c14e 100644 --- a/message/amd/src/preferences_processor_form.js +++ b/message/amd/src/preferences_processor_form.js @@ -21,15 +21,13 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_events'], - function($, ajax, notification, CustomEvents) { + function($, Ajax, Notification, CustomEvents) { /** * Constructor for the ProcessorForm. * - * @param element jQuery object root element of the preference - * @return object ProcessorForm + * @param {object} element jQuery object root element of the preference */ var ProcessorForm = function(element) { this.root = $(element); @@ -75,7 +73,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve * Check if this processor is loading. * * @method isLoading - * @return bool + * @return {bool} */ ProcessorForm.prototype.isLoading = function() { return this.root.hasClass('loading'); @@ -85,7 +83,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve * Persist the processor configuration. * * @method save - * @return promise + * @return {object} jQuery promise */ ProcessorForm.prototype.save = function() { if (this.isLoading()) { @@ -104,9 +102,11 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve } }; - return ajax.call([request])[0] - .fail(notification.exception) - .always(function() { this.stopLoading(); }.bind(this)); + return Ajax.call([request])[0] + .fail(Notification.exception) + .always(function() { + this.stopLoading(); + }.bind(this)); }; return ProcessorForm; diff --git a/message/amd/src/toggle_contact_button.js b/message/amd/src/toggle_contact_button.js index 70d46bd712e..aa22a420405 100644 --- a/message/amd/src/toggle_contact_button.js +++ b/message/amd/src/toggle_contact_button.js @@ -21,17 +21,16 @@ * @package message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 3.2 */ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/custom_interaction_events'], - function($, ajax, templates, notification, customEvents) { + function($, Ajax, Templates, Notification, CustomEvents) { /** * Check the state of the element, if the current user is a contact or not. * * @method isContact - * @param element jQuery object for the button - * @return bool + * @param {object} element jQuery object for the button + * @return {bool} */ var isContact = function(element) { return element.attr('data-is-contact') == '1'; @@ -41,7 +40,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * Record that the user is a contact. * * @method setContact - * @param element jQuery object for the button + * @param {object} element jQuery object for the button */ var setContact = function(element) { element.attr('data-is-contact', '1'); @@ -51,7 +50,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * Record that the user is not a contact. * * @method setNotContact - * @param element jQuery object for the button + * @param {object} element jQuery object for the button */ var setNotContact = function(element) { element.attr('data-is-contact', '0'); @@ -61,8 +60,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * Get the id for the user being viewed. * * @method getUserId - * @param element jQuery object for the button - * @return int + * @param {object} element jQuery object for the button + * @return {int} */ var getUserId = function(element) { return element.attr('data-userid'); @@ -72,8 +71,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * Check if this element is currently loading. * * @method isLoading - * @param element jQuery object for the button - * @return bool + * @param {object} element jQuery object for the button + * @return {bool} */ var isLoading = function(element) { return element.hasClass('loading') || element.attr('disabled'); @@ -84,9 +83,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * while the request is being performed. * * @method sendRequest - * @param element jQuery object for the button - * @param request request hash to send - * @return jQuery promise + * @param {object} element jQuery object for the button + * @param {object} request Request hash to send + * @return {object} jQuery promise */ var sendRequest = function(element, request) { if (isLoading(element)) { @@ -96,8 +95,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust element.addClass('loading'); element.attr('disabled', 'disabled'); - return ajax.call([request])[0] - .fail(notification.exception) + return Ajax.call([request])[0] + .fail(Notification.exception) .always(function() { element.removeClass('loading'); element.removeAttr('disabled'); @@ -110,7 +109,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * remove contact button upon success. * * @method addContact - * @param element jQuery object for the button + * @param {object} element jQuery object for the button */ var addContact = function(element) { if (isLoading(element)) { @@ -125,8 +124,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust }; sendRequest(element, request).done(function() { setContact(element); - templates.render('message/remove_contact_button', {}).done(function(html, js) { - templates.replaceNodeContents(element, html, js); + Templates.render('message/remove_contact_button', {}).done(function(html, js) { + Templates.replaceNodeContents(element, html, js); }); }); }; @@ -137,7 +136,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * add contact button upon success. * * @method removeContact - * @param element jQuery object for the button + * @param {object} element jQuery object for the button */ var removeContact = function(element) { if (isLoading(element)) { @@ -153,8 +152,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust sendRequest(element, request).done(function() { setNotContact(element); - templates.render('message/add_contact_button', {}).done(function(html, js) { - templates.replaceNodeContents(element, html, js); + Templates.render('message/add_contact_button', {}).done(function(html, js) { + Templates.replaceNodeContents(element, html, js); }); }); }; @@ -164,21 +163,21 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * ajax requests to add or remove a contact where appropriate. * * @method enhance - * @param element jQuery object for the button + * @param {object} element jQuery object for the button */ var enhance = function(element) { element = $(element); if (!element.children('.loading-icon').length) { // Add the loading gif if it isn't already there. - templates.render('core/loading', {}).done(function(html, js) { + Templates.render('core/loading', {}).done(function(html, js) { element.append(html, js); }); } - customEvents.define(element, [customEvents.events.activate]); + CustomEvents.define(element, [CustomEvents.events.activate]); - element.on(customEvents.events.activate, function(e, data) { + element.on(CustomEvents.events.activate, function(e, data) { if (isContact(element)) { removeContact(element); } else { diff --git a/message/classes/api.php b/message/classes/api.php index b863d26dedf..1348e5dcfbe 100644 --- a/message/classes/api.php +++ b/message/classes/api.php @@ -24,10 +24,10 @@ namespace core_message; -require_once($CFG->dirroot . '/lib/messagelib.php'); - defined('MOODLE_INTERNAL') || die(); +require_once($CFG->dirroot . '/lib/messagelib.php'); + /** * Class used to return information to display for the message area. * @@ -64,7 +64,7 @@ class api { JOIN {user} u2 ON m.useridto = u2.id LEFT JOIN {message_contacts} mc2 - ON (mc2.contactid = u2.id AND mc2.userid = ?) + ON (mc2.contactid = u2.id AND mc2.userid = ?) WHERE ((useridto = ? AND timeusertodeleted = 0) OR (useridfrom = ? AND timeuserfromdeleted = 0)) AND notification = 0 @@ -79,7 +79,7 @@ class api { JOIN {user} u ON mr.useridfrom = u.id LEFT JOIN {message_contacts} mc - ON (mc.contactid = u.id AND mc.userid = ?) + ON (mc.contactid = u.id AND mc.userid = ?) JOIN {user} u2 ON mr.useridto = u2.id LEFT JOIN {message_contacts} mc2 @@ -144,7 +144,6 @@ class api { ORDER BY " . $DB->sql_fullname(); $params = array_merge(array('userid' => $userid, 'userid2' => $userid, 'search' => '%' . $search . '%'), $params); - // Convert all the user records into contacts. $contacts = array(); if ($users = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) { @@ -189,8 +188,8 @@ class api { AND " . $DB->sql_like($fullname, ':search', false) . " AND u.id $exclude ORDER BY " . $DB->sql_fullname(); - if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'search' => '%' . $search . '%') + - $excludeparams, 0, $limitnum)) { + if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'search' => '%' . $search . '%') + $excludeparams, + 0, $limitnum)) { foreach ($users as $user) { $contacts[] = \core_message\helper::create_contact($user); } @@ -218,12 +217,12 @@ class api { AND u.confirmed = 1 AND " . $DB->sql_like($fullname, ':search', false) . " AND u.id $exclude - AND u.id NOT IN (SELECT contactid - FROM {message_contacts} + AND u.id NOT IN (SELECT contactid + FROM {message_contacts} WHERE userid = :userid) ORDER BY " . $DB->sql_fullname(); - if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'search' => '%' . $search . '%') + - $excludeparams, 0, $limitnum)) { + if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'search' => '%' . $search . '%') + $excludeparams, + 0, $limitnum)) { foreach ($users as $user) { $noncontacts[] = \core_message\helper::create_contact($user); } @@ -342,8 +341,11 @@ class api { $data->country = isset($userfields['country']) ? $userfields['country'] : ''; $data->email = isset($userfields['email']) ? $userfields['email'] : ''; $data->profileimageurl = isset($userfields['profileimageurl']) ? $userfields['profileimageurl'] : ''; - $data->profileimageurlsmall = isset($userfields['profileimageurlsmall']) ? - $userfields['profileimageurlsmall'] : ''; + if (isset($userfields['profileimageurlsmall'])) { + $data->profileimageurlsmall = $userfields['profileimageurlsmall']; + } else { + $data->profileimageurlsmall = ''; + } if (isset($userfields['lastaccess'])) { $data->isonline = \core_message\helper::is_online($userfields['lastaccess']); } else { diff --git a/message/classes/helper.php b/message/classes/helper.php index 62ee8a031de..ead946503d8 100644 --- a/message/classes/helper.php +++ b/message/classes/helper.php @@ -45,7 +45,8 @@ class helper { * @param string $sort * @return array of messages */ - public static function get_messages($userid, $otheruserid, $timedeleted = 0, $limitfrom = 0, $limitnum = 0, $sort = 'timecreated ASC') { + public static function get_messages($userid, $otheruserid, $timedeleted = 0, $limitfrom = 0, $limitnum = 0, + $sort = 'timecreated ASC') { global $DB; $sql = "SELECT id, useridfrom, useridto, subject, fullmessage, fullmessagehtml, fullmessageformat, @@ -153,7 +154,7 @@ class helper { } } // Check if the user is online. - $data->isonline = \core_message\helper::is_online($userfields->lastaccess); + $data->isonline = self::is_online($userfields->lastaccess); $data->isblocked = isset($contact->blocked) ? $contact->blocked : 0; $data->isread = isset($contact->isread) ? $contact->isread : 0; $data->unreadcount = isset($contact->unreadcount) ? $contact->unreadcount : null; diff --git a/message/classes/output/messagearea/contact.php b/message/classes/output/messagearea/contact.php index 07f3476e60e..d63baf2ef1e 100644 --- a/message/classes/output/messagearea/contact.php +++ b/message/classes/output/messagearea/contact.php @@ -24,6 +24,8 @@ namespace core_message\output\messagearea; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; diff --git a/message/classes/output/messagearea/contacts.php b/message/classes/output/messagearea/contacts.php index 8bb4819e061..6164cbc88cf 100644 --- a/message/classes/output/messagearea/contacts.php +++ b/message/classes/output/messagearea/contacts.php @@ -24,6 +24,8 @@ namespace core_message\output\messagearea; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; diff --git a/message/classes/output/messagearea/message.php b/message/classes/output/messagearea/message.php index 284bd320be0..00813498ca4 100644 --- a/message/classes/output/messagearea/message.php +++ b/message/classes/output/messagearea/message.php @@ -24,6 +24,8 @@ namespace core_message\output\messagearea; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; diff --git a/message/classes/output/messagearea/message_area.php b/message/classes/output/messagearea/message_area.php index dba2b867ca1..58b85cff449 100644 --- a/message/classes/output/messagearea/message_area.php +++ b/message/classes/output/messagearea/message_area.php @@ -24,6 +24,8 @@ namespace core_message\output\messagearea; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; diff --git a/message/classes/output/messagearea/message_search_results.php b/message/classes/output/messagearea/message_search_results.php index f2aee38b42c..a2547ecc94c 100644 --- a/message/classes/output/messagearea/message_search_results.php +++ b/message/classes/output/messagearea/message_search_results.php @@ -24,6 +24,8 @@ namespace core_message\output\messagearea; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; diff --git a/message/classes/output/messagearea/messages.php b/message/classes/output/messagearea/messages.php index 5bf0bebc7a2..adf07b406ec 100644 --- a/message/classes/output/messagearea/messages.php +++ b/message/classes/output/messagearea/messages.php @@ -24,6 +24,8 @@ namespace core_message\output\messagearea; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; diff --git a/message/classes/output/messagearea/people_search_results.php b/message/classes/output/messagearea/people_search_results.php index 1ff123555c2..a9ee73bfa46 100644 --- a/message/classes/output/messagearea/people_search_results.php +++ b/message/classes/output/messagearea/people_search_results.php @@ -24,6 +24,8 @@ namespace core_message\output\messagearea; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; diff --git a/message/classes/output/messagearea/profile.php b/message/classes/output/messagearea/profile.php index 1773650396d..53a473f4a6f 100644 --- a/message/classes/output/messagearea/profile.php +++ b/message/classes/output/messagearea/profile.php @@ -24,6 +24,8 @@ namespace core_message\output\messagearea; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; diff --git a/message/classes/output/popup_notification.php b/message/classes/output/popup_notification.php index bd5c37ab210..cc3a9d5a682 100644 --- a/message/classes/output/popup_notification.php +++ b/message/classes/output/popup_notification.php @@ -24,6 +24,8 @@ namespace core_message\output; +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->dirroot . '/message/lib.php'); use renderable; @@ -41,25 +43,22 @@ use core_user; class popup_notification implements templatable, renderable { /** - * The notification. + * @var \stdClass The notification. */ protected $notification; /** - * Indicates if the receiver of the notification should have their - * details embedded in the output. + * @var \stdClass Indicates if the receiver of the notification should have their details embedded in the output. */ protected $embeduserto; /** - * Indicates if the sender of the notification should have their - * details embedded in the output. + * @var \stdClass Indicates if the sender of the notification should have their details embedded in the output. */ protected $embeduserfrom; /** - * A cache for the receiver's full name, if it's already known, so that - * a DB lookup isn't required. + * @var string A cache for the receiver's full name, if it's already known, so that a DB lookup isn't required. */ protected $usertofullname; @@ -67,10 +66,11 @@ class popup_notification implements templatable, renderable { * Constructor. * * @param \stdClass $notification + * @param \stdClass $embeduserto + * @param \stdClass $embeduserfrom + * @param string $usertofullname */ - public function __construct($notification, $embeduserto, - $embeduserfrom, $usertofullname = '') { - + public function __construct($notification, $embeduserto, $embeduserfrom, $usertofullname = '') { $this->notification = $notification; $this->embeduserto = $embeduserto; $this->embeduserfrom = $embeduserfrom; diff --git a/message/classes/output/preferences/message_notification_list.php b/message/classes/output/preferences/message_notification_list.php index 8137a943278..f1f35a8e1e7 100644 --- a/message/classes/output/preferences/message_notification_list.php +++ b/message/classes/output/preferences/message_notification_list.php @@ -15,8 +15,7 @@ // along with Moodle. If not, see . /** - * Contains message_notification_list class for displaying on message preferences - * page. + * Contains message_notification_list class for displaying on message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -25,26 +24,28 @@ namespace core_message\output\preferences; +defined('MOODLE_INTERNAL') || die(); + /** - * Class to create context for the list of notifications on the message - * preferences page. + * Class to create context for the list of notifications on the message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class message_notification_list extends notification_list { + /** * Create the list component output object. * * @param string $component * @param array $readyprocessors * @param array $providers - * @param stdClass $preferences - * @param stdClass $user + * @param \stdClass $preferences + * @param \stdClass $user + * @return message_notification_list_component */ protected function create_list_component($component, $readyprocessors, $providers, $preferences, $user) { - return new \core_message\output\preferences\message_notification_list_component( - $component, $readyprocessors, $providers, $preferences, $user); + return new message_notification_list_component($component, $readyprocessors, $providers, $preferences, $user); } } diff --git a/message/classes/output/preferences/message_notification_list_component.php b/message/classes/output/preferences/message_notification_list_component.php index 4397be82044..32d77519771 100644 --- a/message/classes/output/preferences/message_notification_list_component.php +++ b/message/classes/output/preferences/message_notification_list_component.php @@ -15,8 +15,7 @@ // along with Moodle. If not, see . /** - * Contains notification_list_component class for displaying on message preferences - * page. + * Contains notification_list_component class for displaying on message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -25,20 +24,22 @@ namespace core_message\output\preferences; +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->dirroot . '/message/lib.php'); use renderable; use templatable; /** - * Class to create context for a notification component on the message - * preferences page. + * Class to create context for a notification component on the message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class message_notification_list_component extends notification_list_component { + /** * Determine if the preference should be displayed. * diff --git a/message/classes/output/preferences/notification_list.php b/message/classes/output/preferences/notification_list.php index 2cf934ff1a1..bfba030bb19 100644 --- a/message/classes/output/preferences/notification_list.php +++ b/message/classes/output/preferences/notification_list.php @@ -15,8 +15,7 @@ // along with Moodle. If not, see . /** - * Contains notification_list class for displaying on message preferences - * page. + * Contains notification_list class for displaying on message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -25,13 +24,14 @@ namespace core_message\output\preferences; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; use context_user; /** - * Class to create context for the list of notifications on the message - * preferences page. + * Class to create context for the list of notifications on the message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -40,22 +40,22 @@ use context_user; class notification_list implements templatable, renderable { /** - * A list of message processors. + * @var array A list of message processors. */ protected $processors; /** - * A list of message providers. + * @var array A list of message providers. */ protected $providers; /** - * A list of message preferences. + * @var array A list of message preferences. */ protected $preferences; /** - * A user. + * @var \stdClass A user. */ protected $user; @@ -64,8 +64,8 @@ class notification_list implements templatable, renderable { * * @param array $processors * @param array $providers - * @param stdClass $preferences - * @param stdClass $user + * @param \stdClass $preferences + * @param \stdClass $user */ public function __construct($processors, $providers, $preferences, $user) { $this->processors = $processors; @@ -80,12 +80,12 @@ class notification_list implements templatable, renderable { * @param string $component * @param array $readyprocessors * @param array $providers - * @param stdClass $preferences - * @param stdClass $user + * @param \stdClass $preferences + * @param \stdClass $user + * @return notification_list_component */ protected function create_list_component($component, $readyprocessors, $providers, $preferences, $user) { - return new \core_message\output\preferences\notification_list_component( - $component, $readyprocessors, $providers, $preferences, $user); + return new notification_list_component($component, $readyprocessors, $providers, $preferences, $user); } public function export_for_template(\renderer_base $output) { @@ -102,7 +102,7 @@ class notification_list implements templatable, renderable { foreach ($providers as $provider) { if ($provider->component != 'moodle') { if (substr($provider->component, 0, 4) == 'mod_') { - // Activities + // Activities. $activitycomponents[] = $provider->component; } else { // Other stuff. @@ -111,7 +111,6 @@ class notification_list implements templatable, renderable { } } - $activitycomponents = array_unique($activitycomponents); asort($activitycomponents); $othercomponents = array_unique($othercomponents); diff --git a/message/classes/output/preferences/notification_list_component.php b/message/classes/output/preferences/notification_list_component.php index 5ca1044ad57..8a77d9436cf 100644 --- a/message/classes/output/preferences/notification_list_component.php +++ b/message/classes/output/preferences/notification_list_component.php @@ -15,8 +15,7 @@ // along with Moodle. If not, see . /** - * Contains notification_list_component class for displaying on message preferences - * page. + * Contains notification_list_component class for displaying on message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -25,14 +24,15 @@ namespace core_message\output\preferences; +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->dirroot . '/message/lib.php'); use renderable; use templatable; /** - * Class to create context for a notification component on the message - * preferences page. + * Class to create context for a notification component on the message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -41,27 +41,27 @@ use templatable; class notification_list_component implements templatable, renderable { /** - * A list of message processors. + * @var array A list of message processors. */ protected $processors; /** - * A list of message providers. + * @var array A list of message providers. */ protected $providers; /** - * A list of message preferences. + * @var array A list of message preferences. */ protected $preferences; /** - * The component name. + * @var string The component name. */ protected $component; /** - * A user. + * @var \stdClass A user. */ protected $user; @@ -71,7 +71,8 @@ class notification_list_component implements templatable, renderable { * @param string $component * @param array $processors * @param array $providers - * @param stdClass $preferences + * @param \stdClass $preferences + * @param \stdClass $user */ public function __construct($component, $processors, $providers, $preferences, $user) { $this->processors = $processors; @@ -84,7 +85,7 @@ class notification_list_component implements templatable, renderable { /** * Get the base key prefix for the given provider. * - * @param stdClass message provider + * @param \stdClass $provider The message provider * @return string */ private function get_preference_base($provider) { @@ -94,7 +95,7 @@ class notification_list_component implements templatable, renderable { /** * Get the display name for the given provider. * - * @param stdClass $provider message provider + * @param \stdClass $provider The message provider * @return string */ private function get_provider_display_name($provider) { @@ -152,7 +153,7 @@ class notification_list_component implements templatable, renderable { ]; foreach ($processors as $processor) { - $notificationprocessor = new \core_message\output\preferences\notification_list_processor($processor, $provider, $preferences); + $notificationprocessor = new notification_list_processor($processor, $provider, $preferences); $notificationcontext['processors'][] = $notificationprocessor->export_for_template($output); } diff --git a/message/classes/output/preferences/notification_list_processor.php b/message/classes/output/preferences/notification_list_processor.php index b334b109767..b24f712c4fc 100644 --- a/message/classes/output/preferences/notification_list_processor.php +++ b/message/classes/output/preferences/notification_list_processor.php @@ -15,8 +15,7 @@ // along with Moodle. If not, see . /** - * Contains notification_list_processor class for displaying on message preferences - * page. + * Contains notification_list_processor class for displaying on message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -25,14 +24,15 @@ namespace core_message\output\preferences; +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->dirroot . '/message/lib.php'); use renderable; use templatable; /** - * Class to create context for a notification component on the message - * preferences page. + * Class to create context for a notification component on the message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -41,26 +41,26 @@ use templatable; class notification_list_processor implements templatable, renderable { /** - * A notification processor. + * @var \stdClass A notification processor. */ protected $processor; /** - * A notification provider. + * @var \stdClass A notification provider. */ protected $provider; /** - * A list of message preferences. + * @var \stdClass A list of message preferences. */ protected $preferences; /** * Constructor. * - * @param stdClass $processor - * @param stdClass $provider - * @param stdClass $preferences + * @param \stdClass $processor + * @param \stdClass $provider + * @param \stdClass $preferences */ public function __construct($processor, $provider, $preferences) { $this->processor = $processor; @@ -81,8 +81,6 @@ class notification_list_processor implements templatable, renderable { * Check if the given preference is enabled or not. * * @param string $name preference name - * @param stdClass $processor the processors for the preference - * @param stdClass $preferences the preferences config * @return bool */ private function is_preference_enabled($name) { @@ -91,12 +89,12 @@ class notification_list_processor implements templatable, renderable { $defaultpreferences = get_message_output_default_preferences(); $checked = false; - // See if user has touched this preference + // See if user has touched this preference. if (isset($preferences->{$name})) { - // User have some preferneces for this state in the database, use them + // User has some preferences for this state in the database. $checked = isset($preferences->{$name}[$processor->name]); } else { - // User has not set this preference yet, using site default preferences set by admin + // User has not set this preference yet, using site default preferences set by admin. $defaultpreference = 'message_provider_'.$name; if (isset($defaultpreferences->{$defaultpreference})) { $checked = (int)in_array($processor->name, explode(',', $defaultpreferences->{$defaultpreference})); @@ -108,9 +106,7 @@ class notification_list_processor implements templatable, renderable { public function export_for_template(\renderer_base $output) { $processor = $this->processor; - $provider = $this->provider; - $preferences = $this->preferences; - $preferencebase = $this->get_preference_base($provider); + $preferencebase = $this->get_preference_base(); $permitted = MESSAGE_DEFAULT_PERMITTED; $defaultpreferences = get_message_output_default_preferences(); $defaultpreference = $processor->name.'_provider_'.$preferencebase.'_permitted'; @@ -122,21 +118,20 @@ class notification_list_processor implements templatable, renderable { 'loggedin' => [ 'name' => 'loggedin', 'displayname' => get_string('loggedindescription', 'message'), - 'checked' => $this->is_preference_enabled($preferencebase.'_loggedin', $processor, $preferences), + 'checked' => $this->is_preference_enabled($preferencebase.'_loggedin'), ], 'loggedoff' => [ 'name' => 'loggedoff', 'displayname' => get_string('loggedoffdescription', 'message'), - 'checked' => $this->is_preference_enabled($preferencebase.'_loggedoff', $processor, $preferences), + 'checked' => $this->is_preference_enabled($preferencebase.'_loggedoff'), ], ]; - // determine the default setting + // Determine the default setting. if (isset($defaultpreferences->{$defaultpreference})) { $permitted = $defaultpreferences->{$defaultpreference}; } - // If settings are disallowed or forced, just display the - // corresponding message, if not use user settings. + // If settings are disallowed or forced, just display the corresponding message, if not use user settings. if ($permitted == 'disallowed') { $context['locked'] = true; $context['lockedmessage'] = get_string('disallowed', 'message'); diff --git a/message/classes/output/preferences/processor.php b/message/classes/output/preferences/processor.php index e868a08b04a..c743b125e94 100644 --- a/message/classes/output/preferences/processor.php +++ b/message/classes/output/preferences/processor.php @@ -15,8 +15,7 @@ // along with Moodle. If not, see . /** - * Contains processor class for displaying on message preferences - * page. + * Contains processor class for displaying on message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -25,12 +24,13 @@ namespace core_message\output\preferences; +defined('MOODLE_INTERNAL') || die(); + use renderable; use templatable; /** - * Class to create context for one of the message processors settings - * on the message preferences page. + * Class to create context for one of the message processors settings on the message preferences page. * * @package core_message * @copyright 2016 Ryan Wyllie @@ -39,31 +39,32 @@ use templatable; class processor implements templatable, renderable { /** - * The message processor. + * @var \stdClass The message processor. */ protected $processor; /** - * A list of message preferences. + * @var \stdClass list of message preferences. */ protected $preferences; /** - * A user. + * @var \stdClass A user. */ protected $user; /** - * The processor type. + * @var string The processor type. */ protected $type; /** * Constructor. * - * @param stdClass $processor - * @param stdClass $preferences - * @param stdClass $user + * @param \stdClass $processor + * @param \stdClass $preferences + * @param \stdClass $user + * @param string $type */ public function __construct($processor, $preferences, $user, $type) { $this->processor = $processor; diff --git a/message/classes/output/processor.php b/message/classes/output/processor.php index 5ca7038ca87..fa374544c57 100644 --- a/message/classes/output/processor.php +++ b/message/classes/output/processor.php @@ -24,6 +24,8 @@ namespace core_message\output; +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->dirroot . '/message/lib.php'); use renderable; @@ -39,12 +41,12 @@ use templatable; class processor implements templatable, renderable { /** - * The message processor + * @var \stdClass The message processor */ protected $processor; /** - * The user + * @var \stdClass The user */ protected $user; diff --git a/message/externallib.php b/message/externallib.php index 28472423bfe..8642aded798 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -498,7 +498,8 @@ class core_message_external extends external_api { * @throws moodle_exception * @since 3.2 */ - public static function data_for_messagearea_search_people_in_course($userid, $courseid, $search, $limitfrom = 0, $limitnum = 0) { + public static function data_for_messagearea_search_people_in_course($userid, $courseid, $search, $limitfrom = 0, + $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. @@ -865,7 +866,8 @@ class core_message_external extends external_api { * @throws moodle_exception * @since 3.2 */ - public static function data_for_messagearea_messages($currentuserid, $otheruserid, $limitfrom = 0, $limitnum = 0, $newest = false) { + public static function data_for_messagearea_messages($currentuserid, $otheruserid, $limitfrom = 0, $limitnum = 0, + $newest = false) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. @@ -909,7 +911,8 @@ class core_message_external extends external_api { public static function data_for_messagearea_messages_returns() { return new external_single_structure( array( - 'iscurrentuser' => new external_value(PARAM_BOOL, 'Is the currently logged in user the user we are viewing the messages on behalf of?'), + 'iscurrentuser' => new external_value(PARAM_BOOL, 'Is the currently logged in user the user we are viewing + the messages on behalf of?'), 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), 'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'), 'otheruserfullname' => new external_value(PARAM_NOTAGS, 'The other user\'s fullname'), @@ -1042,7 +1045,8 @@ class core_message_external extends external_api { public static function data_for_messagearea_get_profile_returns() { return new external_single_structure( array( - 'iscurrentuser' => new external_value(PARAM_BOOL, 'Is the currently logged in user the user we are viewing the profile on behalf of?'), + 'iscurrentuser' => new external_value(PARAM_BOOL, 'Is the currently logged in user the user we are viewing + the profile on behalf of?'), 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), 'otheruserid' => new external_value(PARAM_INT, 'The id of the user whose profile we are viewing'), 'email' => new external_value(core_user::get_property_type('email'), 'An email address'), @@ -1071,7 +1075,6 @@ class core_message_external extends external_api { /** * Get contacts. * - * @param array $userids array of user IDs. * @return external_description * @since Moodle 2.5 */ @@ -1581,7 +1584,8 @@ class core_message_external extends external_api { } $sort = $newestfirst ? 'DESC' : 'ASC'; - $notifications = \core_message\api::get_popup_notifications($useridto, $status, $embeduserto, $embeduserfrom, $sort, $limit, $offset); + $notifications = \core_message\api::get_popup_notifications($useridto, $status, $embeduserto, + $embeduserfrom, $sort, $limit, $offset); $notificationcontexts = []; if ($notifications) { @@ -1625,11 +1629,13 @@ class core_message_external extends external_api { 'notifications' => new external_multiple_structure( new external_single_structure( array( - 'id' => new external_value(PARAM_INT, 'Notification id (this is not guaranteed to be unique within this result set)'), + 'id' => new external_value(PARAM_INT, 'Notification id (this is not guaranteed to be unique + within this result set)'), 'useridfrom' => new external_value(PARAM_INT, 'User from id'), 'useridto' => new external_value(PARAM_INT, 'User to id'), 'subject' => new external_value(PARAM_TEXT, 'The notification subject'), - 'shortenedsubject' => new external_value(PARAM_TEXT, 'The notification subject shortened with ellipsis'), + 'shortenedsubject' => new external_value(PARAM_TEXT, 'The notification subject shortened + with ellipsis'), 'text' => new external_value(PARAM_RAW, 'The message text formated'), 'fullmessage' => new external_value(PARAM_RAW, 'The message'), 'fullmessageformat' => new external_format_value('fullmessage'), @@ -1646,7 +1652,8 @@ class core_message_external extends external_api { 'read' => new external_value(PARAM_BOOL, 'notification read status'), 'deleted' => new external_value(PARAM_BOOL, 'notification deletion status'), 'iconurl' => new external_value(PARAM_URL, 'URL for notification icon'), - 'component' => new external_value(PARAM_TEXT, 'The component that generated the notification', VALUE_OPTIONAL), + 'component' => new external_value(PARAM_TEXT, 'The component that generated the notification', + VALUE_OPTIONAL), 'eventtype' => new external_value(PARAM_TEXT, 'The type of notification', VALUE_OPTIONAL), ), 'message' ) @@ -1715,7 +1722,7 @@ class core_message_external extends external_api { // Check if the current user is the sender/receiver or just a privileged user. if ($useridto != $USER->id and $useridfrom != $USER->id and - // deleteanymessage seems more reasonable here than readallmessages. + // The deleteanymessage cap seems more reasonable here than readallmessages. !has_capability('moodle/site:deleteanymessage', $context)) { throw new moodle_exception('accessdenied', 'admin'); } @@ -1972,7 +1979,8 @@ class core_message_external extends external_api { return new external_function_parameters( array( 'messageid' => new external_value(PARAM_INT, 'id of the message (in the message table)'), - 'timeread' => new external_value(PARAM_INT, 'timestamp for when the message should be marked read', VALUE_DEFAULT, 0) + 'timeread' => new external_value(PARAM_INT, 'timestamp for when the message should be marked read', + VALUE_DEFAULT, 0) ) ); } @@ -2104,7 +2112,7 @@ class core_message_external extends external_api { // Check if the current user is the sender/receiver or just a privileged user. if ($useridto != $USER->id and $useridfrom != $USER->id and - // deleteanymessage seems more reasonable here than readallmessages. + // The deleteanymessage cap seems more reasonable here than readallmessages. !has_capability('moodle/site:deleteanymessage', $context)) { throw new moodle_exception('accessdenied', 'admin'); } @@ -2383,7 +2391,8 @@ class core_message_external extends external_api { /** * Get a message processor. * - * @param string $name the name of the processor + * @param int $userid + * @param string $name the name of the processor * @return external_description * @throws moodle_exception * @since 3.2 diff --git a/message/lib.php b/message/lib.php index a53ee0579fb..3ed279c34f3 100644 --- a/message/lib.php +++ b/message/lib.php @@ -47,10 +47,10 @@ define('MESSAGE_SEARCH_MAX_RESULTS', 200); define('MESSAGE_CONTACTS_PER_PAGE',10); define('MESSAGE_MAX_COURSE_NAME_LENGTH', 30); -define('MESSAGE_UNREAD','unread'); -define('MESSAGE_READ','read'); -define('MESSAGE_TYPE_NOTIFICATION','notification'); -define('MESSAGE_TYPE_MESSAGE','message'); +define('MESSAGE_UNREAD', 'unread'); +define('MESSAGE_READ', 'read'); +define('MESSAGE_TYPE_NOTIFICATION', 'notification'); +define('MESSAGE_TYPE_MESSAGE', 'message'); /** diff --git a/message/notificationpreferences.php b/message/notificationpreferences.php index 7f6abf7328e..322a913c586 100644 --- a/message/notificationpreferences.php +++ b/message/notificationpreferences.php @@ -53,18 +53,18 @@ $personalcontext = context_user::instance($user->id); $PAGE->set_context($personalcontext); $PAGE->set_pagelayout('admin'); -// check access control +// Check access control. if ($user->id == $USER->id) { - //editing own message profile + // Editing own message profile. require_capability('moodle/user:editownmessageprofile', $systemcontext); } else { - // teachers, parents, etc. + // Teachers, parents, etc. require_capability('moodle/user:editmessageprofile', $personalcontext); - // no editing of guest user account + // No editing of guest user account. if (isguestuser($user->id)) { print_error('guestnoeditmessageother', 'message'); } - // no editing of admins by non admins! + // No editing of admins by non admins! if (is_siteadmin($user) and !is_siteadmin($USER)) { print_error('useradmineditadmin'); } @@ -72,12 +72,12 @@ if ($user->id == $USER->id) { $PAGE->navigation->extend_for_user($user); } -/// Display page header +// Display page header. $strmessaging = get_string('notificationpreferences', 'message'); $PAGE->set_title($strmessaging); $PAGE->set_heading(fullname($user)); -// Grab the renderer +// Grab the renderer. $renderer = $PAGE->get_renderer('core', 'message'); $messagingoptions = $renderer->render_user_notification_preferences($user); diff --git a/message/output/popup/db/events.php b/message/output/popup/db/events.php index 617b8ad02af..3df04ba306f 100644 --- a/message/output/popup/db/events.php +++ b/message/output/popup/db/events.php @@ -17,12 +17,14 @@ /** * Event observers definition. * - * @package message_output_popup + * @package message_popup * @category event * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + $observers = array( // Message viewed. diff --git a/message/renderer.php b/message/renderer.php index 844f8769a7b..f1e37e9916b 100644 --- a/message/renderer.php +++ b/message/renderer.php @@ -224,10 +224,12 @@ class core_message_renderer extends plugin_renderer_base { public function render_user_notification_preferences($user) { $processors = get_message_processors(); $providers = message_get_providers_for_user($user->id); - $preferences = \core_message\api::get_all_message_preferences($processors, $providers, $user); - $notificationlistoutput = new \core_message\output\preferences\notification_list($processors, $providers, $preferences, $user); - return $this->render_from_template('message/preferences_notifications_list', $notificationlistoutput->export_for_template($this)); + $preferences = \core_message\api::get_all_message_preferences($processors, $providers, $user); + $notificationlistoutput = new \core_message\output\preferences\notification_list($processors, $providers, + $preferences, $user); + return $this->render_from_template('message/preferences_notifications_list', + $notificationlistoutput->export_for_template($this)); } /** @@ -251,7 +253,8 @@ class core_message_renderer extends plugin_renderer_base { return $provider->component === 'moodle'; }); $preferences = \core_message\api::get_all_message_preferences($readyprocessors, $providers, $user); - $notificationlistoutput = new \core_message\output\preferences\message_notification_list($readyprocessors, $providers, $preferences, $user); + $notificationlistoutput = new \core_message\output\preferences\message_notification_list($readyprocessors, + $providers, $preferences, $user); $context = $notificationlistoutput->export_for_template($this); $context['blocknoncontacts'] = get_user_preferences('message_blocknoncontacts', '', $user->id) ? true : false; diff --git a/message/tests/externallib_test.php b/message/tests/externallib_test.php index 850ae8fafa0..8beba1799f9 100644 --- a/message/tests/externallib_test.php +++ b/message/tests/externallib_test.php @@ -110,9 +110,11 @@ class core_message_externallib_testcase extends externallib_advanced_testcase { * @param stdClass $userto user object of the one receiving the message. * @param string $message message to send. * @param int $timecreated time the message was created. + * @param int $timeread the the message was read * @return int the id of the message */ - protected function send_fake_read_popup_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0, $timeread = 0) { + protected function send_fake_read_popup_notification($userfrom, $userto, $message = 'Hello world!', + $timecreated = 0, $timeread = 0) { global $DB; $record = new stdClass(); diff --git a/message/tests/messagelib_test.php b/message/tests/messagelib_test.php index 2d0b17aaace..cf50693078e 100644 --- a/message/tests/messagelib_test.php +++ b/message/tests/messagelib_test.php @@ -125,9 +125,11 @@ class core_message_messagelib_testcase extends advanced_testcase { * @param stdClass $userto user object of the one receiving the message. * @param string $message message to send. * @param int $timecreated time the message was created. + * @param int $timeread the the message was read * @return int the id of the message */ - protected function send_fake_read_popup_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0, $timeread = 0) { + protected function send_fake_read_popup_notification($userfrom, $userto, $message = 'Hello world!', + $timecreated = 0, $timeread = 0) { global $DB; $record = new stdClass(); diff --git a/theme/bootstrapbase/less/moodle/message.less b/theme/bootstrapbase/less/moodle/message.less index a39099326c6..2430b242919 100644 --- a/theme/bootstrapbase/less/moodle/message.less +++ b/theme/bootstrapbase/less/moodle/message.less @@ -20,7 +20,7 @@ .status { .online-text { display: none; - color: #77dd77; + color: #7d7; } .offline-text { diff --git a/theme/bootstrapbase/less/moodle/popover_region.less b/theme/bootstrapbase/less/moodle/popover_region.less index 3a456b7b615..020d4c5957b 100644 --- a/theme/bootstrapbase/less/moodle/popover_region.less +++ b/theme/bootstrapbase/less/moodle/popover_region.less @@ -398,7 +398,6 @@ width: 30px; display: inline-block; text-align: center; - vertical-align: middle; float: left; img { diff --git a/theme/bootstrapbase/style/moodle.css b/theme/bootstrapbase/style/moodle.css index 4c403f7e39d..c2f9d0d30bf 100644 --- a/theme/bootstrapbase/style/moodle.css +++ b/theme/bootstrapbase/style/moodle.css @@ -5771,7 +5771,7 @@ a.ygtvspacer:hover { } .messaging-area-container .status .online-text { display: none; - color: #77dd77; + color: #7d7; } .messaging-area-container .status .offline-text { color: #ff6961; @@ -7786,7 +7786,6 @@ body.path-question-type .mform fieldset.hidden { width: 30px; display: inline-block; text-align: center; - vertical-align: middle; float: left; } .popover-region-messages.popover-region .popover-region-container .popover-region-content-container .popover-region-content .content-item-container .content-item .profile-image-container img {