Skip to content

Commit

Permalink
Merge branch 'MDL-42531-alt' of https://github.com/jonof/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Jun 16, 2014
2 parents 070d5b1 + c462c35 commit a3d7a82
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 95 deletions.
6 changes: 3 additions & 3 deletions mod/assign/batchsetallocatedmarkerform.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public function definition() {
$mform = $this->_form;
$params = $this->_customdata;

$mform->addElement('header', 'general', get_string('batchsetallocatedmarker', 'assign', count($params['users'])));
$mform->addElement('header', 'general', get_string('batchsetallocatedmarker', 'assign', $params['userscount']));
$mform->addElement('static', 'userslist', get_string('selectedusers', 'assign'), $params['usershtml']);

$options = $params['markers'];
$mform->addElement('select', 'allocatedmarker', get_string('allocatedmarker', 'assign'), $options);

$mform->addElement('hidden', 'id', $params['cm']);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'action', 'setbatchmarkingallocation');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'selectedusers', implode(',', $params['users']));
$mform->addElement('hidden', 'selectedusers');
$mform->setType('selectedusers', PARAM_SEQUENCE);
$this->add_action_buttons(true, get_string('savechanges'));

Expand Down
6 changes: 3 additions & 3 deletions mod/assign/batchsetmarkingworkflowstateform.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ class mod_assign_batch_set_marking_workflow_state_form extends moodleform {
public function definition() {
$mform = $this->_form;
$params = $this->_customdata;
$formheader = get_string('batchsetmarkingworkflowstateforusers', 'assign', count($params['users']));
$formheader = get_string('batchsetmarkingworkflowstateforusers', 'assign', $params['userscount']);

$mform->addElement('header', 'general', $formheader);
$mform->addElement('static', 'userslist', get_string('selectedusers', 'assign'), $params['usershtml']);

$options = $params['markingworkflowstates'];
$mform->addElement('select', 'markingworkflowstate', get_string('markingworkflowstate', 'assign'), $options);

$mform->addElement('hidden', 'id', $params['cm']);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'action', 'setbatchmarkingworkflowstate');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'selectedusers', implode(',', $params['users']));
$mform->addElement('hidden', 'selectedusers');
$mform->setType('selectedusers', PARAM_SEQUENCE);
$this->add_action_buttons(true, get_string('savechanges'));

