Merge branch 'MDL-44598_master' of https://github.com/jonof/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2015-11-30 23:52:45 +01:00
commit 71a2aaabd4
3 changed files with 107 additions and 48 deletions

View file

@ -44,19 +44,25 @@ class mod_assign_extension_form extends moodleform {
*/ */
public function definition() { public function definition() {
$mform = $this->_form; $mform = $this->_form;
$params = $this->_customdata;
list($coursemoduleid, $userid, $batchusers, $instance, $data) = $this->_customdata;
// Instance variable is used by the form validation function. // Instance variable is used by the form validation function.
$instance = $params['instance'];
$this->instance = $instance; $this->instance = $instance;
if ($batchusers) { if (!empty($params['userscount'])) {
$listusersmessage = get_string('grantextensionforusers', 'assign', count(explode(',', $batchusers))); $listusersmessage = get_string('grantextensionforusers', 'assign', $params['userscount']);
$mform->addElement('static', 'applytoselectedusers', '', $listusersmessage); $mform->addElement('header', 'general', $listusersmessage);
$mform->addElement('static', 'userslist', get_string('selectedusers', 'assign'), $params['usershtml']);
} else {
$mform->addElement('static', 'userslist', '', $params['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));
} }
$finaldate = 0;
if ($instance->duedate) { if ($instance->duedate) {
$mform->addElement('static', 'duedate', get_string('duedate', 'assign'), userdate($instance->duedate)); $mform->addElement('static', 'duedate', get_string('duedate', 'assign'), userdate($instance->duedate));
$finaldate = $instance->duedate; $finaldate = $instance->duedate;
@ -68,19 +74,17 @@ class mod_assign_extension_form extends moodleform {
$mform->addElement('date_time_selector', 'extensionduedate', $mform->addElement('date_time_selector', 'extensionduedate',
get_string('extensionduedate', 'assign'), array('optional'=>true)); get_string('extensionduedate', 'assign'), array('optional'=>true));
$mform->setDefault('extensionduedate', $finaldate); $mform->setDefault('extensionduedate', $finaldate);
$mform->addElement('hidden', 'id', $coursemoduleid);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'userid', $userid); $mform->addElement('hidden', 'userid');
$mform->setType('userid', PARAM_INT); $mform->setType('userid', PARAM_INT);
$mform->addElement('hidden', 'selectedusers', $batchusers); $mform->addElement('hidden', 'selectedusers');
$mform->setType('selectedusers', PARAM_SEQUENCE); $mform->setType('selectedusers', PARAM_SEQUENCE);
$mform->addElement('hidden', 'action', 'saveextension'); $mform->addElement('hidden', 'action', 'saveextension');
$mform->setType('action', PARAM_ALPHA); $mform->setType('action', PARAM_ALPHA);
$this->add_action_buttons(true, get_string('savechanges', 'assign'));
if ($data) { $this->add_action_buttons(true, get_string('savechanges', 'assign'));
$this->set_data($data);
}
} }
/** /**

View file

@ -2012,39 +2012,76 @@ class assign {
require_once($CFG->dirroot . '/mod/assign/extensionform.php'); require_once($CFG->dirroot . '/mod/assign/extensionform.php');
$o = ''; $o = '';
$batchusers = optional_param('selectedusers', '', PARAM_SEQUENCE);
$data = new stdClass(); $data = new stdClass();
$data->extensionduedate = null; $data->id = $this->get_course_module()->id;
$userid = 0;
if (!$batchusers) {
$userid = required_param('userid', PARAM_INT);
$flags = $this->get_user_flags($userid, false); $formparams = array(
'instance' => $this->get_instance()
);
$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); $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) { if ($flags) {
$data->extensionduedate = $flags->extensionduedate; $data->extensionduedate = $flags->extensionduedate;
} }
$data->userid = $userid;
} else { $usershtml = $this->get_renderer()->render(new assign_user_summary($user,
$data->batchusers = $batchusers; $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;
} }
$mform = new mod_assign_extension_form(null, $formparams);
$mform->set_data($data);
$header = new assign_header($this->get_instance(), $header = new assign_header($this->get_instance(),
$this->get_context(), $this->get_context(),
$this->show_intro(), $this->show_intro(),
$this->get_course_module()->id, $this->get_course_module()->id,
get_string('grantextension', 'assign')); get_string('grantextension', 'assign'));
$o .= $this->get_renderer()->render($header); $o .= $this->get_renderer()->render($header);
if (!$mform) {
$formparams = array($this->get_course_module()->id,
$userid,
$batchusers,
$this->get_instance(),
$data);
$mform = new mod_assign_extension_form(null, $formparams);
}
$o .= $this->get_renderer()->render(new assign_form('extensionform', $mform)); $o .= $this->get_renderer()->render(new assign_form('extensionform', $mform));
$o .= $this->view_footer(); $o .= $this->view_footer();
return $o; return $o;
@ -3707,7 +3744,6 @@ 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';
@ -5296,34 +5332,34 @@ class assign {
require_once($CFG->dirroot . '/mod/assign/extensionform.php'); require_once($CFG->dirroot . '/mod/assign/extensionform.php');
require_sesskey(); require_sesskey();
$batchusers = optional_param('selectedusers', '', PARAM_SEQUENCE); $formparams = array(
$userid = 0; 'instance' => $this->get_instance(),
if (!$batchusers) { 'userscount' => 0,
$userid = required_param('userid', PARAM_INT); 'usershtml' => '',
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST); );
}
$mform = new mod_assign_extension_form(null, array($this->get_course_module()->id, $mform = new mod_assign_extension_form(null, $formparams);
$userid,
$batchusers,
$this->get_instance(),
null));
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {
return true; return true;
} }
if ($formdata = $mform->get_data()) { if ($formdata = $mform->get_data()) {
if ($batchusers) { if (!empty($formdata->selectedusers)) {
$users = explode(',', $batchusers); $users = explode(',', $formdata->selectedusers);
$result = true; $result = true;
foreach ($users as $userid) { foreach ($users as $userid) {
$result = $this->save_user_extension($userid, $formdata->extensionduedate) && $result; $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$result = $this->save_user_extension($user->id, $formdata->extensionduedate) && $result;
} }
return $result; return $result;
} else { }
return $this->save_user_extension($userid, $formdata->extensionduedate); if (!empty($formdata->userid)) {
$user = $DB->get_record('user', array('id' => $formdata->userid), '*', MUST_EXIST);
return $this->save_user_extension($user->id, $formdata->extensionduedate);
} }
} }
return false; return false;
} }

View file

@ -13,11 +13,19 @@ Feature: Grant an extension to an offline student
| teacher1 | Teacher | 1 | teacher1@example.com | | teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com | | student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com | | student2 | Student | 2 | student2@example.com |
| student3 | Student | 3 | student3@example.com |
| student4 | Student | 4 | student4@example.com |
| student5 | Student | 5 | student5@example.com |
| student6 | Student | 6 | student6@example.com |
And the following "course enrolments" exist: And the following "course enrolments" exist:
| user | course | role | | user | course | role |
| teacher1 | C1 | editingteacher | | teacher1 | C1 | editingteacher |
| student1 | C1 | student | | student1 | C1 | student |
| student2 | C1 | student | | student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
| student5 | C1 | student |
| student6 | C1 | student |
@javascript @javascript
Scenario: Granting an extension to an offline assignment Scenario: Granting an extension to an offline assignment
@ -30,6 +38,7 @@ Feature: Grant an extension to an offline student
When I follow "View/grade all submissions" When I follow "View/grade all submissions"
And I click on "Edit" "link" in the "Student 1" "table_row" And I click on "Edit" "link" in the "Student 1" "table_row"
And I follow "Grant extension" 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 field "Enable" to "1"
And I press "Save changes" And I press "Save changes"
Then I should see "Extension granted until:" in the "Student 1" "table_row" Then I should see "Extension granted until:" in the "Student 1" "table_row"
@ -51,10 +60,20 @@ Feature: Grant an extension to an offline student
And I set the field "selectall" to "1" And I set the field "selectall" to "1"
And I set the field "operation" to "Grant extension" And I set the field "operation" to "Grant extension"
And I click on "Go" "button" confirming the dialogue 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 field "Enable" to "1"
And I press "Save changes" And I press "Save changes"
Then I should see "Extension granted until:" in the "Student 1" "table_row" Then I should see "Extension granted until:" in the "Student 1" "table_row"
And I should see "Extension granted until:" in the "Student 2" "table_row" And I should see "Extension granted until:" in the "Student 2" "table_row"
And I should see "Extension granted until:" in the "Student 3" "table_row"
And I should see "Extension granted until:" in the "Student 4" "table_row"
And I should see "Extension granted until:" in the "Student 5" "table_row"
And I should see "Extension granted until:" in the "Student 6" "table_row"
And I log out And I log out
And I log in as "student1" And I log in as "student1"
And I follow "Course 1" And I follow "Course 1"