MDL-60108 registration: Simplify, add commnews and separate emails

This commit is contained in:
Marina Glancy 2017-09-19 16:22:28 +08:00
parent 9a316f3367
commit af925a541d
7 changed files with 201 additions and 106 deletions

View file

@ -36,14 +36,6 @@ class core_register_renderer extends plugin_renderer_base {
* @return string * @return string
*/ */
public function moodleorg_registration_message() { public function moodleorg_registration_message() {
$moodleorgstatslink = html_writer::link('http://moodle.net/stats', return format_text(get_string('registermoodlenet', 'admin'), FORMAT_MARKDOWN, ['noclean' => true]);
get_string('statsmoodleorg', 'admin'),
array('target' => '_blank'));
$moodleorgregmsg = get_string('registermoodleorg', 'admin');
$items = array(get_string('registermoodleorgli1', 'admin'),
get_string('registermoodleorgli2', 'admin', $moodleorgstatslink));
$moodleorgregmsg .= html_writer::alist($items);
return $moodleorgregmsg;
} }
} }

View file

@ -938,6 +938,15 @@ $string['quizattemptsupgradedmessage'] = 'In Moodle 2.1 there was a major upgrad
$string['recaptchaprivatekey'] = 'ReCAPTCHA secret key'; $string['recaptchaprivatekey'] = 'ReCAPTCHA secret key';
$string['recaptchapublickey'] = 'ReCAPTCHA site key'; $string['recaptchapublickey'] = 'ReCAPTCHA site key';
$string['register'] = 'Register your site'; $string['register'] = 'Register your site';
$string['registermoodlenet'] = 'We\'d love to stay in touch for important things for your Moodle site!
By registering,
* You are contributing to our collective knowledge about the users of Moodle which helps us improve Moodle and all our community services
* Youll be one of the first to find out about important notifications such as security alerts and new Moodle releases.
* You can access and activate mobile push notifications from your Moodle site through our free [Moodle Mobile app](https://download.moodle.org/mobile/)
* Optionally, your site can be included as a proud member and supporter of the Moodle community on the [list of registered sites](https://moodle.net/stats).
';
$string['registermoodleorg'] = 'When you register your site'; $string['registermoodleorg'] = 'When you register your site';
$string['registermoodleorgli1'] = 'You are added to a low-volume mailing list for important notifications such as security alerts and new releases of Moodle.'; $string['registermoodleorgli1'] = 'You are added to a low-volume mailing list for important notifications such as security alerts and new releases of Moodle.';
$string['registermoodleorgli2'] = 'Statistics about your site will be added to the {$a} of the worldwide Moodle community.'; $string['registermoodleorgli2'] = 'Statistics about your site will be added to the {$a} of the worldwide Moodle community.';

View file

@ -154,3 +154,5 @@ moodleorghubname,core_admin
hubs,core_admin hubs,core_admin
quickdownloadcalendar,core_calendar quickdownloadcalendar,core_calendar
ical,core_calendar ical,core_calendar
privacy,core_hub
privacy_help,core_hub

View file

@ -114,8 +114,6 @@ $string['postaladdress'] = 'Postal address';
$string['postaladdress_help'] = 'Postal address of this site, or of the entity represented by this site.'; $string['postaladdress_help'] = 'Postal address of this site, or of the entity represented by this site.';
$string['postsnumber'] = 'Number of posts ({$a})'; $string['postsnumber'] = 'Number of posts ({$a})';
$string['previousregistrationdeleted'] = 'The previous registration has been deleted from {$a}. You can restart the registration process. Thank you.'; $string['previousregistrationdeleted'] = 'The previous registration has been deleted from {$a}. You can restart the registration process. Thank you.';
$string['privacy'] = 'Privacy';
$string['privacy_help'] = 'The hub may want to display a list of registered sites. If it does then you can choose whether or not you want to appear on that list.';
$string['publicationinfo'] = 'Course publication information'; $string['publicationinfo'] = 'Course publication information';
$string['publishcourse'] = 'Publish {$a}'; $string['publishcourse'] = 'Publish {$a}';
$string['publishcourseon'] = 'Publish on {$a}'; $string['publishcourseon'] = 'Publish on {$a}';
@ -152,30 +150,36 @@ $string['shareon'] = 'Upload this course to {$a}';
$string['sharepublication_help'] = 'Uploading this course to a community server will enable people to download it and install it on their own Moodle sites.'; $string['sharepublication_help'] = 'Uploading this course to a community server will enable people to download it and install it on their own Moodle sites.';
$string['siteadmin'] = 'Administrator'; $string['siteadmin'] = 'Administrator';
$string['siteadmin_help'] = 'The full name of the site administrator.'; $string['siteadmin_help'] = 'The full name of the site administrator.';
$string['sitecommnews'] = 'Updates about Moodle news and features';
$string['sitecommnews_help'] = 'You have the option of subscribing to our low volume email list including a newsletter about happenings in the Moodle community. ';
$string['sitecommnewsno'] = 'No, I do not want to receive any email from Moodle HQ';
$string['sitecommnewsyes'] = 'Yes please, include me in Moodles regular e-newsletter updates';
$string['sitecountry'] = 'Country'; $string['sitecountry'] = 'Country';
$string['sitecountry_help'] = 'The country your organisation is in.'; $string['sitecountry_help'] = 'The country your organisation or institution is located in.';
$string['sitedesc'] = 'Description'; $string['sitedesc'] = 'Description';
$string['sitedesc_help'] = 'This description of your site may be shown in the site listing. Please use plain text only.'; $string['sitedesc_help'] = 'Provide some information about how you are using Moodle.';
$string['sitegeolocation'] = 'Geolocation'; $string['sitegeolocation'] = 'Geolocation';
$string['sitegeolocation_help'] = 'In future we may provide location-based searching in the hubs. If you want to specify the location for your site use a latitude/longitude value here (eg: -31.947884,115.871285). One way to find this is to use Google Maps.'; $string['sitegeolocation_help'] = 'In future we may provide location-based searching in the hubs. If you want to specify the location for your site use a latitude/longitude value here (eg: -31.947884,115.871285). One way to find this is to use Google Maps.';
$string['siteemail'] = 'Email address'; $string['siteemail'] = 'Admin email address';
$string['siteemail_help'] = 'You need to provide an email address so the hub administrator can contact you if necessary. This will not be used for any other purpose. It is recommended to enter a email address related to a position (example: sitemanager@example.com) and not directly to a person.'; $string['siteemail_help'] = 'An email address is necessary so that Moodle HQ can contact you if required. It may also be used for other purposes as you allow below. We recommend a generic email address related to a position (eg.: sitemanager@example.com), not a personal address.';
$string['sitelang'] = 'Language'; $string['sitelang'] = 'Language';
$string['sitelang_help'] = 'Your site language will be displayed on the site listing.'; $string['sitelang_help'] = 'What is the main language used on your Moodle site?';
$string['sitename'] = 'Name'; $string['sitename'] = 'Name';
$string['sitename_help'] = 'The name of the site will be shown on the site listing if the hub allows that.'; $string['sitename_help'] = 'The name of the site will be shown on the site listing if the hub allows that.';
$string['sitephone'] = 'Phone'; $string['sitephone'] = 'Phone';
$string['sitephone_help'] = 'Your phone number will only be seen by the hub administrator.'; $string['sitephone_help'] = 'Your phone number will only be seen by the hub administrator.';
$string['siteprivacy'] = 'Privacy'; $string['siteprivacy'] = 'Site listing';
$string['siteprivacynotpublished'] = 'Please do not publish this site'; $string['siteprivacy_help'] = 'You can choose to have your site listed publicly in the list of registered sites, with or without a link to your site.';
$string['siteprivacypublished'] = 'Publish the site name only'; $string['siteprivacynotpublished'] = 'Do not list my site';
$string['siteprivacylinked'] = 'Publish the site name with a link'; $string['siteprivacypublished'] = 'Only display my site name';
$string['siteregistrationcontact'] = 'Contact form'; $string['siteprivacylinked'] = 'Display my site name with the link';
$string['siteregistrationcontact_help'] = 'If you allow it, other people may be able to contact you via a contact form on the hub. They will never be able to see your email address.'; $string['siteregistrationcontact'] = 'Display contact form';
$string['siteregistrationemail'] = 'Email notifications'; $string['siteregistrationcontact_help'] = 'If you allow it, other people in our Moodle community (who need a login account) can contact you via a form on our Moodle community site. However, they will never be able to see your email address.';
$string['siteregistrationemail_help'] = 'If you enable this the hub administrator may email you to inform you of important news like security issues.'; $string['siteregistrationemail'] = 'Notifications about important security and technical issues.';
$string['siteregistrationemail_help'] = 'You have the option of subscribing to our low volume email list for important news (on security issues or new releases).';
$string['siteregistrationupdated'] = 'Site registration updated'; $string['siteregistrationupdated'] = 'Site registration updated';
$string['siterelease'] = 'Moodle release'; $string['siterelease'] = 'Moodle release';
$string['sitereleasenum'] = 'Moodle release ({$a})';
$string['siterelease_help'] = 'Moodle release number of this site.'; $string['siterelease_help'] = 'Moodle release number of this site.';
$string['siteurl'] = 'Site URL'; $string['siteurl'] = 'Site URL';
$string['siteurl_help'] = 'The URL is the address of this site. If privacy settings allow people to see site addresses then this is the URL that will be used.'; $string['siteurl_help'] = 'The URL is the address of this site. If privacy settings allow people to see site addresses then this is the URL that will be used.';
@ -200,6 +204,7 @@ $string['unregistrationerror'] = 'An error occurred when the site tried to unreg
$string['update'] = 'Update'; $string['update'] = 'Update';
$string['updatesite'] = 'Update registration on {$a}'; $string['updatesite'] = 'Update registration on {$a}';
$string['updatestatus'] = 'Check it now.'; $string['updatestatus'] = 'Check it now.';
$string['usedifferentemail'] = 'Use different email';
$string['urlalreadyregistered'] = 'Your site seems to be already registered on Moodle.net, which means something has gone wrong. Please contact the Moodle.net administrator to reset your registration so you can try again.'; $string['urlalreadyregistered'] = 'Your site seems to be already registered on Moodle.net, which means something has gone wrong. Please contact the Moodle.net administrator to reset your registration so you can try again.';
$string['usersnumber'] = 'Number of users ({$a})'; $string['usersnumber'] = 'Number of users ({$a})';
$string['wrongtoken'] = 'The registration failed for some unknown reason (network?). Please try again.'; $string['wrongtoken'] = 'The registration failed for some unknown reason (network?). Please try again.';
@ -240,6 +245,8 @@ $string['nosearch'] = 'Don\'t publish hub or courses';
$string['notregisteredonmoodleorg'] = 'Your administrator needs to register this site with moodle.org.'; $string['notregisteredonmoodleorg'] = 'Your administrator needs to register this site with moodle.org.';
$string['orenterprivatehub'] = 'Alternatively, enter a private hub URL:'; $string['orenterprivatehub'] = 'Alternatively, enter a private hub URL:';
$string['prioritise'] = 'Prioritise'; $string['prioritise'] = 'Prioritise';
$string['privacy'] = 'Privacy';
$string['privacy_help'] = 'The hub may want to display a list of registered sites. If it does then you can choose whether or not you want to appear on that list.';
$string['private'] = 'Private'; $string['private'] = 'Private';
$string['privatehuburl'] = 'Private hub URL'; $string['privatehuburl'] = 'Private hub URL';
$string['publichub'] = 'Public hub'; $string['publichub'] = 'Public hub';

View file

@ -1555,8 +1555,8 @@ $string['refresh'] = 'Refresh';
$string['refreshingevents'] = 'Refreshing events'; $string['refreshingevents'] = 'Refreshing events';
$string['registration'] = 'Moodle registration'; $string['registration'] = 'Moodle registration';
$string['registrationcontact'] = 'Contact from the public'; $string['registrationcontact'] = 'Contact from the public';
$string['registrationcontactno'] = 'No, I do not want a contact form in the site listing'; $string['registrationcontactno'] = 'No, I do not want to be contacted by other people';
$string['registrationcontactyes'] = 'Yes, provide a form for prospective Moodlers to contact me'; $string['registrationcontactyes'] = 'Yes, provide a form for other Moodlers to contact me';
$string['registrationemail'] = 'Email notifications'; $string['registrationemail'] = 'Email notifications';
$string['registrationinfo'] = '<p>This page allows you to register your Moodle site with moodle.org. Registration is free. $string['registrationinfo'] = '<p>This page allows you to register your Moodle site with moodle.org. Registration is free.
The main benefit of registering is that you will be added to a low-volume mailing list The main benefit of registering is that you will be added to a low-volume mailing list
@ -1567,9 +1567,9 @@ for important notifications such as security alerts and new releases of Moodle.<
<p>If you choose, you can allow your site name, country and URL to be added to the public list of Moodle Sites.</p> <p>If you choose, you can allow your site name, country and URL to be added to the public list of Moodle Sites.</p>
<p>All new registrations are verified manually before they are added to the list, but once you are added you can update your registration (and your entry on the public list) at any time by resubmitting this form.</p>'; <p>All new registrations are verified manually before they are added to the list, but once you are added you can update your registration (and your entry on the public list) at any time by resubmitting this form.</p>';
$string['registrationinfotitle'] = 'Registration information'; $string['registrationinfotitle'] = 'Registration information';
$string['registrationno'] = 'No, I do not want to receive email'; $string['registrationno'] = 'No, I do not want to receive any email from Moodle HQ';
$string['registrationsend'] = 'Send registration information to moodle.org'; $string['registrationsend'] = 'Send registration information to moodle.org';
$string['registrationyes'] = 'Yes, please notify me about important issues'; $string['registrationyes'] = 'Yes, notify me about important news (e.g. security issues or releases) ';
$string['reject'] = 'Reject'; $string['reject'] = 'Reject';
$string['rejectdots'] = 'Reject...'; $string['rejectdots'] = 'Reject...';
$string['reload'] = 'Reload'; $string['reload'] = 'Reload';

View file

@ -29,6 +29,7 @@ use moodle_exception;
use moodle_url; use moodle_url;
use context_system; use context_system;
use stdClass; use stdClass;
use html_writer;
/** /**
* Methods to use when publishing and searching courses on moodle.net * Methods to use when publishing and searching courses on moodle.net
@ -41,7 +42,7 @@ class registration {
/** @var Fields used in a site registration form */ /** @var Fields used in a site registration form */
const FORM_FIELDS = ['name', 'description', 'contactname', 'contactemail', 'contactphone', 'imageurl', 'privacy', 'street', const FORM_FIELDS = ['name', 'description', 'contactname', 'contactemail', 'contactphone', 'imageurl', 'privacy', 'street',
'regioncode', 'countrycode', 'geolocation', 'contactable', 'emailalert', 'language']; 'regioncode', 'countrycode', 'geolocation', 'contactable', 'emailalert', 'emailalertemail', 'commnews', 'commnewsemail', 'language'];
/** @var Site privacy: not displayed */ /** @var Site privacy: not displayed */
const HUB_SITENOTPUBLISHED = 'notdisplayed'; const HUB_SITENOTPUBLISHED = 'notdisplayed';
@ -162,7 +163,6 @@ class registration {
$siteinfo['modulenumberaverage'] = average_number_of_courses_modules(); $siteinfo['modulenumberaverage'] = average_number_of_courses_modules();
// Version and url. // Version and url.
$siteinfo['moodleversion'] = $CFG->version;
$siteinfo['moodlerelease'] = $CFG->release; $siteinfo['moodlerelease'] = $CFG->release;
$siteinfo['url'] = $CFG->wwwroot; $siteinfo['url'] = $CFG->wwwroot;
@ -185,6 +185,49 @@ class registration {
return $siteinfo; return $siteinfo;
} }
/**
* Human-readable summary of data that will be sent to moodle.net
*
* @param array $siteinfo result of get_site_info()
* @return string
*/
public static function get_stats_summary($siteinfo) {
$summary = html_writer::tag('p', get_string('sendfollowinginfo_help', 'hub')) .
html_writer::start_tag('ul');
$mobileservicesenabled = $siteinfo['mobileservicesenabled'] ? get_string('yes') : get_string('no');
$mobilenotificationsenabled = $siteinfo['mobilenotificationsenabled'] ? get_string('yes') : get_string('no');
$moodlerelease = $siteinfo['moodlerelease'];
if (preg_match('/^(\d+\.\d.*?)[\. ]/', $moodlerelease, $matches)) {
$moodlerelease = $matches[1];
}
$senddata = [
'moodlerelease' => get_string('sitereleasenum', 'hub', $moodlerelease),
'courses' => get_string('coursesnumber', 'hub', $siteinfo['courses']),
'users' => get_string('usersnumber', 'hub', $siteinfo['users']),
'enrolments' => get_string('roleassignmentsnumber', 'hub', $siteinfo['enrolments']),
'posts' => get_string('postsnumber', 'hub', $siteinfo['posts']),
'questions' => get_string('questionsnumber', 'hub', $siteinfo['questions']),
'resources' => get_string('resourcesnumber', 'hub', $siteinfo['resources']),
'badges' => get_string('badgesnumber', 'hub', $siteinfo['badges']),
'issuedbadges' => get_string('issuedbadgesnumber', 'hub', $siteinfo['issuedbadges']),
'participantnumberaverage' => get_string('participantnumberaverage', 'hub',
format_float($siteinfo['participantnumberaverage'], 2)),
'modulenumberaverage' => get_string('modulenumberaverage', 'hub',
format_float($siteinfo['modulenumberaverage'], 2)),
'mobileservicesenabled' => get_string('mobileservicesenabled', 'hub', $mobileservicesenabled),
'mobilenotificationsenabled' => get_string('mobilenotificationsenabled', 'hub', $mobilenotificationsenabled),
'registereduserdevices' => get_string('registereduserdevices', 'hub', $siteinfo['registereduserdevices']),
'registeredactiveuserdevices' => get_string('registeredactiveuserdevices', 'hub', $siteinfo['registeredactiveuserdevices']),
];
foreach ($senddata as $key => $str) {
$summary .= html_writer::tag('li', $str, ['class' => 'site' . $key]);
}
$summary .= html_writer::end_tag('ul');
return $summary;
}
/** /**
* Save registration info locally so it can be retrieved when registration needs to be updated * Save registration info locally so it can be retrieved when registration needs to be updated
* *

View file

@ -26,6 +26,7 @@ namespace core\hub;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
use context_course; use context_course;
use stdClass;
global $CFG; global $CFG;
require_once($CFG->libdir . '/formslib.php'); require_once($CFG->libdir . '/formslib.php');
@ -63,6 +64,7 @@ class site_registration_form extends \moodleform {
'language' => explode('_', current_language())[0], 'language' => explode('_', current_language())[0],
'geolocation' => '', 'geolocation' => '',
'emailalert' => 1, 'emailalert' => 1,
'commnews' => 1
]); ]);
@ -70,18 +72,16 @@ class site_registration_form extends \moodleform {
$mform->addElement('text', 'name', get_string('sitename', 'hub'), $mform->addElement('text', 'name', get_string('sitename', 'hub'),
array('class' => 'registration_textfield')); array('class' => 'registration_textfield'));
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT); $mform->setType('name', PARAM_TEXT);
$mform->addHelpButton('name', 'sitename', 'hub'); $mform->addHelpButton('name', 'sitename', 'hub');
$mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), registration::site_privacy_options()); $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), registration::site_privacy_options());
$mform->setType('privacy', PARAM_ALPHA); $mform->setType('privacy', PARAM_ALPHA);
$mform->addHelpButton('privacy', 'privacy', 'hub'); $mform->addHelpButton('privacy', 'siteprivacy', 'hub');
unset($options); unset($options);
$mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'), $mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'),
array('rows' => 8, 'cols' => 41)); array('rows' => 3, 'cols' => 41));
$mform->addRule('description', $strrequired, 'required', null, 'client');
$mform->setType('description', PARAM_TEXT); $mform->setType('description', PARAM_TEXT);
$mform->addHelpButton('description', 'sitedesc', 'hub'); $mform->addHelpButton('description', 'sitedesc', 'hub');
@ -91,8 +91,8 @@ class site_registration_form extends \moodleform {
$mform->setType('language', PARAM_ALPHANUMEXT); $mform->setType('language', PARAM_ALPHANUMEXT);
$mform->addHelpButton('language', 'sitelang', 'hub'); $mform->addHelpButton('language', 'sitelang', 'hub');
$mform->addElement('textarea', 'street', get_string('postaladdress', 'hub'), // Postal address was part of this form before but not any more.
array('rows' => 4, 'cols' => 41)); $mform->addElement('hidden', 'street');
$mform->setType('street', PARAM_TEXT); $mform->setType('street', PARAM_TEXT);
$mform->addHelpButton('street', 'postaladdress', 'hub'); $mform->addHelpButton('street', 'postaladdress', 'hub');
@ -105,22 +105,19 @@ class site_registration_form extends \moodleform {
$mform->addHelpButton('countrycode', 'sitecountry', 'hub'); $mform->addHelpButton('countrycode', 'sitecountry', 'hub');
$mform->addRule('countrycode', $strrequired, 'required', null, 'client'); $mform->addRule('countrycode', $strrequired, 'required', null, 'client');
$mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'), // Geolocation was part of this form before but not any more.
array('class' => 'registration_textfield')); $mform->addElement('hidden', 'geolocation');
$mform->setType('geolocation', PARAM_RAW); $mform->setType('geolocation', PARAM_RAW);
$mform->addHelpButton('geolocation', 'sitegeolocation', 'hub'); $mform->addHelpButton('geolocation', 'sitegeolocation', 'hub');
$mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'), // Admin name was part of this form before but not any more.
array('class' => 'registration_textfield')); $mform->addElement('hidden', 'contactname');
$mform->addRule('contactname', $strrequired, 'required', null, 'client');
$mform->setType('contactname', PARAM_TEXT); $mform->setType('contactname', PARAM_TEXT);
$mform->addHelpButton('contactname', 'siteadmin', 'hub'); $mform->addHelpButton('contactname', 'siteadmin', 'hub');
$mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'), $mform->addElement('hidden', 'contactphone');
array('class' => 'registration_textfield'));
$mform->setType('contactphone', PARAM_TEXT); $mform->setType('contactphone', PARAM_TEXT);
$mform->addHelpButton('contactphone', 'sitephone', 'hub'); $mform->addHelpButton('contactphone', 'sitephone', 'hub');
$mform->setForceLtr('contactphone');
$mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'), $mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'),
array('class' => 'registration_textfield')); array('class' => 'registration_textfield'));
@ -134,79 +131,30 @@ class site_registration_form extends \moodleform {
$mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options); $mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options);
$mform->setType('contactable', PARAM_INT); $mform->setType('contactable', PARAM_INT);
$mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub'); $mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub');
$mform->hideIf('contactable', 'privacy', 'eq', registration::HUB_SITENOTPUBLISHED);
unset($options); unset($options);
$options = array(); $this->add_select_with_email('emailalert', 'siteregistrationemail', [
$options[0] = get_string("registrationno"); 0 => get_string('registrationno'),
$options[1] = get_string("registrationyes"); 1 => get_string('registrationyes'),
$mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options); ]);
$mform->setType('emailalert', PARAM_INT);
$mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub'); $this->add_select_with_email('commnews', 'sitecommnews', [
unset($options); 0 => get_string('sitecommnewsno', 'hub'),
1 => get_string('sitecommnewsyes', 'hub'),
]);
// TODO site logo. // TODO site logo.
$mform->addElement('hidden', 'imageurl', ''); // TODO: temporary. $mform->addElement('hidden', 'imageurl', ''); // TODO: temporary.
$mform->setType('imageurl', PARAM_URL); $mform->setType('imageurl', PARAM_URL);
$mform->addElement('header', 'sitestats', get_string('sendfollowinginfo', 'hub'));
$mform->setExpanded('sitestats', false);
$mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $siteinfo['url']); $mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $siteinfo['url']);
$mform->addHelpButton('urlstring', 'siteurl', 'hub'); $mform->addHelpButton('urlstring', 'siteurl', 'hub');
$mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version);
$mform->addElement('hidden', 'moodleversion', $siteinfo['moodleversion']);
$mform->setType('moodleversion', PARAM_INT);
$mform->addHelpButton('versionstring', 'siteversion', 'hub');
$mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release);
$mform->addElement('hidden', 'moodlerelease', $siteinfo['moodlerelease']);
$mform->setType('moodlerelease', PARAM_TEXT);
$mform->addHelpButton('releasestring', 'siterelease', 'hub');
// Display statistic that are going to be retrieve by moodle.net. // Display statistic that are going to be retrieve by moodle.net.
$mform->addElement('static', 'siteinfosummary', get_string('sendfollowinginfo', 'hub'), registration::get_stats_summary($siteinfo));
$mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
" " . get_string('coursesnumber', 'hub', $siteinfo['courses']));
$mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
$mform->addElement('static', 'userslabel', '',
" " . get_string('usersnumber', 'hub', $siteinfo['users']));
$mform->addElement('static', 'roleassignmentslabel', '',
" " . get_string('roleassignmentsnumber', 'hub', $siteinfo['enrolments']));
$mform->addElement('static', 'postslabel', '',
" " . get_string('postsnumber', 'hub', $siteinfo['posts']));
$mform->addElement('static', 'questionslabel', '',
" " . get_string('questionsnumber', 'hub', $siteinfo['questions']));
$mform->addElement('static', 'resourceslabel', '',
" " . get_string('resourcesnumber', 'hub', $siteinfo['resources']));
$mform->addElement('static', 'badgeslabel', '',
" " . get_string('badgesnumber', 'hub', $siteinfo['badges']));
$mform->addElement('static', 'issuedbadgeslabel', '',
" " . get_string('issuedbadgesnumber', 'hub', $siteinfo['issuedbadges']));
$mform->addElement('static', 'participantnumberaveragelabel', '',
" " . get_string('participantnumberaverage', 'hub', $siteinfo['participantnumberaverage']));
$mform->addElement('static', 'modulenumberaveragelabel', '',
" " . get_string('modulenumberaverage', 'hub', $siteinfo['modulenumberaverage']));
$mobileservicestatus = $siteinfo['mobileservicesenabled'] ? get_string('yes') : get_string('no');
$mform->addElement('static', 'mobileservicesenabledlabel', '',
" " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
$mobilenotificationsstatus = $siteinfo['mobilenotificationsenabled'] ? get_string('yes') : get_string('no');
$mform->addElement('static', 'mobilenotificationsenabledlabel', '',
" " . get_string('mobilenotificationsenabled', 'hub', $mobilenotificationsstatus));
$mform->addElement('static', 'registereduserdeviceslabel', '',
" " . get_string('registereduserdevices', 'hub', $siteinfo['registereduserdevices']));
$mform->addElement('static', 'registeredactiveuserdeviceslabel', '',
" " . get_string('registeredactiveuserdevices', 'hub', $siteinfo['registeredactiveuserdevices']));
// Check if it's a first registration or update. // Check if it's a first registration or update.
if (registration::is_registered()) { if (registration::is_registered()) {
@ -222,5 +170,99 @@ class site_registration_form extends \moodleform {
$this->set_data($siteinfo); $this->set_data($siteinfo);
} }
/**
* Add yes/no select with additional checkbox allowing to specify another email
*
* @param string $elementname
* @param string $stridentifier
* @param array|null $options options for the select element
*/
protected function add_select_with_email($elementname, $stridentifier, $options = null) {
$mform = $this->_form;
if ($options === null) {
$options = [0 => get_string('no'), 1 => get_string('yes')];
}
$group = [
$mform->createElement('select', $elementname, get_string($stridentifier, 'hub'), $options),
$mform->createElement('static', $elementname . 'sep', '', '<br/>'),
$mform->createElement('advcheckbox', $elementname . 'newemail', '', get_string('usedifferentemail', 'hub'),
['onchange' => "this.form.elements['{$elementname}email'].focus();"]),
$mform->createElement('text', $elementname . 'email', get_string('email'))
];
$mform->addElement('group', $elementname . 'group', get_string($stridentifier, 'hub'), $group, '', false);
$mform->hideIf($elementname . 'email', $elementname, 'eq', 0);
$mform->hideIf($elementname . 'newemail', $elementname, 'eq', 0);
$mform->hideIf($elementname . 'email', $elementname . 'newemail', 'notchecked');
$mform->setType($elementname, PARAM_INT);
$mform->setType($elementname . 'email', PARAM_RAW_TRIMMED); // E-mail will be validated in validation().
$mform->addHelpButton($elementname . 'group', $stridentifier, 'hub');
}
/**
* Load in existing data as form defaults
*
* @param stdClass|array $defaultvalues object or array of default values
*/
public function set_data($defaultvalues) {
if (is_object($defaultvalues)) {
$defaultvalues = (array)$defaultvalues;
}
$defaultvalues['emailalertnewemail'] = !empty($defaultvalues['emailalert']) && !empty($defaultvalues['emailalertemail']);
if (empty($defaultvalues['emailalertnewemail'])) {
$defaultvalues['emailalertemail'] = '';
}
$defaultvalues['commnewsnewemail'] = !empty($defaultvalues['commnews']) && !empty($defaultvalues['commnewsemail']);
if (empty($defaultvalues['commnewsnewemail'])) {
$defaultvalues['commnewsemail'] = '';
}
parent::set_data($defaultvalues);
}
/**
* Validation of the form data
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
// Validate optional emails. We do not use PARAM_EMAIL because it blindly clears the field if it is not a valid email.
if (!empty($data['emailalert']) && !empty($data['emailalertnewemail']) && !validate_email($data['emailalertemail'])) {
$errors['emailalertgroup'] = get_string('invalidemail');
}
if (!empty($data['commnews']) && !empty($data['commnewsnewemail']) && !validate_email($data['commnewsemail'])) {
$errors['commnewsgroup'] = get_string('invalidemail');
}
return $errors;
}
/**
* Returns the form data
*
* @return stdClass
*/
public function get_data() {
if ($data = parent::get_data()) {
// Never return '*newemail' checkboxes, always return 'emailalertemail' and 'commnewsemail' even if not applicable.
if (empty($data->emailalert) || empty($data->emailalertnewemail)) {
$data->emailalertemail = null;
}
unset($data->emailalertnewemail);
if (empty($data->commnews) || empty($data->commnewsnewemail)) {
$data->commnewsemail = null;
}
unset($data->commnewsnewemail);
// Always return 'contactable'.
$data->contactable = empty($data->contactable) ? 0 : 1;
}
return $data;
}
} }