MDL-83518 core_message: Add processor restriction support
This commit is contained in:
@@ -139,6 +139,7 @@ $string['notificationimage'] = 'Notification image';
|
||||
$string['notifications'] = 'Notifications';
|
||||
$string['notincontactsheading'] = '{$a} is not in your contacts';
|
||||
$string['notincontacts'] = 'You need to add {$a} to your contacts to be able to send them messages.';
|
||||
$string['notsupported'] = 'Not supported';
|
||||
$string['numparticipants'] = '{$a} participants';
|
||||
$string['off'] = 'Off';
|
||||
$string['offline'] = 'Offline';
|
||||
|
||||
+38
-10
@@ -24,6 +24,7 @@
|
||||
|
||||
namespace core_message;
|
||||
use DOMDocument;
|
||||
use stdclass;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -137,7 +138,7 @@ class helper {
|
||||
|
||||
foreach ($messages as $message) {
|
||||
// Store the message information.
|
||||
$msg = new \stdClass();
|
||||
$msg = new stdClass();
|
||||
$msg->id = $message->id;
|
||||
$msg->useridfrom = $message->useridfrom;
|
||||
$msg->text = message_format_message_text($message);
|
||||
@@ -172,16 +173,16 @@ class helper {
|
||||
/**
|
||||
* Helper function for creating a contact object.
|
||||
*
|
||||
* @param \stdClass $contact
|
||||
* @param stdClass $contact
|
||||
* @param string $prefix
|
||||
* @return \stdClass
|
||||
* @return stdClass
|
||||
*/
|
||||
public static function create_contact($contact, $prefix = '') {
|
||||
global $PAGE;
|
||||
|
||||
// Create the data we are going to pass to the renderable.
|
||||
$userfields = \user_picture::unalias($contact, array('lastaccess'), $prefix . 'id', $prefix);
|
||||
$data = new \stdClass();
|
||||
$data = new stdClass();
|
||||
$data->userid = $userfields->id;
|
||||
$data->useridfrom = null;
|
||||
$data->fullname = fullname($userfields);
|
||||
@@ -222,7 +223,7 @@ class helper {
|
||||
/**
|
||||
* Helper function for checking if we should show the user's online status.
|
||||
*
|
||||
* @param \stdClass $user
|
||||
* @param stdClass $user
|
||||
* @return boolean
|
||||
*/
|
||||
public static function show_online_status($user) {
|
||||
@@ -263,10 +264,10 @@ class helper {
|
||||
*
|
||||
* @param array $providers
|
||||
* @param int $userid
|
||||
* @return \stdClass
|
||||
* @return stdClass
|
||||
*/
|
||||
public static function get_providers_preferences($providers, $userid) {
|
||||
$preferences = new \stdClass();
|
||||
$preferences = new stdClass();
|
||||
|
||||
// Get providers preferences.
|
||||
foreach ($providers as $provider) {
|
||||
@@ -453,7 +454,7 @@ class helper {
|
||||
$members = [];
|
||||
foreach ($otherusers as $member) {
|
||||
// Set basic data.
|
||||
$data = new \stdClass();
|
||||
$data = new stdClass();
|
||||
$data->id = $member->id;
|
||||
$data->fullname = fullname($member);
|
||||
|
||||
@@ -668,12 +669,12 @@ class helper {
|
||||
* * deleted
|
||||
* * all potential fullname fields
|
||||
*
|
||||
* @param \stdClass $user
|
||||
* @param stdClass $user
|
||||
* @param array $userfields An array of userfields to be returned, the values must be a
|
||||
* subset of user_get_default_fields (optional)
|
||||
* @return array the array of userdetails, if visible, or an empty array otherwise.
|
||||
*/
|
||||
public static function search_get_user_details(\stdClass $user, array $userfields = []): array {
|
||||
public static function search_get_user_details(stdClass $user, array $userfields = []): array {
|
||||
global $CFG, $USER;
|
||||
require_once($CFG->dirroot . '/user/lib.php');
|
||||
|
||||
@@ -721,4 +722,31 @@ class helper {
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the support for SMS in different components.
|
||||
*
|
||||
* At the moment, SMS is not supported for all the components.
|
||||
* Components that supports SMS, can implement the callback to let the notification API support them.
|
||||
*
|
||||
* @param stdclass $messagedata The message data
|
||||
* @return bool
|
||||
*/
|
||||
public static function supports_sms_notifications(stdclass $messagedata): bool {
|
||||
// Notification API assigns system ones as component 'moodle'.
|
||||
// We need a special mechanism to handle that as component callback will throw errors.
|
||||
if ($messagedata->component === 'moodle') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$smssupport = component_callback(
|
||||
$messagedata->component,
|
||||
'supports_sms_notifications'
|
||||
);
|
||||
|
||||
if (empty($smssupport)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +150,12 @@ class notification_list_processor implements templatable, renderable {
|
||||
}
|
||||
}
|
||||
|
||||
$supportsprocessor = true;
|
||||
if ($processor->name === 'sms') {
|
||||
$supportsprocessor = \core_message\helper::supports_sms_notifications($this->provider);
|
||||
}
|
||||
$context['supportsprocessor'] = $supportsprocessor;
|
||||
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,12 @@ class core_message_renderer extends plugin_renderer_base {
|
||||
foreach ($processors as $processor) {
|
||||
$setting = new StdClass();
|
||||
|
||||
$supportsprocessor = true;
|
||||
if ($processor->name === 'sms') {
|
||||
$supportsprocessor = core_message\helper::supports_sms_notifications($provider);
|
||||
}
|
||||
$setting->supportsprocessor = $supportsprocessor;
|
||||
|
||||
$setting->lockedsetting = $providersettingprefix.'locked['.$processor->name.']';
|
||||
$preference = $processor->name.'_provider_'.$providersettingprefix.'locked';
|
||||
|
||||
|
||||
@@ -59,7 +59,8 @@
|
||||
"lockedlabel": "Sending Assignment via Web locked status",
|
||||
"enabledsetting": "mod_assign_assign_notification_enabled[popup]",
|
||||
"enabled": 1,
|
||||
"enabledlabel": "Sending Assignment via Web enabled status"
|
||||
"enabledlabel": "Sending Assignment via Web enabled status",
|
||||
"supportsprocessor": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -106,34 +107,41 @@
|
||||
</td>
|
||||
{{#settings}}
|
||||
<td class="text-start">
|
||||
<div data-preference="{{{enabledsetting}}}">
|
||||
<div class="form-check form-switch {{#locked}} dimmed_text{{/locked}} pb-1">
|
||||
<input type="checkbox"
|
||||
id="{{{enabledsetting}}}"
|
||||
name="{{{enabledsetting}}}"
|
||||
class="form-check-input enabled_message_setting"
|
||||
{{#enabled}}checked{{/enabled}}
|
||||
>
|
||||
<label for="{{{enabledsetting}}}" class="form-check-label"
|
||||
title="{{enabledlabel}}">
|
||||
{{#str}} enabled, core_message {{/str}}
|
||||
</label>
|
||||
{{#supportsprocessor}}
|
||||
<div data-preference="{{{enabledsetting}}}">
|
||||
<div class="form-check form-switch {{#locked}} dimmed_text{{/locked}} pb-1">
|
||||
<input type="checkbox"
|
||||
id="{{{enabledsetting}}}"
|
||||
name="{{{enabledsetting}}}"
|
||||
class="form-check-input enabled_message_setting"
|
||||
{{#enabled}}checked{{/enabled}}
|
||||
>
|
||||
<label for="{{{enabledsetting}}}" class="form-check-label"
|
||||
title="{{enabledlabel}}">
|
||||
{{#str}} enabled, core_message {{/str}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-preference="{{{lockedsetting}}}">
|
||||
<div class="form-check form-switch pt-1">
|
||||
<input type="checkbox"
|
||||
id="{{{lockedsetting}}}"
|
||||
name="{{{lockedsetting}}}"
|
||||
class="form-check-input locked_message_setting"
|
||||
{{#locked}}checked{{/locked}}
|
||||
>
|
||||
<label for="{{{lockedsetting}}}" class="form-check-label"
|
||||
title="{{lockedlabel}}">
|
||||
{{#str}} forced, core_message {{/str}}
|
||||
</label>
|
||||
<div data-preference="{{{lockedsetting}}}">
|
||||
<div class="form-check form-switch pt-1">
|
||||
<input type="checkbox"
|
||||
id="{{{lockedsetting}}}"
|
||||
name="{{{lockedsetting}}}"
|
||||
class="form-check-input locked_message_setting"
|
||||
{{#locked}}checked{{/locked}}
|
||||
>
|
||||
<label for="{{{lockedsetting}}}" class="form-check-label"
|
||||
title="{{lockedlabel}}">
|
||||
{{#str}} forced, core_message {{/str}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/supportsprocessor}}
|
||||
{{^supportsprocessor}}
|
||||
<div class="text-center">
|
||||
{{#str}} notsupported, core_message {{/str}}
|
||||
</div>
|
||||
{{/supportsprocessor}}
|
||||
</td>
|
||||
{{/settings}}
|
||||
</tr>
|
||||
|
||||
@@ -41,7 +41,8 @@
|
||||
"locked": 0,
|
||||
"userconfigured": 1,
|
||||
"enabled": 1,
|
||||
"enabledlabel": "Sending Assignment enabled status"
|
||||
"enabledlabel": "Sending Assignment enabled status",
|
||||
"supportsprocessor": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -50,27 +51,34 @@
|
||||
<td class="preference-name">{{{displayname}}}</td>
|
||||
{{#processors}}
|
||||
<td {{^userconfigured}}class="disabled"{{/userconfigured}} data-processor-name="{{name}}">
|
||||
{{#locked}}
|
||||
<div class="dimmed_text" title="{{lockedlabel}}">{{{lockedmessage}}}</div>
|
||||
{{/locked}}
|
||||
{{^locked}}
|
||||
<form>
|
||||
<div class="preference-state" data-preference="{{{preferencekey}}}_{{{name}}}">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox"
|
||||
id="{{{preferencekey}}}_{{{name}}}"
|
||||
name="{{{preferencekey}}}_{{{name}}}"
|
||||
class="form-check-input notification_enabled{{#disableall}} disabled{{/disableall}}"
|
||||
{{#disableall}} disabled="true" {{/disableall}}
|
||||
{{#enabled}}checked{{/enabled}}
|
||||
>
|
||||
<label for="{{{preferencekey}}}_{{{name}}}" class="form-check-label"
|
||||
title="{{enabledlabel}}" >
|
||||
</label>
|
||||
{{#supportsprocessor}}
|
||||
{{#locked}}
|
||||
<div class="dimmed_text" title="{{lockedlabel}}">{{{lockedmessage}}}</div>
|
||||
{{/locked}}
|
||||
{{^locked}}
|
||||
<form>
|
||||
<div class="preference-state" data-preference="{{{preferencekey}}}_{{{name}}}">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox"
|
||||
id="{{{preferencekey}}}_{{{name}}}"
|
||||
name="{{{preferencekey}}}_{{{name}}}"
|
||||
class="form-check-input notification_enabled{{#disableall}} disabled{{/disableall}}"
|
||||
{{#disableall}} disabled="true" {{/disableall}}
|
||||
{{#enabled}}checked{{/enabled}}
|
||||
>
|
||||
<label for="{{{preferencekey}}}_{{{name}}}" class="form-check-label"
|
||||
title="{{enabledlabel}}" >
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{{/locked}}
|
||||
</form>
|
||||
{{/locked}}
|
||||
{{/supportsprocessor}}
|
||||
{{^supportsprocessor}}
|
||||
<div class="text-center">
|
||||
{{#str}} notsupported, core_message {{/str}}
|
||||
</div>
|
||||
{{/supportsprocessor}}
|
||||
</td>
|
||||
{{/processors}}
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user