From 539af60201b5d9a3231d551e6b10783616314699 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 13 Sep 2013 11:50:00 +0800 Subject: [PATCH] MDL-37148 assign: codechecker cleanups --- mod/assign/externallib.php | 9 ++++++- mod/assign/feedback/file/locallib.php | 7 +++++- mod/assign/lib.php | 12 ++++----- mod/assign/locallib.php | 12 ++++----- mod/assign/submission/file/locallib.php | 7 +++++- mod/assign/tests/externallib_test.php | 33 +++++++++++++++++-------- 6 files changed, 55 insertions(+), 25 deletions(-) diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index 09db0b8f76b..18531bdba5e 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -1528,7 +1528,14 @@ class mod_assign_external extends external_api { * @return null * @since Moodle 2.6 */ - public static function save_grade($assignmentid, $userid, $grade, $attemptnumber, $addattempt, $workflowstate, $applytoall, $plugindata) { + public static function save_grade($assignmentid, + $userid, + $grade, + $attemptnumber, + $addattempt, + $workflowstate, + $applytoall, + $plugindata) { global $CFG, $USER; require_once("$CFG->dirroot/mod/assign/locallib.php"); diff --git a/mod/assign/feedback/file/locallib.php b/mod/assign/feedback/file/locallib.php index c537a438185..b4db0ae1c28 100644 --- a/mod/assign/feedback/file/locallib.php +++ b/mod/assign/feedback/file/locallib.php @@ -616,7 +616,12 @@ class assign_feedback_file extends assign_feedback_plugin { * @return external_description|null */ public function get_external_parameters() { - return array('files_filemanager' => new external_value(PARAM_INT, 'The id of a draft area containing files for this feedback.')); + return array( + 'files_filemanager' => new external_value( + PARAM_INT, + 'The id of a draft area containing files for this feedback.' + ) + ); } } diff --git a/mod/assign/lib.php b/mod/assign/lib.php index 49a13f10260..65e5cc254a4 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -280,11 +280,11 @@ function assign_get_coursemodule_info($coursemodule) { * @param stdClass $currentcontext Current context of block */ function assign_page_type_list($pagetype, $parentcontext, $currentcontext) { - $module_pagetype = array( + $modulepagetype = array( 'mod-assign-*' => get_string('page-mod-assign-x', 'assign'), 'mod-assign-view' => get_string('page-mod-assign-view', 'assign'), ); - return $module_pagetype; + return $modulepagetype; } /** @@ -656,10 +656,10 @@ function assign_get_recent_mod_activity(&$activities, } $groupmode = groups_get_activity_groupmode($cm, $course); - $cm_context = context_module::instance($cm->id); - $grader = has_capability('moodle/grade:viewall', $cm_context); - $accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context); - $viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context); + $cmcontext = context_module::instance($cm->id); + $grader = has_capability('moodle/grade:viewall', $cmcontext); + $accessallgroups = has_capability('moodle/site:accessallgroups', $cmcontext); + $viewfullnames = has_capability('moodle/site:viewfullnames', $cmcontext); if (is_null($modinfo->get_groups())) { // Load all my groups and cache it in modinfo. diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index f4eb9c5e592..30bd6dcf043 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -2003,10 +2003,10 @@ class assign { $submitted = get_string('submissionstatus_', 'assign'); } } - $grading_info = grade_get_grades($course->id, 'mod', 'assign', $cm->instance, $USER->id); - if (isset($grading_info->items[0]->grades[$USER->id]) && - !$grading_info->items[0]->grades[$USER->id]->hidden ) { - $grade = $grading_info->items[0]->grades[$USER->id]->str_grade; + $gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $cm->instance, $USER->id); + if (isset($gradinginfo->items[0]->grades[$USER->id]) && + !$gradinginfo->items[0]->grades[$USER->id]->hidden ) { + $grade = $gradinginfo->items[0]->grades[$USER->id]->str_grade; } else { $grade = '-'; } @@ -3651,7 +3651,8 @@ class assign { // Only show the grade if it is not hidden in gradebook. if (!empty($gradebookgrade->grade) && ($cangrade || !$gradebookgrade->hidden)) { if ($controller = $gradingmanager->get_active_controller()) { - $controller->set_grade_range(make_grades_menu($this->get_instance()->grade), $this->get_instance()->grade > 0); + $menu = make_grades_menu($this->get_instance()->grade); + $controller->set_grade_range($menu, $this->get_instance()->grade > 0); $gradefordisplay = $controller->render_grade($PAGE, $grade->id, $gradingitem, @@ -6023,7 +6024,6 @@ class assign { } } - $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); $logmessage = get_string('unlocksubmissionforstudent', diff --git a/mod/assign/submission/file/locallib.php b/mod/assign/submission/file/locallib.php index f981aa3d30e..7b8facb37e2 100644 --- a/mod/assign/submission/file/locallib.php +++ b/mod/assign/submission/file/locallib.php @@ -484,6 +484,11 @@ class assign_submission_file extends assign_submission_plugin { * @return external_description|null */ public function get_external_parameters() { - return array('files_filemanager' => new external_value(PARAM_INT, 'The id of a draft area containing files for this submission.')); + return array( + 'files_filemanager' => new external_value( + PARAM_INT, + 'The id of a draft area containing files for this submission.' + ) + ); } } diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index 31a13d3c4ab..aeb0cb3eb7f 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -481,7 +481,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); - // Ready to test + // Ready to test. $this->setUser($teacher); $students = array($student1->id, $student2->id); $result = mod_assign_external::lock_submissions($instance->id, $students); @@ -545,7 +545,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); - // Ready to test + // Ready to test. $this->setUser($teacher); $students = array($student1->id, $student2->id); $result = mod_assign_external::lock_submissions($instance->id, $students); @@ -786,7 +786,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $result = mod_assign_external::submit_for_grading($instance->id); $this->assertEquals(0, count($result)); - // Ready to test + // Ready to test. $this->setUser($teacher); $students = array($student1->id, $student2->id); $result = mod_assign_external::revert_submissions_to_draft($instance->id, array($student1->id)); @@ -868,7 +868,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $fs->create_file_from_string($filerecord, 'image contents (not really)'); - // Now try a submission + // Now try a submission. $submissionpluginparams = array(); $submissionpluginparams['files_filemanager'] = $draftidfile; $onlinetexteditorparams = array('text'=>'Yeeha!', @@ -936,13 +936,20 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $fs = get_file_storage(); $fs->create_file_from_string($filerecord, 'text contents'); - // Now try a grade + // Now try a grade. $feedbackpluginparams = array(); $feedbackpluginparams['files_filemanager'] = $draftidfile; $feedbackeditorparams = array('text'=>'Yeeha!', 'format'=>1); $feedbackpluginparams['assignfeedbackcomments_editor'] = $feedbackeditorparams; - $result = mod_assign_external::save_grade($instance->id, $student1->id, 50.0, -1, true, 'released', false, $feedbackpluginparams); + $result = mod_assign_external::save_grade($instance->id, + $student1->id, + 50.0, + -1, + true, + 'released', + false, + $feedbackpluginparams); // No warnings. $this->assertEquals(0, count($result)); @@ -950,7 +957,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $result = mod_assign_external::get_grades(array($instance->id)); $this->assertEquals($result['assignments'][0]['grades'][0]['grade'], '50.0'); - } /** @@ -988,7 +994,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id); - // Now try a submission + // Now try a submission. $this->setUser($student1); $draftidonlinetext = file_get_unused_draft_itemid(); $submissionpluginparams = array(); @@ -1001,13 +1007,20 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $this->setUser($teacher); // Add a grade and reopen the attempt. - // Now try a grade + // Now try a grade. $feedbackpluginparams = array(); $feedbackpluginparams['files_filemanager'] = file_get_unused_draft_itemid(); $feedbackeditorparams = array('text'=>'Yeeha!', 'format'=>1); $feedbackpluginparams['assignfeedbackcomments_editor'] = $feedbackeditorparams; - $result = mod_assign_external::save_grade($instance->id, $student1->id, 50.0, -1, true, 'released', false, $feedbackpluginparams); + $result = mod_assign_external::save_grade($instance->id, + $student1->id, + 50.0, + -1, + true, + 'released', + false, + $feedbackpluginparams); $this->setUser($student1); // Now copy the previous attempt.