Skip to content

Commit

Permalink
MDL-58694 admin: Add mobile related data to site registration
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Apr 25, 2017
1 parent faedb27 commit bf1babe
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
64 changes: 64 additions & 0 deletions admin/registration/forms.php
Expand Up @@ -249,6 +249,11 @@ public function definition() {
$mediancoursesize = get_config('hub', 'site_mediancoursesize_' . $cleanhuburl);
$participantnumberaveragecfg = get_config('hub', 'site_participantnumberaverage_' . $cleanhuburl);
$modulenumberaveragecfg = get_config('hub', 'site_modulenumberaverage_' . $cleanhuburl);
// Mobile related information.
$mobileservicesenabled = get_config('hub', 'site_mobileservicesenabled_' . $cleanhuburl);
$mobilenotificacionsenabled = get_config('hub', 'site_mobilenotificacionsenabled_' . $cleanhuburl);
$registereduserdevices = get_config('hub', 'site_registereduserdevices_' . $cleanhuburl);
$registeredactiveuserdevices = get_config('hub', 'site_registeredactiveuserdevices_' . $cleanhuburl);

//hidden parameters
$mform->addElement('hidden', 'huburl', $huburl);
Expand Down Expand Up @@ -386,6 +391,21 @@ public function definition() {
require_once($CFG->libdir . '/badgeslib.php');
$badges = $DB->count_records_select('badge', 'status <> ' . BADGE_STATUS_ARCHIVED);
$issuedbadges = $DB->count_records('badge_issued');
// Mobile related information.
$ismobileenabled = false;
$aremobilenotificationsenabled = false;
$registereduserdevicescount = 0;
$registeredactiveuserdevicescount = 0;
if (!empty($CFG->enablewebservices) && !empty($CFG->enablemobilewebservice)) {
$ismobileenabled = true;
$registereduserdevicescount = $DB->count_records('user_devices');
$airnotifierextpath = $CFG->dirroot . '/message/output/airnotifier/externallib.php';
if (file_exists($airnotifierextpath)) { // Maybe some one uninstalled the plugin.
require_once($airnotifierextpath);
$aremobilenotificationsenabled = (bool) message_airnotifier_external::is_system_configured();
$registeredactiveuserdevicescount = $DB->count_records('message_airnotifier_devices', array('enable' => 1));
}
}

if (HUB_MOODLEORGHUBURL != $huburl) {
$mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'),
Expand Down Expand Up @@ -438,6 +458,28 @@ public function definition() {
" " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
$mform->setDefault('modulenumberaverage', $modulenumberaveragecfg != -1);
$mform->setType('modulenumberaverage', PARAM_FLOAT);

$mobileservicestatus = $ismobileenabled ? 'yes' : 'no';
$mform->addElement('checkbox', 'mobileservicesenabled', '',
" " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
$mform->setDefault('mobileservicesenabled', $mobileservicesenabled != -1);
$mform->setType('mobileservicesenabled', PARAM_INT);

$mobilenotificationsstatus = $aremobilenotificationsenabled ? 'yes' : 'no';
$mform->addElement('checkbox', 'mobilenotificacionsenabled', '',
" " . get_string('mobilenotificacionsenabled', 'hub', $mobilenotificationsstatus));
$mform->setDefault('mobilenotificacionsenabled', $mobilenotificacionsenabled != -1);
$mform->setType('mobilenotificacionsenabled', PARAM_INT);

$mform->addElement('checkbox', 'registereduserdevices', '',
" " . get_string('registereduserdevices', 'hub', $registereduserdevicescount));
$mform->setDefault('registereduserdevices', $registereduserdevices != -1);
$mform->setType('registereduserdevices', PARAM_INT);

$mform->addElement('checkbox', 'registeredactiveuserdevices', '',
" " . get_string('registeredactiveuserdevices', 'hub', $registeredactiveuserdevicescount));
$mform->setDefault('registeredactiveuserdevices', $registeredactiveuserdevices != -1);
$mform->setType('registeredactiveuserdevices', PARAM_INT);
} else {
$mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
" " . get_string('coursesnumber', 'hub', $coursecount));
Expand Down Expand Up @@ -489,6 +531,28 @@ public function definition() {
" " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
$mform->addElement('hidden', 'modulenumberaverage', 1);
$mform->setType('modulenumberaverage', PARAM_FLOAT);

$mobileservicestatus = $ismobileenabled ? 'yes' : 'no';
$mform->addElement('static', 'mobileservicesenabledlabel', '',
" " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
$mform->addElement('hidden', 'mobileservicesenabled', 1);
$mform->setType('mobileservicesenabled', PARAM_INT);

$mobilenotificationsstatus = $aremobilenotificationsenabled ? 'yes' : 'no';
$mform->addElement('static', 'mobilenotificacionsenabledlabel', '',
" " . get_string('mobilenotificacionsenabled', 'hub', $mobilenotificationsstatus));
$mform->addElement('hidden', 'mobilenotificacionsenabled', 1);
$mform->setType('mobilenotificacionsenabled', PARAM_INT);

$mform->addElement('static', 'registereduserdeviceslabel', '',
" " . get_string('registereduserdevices', 'hub', $registereduserdevicescount));
$mform->addElement('hidden', 'registereduserdevices', 1);
$mform->setType('registereduserdevices', PARAM_INT);

$mform->addElement('static', 'registeredactiveuserdeviceslabel', '',
" " . get_string('registeredactiveuserdevices', 'hub', $registeredactiveuserdevicescount));
$mform->addElement('hidden', 'registeredactiveuserdevices', 1);
$mform->setType('registeredactiveuserdevices', PARAM_INT);
}

//check if it's a first registration or update
Expand Down
15 changes: 15 additions & 0 deletions admin/registration/lib.php
Expand Up @@ -280,6 +280,21 @@ public function get_site_info($huburl) {
$siteinfo['moodleversion'] = $CFG->version;
$siteinfo['moodlerelease'] = $CFG->release;
$siteinfo['url'] = $CFG->wwwroot;
// Mobile related information.
$siteinfo['mobileservicesenabled'] = 0;
$siteinfo['mobilenotificacionsenabled'] = 0;
$siteinfo['registereduserdevices'] = 0;
$siteinfo['registeredactiveuserdevices'] = 0;
if (!empty($CFG->enablewebservices) && !empty($CFG->enablemobilewebservice)) {
$siteinfo['mobileservicesenabled'] = 1;
$siteinfo['registereduserdevices'] = $DB->count_records('user_devices');
$airnotifierextpath = $CFG->dirroot . '/message/output/airnotifier/externallib.php';
if (file_exists($airnotifierextpath)) { // Maybe some one uninstalled the plugin.
require_once($airnotifierextpath);
$siteinfo['mobilenotificacionsenabled'] = message_airnotifier_external::is_system_configured();
$siteinfo['registeredactiveuserdevices'] = $DB->count_records('message_airnotifier_devices', array('enable' => 1));
}
}

return $siteinfo;
}
Expand Down
11 changes: 10 additions & 1 deletion admin/registration/register.php
Expand Up @@ -68,7 +68,8 @@
// Set to -1 all optional data marked as "don't send" by the admin.
// The function get_site_info() will not calculate the optional data if config is set to -1.
$inputnames = array('courses', 'users', 'roleassignments', 'posts', 'questions', 'resources',
'badges', 'issuedbadges', 'modulenumberaverage', 'participantnumberaverage');
'badges', 'issuedbadges', 'modulenumberaverage', 'participantnumberaverage',
'mobileservicesenabled', 'mobilenotificacionsenabled', 'registereduserdevices', 'registeredactiveuserdevices');
foreach ($inputnames as $inputname) {
if (empty($fromform->{$inputname})) {
$fromform->{$inputname} = -1;
Expand Down Expand Up @@ -101,6 +102,10 @@
set_config('site_issuedbadges_' . $cleanhuburl, $fromform->issuedbadges, 'hub');
set_config('site_modulenumberaverage_' . $cleanhuburl, $fromform->modulenumberaverage, 'hub');
set_config('site_participantnumberaverage_' . $cleanhuburl, $fromform->participantnumberaverage, 'hub');
set_config('site_mobileservicesenabled_' . $cleanhuburl, $fromform->mobileservicesenabled, 'hub');
set_config('site_mobilenotificacionsenabled_' . $cleanhuburl, $fromform->mobilenotificacionsenabled, 'hub');
set_config('site_registereduserdevices_' . $cleanhuburl, $fromform->registereduserdevices, 'hub');
set_config('site_registeredactiveuserdevices_' . $cleanhuburl, $fromform->registeredactiveuserdevices, 'hub');
}

/////// UPDATE ACTION ////////
Expand Down Expand Up @@ -143,6 +148,10 @@
$fromform->modulenumberaverage = $siteinfo['modulenumberaverage'];
$fromform->participantnumberaverage = $siteinfo['participantnumberaverage'];
$fromform->street = $siteinfo['street'];
$fromform->mobileservicesenabled = $siteinfo['mobileservicesenabled'];
$fromform->mobilenotificacionsenabled = $siteinfo['mobilenotificacionsenabled'];
$fromform->registereduserdevices = $siteinfo['registereduserdevices'];
$fromform->registeredactiveuserdevices = $siteinfo['registeredactiveuserdevices'];

$params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)

Expand Down
4 changes: 4 additions & 0 deletions lang/en/hub.php
Expand Up @@ -117,6 +117,8 @@
$string['licence_help'] = 'Select the licence you want to distribute your course under.';
$string['licence_link'] = 'licenses';
$string['logourl'] = 'Logo URL';
$string['mobilenotificacionsenabled'] = 'Mobile notifications enabled ({$a})';
$string['mobileservicesenabled'] = 'Mobile services enabled ({$a})';
$string['modulenumberaverage'] = 'Average number of course modules ({$a})';
$string['moodleorg'] = 'Moodle';
$string['mustselectsubject'] = 'You must select a subject';
Expand Down Expand Up @@ -160,6 +162,8 @@
$string['registrationinfo'] = 'Registration information';
$string['registeredmoodleorg'] = 'Moodle ({$a})';
$string['registeredon'] = 'Where your site is registered';
$string['registereduserdevices'] = 'Number of user\'s registered mobile devices ({$a})';
$string['registeredactiveuserdevices'] = 'Number of active user\'s registered mobile devices ({$a})';
$string['registermoochtips'] = 'Register your site with Moodle to get security alerts and access to Moodle.net, our course sharing platform.';
$string['registersite'] = 'Register with {$a}';
$string['registerwith'] = 'Register with a hub';
Expand Down

0 comments on commit bf1babe

Please sign in to comment.