Expand Down
137 changes: 88 additions & 49 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3493,9 +3493,8 @@ protected function view_batch_set_workflow_state($mform) {
$users = $submitteddata->selectedusers;
$userlist = explode(',', $users);

$formparams = array('cm'=>$this->get_course_module()->id,
'users'=>$userlist,
'context'=>$this->get_context());
$formdata = array('id' => $this->get_course_module()->id,
'selectedusers' => $users);

$usershtml = '';

Expand All @@ -3519,10 +3518,14 @@ protected function view_batch_set_workflow_state($mform) {
$usercount += 1;
}

$formparams['usershtml'] = $usershtml;
$formparams['markingworkflowstates'] = $this->get_marking_workflow_states_for_current_user();
$formparams = array(
'userscount' => count($userlist),
'usershtml' => $usershtml,
'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()
);

$mform = new mod_assign_batch_set_marking_workflow_state_form(null, $formparams);
$mform->set_data($formdata); // Initialises the hidden elements.
$o .= $this->get_renderer()->header();
$o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
$o .= $this->view_footer();
Expand All @@ -3549,9 +3552,8 @@ public function view_batch_markingallocation($mform) {
$users = $submitteddata->selectedusers;
$userlist = explode(',', $users);

$formparams = array('cm'=>$this->get_course_module()->id,
'users'=>$userlist,
'context'=>$this->get_context());
$formdata = array('id' => $this->get_course_module()->id,
'selectedusers' => $users);

$usershtml = '';

Expand All @@ -3575,7 +3577,11 @@ public function view_batch_markingallocation($mform) {
$usercount += 1;
}

$formparams['usershtml'] = $usershtml;
$formparams = array(
'userscount' => count($userlist),
'usershtml' => $usershtml,
);

$markers = get_users_by_capability($this->get_context(), 'mod/assign:grade');
$markerlist = array();
foreach ($markers as $marker) {
Expand All @@ -3585,6 +3591,7 @@ public function view_batch_markingallocation($mform) {
$formparams['markers'] = $markerlist;

$mform = new mod_assign_batch_set_allocatedmarker_form(null, $formparams);
$mform->set_data($formdata); // Initialises the hidden elements.
$o .= $this->get_renderer()->header();
$o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
$o .= $this->view_footer();
Expand Down Expand Up @@ -6119,34 +6126,48 @@ public function lock_submission($userid) {
* @return void
*/
protected function process_set_batch_marking_workflow_state() {
global $DB;
global $CFG, $DB;

require_sesskey();
// Include batch marking workflow form.
require_once($CFG->dirroot . '/mod/assign/batchsetmarkingworkflowstateform.php');

$batchusers = required_param('selectedusers', PARAM_TEXT);
$state = required_param('markingworkflowstate', PARAM_ALPHA);
$useridlist = explode(',', $batchusers);
$formparams = array(
'userscount' => 0, // This form is never re-displayed, so we don't need to
'usershtml' => '', // initialise these parameters with real information.
'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()
);

foreach ($useridlist as $userid) {
$flags = $this->get_user_flags($userid, true);
$mform = new mod_assign_batch_set_marking_workflow_state_form(null, $formparams);

if ($mform->is_cancelled()) {
return true;
}

$flags->workflowstate = $state;
if ($formdata = $mform->get_data()) {
$useridlist = explode(',', $formdata->selectedusers);
$state = $formdata->markingworkflowstate;

$gradingdisabled = $this->grading_disabled($userid);
foreach ($useridlist as $userid) {
$flags = $this->get_user_flags($userid, true);

// Will not apply update if user does not have permission to assign this workflow state.
if (!$gradingdisabled && $this->update_user_flags($flags)) {
if ($state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
// Update Gradebook.
$assign = clone $this->get_instance();
$assign->cmidnumber = $this->get_course_module()->idnumber;
// Set assign gradebook feedback plugin status.
$assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled();
assign_update_grades($assign, $userid);
}
$flags->workflowstate = $state;

$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
\mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger();
$gradingdisabled = $this->grading_disabled($userid);

// Will not apply update if user does not have permission to assign this workflow state.
if (!$gradingdisabled && $this->update_user_flags($flags)) {
if ($state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
// Update Gradebook.
$assign = clone $this->get_instance();
$assign->cmidnumber = $this->get_course_module()->idnumber;
// Set assign gradebook feedback plugin status.
$assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled();
assign_update_grades($assign, $userid);
}

$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
\mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger();
}
}
}
}
Expand All @@ -6157,32 +6178,50 @@ protected function process_set_batch_marking_workflow_state() {
* @return void
*/
protected function process_set_batch_marking_allocation() {
global $DB;
global $CFG, $DB;

require_sesskey();
require_capability('mod/assign:manageallocations', $this->context);
// Include batch marking allocation form.
require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');

$batchusers = required_param('selectedusers', PARAM_TEXT);
$markerid = required_param('allocatedmarker', PARAM_INT);
$marker = $DB->get_record('user', array('id' => $markerid), '*', MUST_EXIST);
$formparams = array(
'userscount' => 0, // This form is never re-displayed, so we don't need to
'usershtml' => '' // initialise these parameters with real information.
);

$useridlist = explode(',', $batchusers);
$markers = get_users_by_capability($this->get_context(), 'mod/assign:grade');
$markerlist = array();
foreach ($markers as $marker) {
$markerlist[$marker->id] = fullname($marker);
}

foreach ($useridlist as $userid) {
$flags = $this->get_user_flags($userid, true);
if ($flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW ||
$flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW ||
$flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE ||
$flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
$formparams['markers'] = $markerlist;

continue; // Allocated marker can only be changed in certain workflow states.
}
$mform = new mod_assign_batch_set_allocatedmarker_form(null, $formparams);

if ($mform->is_cancelled()) {
return true;
}

if ($formdata = $mform->get_data()) {
$useridlist = explode(',', $formdata->selectedusers);
$marker = $DB->get_record('user', array('id' => $formdata->allocatedmarker), '*', MUST_EXIST);

foreach ($useridlist as $userid) {
$flags = $this->get_user_flags($userid, true);
if ($flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW ||
$flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW ||
$flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE ||
$flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {

$flags->allocatedmarker = $marker->id;
continue; // Allocated marker can only be changed in certain workflow states.
}

$flags->allocatedmarker = $marker->id;

if ($this->update_user_flags($flags)) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
\mod_assign\event\marker_updated::create_from_marker($this, $user, $marker)->trigger();
if ($this->update_user_flags($flags)) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
\mod_assign\event\marker_updated::create_from_marker($this, $user, $marker)->trigger();
}
}
}
}
Expand Down
84 changes: 46 additions & 38 deletions mod/assign/tests/base_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,32 @@ public function testable_process_save_quick_grades($postdata) {
}

public function testable_process_set_batch_marking_allocation($selectedusers, $markerid) {
// Ugly hack to get something into the method.
global $_POST;
$_POST['selectedusers'] = $selectedusers;
$_POST['allocatedmarker'] = $markerid;
global $CFG;
require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');

// Simulate the form submission.
$data = array();
$data['id'] = $this->get_course_module()->id;
$data['selectedusers'] = $selectedusers;
$data['allocatedmarker'] = $markerid;
$data['action'] = 'setbatchmarkingallocation';
mod_assign_batch_set_allocatedmarker_form::mock_submit($data);

return parent::process_set_batch_marking_allocation();
}

public function testable_process_set_batch_marking_workflow_state($selectedusers, $state) {
// Ugly hack to get something into the method.
global $_POST;
$_POST['selectedusers'] = $selectedusers;
$_POST['markingworkflowstate'] = $state;
global $CFG;
require_once($CFG->dirroot . '/mod/assign/batchsetmarkingworkflowstateform.php');

// Simulate the form submission.
$data = array();
$data['id'] = $this->get_course_module()->id;
$data['selectedusers'] = $selectedusers;
$data['markingworkflowstate'] = $state;
$data['action'] = 'setbatchmarkingworkflowstate';
mod_assign_batch_set_marking_workflow_state_form::mock_submit($data);

return parent::process_set_batch_marking_workflow_state();
}

Expand All @@ -291,47 +305,41 @@ public function testable_get_graders($userid) {
return parent::get_graders($userid);
}

public function testable_view_batch_set_workflow_state() {
global $CFG;

require_once($CFG->dirroot . '/mod/assign/batchsetmarkingworkflowstateform.php');

// Mock submit data.
$data = array();
$data['selectedusers'] = '1';
mod_assign_batch_set_marking_workflow_state_form::mock_submit($data);

// Set required variables in the form - not valid just allows us to continue.
$formparams = array();
$formparams['users'] = array(1);
$formparams['usershtml'] = 1;
$formparams['cm'] = $this->get_course_module()->id;
$formparams['context'] = $this->get_context();
$formparams['markingworkflowstates'] = 1;
$mform = new mod_assign_batch_set_marking_workflow_state_form('', $formparams);

public function testable_view_batch_set_workflow_state($selectedusers) {
$mform = $this->testable_grading_batch_operations_form('setmarkingworkflowstate', $selectedusers);
return parent::view_batch_set_workflow_state($mform);
}

public function testable_view_batch_markingallocation() {
public function testable_view_batch_markingallocation($selectedusers) {
$mform = $this->testable_grading_batch_operations_form('setmarkingallocation', $selectedusers);
return parent::view_batch_markingallocation($mform);
}

public function testable_grading_batch_operations_form($operation, $selectedusers) {
global $CFG;

require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');
require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');

// Mock submit data.
// Mock submit the grading operations form.
$data = array();
$data['selectedusers'] = '1';
mod_assign_batch_set_allocatedmarker_form::mock_submit($data);
$data['id'] = $this->get_course_module()->id;
$data['selectedusers'] = $selectedusers;
$data['returnaction'] = 'grading';
$data['operation'] = $operation;
mod_assign_grading_batch_operations_form::mock_submit($data);

// Set required variables in the form - not valid just allows us to continue.
// Set required variables in the form.
$formparams = array();
$formparams['users'] = array(1);
$formparams['usershtml'] = 1;
$formparams['submissiondrafts'] = 1;
$formparams['duedate'] = 1;
$formparams['attemptreopenmethod'] = ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
$formparams['feedbackplugins'] = array();
$formparams['markingworkflow'] = 1;
$formparams['markingallocation'] = 1;
$formparams['cm'] = $this->get_course_module()->id;
$formparams['context'] = $this->get_context();
$formparams['markers'] = 1;
$mform = new mod_assign_batch_set_allocatedmarker_form('', $formparams);
$mform = new mod_assign_grading_batch_operations_form(null, $formparams);

return parent::view_batch_markingallocation($mform);
return $mform;
}
}
4 changes: 2 additions & 2 deletions mod/assign/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ public function test_batch_set_workflow_state_viewed() {

// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->testable_view_batch_set_workflow_state();
$assign->testable_view_batch_set_workflow_state($this->students[0]->id);
$events = $sink->get_events();
$event = reset($events);

Expand All @@ -942,7 +942,7 @@ public function test_batch_set_marker_allocation_viewed() {

// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->testable_view_batch_markingallocation();
$assign->testable_view_batch_markingallocation($this->students[0]->id);
$events = $sink->get_events();
$event = reset($events);

Expand Down

0 comments on commit a3d7a82

Please sign in to comment.