Skip to content

Commit

Permalink
MDL-81732 core_sms: Add SMS gateway management UI
Browse files Browse the repository at this point in the history
  • Loading branch information
safatshahin authored and mickhawkins committed Aug 26, 2024
1 parent e0c5f25 commit 1e982a0
Show file tree
Hide file tree
Showing 34 changed files with 1,692 additions and 36 deletions.
31 changes: 31 additions & 0 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,37 @@
}
}

// SMS plugins.
if ($hassiteconfig) {
$ADMIN->add(
'modules',
new admin_category(
'sms',
new lang_string('sms', 'core_sms'),
),
);
$ADMIN->add(
'sms',
new admin_externalpage(
'smsgateway',
new lang_string('manage_sms_gateways', 'core_sms'),
$CFG->wwwroot . '/sms/sms_gateways.php',
),
);
foreach (core_component::get_plugin_list('smsgateway') as $plugin => $path) {
$settingspath = $path . '/settings.php';
if (file_exists($settingspath)) {
$settings = new admin_settingpage(
'smsgateway_' . $plugin . '_settings',
new lang_string('pluginname', 'smsgateway_' . $plugin),
'moodle/site:config',
);
include($settingspath);
$ADMIN->add('smsgateway', $settings);
}
}
}

// Content bank content types.
if ($hassiteconfig) {
$ADMIN->add('modules', new admin_category('contentbanksettings', new lang_string('contentbank')));
Expand Down
2 changes: 2 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@
$string['digitalminor_desc'] = 'Please ask your parent/guardian to contact:';
$string['directory'] = 'Directory';
$string['disable'] = 'Disable';
$string['disabled'] = 'Disabled';
$string['disabledcomments'] = 'Comments are disabled';
$string['dismissnotification'] = 'Dismiss this notification';
$string['displayingfirst'] = 'Only the first {$a->count} {$a->things} are displayed';
Expand Down Expand Up @@ -790,6 +791,7 @@
$string['emptydragdropregion'] = 'empty region';
$string['emptysectionids'] = 'Empty section IDs';
$string['enable'] = 'Enable';
$string['enabled'] = 'Enabled';
$string['encryptedcode'] = 'Encrypted code';
$string['enddate'] = 'Course end date';
$string['enddate_help'] = 'The end date doesn’t restrict student access to the course. It determines whether a course is listed as Past in My courses.';
Expand Down
16 changes: 16 additions & 0 deletions lang/en/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
* @copyright 2024 Andrew Lyons <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['actions'] = 'Actions';
$string['configure_sms_gateway'] = 'Configure SMS gateway';
$string['countrycode'] = 'Country code';
$string['countrycode_help'] = 'Set the default phone number format to exclude the "+" symbol if user does not enter an international number with it.';
$string['createnewgateway'] = 'Create a new SMS gateway';
$string['delete_sms_gateway'] = 'Delete SMS gateway';
$string['delete_sms_gateway_confirmation'] = 'Are you sure you want to delete the SMS gateway?';
$string['gateway'] = 'Gateway';
$string['gateway_name'] = 'Gateway name';
$string['manage_sms_gateways'] = 'Manage SMS gateways';
$string['phonenumbernotvalid'] = 'Format of phone number not recognised: {$a->message}';
$string['privacy:metadata:sms_messages'] = 'Stores messages sent via SMS';
$string['privacy:metadata:sms_messages:content'] = 'The message text';
Expand All @@ -32,10 +42,16 @@
$string['privacy:metadata:sms_messages:timecreated'] = 'The time the message was created';
$string['privacy:sms:sensitive_not_shown'] = 'The content of this message was not stored as it was marked as containing sensitive content.';
$string['sms'] = 'SMS';
$string['sms_form_information'] = 'This page allow you to set up and manage your SMS gateway for sending text messages.';
$string['status:gateway_failed'] = 'The gateway has failed to send the message';
$string['status:gateway_not_available'] = 'The gateway is not available to send the message';
$string['status:gateway_queued'] = 'The message is queued to be sent by the gateway';
$string['status:gateway_rejected'] = 'The gateway has rejected the message';
$string['status:gateway_sent'] = 'The message has been sent by the gateway';
$string['status:message_over_size'] = 'The message is too large to be sent by the gateway';
$string['status:unknown'] = 'Unable to determine the status of the message';
$string['sms_gateways'] = 'SMS gateways';
$string['sms_gateway_deleted'] = '{$a->gateway} SMS gateway has been deleted';
$string['sms_gateway_delete_failed'] = 'Cannot delete the {$a->gateway} SMS gateway. The gateway is either in use or there\'s a database issue. Check if the gateway is active or contact your database administrator for help.';
$string['sms_gateway_disable_failed'] = 'Cannot disable the SMS gateway. The gateway is either in use or there\'s a database issue. Check if the gateway is active or contact your database administrator for help.';
$string['select_sms_gateways'] = 'SMS gateway provider';
22 changes: 22 additions & 0 deletions lib/classes/plugininfo/smsgateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace core\plugininfo;

use core_plugin_manager;
use moodle_url;

/**
Expand Down Expand Up @@ -69,4 +70,25 @@ public static function get_manage_url(): moodle_url {
'section' => 'smsgateway',
]);
}

public static function get_enabled_plugins(): ?array {
$pluginmanager = core_plugin_manager::instance();
$plugins = $pluginmanager->get_installed_plugins('smsgateway');

if (!$plugins) {
return [];
}

$plugins = array_keys($plugins);

// Filter to return only enabled plugins.
$enabled = [];
foreach ($plugins as $plugin) {
$disabled = get_config('smsgateway_' . $plugin, 'disabled');
if (empty($disabled)) {
$enabled[$plugin] = $plugin;
}
}
return $enabled;
}
}
1 change: 1 addition & 0 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4880,6 +4880,7 @@
<TABLE NAME="sms_gateways" COMMENT="Instances of SMS gateways">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="gateway" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="config" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
Expand Down
6 changes: 6 additions & 0 deletions lib/db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,12 @@
'ajax' => true,
'readonlysession' => true,
],
'core_sms_set_gateway_status' => [
'classname' => 'core_sms\external\sms_gateway_status',
'description' => 'Set the sms gateway status',
'type' => 'write',
'ajax' => true,
],
);

$services = array(
Expand Down
1 change: 1 addition & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ function xmldb_main_upgrade($oldversion) {

// Adding fields to table sms_gateways.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('gateway', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('enabled', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
$table->add_field('config', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@
<directory suffix="_test.php">communication/tests</directory>
<exclude>communication/tests/classes</exclude>
</testsuite>
<testsuite name="core_sms_testsuite">
<directory suffix="_test.php">sms/tests</directory>
</testsuite>

<!--Plugin suites: use admin/tool/phpunit/cli/util.php to build phpunit.xml from
phpunit.xml.dist with up-to-date list of plugins in current install-->
Expand Down
11 changes: 11 additions & 0 deletions sms/amd/build/smsgatewaychooser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sms/amd/build/smsgatewaychooser.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions sms/amd/build/smsgatewaytoggle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1e982a0

Please sign in to comment.