Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 25... Línea 25...
25
namespace core\hub;
25
namespace core\hub;
26
defined('MOODLE_INTERNAL') || die();
26
defined('MOODLE_INTERNAL') || die();
Línea 27... Línea 27...
27
 
27
 
28
use context_course;
28
use context_course;
-
 
29
use stdClass;
-
 
30
use html_writer;
Línea 29... Línea 31...
29
use stdClass;
31
use moodle_url;
30
 
32
 
Línea 31... Línea 33...
31
global $CFG;
33
global $CFG;
Línea 49... Línea 51...
49
 
51
 
50
        $strrequired = get_string('required');
52
        $strrequired = get_string('required');
51
        $mform = & $this->_form;
53
        $mform = & $this->_form;
52
        $admin = get_admin();
54
        $admin = get_admin();
-
 
55
        $site = get_site();
Línea 53... Línea 56...
53
        $site = get_site();
56
        $registered = $this->_customdata['registered'];
54
 
57
 
55
        $siteinfo = registration::get_site_info([
58
        $siteinfo = registration::get_site_info([
56
            'name' => format_string($site->fullname, true, array('context' => context_course::instance(SITEID))),
59
            'name' => format_string($site->fullname, true, array('context' => context_course::instance(SITEID))),
Línea 63... Línea 66...
63
            'regioncode' => '-', // Not supported yet.
66
            'regioncode' => '-', // Not supported yet.
64
            'language' => explode('_', current_language())[0],
67
            'language' => explode('_', current_language())[0],
65
            'geolocation' => '',
68
            'geolocation' => '',
66
            'emailalert' => 0,
69
            'emailalert' => 0,
67
            'commnews' => 0,
70
            'commnews' => 0,
68
            'policyagreed' => 0
71
            'policyagreed' => 0,
69
 
-
 
-
 
72
            'organisationtype' => '',
70
        ]);
73
        ]);
Línea 71... Línea 74...
71
 
74
 
72
        // Fields that need to be highlighted.
75
        // Fields that need to be highlighted.
Línea 77... Línea 80...
77
        $mform->addElement('text', 'name', get_string('sitename', 'hub'),
80
        $mform->addElement('text', 'name', get_string('sitename', 'hub'),
78
            array('class' => 'registration_textfield', 'maxlength' => 255));
81
            array('class' => 'registration_textfield', 'maxlength' => 255));
79
        $mform->setType('name', PARAM_TEXT);
82
        $mform->setType('name', PARAM_TEXT);
80
        $mform->addHelpButton('name', 'sitename', 'hub');
83
        $mform->addHelpButton('name', 'sitename', 'hub');
Línea -... Línea 84...
-
 
84
 
-
 
85
        $organisationtypes = registration::get_site_organisation_type_options();
-
 
86
        \core_collator::asort($organisationtypes);
-
 
87
        // Prepend the empty/default value here. We are not using array_merge to preserve keys.
-
 
88
        $organisationtypes = ['' => get_string('siteorganisationtype:donotshare', 'hub')] + $organisationtypes;
-
 
89
        $mform->addElement('select', 'organisationtype', get_string('siteorganisationtype', 'hub'), $organisationtypes);
-
 
90
        $mform->setType('organisationtype', PARAM_ALPHANUM);
-
 
91
        $mform->addHelpButton('organisationtype', 'siteorganisationtype', 'hub');
81
 
92
 
82
        $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), registration::site_privacy_options());
93
        $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), registration::site_privacy_options());
83
        $mform->setType('privacy', PARAM_ALPHA);
94
        $mform->setType('privacy', PARAM_ALPHA);
84
        $mform->addHelpButton('privacy', 'siteprivacy', 'hub');
95
        $mform->addHelpButton('privacy', 'siteprivacy', 'hub');
Línea 127... Línea 138...
127
            array('class' => 'registration_textfield'));
138
            array('class' => 'registration_textfield'));
128
        $mform->addRule('contactemail', $strrequired, 'required', null, 'client');
139
        $mform->addRule('contactemail', $strrequired, 'required', null, 'client');
129
        $mform->setType('contactemail', PARAM_EMAIL);
140
        $mform->setType('contactemail', PARAM_EMAIL);
130
        $mform->addHelpButton('contactemail', 'siteemail', 'hub');
141
        $mform->addHelpButton('contactemail', 'siteemail', 'hub');
Línea 131... Línea -...
131
 
-
 
132
        $options = array();
-
 
133
        $options[0] = get_string("registrationcontactno");
-
 
134
        $options[1] = get_string("registrationcontactyes");
-
 
135
        $mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options);
-
 
136
        $mform->setType('contactable', PARAM_INT);
-
 
137
        $mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub');
-
 
138
        $mform->hideIf('contactable', 'privacy', 'eq', registration::HUB_SITENOTPUBLISHED);
-
 
139
        unset($options);
-
 
140
 
142
 
Línea -... Línea 143...
-
 
