Merge branch 'MDL-55472-assign-extend-ignored-validation' of https://github.com/ilya-catalyst/moodle

This commit is contained in:
Dan Poltawski 2016-09-26 15:31:30 +01:00
commit 6e181725ca
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
*/
public function definition() {
global $DB;
$mform = $this->_form;
$params = $this->_customdata;
@ -50,13 +52,37 @@ class mod_assign_extension_form extends moodleform {
$instance = $params['instance'];
$this->instance = $instance;
if (!empty($params['userscount'])) {
$listusersmessage = get_string('grantextensionforusers', 'assign', $params['userscount']);
$mform->addElement('header', 'general', $listusersmessage);
$mform->addElement('static', 'userslist', get_string('selectedusers', 'assign'), $params['usershtml']);
} else {
$mform->addElement('static', 'userslist', '', $params['usershtml']);
// Get the assignment class.
$assign = $params['assign'];
$userlist = $params['userlist'];
$usercount = 0;
$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) {
$mform->addElement('static', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'),
userdate($instance->allowsubmissionsfromdate));

View File

@ -2226,7 +2226,7 @@ class assign {
* @return string
*/
protected function view_grant_extension($mform) {
global $DB, $CFG;
global $CFG;
require_once($CFG->dirroot . '/mod/assign/extensionform.php');
$o = '';
@ -2235,64 +2235,24 @@ class assign {
$data->id = $this->get_course_module()->id;
$formparams = array(
'instance' => $this->get_instance()
'instance' => $this->get_instance(),
'assign' => $this
);
$extrauserfields = get_extra_user_fields($this->get_context());
if ($mform) {
$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;
$users = optional_param('userid', 0, PARAM_INT);
if (!$users) {
$users = required_param('selectedusers', PARAM_SEQUENCE);
}
$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);
$header = new assign_header($this->get_instance(),
$this->get_context(),
@ -4176,6 +4136,7 @@ class assign {
if ($data->operation == 'grantextension') {
// Reset the form so the grant extension page will create the extension form.
$mform = null;
return 'grantextension';
} else if ($data->operation == 'setmarkingworkflowstate') {
return 'viewbatchsetmarkingworkflowstate';
@ -5832,10 +5793,16 @@ class assign {
require_once($CFG->dirroot . '/mod/assign/extensionform.php');
require_sesskey();
$users = optional_param('userid', 0, PARAM_INT);
if (!$users) {
$users = required_param('selectedusers', PARAM_SEQUENCE);
}
$userlist = explode(',', $users);
$formparams = array(
'instance' => $this->get_instance(),
'userscount' => 0,
'usershtml' => '',
'assign' => $this,
'userlist' => $userlist
);
$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 "Test assignment name"
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"