MDL-68294 tool_mobile: New subscription page
This commit is contained in:
@@ -660,4 +660,78 @@ class api {
|
||||
|
||||
return $imagedata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Moodle app plan subscription information for the current site as it is returned by the Apps Portal.
|
||||
*
|
||||
* @return array Subscription information
|
||||
*/
|
||||
public static function get_subscription_information() : ?array {
|
||||
global $CFG;
|
||||
|
||||
// Use session cache to prevent multiple requests.
|
||||
$cache = \cache::make('tool_mobile', 'subscriptiondata');
|
||||
$subscriptiondata = $cache->get(0);
|
||||
if ($subscriptiondata !== false) {
|
||||
return $subscriptiondata;
|
||||
}
|
||||
|
||||
$mobilesettings = get_config('tool_mobile');
|
||||
|
||||
// To validate that the requests come from this site we need to send some private information that only is known by the
|
||||
// Moodle Apps portal or the Sites registration database.
|
||||
$credentials = [];
|
||||
|
||||
if (!empty($CFG->airnotifieraccesskey)) {
|
||||
$credentials[] = ['type' => 'airnotifieraccesskey', 'value' => $CFG->airnotifieraccesskey];
|
||||
}
|
||||
if (\core\hub\registration::is_registered()) {
|
||||
$credentials[] = ['type' => 'siteid', 'value' => $CFG->siteidentifier];
|
||||
}
|
||||
|
||||
// Parameters for the WebService returning site information.
|
||||
$fnparams = (object) [
|
||||
'siteurl' => $CFG->wwwroot,
|
||||
'appids' => [$mobilesettings->androidappid, $mobilesettings->iosappid],
|
||||
'credentials' => $credentials,
|
||||
];
|
||||
// Prepare the arguments for a request to the AJAX nologin endpoint.
|
||||
$args = [
|
||||
(object) [
|
||||
'index' => 0,
|
||||
'methodname' => 'local_apps_get_site_info',
|
||||
'args' => $fnparams,
|
||||
]
|
||||
];
|
||||
|
||||
// Ask the Moodle Apps Portal for the subscription information.
|
||||
$curl = new curl();
|
||||
$curl->setopt(array('CURLOPT_TIMEOUT' => 10, 'CURLOPT_CONNECTTIMEOUT' => 10));
|
||||
|
||||
$serverurl = static::MOODLE_APPS_PORTAL_URL . "/lib/ajax/service-nologin.php";
|
||||
$query = 'args=' . urlencode(json_encode($args));
|
||||
$wsresponse = @json_decode($curl->post($serverurl, $query), true);
|
||||
|
||||
$info = $curl->get_info();
|
||||
if ($curlerrno = $curl->get_errno()) {
|
||||
// CURL connection error.
|
||||
debugging("Unexpected response from the Moodle Apps Portal server, CURL error number: $curlerrno");
|
||||
return null;
|
||||
} else if ($info['http_code'] != 200) {
|
||||
// Unexpected error from server.
|
||||
debugging('Unexpected response from the Moodle Apps Portal server, HTTP code:' . $info['httpcode']);
|
||||
return null;
|
||||
} else if (!empty($wsresponse[0]['error'])) {
|
||||
// Unexpected error from Moodle Apps Portal.
|
||||
debugging('Unexpected response from the Moodle Apps Portal server:' . json_encode($wsresponse[0]));
|
||||
return null;
|
||||
} else if (empty($wsresponse[0]['data'])) {
|
||||
debugging('Unexpected response from the Moodle Apps Portal server:' . json_encode($wsresponse));
|
||||
return null;
|
||||
}
|
||||
|
||||
$cache->set(0, $wsresponse[0]['data']);
|
||||
|
||||
return $wsresponse[0]['data'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Renderer.
|
||||
*
|
||||
* @package tool_mobile
|
||||
* @copyright 2020 Moodle Pty Ltd
|
||||
* @author <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_mobile\output;
|
||||
|
||||
use plugin_renderer_base;
|
||||
|
||||
|
||||
/**
|
||||
* Renderer class.
|
||||
*
|
||||
* @package tool_mobile
|
||||
* @copyright 2020 Moodle Pty Ltd
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Defer to template.
|
||||
*
|
||||
* @param \tool_mobile\output\subscription $subscription Subscription
|
||||
* @return string HTML
|
||||
*/
|
||||
protected function render_subscription(\tool_mobile\output\subscription $subscription): string {
|
||||
$data = $subscription->export_for_template($this);
|
||||
return parent::render_from_template('tool_mobile/subscription', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Subscription page.
|
||||
*
|
||||
* @package tool_mobile
|
||||
* @copyright 2020 Moodle Pty Ltd
|
||||
* @author <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_mobile\output;
|
||||
|
||||
/**
|
||||
* Subscription page.
|
||||
*
|
||||
* @package tool_mobile
|
||||
* @copyright 2020 Moodle Pty Ltd
|
||||
* @author <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class subscription implements \renderable, \templatable {
|
||||
|
||||
/**
|
||||
* Subscription data.
|
||||
*
|
||||
* @var array subscription data
|
||||
*/
|
||||
protected $subscriptiondata;
|
||||
|
||||
/**
|
||||
* Constructor for the class, sets the subscription data.
|
||||
*
|
||||
* @param array $subscriptiondata subscription data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $subscriptiondata) {
|
||||
$this->subscriptiondata = $subscriptiondata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the data.
|
||||
*
|
||||
* @param \renderer_base $output
|
||||
* @return array with the subscription information
|
||||
*/
|
||||
public function export_for_template(\renderer_base $output): array {
|
||||
global $CFG;
|
||||
|
||||
$ms = get_config('tool_mobile'); // Get mobile settings.
|
||||
|
||||
$data = $this->subscriptiondata;
|
||||
$data['appsportalurl'] = \tool_mobile\api::MOODLE_APPS_PORTAL_URL;
|
||||
|
||||
// First prepare messages that may come from the WS.
|
||||
if (!empty($data['messages'])) {
|
||||
foreach ($data['messages'] as $msg) {
|
||||
$data['messages' . $msg['type']][] = ['message' => $msg['message']];
|
||||
}
|
||||
}
|
||||
unset($data['messages']);
|
||||
|
||||
// Now prepare statistics information.
|
||||
if (isset($data['statistics']['notifications'])) {
|
||||
$data['notifications'] = $data['statistics']['notifications'];
|
||||
unset($data['statistics']['notifications']);
|
||||
|
||||
// Find current month data.
|
||||
$data['notifications']['currentactivedevices'] = 0;
|
||||
|
||||
if (isset($data['notifications']['monthly'][0])) {
|
||||
$currentmonth = $data['notifications']['monthly'][0];
|
||||
$data['notifications']['currentactivedevices'] = $currentmonth['activedevices'];
|
||||
if (!empty($currentmonth['limitreachedtime'])) {
|
||||
$data['notifications']['limitreachedtime'] = $currentmonth['limitreachedtime'];
|
||||
$data['notifications']['ignorednotificationswarning'] = [
|
||||
'message' => get_string('notificationslimitreached', 'tool_mobile', $data['appsportalurl'])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Review features.
|
||||
foreach ($data['subscription']['features'] as &$feature) {
|
||||
|
||||
// Check the type of features, if it is a limitation or functionality feature.
|
||||
if (array_key_exists('limit', $feature)) {
|
||||
|
||||
if (empty($feature['limit'])) { // Unlimited, no need to calculate current values.
|
||||
$feature['humanstatus'] = get_string('unlimited');
|
||||
$feature['showbar'] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($feature['name']) {
|
||||
// Check active devices.
|
||||
case 'pushnotificationsdevices':
|
||||
if (isset($data['notifications']['currentactivedevices'])) {
|
||||
$feature['status'] = $data['notifications']['currentactivedevices'];
|
||||
}
|
||||
break;
|
||||
// Check menu items.
|
||||
case 'custommenuitems':
|
||||
$els = rtrim($ms->custommenuitems, "\n");
|
||||
$feature['status'] = empty($ms->custommenuitems) ? 0 : count(explode("\n", $els));
|
||||
break;
|
||||
// Check language strings.
|
||||
case 'customlanguagestrings':
|
||||
$els = rtrim($ms->customlangstrings, "\n");
|
||||
$feature['status'] = empty($ms->customlangstrings) ? 0 : count(explode("\n", $els));
|
||||
break;
|
||||
// Check disabled features strings.
|
||||
case 'disabledfeatures':
|
||||
$feature['status'] = empty($ms->disabledfeatures) ? 0 : count(explode(',', $ms->disabledfeatures));
|
||||
break;
|
||||
}
|
||||
|
||||
$feature['humanstatus'] = '?/' . $feature['limit'];
|
||||
// Check if we should display the bar and how.
|
||||
if (isset($feature['status']) && is_int($feature['status'])) {
|
||||
$feature['humanstatus'] = $feature['status'] . '/' . $feature['limit'];
|
||||
$feature['showbar'] = 1;
|
||||
|
||||
if ($feature['status'] == $feature['limit']) {
|
||||
$feature['barclass'] = 'bg-warning';
|
||||
}
|
||||
|
||||
if ($feature['status'] > $feature['limit']) {
|
||||
$feature['barclass'] = 'bg-danger';
|
||||
$feature['humanstatus'] .= ' - ' . get_string('subscriptionlimitsurpassed', 'tool_mobile');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$feature['humanstatus'] = empty($feature['enabled']) ? get_string('notincluded') : get_string('included');
|
||||
|
||||
if (empty($feature['enabled'])) {
|
||||
switch ($feature['name']) {
|
||||
// Check remote themes.
|
||||
case 'remotethemes':
|
||||
if (!empty($CFG->mobilecssurl)) {
|
||||
$feature['message'] = [
|
||||
'type' => 'danger', 'message' => get_string('subscriptionfeaturenotapplied', 'tool_mobile')];
|
||||
}
|
||||
break;
|
||||
// Check site logo.
|
||||
case 'sitelogo':
|
||||
if ($output->get_logo_url() || $output->get_compact_logo_url()) {
|
||||
$feature['message'] = [
|
||||
'type' => 'danger', 'message' => get_string('subscriptionfeaturenotapplied', 'tool_mobile')];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usort($data['subscription']['features'],
|
||||
function (array $featurea, array $featureb) {
|
||||
$isfeaturea = !array_key_exists('limit', $featurea);
|
||||
$isfeatureb = !array_key_exists('limit', $featureb);
|
||||
|
||||
if (!$isfeaturea && $isfeatureb) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -30,5 +30,10 @@ $definitions = array(
|
||||
'simplekeys' => true,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 1
|
||||
)
|
||||
),
|
||||
'subscriptiondata' => array(
|
||||
'mode' => cache_store::MODE_SESSION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => false,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -31,6 +31,7 @@ $string['apprequired'] = 'This functionality is only available when accessed via
|
||||
$string['autologinkeygenerationlockout'] = 'Auto-login key generation is blocked. You need to wait 6 minutes between requests.';
|
||||
$string['autologinnotallowedtoadmins'] = 'Auto-login is not allowed for site admins.';
|
||||
$string['cachedef_plugininfo'] = 'This stores the list of plugins with mobile addons';
|
||||
$string['cachedef_subscriptiondata'] = 'This stores the Moodle app subscription information.';
|
||||
$string['clickheretolaunchtheapp'] = 'Click here if the app does not open automatically.';
|
||||
$string['configmobilecssurl'] = 'A CSS file to customise your mobile app interface.';
|
||||
$string['customlangstrings'] = 'Custom language strings';
|
||||
@@ -86,12 +87,22 @@ $string['mobileapp'] = 'Mobile app';
|
||||
$string['mobileappconnected'] = 'Mobile app connected';
|
||||
$string['mobileappenabled'] = 'This site has mobile app access enabled.<br /><a href="{$a}">Download the mobile app</a>.';
|
||||
$string['mobileappearance'] = 'Mobile appearance';
|
||||
$string['mobileappsubscription'] = 'Moodle app subscription';
|
||||
$string['mobileauthentication'] = 'Mobile authentication';
|
||||
$string['mobilecssurl'] = 'CSS';
|
||||
$string['mobilefeatures'] = 'Mobile features';
|
||||
$string['mobilenotificationsdisabledwarning'] = 'Mobile notifications are not enabled. They should be enabled in Notification settings.';
|
||||
$string['mobilesettings'] = 'Mobile settings';
|
||||
$string['moodleappsportalfeatureswarning'] = 'Please note that some features may be restricted depending on your Moodle app subscription. For details, visit the <a href="{$a}" target="_blank">Moodle Apps Portal</a>.';
|
||||
$string['notifications'] = 'Notifications';
|
||||
$string['notificationsactivedevices'] = 'Active devices';
|
||||
$string['notificationsignorednotifications'] = 'Notifications not sent';
|
||||
$string['notificationslimitreached'] = 'The monthly active user devices limit has been exceeded. Notifications for some users will not be sent. It is recommended that you upgrade your app plan in the <a href="{$a}" target="_blank">Moodle Apps Portal</a>.';
|
||||
$string['notificationsmissingwarning'] = 'Moodle app notification statistics could not be retrieved. This is most likely because mobile notifications are not yet enabled on the site.';
|
||||
$string['notificationsnewdevices'] = 'New devices';
|
||||
$string['notificationsseemore'] = 'Note: Moodle app usage statistics are not calculated in real time. To access more detailed statistics, including data from previous months, please log in to the <a href="{$a}" target="_blank">Moodle Apps Portal</a>.';
|
||||
$string['notificationssentnotifications'] = 'Notifications sent';
|
||||
$string['notificationscurrentactivedevices'] = 'Devices receiving notifications this month';
|
||||
$string['oauth2identityproviders'] = 'OAuth 2 identity providers';
|
||||
$string['offlineuse'] = 'Offline use';
|
||||
$string['pluginname'] = 'Moodle app tools';
|
||||
@@ -111,6 +122,15 @@ $string['selfsignedoruntrustedcertificatewarning'] = 'It seems that the HTTPS ce
|
||||
$string['setuplink'] = 'App download page';
|
||||
$string['setuplink_desc'] = 'URL of page with options to download the mobile app from the App Store and Google Play. The app download page link is displayed in the page footer and in a user\'s profile. Leave blank to not display a link.';
|
||||
$string['smartappbanners'] = 'App Banners';
|
||||
$string['subscription'] = 'Subscription';
|
||||
$string['subscriptioncreated'] = 'Start date';
|
||||
$string['subscriptionerrorrequest'] = 'There was an unexpected error when trying to retrieve your Moodle app subscription information.';
|
||||
$string['subscriptionexpiration'] = 'Expiry date';
|
||||
$string['subscriptionfeaturenotapplied'] = 'This feature is configured on your site but it is not included in your Moodle app plan. Thus, the setting will have no effect.';
|
||||
$string['subscriptionfeatures'] = 'Subscription features';
|
||||
$string['subscriptionlimitsurpassed'] = 'Subscription limit exceeded';
|
||||
$string['subscriptionregister'] = 'For details of the various app plans, and to access Moodle app usage statistics, please visit the <a href="{$a}" target="_blank">Moodle Apps Portal</a>.';
|
||||
$string['subscriptionsseemore'] = 'Note: The information displayed is not updated in real time. You may need to log out and log in again to see updates. For information on upgrading your app plan, please log in to the <a href="{$a}" target="_blank">Moodle Apps Portal</a>.';
|
||||
$string['typeoflogin'] = 'Type of login';
|
||||
$string['typeoflogin_desc'] = 'If the site uses a SSO authentication method, then select via a browser window or via an embedded browser. An embedded browser provides a better user experience, though it doesn\'t work with all SSO plugins.';
|
||||
$string['getmoodleonyourmobile'] = 'Get the mobile app';
|
||||
|
||||
@@ -50,11 +50,20 @@ if ($hassiteconfig) {
|
||||
|
||||
// Show only mobile settings if the mobile service is enabled.
|
||||
if (!empty($CFG->enablemobilewebservice)) {
|
||||
// General notification about limited features due to app restrictions.
|
||||
$notify = new \core\output\notification(
|
||||
get_string('moodleappsportalfeatureswarning', 'tool_mobile', tool_mobile\api::MOODLE_APPS_PORTAL_URL),
|
||||
\core\output\notification::NOTIFY_WARNING);
|
||||
$featuresnotice = $OUTPUT->render($notify);
|
||||
|
||||
$featuresnotice = null;
|
||||
if (empty($CFG->disablemobileappsubscription)) {
|
||||
// General notification about limited features due to app restrictions.
|
||||
$subscriptionurl = (new moodle_url("/$CFG->admin/tool/mobile/subscription.php"))->out(false);
|
||||
$notify = new \core\output\notification(
|
||||
get_string('moodleappsportalfeatureswarning', 'tool_mobile', $subscriptionurl),
|
||||
\core\output\notification::NOTIFY_WARNING);
|
||||
$featuresnotice = $OUTPUT->render($notify);
|
||||
|
||||
$ADMIN->add('mobileapp', new admin_externalpage('mobileappsubscription',
|
||||
new lang_string('mobileappsubscription', 'tool_mobile'),
|
||||
"$CFG->wwwroot/$CFG->admin/tool/mobile/subscription.php"));
|
||||
}
|
||||
|
||||
// Type of login.
|
||||
$temp = new admin_settingpage('mobileauthentication', new lang_string('mobileauthentication', 'tool_mobile'));
|
||||
@@ -92,7 +101,9 @@ if ($hassiteconfig) {
|
||||
// Appearance related settings.
|
||||
$temp = new admin_settingpage('mobileappearance', new lang_string('mobileappearance', 'tool_mobile'));
|
||||
|
||||
$temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeaturesappearance', '', $featuresnotice));
|
||||
if (!empty($featuresnotice)) {
|
||||
$temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeaturesappearance', '', $featuresnotice));
|
||||
}
|
||||
|
||||
$temp->add(new admin_setting_configtext('mobilecssurl', new lang_string('mobilecssurl', 'tool_mobile'),
|
||||
new lang_string('configmobilecssurl', 'tool_mobile'), '', PARAM_URL));
|
||||
@@ -126,7 +137,9 @@ if ($hassiteconfig) {
|
||||
// Features related settings.
|
||||
$temp = new admin_settingpage('mobilefeatures', new lang_string('mobilefeatures', 'tool_mobile'));
|
||||
|
||||
$temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeatures', '', $featuresnotice));
|
||||
if (!empty($featuresnotice)) {
|
||||
$temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeatures', '', $featuresnotice));
|
||||
}
|
||||
|
||||
$temp->add(new admin_setting_heading('tool_mobile/logout',
|
||||
new lang_string('logout'), ''));
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Styles for admin tool mobile.
|
||||
*/
|
||||
|
||||
#page-admin-tool-mobile-subscription dl dt {
|
||||
clear: both;
|
||||
display: inline-block;
|
||||
width: 40%;
|
||||
min-width: 100px;
|
||||
vertical-align: top;
|
||||
padding-top: 1px;
|
||||
}
|
||||
|
||||
#page-admin-tool-mobile-subscription dl dd {
|
||||
display: inline-block;
|
||||
width: 59%;
|
||||
margin-left: 1%;
|
||||
vertical-align: top;
|
||||
padding-top: 1px;
|
||||
}
|
||||
|
||||
#page-admin-tool-mobile-subscription dl.list-narrow dt {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
#page-admin-tool-mobile-subscription dl.list-narrow dd {
|
||||
width: 69%;
|
||||
}
|
||||
|
||||
#page-admin-tool-mobile-subscription progress {
|
||||
width: 100%;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Moodle app subscription information for the current site.
|
||||
*
|
||||
* @package tool_mobile
|
||||
* @copyright 2020 Moodle Pty Ltd
|
||||
* @author <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
admin_externalpage_setup('mobileappsubscription', '', null, '');
|
||||
|
||||
// Check Mobile web services enabled. This page should not be linked in that case, but avoid just in case.
|
||||
if (!$CFG->enablemobilewebservice) {
|
||||
print_error('enablewsdescription', 'webservice');
|
||||
}
|
||||
// Check is this feature is globaly disabled.
|
||||
if (!empty($CFG->disablemobileappsubscription)) {
|
||||
print_error('disabled', 'admin');
|
||||
}
|
||||
|
||||
$subscriptiondata = \tool_mobile\api::get_subscription_information();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if (empty($subscriptiondata)) {
|
||||
echo $OUTPUT->notification(get_string('subscriptionerrorrequest', 'tool_mobile'), \core\output\notification::NOTIFY_ERROR);
|
||||
} else {
|
||||
$templatable = new \tool_mobile\output\subscription($subscriptiondata);
|
||||
echo $PAGE->get_renderer('tool_mobile')->render($templatable);
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
@@ -0,0 +1,229 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template tool_mobile/subscription
|
||||
|
||||
Template for subscription information.
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Context variables required for this template:
|
||||
* registered - Whether the site is registered
|
||||
* appsportalurl - Apps portal url
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"registered" : true,
|
||||
"appsportalurl": "https://apps.moodle.com",
|
||||
"subscription": {
|
||||
"name": "Pro",
|
||||
"description": "This subscription has a Moodle Product Premium plan free of charge",
|
||||
"timecreated": 1587548810,
|
||||
"expiretime": 1618963200,
|
||||
"features": [
|
||||
{
|
||||
"name": "multimediapushnotifications",
|
||||
"enabled": true,
|
||||
"description": "Multimedia push notifications",
|
||||
"humanstatus": "Enabled",
|
||||
"message": {
|
||||
"type" : "warning",
|
||||
"message" : "Temporary disabled for a promotion"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "pushnotificationsdevices",
|
||||
"enabled": false,
|
||||
"limit": 50,
|
||||
"showbar": 1,
|
||||
"description": "Active user devices for notifications",
|
||||
"status": 55,
|
||||
"humanstatus": "55/50",
|
||||
"barclass": "bg-danger"
|
||||
},
|
||||
{
|
||||
"name": "custommenuitems",
|
||||
"enabled": false,
|
||||
"limit": 4,
|
||||
"showbar": 1,
|
||||
"description": "Custom menu items",
|
||||
"status": 2,
|
||||
"humanstatus": "2/4"
|
||||
}
|
||||
]
|
||||
},
|
||||
"messageswarning": [
|
||||
{
|
||||
"message" : "You have surpassed your monthly active user devices limit, some messages are beign ignored. We recommend you to upgrade to a paid plan."
|
||||
}
|
||||
],
|
||||
"notifications": {
|
||||
"totalsentnotifications" : 7600,
|
||||
"totaldevices" : 60,
|
||||
"currentactivedevices" : 55,
|
||||
"ignorednotificationswarning": {
|
||||
"message" : "You have surpassed your monthly active user devices limit, some messages are beign ignored. We recommend you to upgrade to a paid plan."
|
||||
},
|
||||
"monthly" : [
|
||||
{
|
||||
"year": 2020,
|
||||
"month": 4,
|
||||
"sentnotifications": 4500,
|
||||
"newdevices": 20,
|
||||
"activedevices": 55,
|
||||
"ignorednotifications": 40,
|
||||
"limitreachedtime": 1586548810
|
||||
},
|
||||
{
|
||||
"year": 2020,
|
||||
"month": 3,
|
||||
"sentnotifications": 4500,
|
||||
"newdevices":10,
|
||||
"activedevices": 45,
|
||||
"ignorednotifications": 0,
|
||||
"limitreachedtime": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
{{#messageserror}}
|
||||
{{> core/notification_error}}
|
||||
{{/messageserror}}
|
||||
{{#messagessuccess}}
|
||||
{{> core/notification_success}}
|
||||
{{/messagessuccess}}
|
||||
{{#messageswarning}}
|
||||
{{> core/notification_warning}}
|
||||
{{/messageswarning}}
|
||||
{{#messagesinfo}}
|
||||
{{> core/notification_info}}
|
||||
{{/messagesinfo}}
|
||||
|
||||
<div id="subscription-overview" class="box">
|
||||
|
||||
<h2>{{# str }} mobileappsubscription, tool_mobile {{/ str }}</h2>
|
||||
|
||||
{{#messageshtml}}
|
||||
{{{message}}}
|
||||
{{/messageshtml}}
|
||||
|
||||
{{#subscription}}
|
||||
<dl class="list-narrow">
|
||||
<dt>{{# str }} name {{/ str }}</dt><dd>{{name}}</dd>
|
||||
<dt>{{# str }} description {{/ str }}</dt><dd>{{description}}</dd>
|
||||
<dt>{{# str }} subscriptioncreated, tool_mobile {{/ str }}</dt><dd>{{#userdate}} {{timecreated}}, {{#str}} strftimedate {{/str}} {{/userdate}}</dd>
|
||||
{{#expiretime}}
|
||||
<dt>{{# str }} subscriptionexpiration, tool_mobile {{/ str }}</dt><dd>{{#userdate}} {{expiretime}}, {{#str}} strftimedate {{/str}} {{/userdate}}</dd>
|
||||
{{/expiretime}}
|
||||
</dl>
|
||||
|
||||
{{^registered}}
|
||||
{{# str }} subscriptionregister, tool_mobile, {{ appsportalurl }} {{/ str }}
|
||||
{{/registered}}
|
||||
|
||||
<h3>{{# str }} subscriptionfeatures, tool_mobile {{/ str }}</h3>
|
||||
|
||||
{{#features}}
|
||||
<dl>
|
||||
{{^limit}}
|
||||
<dt>{{{description}}}</dt><dd>{{{humanstatus}}}</dd>
|
||||
{{/limit}}
|
||||
{{#limit}}
|
||||
<dt>{{{description}}}</dt><dd>
|
||||
{{#showbar}}
|
||||
<div class="progress">
|
||||
<div class="progress-bar progress-bar-animated {{barclass}}" role="progressbar" style="width: 100%" aria-valuenow="{{status}}" aria-valuemin="0" aria-valuemax="{{limit}}">{{humanstatus}}
|
||||
</div>
|
||||
</div>
|
||||
{{/showbar}}
|
||||
{{^showbar}}
|
||||
{{humanstatus}}
|
||||
{{/showbar}}
|
||||
</dd>
|
||||
{{/limit}}
|
||||
{{#message}}
|
||||
<span class="badge badge-{{type}}">{{message}}</span>
|
||||
{{/message}}
|
||||
</dl>
|
||||
{{/features}}
|
||||
|
||||
{{#registered}}
|
||||
{{# str }} subscriptionsseemore, tool_mobile, {{ appsportalurl }} {{/ str }}
|
||||
{{/registered}}
|
||||
|
||||
{{/subscription}}
|
||||
</div>
|
||||
|
||||
<div id="notifications-overview" class="box">
|
||||
<h3>{{# str }} notifications, tool_mobile {{/ str }}</h3>
|
||||
|
||||
{{^registered}}
|
||||
{{# str }} subscriptionregister, tool_mobile, {{ appsportalurl }} {{/ str }}
|
||||
{{/registered}}
|
||||
|
||||
{{#notifications}}
|
||||
|
||||
{{#ignorednotificationswarning}}
|
||||
{{> core/notification_error}}
|
||||
{{/ignorednotificationswarning}}
|
||||
|
||||
<dl>
|
||||
<dt>{{# str }} notificationscurrentactivedevices, tool_mobile {{/ str }}</dt><dd>{{currentactivedevices}}</dd>
|
||||
</dl>
|
||||
|
||||
<table id="notificationstable" class="generaltable fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center" scope="col">{{#str}}year, form{{/str}}</th>
|
||||
<th class="text-center" scope="col">{{#str}}month{{/str}}</th>
|
||||
<th class="text-center" scope="col">{{#str}}notificationssentnotifications, tool_mobile{{/str}}</th>
|
||||
<th class="text-center" scope="col">{{#str}}notificationsactivedevices, tool_mobile{{/str}}</th>
|
||||
<th class="text-center" scope="col">{{#str}}notificationsnewdevices, tool_mobile{{/str}}</th>
|
||||
<th class="text-center" scope="col">{{#str}}notificationsignorednotifications, tool_mobile{{/str}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#notifications.monthly}}
|
||||
<tr>
|
||||
<td class="text-center">{{year}}</td>
|
||||
<td class="text-center">{{month}}</td>
|
||||
<td class="text-center">{{sentnotifications}}</td>
|
||||
<td class="text-center">{{activedevices}}</td>
|
||||
<td class="text-center">{{newdevices}}</td>
|
||||
<td class="text-center">{{ignorednotifications}}</td>
|
||||
</tr>
|
||||
{{/notifications.monthly}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{#registered}}
|
||||
{{# str }} notificationsseemore, tool_mobile, {{ appsportalurl }} {{/ str }}
|
||||
{{/registered}}
|
||||
|
||||
{{/notifications}}
|
||||
|
||||
{{^notifications}}
|
||||
{{# str }} notificationsmissingwarning, tool_mobile {{/ str }}
|
||||
{{/notifications}}
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user