143
        $this->add_checkbox_with_email('emailalert', 'siteregistrationemail', false, get_string('registrationyes'));
-
 
144
 
141
        $this->add_checkbox_with_email('emailalert', 'siteregistrationemail', false, get_string('registrationyes'));
145
        $privacyurl = new moodle_url('https://moodle.com/privacy-notice/');
142
 
146
        $experttipsandinsightsdesc = html_writer::span(get_string('experttipsandinsightsdesc', 'hub', $privacyurl->out()));
143
        $this->add_checkbox_with_email(
147
        $this->add_checkbox_with_email(
144
            'commnews',
148
            elementname: 'commnews',
145
            'sitecommnews',
149
            stridentifier: 'experttipsandinsights',
-
 
150
            highlight: in_array('commnews', $highlightfields),
146
            in_array('commnews', $highlightfields),
151
            checkboxtext: $experttipsandinsightsdesc,
Línea 147... Línea 152...
147
            get_string('sitecommnewsyes', 'hub')
152
            showhelp: false,
148
        );
153
        );
149
 
154
 
Línea 162... Línea 167...
162
 
167
 
163
        // Display statistic that are going to be retrieve by the sites directory.
168
        // Display statistic that are going to be retrieve by the sites directory.
Línea 164... Línea 169...
164
        $mform->addElement('static', 'siteinfosummary', get_string('sendfollowinginfo', 'hub'), registration::get_stats_summary($siteinfo));
169
        $mform->addElement('static', 'siteinfosummary', get_string('sendfollowinginfo', 'hub'), registration::get_stats_summary($siteinfo));
165
 
170
 
166
        // Check if it's a first registration or update.
171
        // Check if it's a first registration or update.
167
        if (registration::is_registered()) {
172
        if ($registered) {
168
            $buttonlabel = get_string('updatesiteregistration', 'core_hub');
173
            $buttonlabel = get_string('updatesiteregistration', 'core_hub');
169
            $mform->addElement('hidden', 'update', true);
174
            $mform->addElement('hidden', 'update', true);
170
            $mform->setType('update', PARAM_BOOL);
175
            $mform->setType('update', PARAM_BOOL);
Línea 190... Línea 195...
190
        // Set data. Always require to check policyagreed even if it was checked earlier.
195
        // Set data. Always require to check policyagreed even if it was checked earlier.
191
        $this->set_data(['policyagreed' => 0] + $siteinfo);
196
        $this->set_data(['policyagreed' => 0] + $siteinfo);
192
    }
197
    }
Línea 193... Línea 198...
193
 
198
 
194
    /**
-
 
195
     * Add yes/no select with additional checkbox allowing to specify another email
-
 
196
     *
199
    /**
197
     * @deprecated since Moodle 3.11 - MDL-71460 The form elements using this have been converted to checkboxes
-
 
198
     * @todo MDL-71472 - Will be deleted in 4.3
-
 
199
     * @see \core\hub\site_registration_form::add_checkbox_with_email()
-
 
200
     * @param string $elementname
-
 
201
     * @param string $stridentifier
-
 
202
     * @param array|null $options options for the select element
-
 
203
     * @param bool $highlight highlight as a new field
200
     * @deprecated since Moodle 3.11 - MDL-71460 The form elements using this have been converted to checkboxes
204
     */
-
 
205
    protected function add_select_with_email($elementname, $stridentifier, $options = null, $highlight = false) {
-
 
206
        debugging('add_select_with_email() is deprecated. Please use add_checkbox_with_email() instead.', DEBUG_DEVELOPER);
-
 
207
 
-
 
208
        $mform = $this->_form;
-
 
209
 
201
     */
210
        if ($options === null) {
202
    #[\core\attribute\deprecated(
211
            $options = [0 => get_string('no'), 1 => get_string('yes')];
-
 
212
        }
-
 
213
 
203
        '\core\hub\site_registration_form::add_checkbox_with_email()',
214
        $group = [
-
 
215
            $mform->createElement('select', $elementname, get_string($stridentifier, 'hub'), $options),
-
 
216
            $mform->createElement('static', $elementname . 'sep', '', '<br/>'),
-
 
217
            $mform->createElement('advcheckbox', $elementname . 'newemail', '', get_string('usedifferentemail', 'hub'),
-
 
218
                ['onchange' => "this.form.elements['{$elementname}email'].focus();"]),
-
 
219
            $mform->createElement('text', $elementname . 'email', get_string('email'))
204
        since: '3.11',
220
        ];
-
 
221
 
-
 
222
        $element = $mform->addElement('group', $elementname . 'group', get_string($stridentifier, 'hub'), $group, '', false);
205
        mdl: 'MDL-71460',
223
        if ($highlight) {
-
 
224
            $element->setAttributes(['class' => $element->getAttribute('class') . ' needsconfirmation mark']);
206
        final: true,
225
        }
-
 
226
        $mform->hideIf($elementname . 'email', $elementname, 'eq', 0);
-
 
227
        $mform->hideIf($elementname . 'newemail', $elementname, 'eq', 0);
-
 
228
        $mform->hideIf($elementname . 'email', $elementname . 'newemail', 'notchecked');
207
    )]
