MDL-55472 assign: Show userlist on extension form error page

This commit is contained in:
Ilya Tregubov 2016-08-17 15:40:19 +10:00 committed by Ilya Tregubov
parent 26162efe4a
commit ffcfffbe64
3 changed files with 106 additions and 63 deletions

View file

@ -43,6 +43,8 @@ class mod_assign_extension_form extends moodleform {
* Define the form - called by parent constructor * Define the form - called by parent constructor
*/ */
public function definition() { public function definition() {
global $DB;
$mform = $this->_form; $mform = $this->_form;
$params = $this->_customdata; $params = $this->_customdata;
@ -50,13 +52,37 @@ class mod_assign_extension_form extends moodleform {
$instance = $params['instance']; $instance = $params['instance'];
$this->instance = $instance; $this->instance = $instance;
if (!empty($params['userscount'])) { // Get the assignment class.
$listusersmessage = get_string('grantextensionforusers', 'assign', $params['userscount']); $assign = $params['assign'];
$mform->addElement('header', 'general', $listusersmessage); $userlist = $params['userlist'];
$mform->addElement('static', 'userslist', get_string('selectedusers', 'assign'), $params['usershtml']); $usercount = 0;
} else { $usershtml = '';
$mform->addElement('static', 'userslist', '', $params['usershtml']);
$extrauserfields = get_extra_user_fields($assign->get_context());
foreach ($userlist as $userid) {
if ($usercount >= 5) {
$usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
break;
}
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$usershtml .= $assign->get_renderer()->render(new assign_user_summary($user,
$assign->get_course()->id,
has_capability('moodle/site:viewfullnames',
$assign->get_course_context()),
$assign->is_blind_marking(),
$assign->get_uniqueid_for_user($user->id),
$extrauserfields,
!$assign->is_active_user($userid)));
$usercount += 1;
} }
$userscount = count($userlist);
$listusersmessage = get_string('grantextensionforusers', 'assign', $userscount);
$mform->addElement('header', 'general', $listusersmessage);
$mform->addElement('static', 'userslist', get_string('selectedusers', 'assign'), $usershtml);
if ($instance->allowsubmissionsfromdate) { if ($instance->allowsubmissionsfromdate) {
$mform->addElement('static', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'), $mform->addElement('static', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'),
userdate($instance->allowsubmissionsfromdate)); userdate($instance->allowsubmissionsfromdate));

View file

@ -2226,7 +2226,7 @@ class assign {
* @return string * @return string
*/ */
protected function view_grant_extension($mform) { protected function view_grant_extension($mform) {
global $DB, $CFG; global $CFG;
require_once($CFG->dirroot . '/mod/assign/extensionform.php'); require_once($CFG->dirroot . '/mod/assign/extensionform.php');
$o = ''; $o = '';
@ -2235,64 +2235,24 @@ class assign {
$data->id = $this->get_course_module()->id; $data->id = $this->get_course_module()->id;
$formparams = array( $formparams = array(
'instance' => $this->get_instance() 'instance' => $this->get_instance(),
'assign' => $this
); );
$extrauserfields = get_extra_user_fields($this->get_context()); $users = optional_param('userid', 0, PARAM_INT);
if (!$users) {
if ($mform) { $users = required_param('selectedusers', PARAM_SEQUENCE);
$submitteddata = $mform->get_data();
$users = $submitteddata->selectedusers;
$userlist = explode(',', $users);
$data->selectedusers = $users;
$data->userid = 0;
$usershtml = '';
$usercount = 0;
foreach ($userlist as $userid) {
if ($usercount >= 5) {
$usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
break;
}
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$usershtml .= $this->get_renderer()->render(new assign_user_summary($user,
$this->get_course()->id,
has_capability('moodle/site:viewfullnames',
$this->get_course_context()),
$this->is_blind_marking(),
$this->get_uniqueid_for_user($user->id),
$extrauserfields,
!$this->is_active_user($userid)));
$usercount += 1;
}
$formparams['userscount'] = count($userlist);
$formparams['usershtml'] = $usershtml;
} else {
$userid = required_param('userid', PARAM_INT);
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
$flags = $this->get_user_flags($userid, false);
$data->userid = $user->id;
if ($flags) {
$data->extensionduedate = $flags->extensionduedate;
}
$usershtml = $this->get_renderer()->render(new assign_user_summary($user,
$this->get_course()->id,
has_capability('moodle/site:viewfullnames',
$this->get_course_context()),
$this->is_blind_marking(),
$this->get_uniqueid_for_user($user->id),
$extrauserfields,
!$this->is_active_user($userid)));
$formparams['usershtml'] = $usershtml;
} }
$userlist = explode(',', $users);
$mform = new mod_assign_extension_form(null, $formparams); $formparams['userlist'] = $userlist;
$data->selectedusers = $users;
$data->userid = 0;
if (empty($mform)) {
$mform = new mod_assign_extension_form(null, $formparams);
}
$mform->set_data($data); $mform->set_data($data);
$header = new assign_header($this->get_instance(), $header = new assign_header($this->get_instance(),
$this->get_context(), $this->get_context(),
@ -4176,6 +4136,7 @@ class assign {
if ($data->operation == 'grantextension') { if ($data->operation == 'grantextension') {
// Reset the form so the grant extension page will create the extension form. // Reset the form so the grant extension page will create the extension form.
$mform = null;
return 'grantextension'; return 'grantextension';
} else if ($data->operation == 'setmarkingworkflowstate') { } else if ($data->operation == 'setmarkingworkflowstate') {
return 'viewbatchsetmarkingworkflowstate'; return 'viewbatchsetmarkingworkflowstate';
@ -5832,10 +5793,16 @@ class assign {
require_once($CFG->dirroot . '/mod/assign/extensionform.php'); require_once($CFG->dirroot . '/mod/assign/extensionform.php');
require_sesskey(); require_sesskey();
$users = optional_param('userid', 0, PARAM_INT);
if (!$users) {
$users = required_param('selectedusers', PARAM_SEQUENCE);
}
$userlist = explode(',', $users);
$formparams = array( $formparams = array(
'instance' => $this->get_instance(), 'instance' => $this->get_instance(),
'userscount' => 0, 'assign' => $this,
'usershtml' => '', 'userlist' => $userlist
); );
$mform = new mod_assign_extension_form(null, $formparams); $mform = new mod_assign_extension_form(null, $formparams);

View file

@ -79,3 +79,53 @@ Feature: Grant an extension to an offline student
And I follow "Course 1" And I follow "Course 1"
And I follow "Test assignment name" And I follow "Test assignment name"
And I should see "Extension due date" And I should see "Extension due date"
@javascript
Scenario: Validating that extension date is after due date
Given the following "activities" exist:
| activity | course | idnumber | name | intro | assignsubmission_onlinetext_enabled | assignsubmission_file_enabled | allowsubmissionsfromdate | duedate |
| assign | C1 | assign1 | Test assignment name | Test assignment description | 0 | 0 | 1388534400 | 1388620800 |
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Test assignment name"
When I follow "View all submissions"
And I click on "Edit" "link" in the "Student 1" "table_row"
And I follow "Grant extension"
And I should see "Student 1 (student1@example.com)"
And I set the field "Enable" to "1"
And I set the following fields to these values:
| extensionduedate[day] | 1 |
And I press "Save changes"
Then I should see "Extension date must be after the due date"
And I set the following fields to these values:
| extensionduedate[year] | 2013 |
And I press "Save changes"
Then I should see "Extension date must be after the allow submissions from date"
@javascript @_alert
Scenario: Granting extensions to an offline assignment (batch action)
Given the following "activities" exist:
| activity | course | idnumber | name | intro | assignsubmission_onlinetext_enabled | assignsubmission_file_enabled | allowsubmissionsfromdate | duedate |
| assign | C1 | assign1 | Test assignment name | Test assignment description | 0 | 0 | 1388534400 | 1388620800 |
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Test assignment name"
When I follow "View all submissions"
And I set the field "selectall" to "1"
And I set the field "operation" to "Grant extension"
And I click on "Go" "button" confirming the dialogue
And I should see "Student 1 (student1@example.com)"
And I should see "Student 2 (student2@example.com)"
And I should see "Student 3 (student3@example.com)"
And I should see "Student 4 (student4@example.com)"
And I should see "Student 5 (student5@example.com)"
And I should see "1 more..."
And I set the field "Enable" to "1"
And I set the following fields to these values:
| extensionduedate[day] | 1 |
And I press "Save changes"
Then I should see "Extension date must be after the due date"
And I set the following fields to these values:
| extensionduedate[year] | 2013 |
And I press "Save changes"
Then I should see "Extension date must be after the allow submissions from date"