Skip to content

Commit 6e2af17

Browse files
author
rtschu
committed
refactored strings
1 parent 5838944 commit 6e2af17

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

classes/bulkenrol_form.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,37 @@ protected function definition() {
5050

5151
$mform = $this->_form;
5252

53-
// Infotext.
54-
$msg = get_string('bulkenrol_form_intro', 'local_bulkenrol');
55-
$mform->addElement('html', '<div id="intro">'.$msg.'</div>');
56-
5753
// Selector for database field to match list to.
5854
$availablefieldsstring = get_config('local_bulkenrol', 'fieldoptions');
5955
$availablefieldsarray = explode(',', $availablefieldsstring);
60-
if (count($availablefieldsarray) < 1) {
56+
if (count($availablefieldsarray) < 1 or $availablefieldsarray[0] == '') {
6157
print_error(get_string('error_no_options_available', 'local_bulkenrol'));
6258
}
59+
60+
$selectoptions = [];
61+
foreach ($availablefieldsarray as $fieldoption) {
62+
$selectoptions[$fieldoption] = $this->get_fieldname($fieldoption);
63+
}
64+
65+
// Format CSV, replace last , with 'or' and add spaces after remaining.
66+
$fieldnamestring = implode(', ', $selectoptions);
67+
$formattedfieldnamestring = $this->str_last_replace(', ', ' ' . get_string('or', 'local_bulkenrol') . ' ', $fieldnamestring);
68+
69+
// Infotext.
70+
$msg = get_string('bulkenrol_form_intro', 'local_bulkenrol', $formattedfieldnamestring);
71+
$mform->addElement('html', '<div id="intro">'.$msg.'</div>');
72+
73+
// Helptext.
74+
if ($availablefieldsarray[0] == 'u_username') {
75+
$helpstringidentifier = 'userlist_username';
76+
} else if ($availablefieldsarray[0] == 'u_idnumber') {
77+
$helpstringidentifier = 'userlist_idnumber';
78+
} else {
79+
$helpstringidentifier = 'userlist_email';
80+
}
81+
6382
$singleoption = count($availablefieldsarray) == 1;
6483
if (!$singleoption) {
65-
$selectoptions = [];
66-
foreach ($availablefieldsarray as $fieldoption) {
67-
$selectoptions[$fieldoption] = $this->get_fieldname($fieldoption);
68-
}
6984
$mform->addElement('select', 'dbfield', get_string('choose_field', 'local_bulkenrol'), $selectoptions);
7085
$listfieldtitle = get_string('userlist', 'local_bulkenrol');
7186
} else {
@@ -79,7 +94,7 @@ protected function definition() {
7994
$mform->addElement('textarea', 'uservalues',
8095
$listfieldtitle, 'wrap="virtual" rows="10" cols="80"');
8196
$mform->addRule('uservalues', null, 'required');
82-
$mform->addHelpButton('uservalues', 'userlist', 'local_bulkenrol');
97+
$mform->addHelpButton('uservalues', $helpstringidentifier, 'local_bulkenrol');
8398

8499
// Add form content if the user came back to check his input.
85100
$localbulkenroleditlist = optional_param('editlist', 0, PARAM_ALPHANUMEXT);
@@ -131,4 +146,14 @@ private function get_fieldname($fieldoption) {
131146
throw new \UnexpectedValueException("field is not from usertable (u_) or customfield (c_)");
132147
}
133148
}
149+
150+
private function str_last_replace($search, $replace, $subject) {
151+
$pos = strrpos($subject, $search);
152+
153+
if ($pos !== false) {
154+
$subject = substr_replace($subject, $replace, $pos, strlen($search));
155+
}
156+
157+
return $subject;
158+
}
134159
}

lang/en/local_bulkenrol.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
defined('MOODLE_INTERNAL') || die();
2626

2727
$string['bulkenrol:enrolusers'] = 'Use user bulk enrolment';
28-
$string['bulkenrol_form_intro'] = 'Here, you can bulk enrol users to your course. A user to be enrolled is identified by his e-mail address stored in his Moodle account.';
28+
$string['bulkenrol_form_intro'] = 'Here, you can bulk enrol users to your course. A user to be enrolled is identified by their {$a}.';
2929
$string['choose_field'] = 'Choose field to match list to';
3030
$string['enrol_users_successful'] = 'User bulk enrolment successful';
3131
$string['enrol_users'] = 'Enrol users';
@@ -38,36 +38,36 @@
3838
$string['error_getting_user_for_data'] = 'There was a problem when getting the user record for <em>{$a}</em> from the database.';
3939
$string['error_group_add_members'] = 'There was a problem when adding the users to the course group(s).';
4040
$string['error_group_add_member'] = 'There was a problem when adding the user <em>{$a->data}</em> to the course group <em>{$a->group}</em>.';
41-
$string['error_invalid_email'] = 'Invalid e-mail address found in line {$a->row} (<em>{$a->email}</em>). This line will be ignored.';
42-
$string['error_more_than_one_record_for_data'] = 'More than one existing Moodle user account <em>{$a}</em>em> found.<br /> This line will be ignored, none of the existing Moodle users will be enrolled.';
43-
$string['error_no_email'] = 'No e-mail address found in line {$a->line} (<em>{$a->content}</em>). This line will be ignored.';
41+
$string['error_more_than_one_record_for_data'] = 'More than one existing Moodle user account with {$a->field} <em>{$a->identifier}</em>em> found.<br /> This line will be ignored, none of the existing Moodle users will be enrolled.';
4442
$string['error_no_valid_data_in_list'] = 'No valid entrys were found in the given list.<br />Please <a href=\'{$a->url}\'>go back and check your input</a>.';
45-
$string['error_no_record_found_for_email'] = 'No existing Moodle user account with e-mail address <em>{$a}</em>.<br />This line will be ignored, there won\'t be a Moodle user account created on-the-fly.';
46-
$string['error_usermails_empty'] = 'List of e-mail addresses is empty. Please add at least one e-mail address.';
47-
$string['error_check_is_already_member'] = 'Error checking if the user (<em>{$a->email}</em>) is already a member of group (<em>{$a->groupname}</em>). {$a->error}';
4843
$string['groupinfos_headline'] = 'Groups included in the list';
4944
$string['group_name_headline'] = 'Group name';
5045
$string['group_status_create'] = 'Group will be created';
5146
$string['group_status_exists'] = 'Group already exists';
5247
$string['group_status_headline'] = 'Group status';
5348
$string['hints'] = 'Hints';
54-
$string['error_no_record_found_for_email'] = 'No existing Moodle user account <em>{$a}</em> was found.<br />This line will be ignored, there won\'t be a Moodle user account created on-the-fly.';
5549
$string['error_no_data'] = 'No data found (<em>{$a}</em>). This line will be ignored.';
5650
$string['error_no_record_found_for_data'] = 'No existing Moodle user account <em>{$a}</em> was found.<br />This line will be ignored, there won\'t be a Moodle user account created on-the-fly.';
57-
$string['error_usermails_empty'] = 'List of e-mail addresses is empty. Please add at least one e-mail address.';
58-
$string['error_check_is_already_member'] = 'Error checking if the user (<em>{$a->data}</em>) is already a member of group (<em>{$a->groupname}</em>). {$a->error}';
51+
$string['error_no_options_available'] = 'Your administrator has disabled all options. Please contact your administrator';
5952
$string['error_list_empty'] = 'List is empty. Please add at least one fieldvalue';
6053
$string['error_check_is_already_member'] = 'Error checking if the user (<em>{$a->data}</em>) is already a member of group (<em>{$a->groupname}</em>). {$a->error}';
6154
$string['fieldoptions'] = 'Fieldoptions';
6255
$string['fieldoptions_desc'] = 'Fields, that teachers can use as identifier to enrol students by.';
6356
$string['pluginname'] = 'User bulk enrolment';
57+
$string['or'] = 'or';
6458
$string['privacy:metadata'] = 'The user bulk enrolment plugin acts as a tool to enrol users into courses, but does not store any personal data.';
6559
$string['role'] = 'Role';
6660
$string['role_assigned'] = 'Assigned role';
6761
$string['role_description'] = 'The role to be used to bulk enrol the users.';
6862
$string['row'] = 'Row';
6963
$string['userlist'] = 'List of users identified by your chosen field';
70-
$string['userlist_help'] = 'To enrol an existing Moodle user into this course, choose a field to identify the user by and add the identifyer to the list. <br /><br />Example for field "email" :<br />[email protected]<br />[email protected]<br /><br />Optionally, you are able to create groups and add the enrolled users to the groups. All you have to do is to add a heading line with a hash sign and the group\'s name, separating the list of users.<br /><br />Example:<br /># Group 1<br />[email protected]<br />[email protected]<br /># Group 2<br />[email protected]<br />[email protected]';
64+
$string['userlist_singleoption'] = 'List of users identified by their {$a}';
65+
$string['userlist_email'] = 'data input';
66+
$string['userlist_username'] = 'data input';
67+
$string['userlist_idnumber'] = 'data input';
68+
$string['userlist_email_help'] = 'To enrol an existing Moodle user into this course, choose a field to identify the user by and add the identifier to the list. <br /><br />Example for field "email" :<br />[email protected]<br />[email protected]<br /><br />Optionally, you are able to create groups and add the enrolled users to the groups. All you have to do is to add a heading line with a hash sign and the group\'s name, separating the list of users.<br /><br />Example:<br /># Group 1<br />[email protected]<br />[email protected]<br /># Group 2<br />[email protected]<br />[email protected]';
69+
$string['userlist_username_help'] = 'To enrol an existing Moodle user into this course, choose a field to identify the user by and add the identifier to the list. <br /><br />Example for field "username" :<br />alice<br />bob<br /><br />Optionally, you are able to create groups and add the enrolled users to the groups. All you have to do is to add a heading line with a hash sign and the group\'s name, separating the list of users.<br /><br />Example:<br /># Group 1<br />alice<br />bob<br /># Group 2<br />carol<br />dave';
70+
$string['userlist_idnumber_help'] = 'To enrol an existing Moodle user into this course, choose a field to identify the user by and add the identifier to the list. <br /><br />Example for field "idnumber" :<br />1001<br />1002<br /><br />Optionally, you are able to create groups and add the enrolled users to the groups. All you have to do is to add a heading line with a hash sign and the group\'s name, separating the list of users.<br /><br />Example:<br /># Group 1<br />1001<br />1002<br /># Group 2<br />1003<br />1004';
7171
$string['users_to_enrol_in_course'] = 'Users to be enrolled into the course';
7272
$string['user_enroled'] = 'User enrolment';
7373
$string['user_enroled_yes'] = 'User will be enrolled';

locallib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function local_bulkenrol_get_user($data, $datafield) {
243243
if (!empty($count)) {
244244
// More than one user with data -> ignore data and don't enrol users later!
245245
if ($count > 1) {
246-
$error = get_string('error_more_than_one_record_for_data', 'local_bulkenrol', $data);
246+
$error = get_string('error_more_than_one_record_for_data', 'local_bulkenrol', array('identifier' => $data, "field" => $datafield));
247247
} else {
248248
$userrecord = current($userrecords);
249249
}

0 commit comments

Comments
 (0)