229
        $mform->setType($elementname, PARAM_INT);
-
 
230
        $mform->setType($elementname . 'email', PARAM_RAW_TRIMMED); // E-mail will be validated in validation().
208
    protected function add_select_with_email() {
231
        $mform->addHelpButton($elementname . 'group', $stridentifier, 'hub');
-
 
232
 
209
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
Línea 233... Línea 210...
233
    }
210
    }
234
 
211
 
235
    /**
212
    /**
236
     * Add yes/no checkbox with additional checkbox allowing to specify another email
213
     * Add yes/no checkbox with additional checkbox allowing to specify another email
237
     *
214
     *
238
     * @param string $elementname
215
     * @param string $elementname
239
     * @param string $stridentifier
216
     * @param string $stridentifier
-
 
217
     * @param bool $highlight highlight as a new field
240
     * @param bool $highlight highlight as a new field
218
     * @param string $checkboxtext The text to show after the text.
241
     * @param string $checkboxtext The text to show after the text.
219
     * @param bool $showhelp Show the help icon.
-
 
220
     */
-
 
221
    protected function add_checkbox_with_email(
-
 
222
        string $elementname,
-
 
223
        string $stridentifier,
-
 
224
        bool $highlight = false,
-
 
225
        string $checkboxtext = '',
242
     */
226
        bool $showhelp = true,
Línea 243... Línea 227...
243
    protected function add_checkbox_with_email($elementname, $stridentifier, $highlight = false, string $checkboxtext = '') {
227
    ): void {
244
        $mform = $this->_form;
228
        $mform = $this->_form;
245
 
229
 
Línea 258... Línea 242...
258
        $mform->hideif($elementname . 'email', $elementname, 'eq', 0);
242
        $mform->hideif($elementname . 'email', $elementname, 'eq', 0);
259
        $mform->hideif($elementname . 'newemail', $elementname, 'eq', 0);
243
        $mform->hideif($elementname . 'newemail', $elementname, 'eq', 0);
260
        $mform->hideif($elementname . 'email', $elementname . 'newemail', 'notchecked');
244
        $mform->hideif($elementname . 'email', $elementname . 'newemail', 'notchecked');
261
        $mform->setType($elementname, PARAM_INT);
245
        $mform->setType($elementname, PARAM_INT);
262
        $mform->setType($elementname . 'email', PARAM_RAW_TRIMMED); // E-mail will be validated in validation().
246
        $mform->setType($elementname . 'email', PARAM_RAW_TRIMMED); // E-mail will be validated in validation().
-
 
247
        if ($showhelp) {
263
        $mform->addHelpButton($elementname . 'group', $stridentifier, 'hub');
248
            $mform->addHelpButton($elementname . 'group', $stridentifier, 'hub');
-
 
249
        }
Línea 264... Línea 250...
264
 
250
 
Línea 265... Línea 251...
265
    }
251
    }
266
 
252
 
Línea 291... Línea 277...
291
     */
277
     */
292
    public function get_data() {
278
    public function get_data() {
293
        if ($data = parent::get_data()) {
279
        if ($data = parent::get_data()) {
294
            // Never return '*newemail' checkboxes, always return 'emailalertemail' and 'commnewsemail' even if not applicable.
280
            // Never return '*newemail' checkboxes, always return 'emailalertemail' and 'commnewsemail' even if not applicable.
295
            if (empty($data->emailalert) || empty($data->emailalertnewemail)) {
281
            if (empty($data->emailalert) || empty($data->emailalertnewemail)) {
296
                $data->emailalertemail = null;
282
                $data->emailalertemail = '';
297
            }
283
            }
298
            unset($data->emailalertnewemail);
284
            unset($data->emailalertnewemail);
299
            if (empty($data->commnews) || empty($data->commnewsnewemail)) {
285
            if (empty($data->commnews) || empty($data->commnewsnewemail)) {
300
                $data->commnewsemail = null;
286
                $data->commnewsemail = '';
301
            }
287
            }
302
            unset($data->commnewsnewemail);
288
            unset($data->commnewsnewemail);
303
            // Always return 'contactable'.
-
 
304
            $data->contactable = empty($data->contactable) ? 0 : 1;
-
 
Línea 305... Línea 289...
305
 
289
 
306
            if (debugging('', DEBUG_DEVELOPER)) {
290
            if (debugging('', DEBUG_DEVELOPER)) {
307
                // Display debugging message for developers who added fields to the form and forgot to add them to registration::FORM_FIELDS.
291
                // Display debugging message for developers who added fields to the form and forgot to add them to registration::FORM_FIELDS.
308
                $keys = array_diff(array_keys((array)$data),
292
                $keys = array_diff(array_keys((array)$data),