From e5403f8c44f272564eca953736a3c9afd45fb1bd Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 29 Nov 2012 11:15:37 +0800 Subject: [PATCH] MDL-36904 Assignment: Fix all errors and warnings from codechecker --- admin/tool/assignmentupgrade/batchupgrade.php | 8 +- admin/tool/assignmentupgrade/index.php | 2 +- .../assignmentupgrade/listnotupgraded.php | 3 +- admin/tool/assignmentupgrade/locallib.php | 39 +- admin/tool/assignmentupgrade/module.js | 1 - .../tool/assignmentupgrade/paginationform.php | 12 +- admin/tool/assignmentupgrade/renderer.php | 11 +- admin/tool/assignmentupgrade/settings.php | 5 +- .../upgradableassignmentsbatchform.php | 12 +- .../upgradableassignmentstable.php | 39 +- .../tool/assignmentupgrade/upgradesingle.php | 7 +- .../upgradesingleconfirm.php | 7 +- mod/assign/adminlib.php | 92 +- mod/assign/adminmanageplugins.php | 9 +- mod/assign/assignmentplugin.php | 59 +- .../backup_assign_activity_task.class.php | 7 +- .../backup/moodle2/backup_assign_stepslib.php | 19 +- .../restore_assign_activity_task.class.php | 23 +- .../moodle2/restore_assign_stepslib.php | 25 +- mod/assign/db/messages.php | 2 +- mod/assign/db/upgrade.php | 49 +- ...ssignfeedback_comments_subplugin.class.php | 21 +- ...ssignfeedback_comments_subplugin.class.php | 17 +- mod/assign/feedback/comments/db/install.php | 4 +- mod/assign/feedback/comments/db/upgrade.php | 12 +- mod/assign/feedback/comments/locallib.php | 72 +- ...up_assignfeedback_file_subplugin.class.php | 16 +- ...re_assignfeedback_file_subplugin.class.php | 11 +- mod/assign/feedback/file/db/install.php | 8 +- mod/assign/feedback/file/db/upgrade.php | 12 +- mod/assign/feedback/file/importzipform.php | 2 +- mod/assign/feedback/file/lib.php | 14 +- mod/assign/feedback/file/locallib.php | 182 +- mod/assign/feedbackplugin.php | 30 +- mod/assign/gradeform.php | 30 +- mod/assign/gradingbatchoperationsform.php | 19 +- mod/assign/gradingoptionsform.php | 18 +- mod/assign/gradingtable.php | 349 ++-- mod/assign/index.php | 4 +- mod/assign/lib.php | 365 ++-- mod/assign/locallib.php | 1789 ++++++++++------- mod/assign/mod_form.php | 93 +- mod/assign/module.js | 9 - mod/assign/quickgradingform.php | 15 +- mod/assign/renderable.php | 269 ++- mod/assign/renderer.php | 231 ++- mod/assign/settings.php | 43 +- mod/assign/submission/comments/db/install.php | 7 +- mod/assign/submission/comments/db/upgrade.php | 10 +- mod/assign/submission/comments/locallib.php | 52 +- ..._assignsubmission_file_subplugin.class.php | 21 +- ..._assignsubmission_file_subplugin.class.php | 17 +- mod/assign/submission/file/db/upgrade.php | 8 +- .../file/lang/en/assignsubmission_file.php | 1 + mod/assign/submission/file/lib.php | 18 +- mod/assign/submission/file/locallib.php | 141 +- mod/assign/submission/file/settings.php | 15 +- ...nsubmission_onlinetext_subplugin.class.php | 21 +- ...nsubmission_onlinetext_subplugin.class.php | 13 +- .../submission/onlinetext/db/install.php | 10 +- .../submission/onlinetext/db/upgrade.php | 10 +- mod/assign/submission/onlinetext/lib.php | 6 +- mod/assign/submission/onlinetext/locallib.php | 141 +- mod/assign/submission_form.php | 3 +- mod/assign/submissionconfirmform.php | 12 +- mod/assign/submissionplugin.php | 2 +- mod/assign/upgradelib.php | 132 +- mod/assign/version.php | 6 +- mod/assign/view.php | 16 +- 69 files changed, 2789 insertions(+), 1939 deletions(-) diff --git a/admin/tool/assignmentupgrade/batchupgrade.php b/admin/tool/assignmentupgrade/batchupgrade.php index a654f6e93c5..bab7a943cbb 100644 --- a/admin/tool/assignmentupgrade/batchupgrade.php +++ b/admin/tool/assignmentupgrade/batchupgrade.php @@ -32,7 +32,7 @@ require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradable require_sesskey(); -// admin_externalpage_setup calls require_login and checks moodle/site:config +// This calls require_login and checks moodle/site:config. admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('batchupgrade')); $PAGE->set_pagelayout('maintenance'); @@ -46,7 +46,8 @@ if (!$confirm) { die(); } raise_memory_limit(MEMORY_EXTRA); -session_get_instance()->write_close(); // release session +// Release session. +session_get_instance()->write_close(); echo $renderer->header(); echo $renderer->heading(get_string('batchupgrade', 'tool_assignmentupgrade')); @@ -62,7 +63,8 @@ $total = count($assignmentids); foreach ($assignmentids as $assignmentid) { list($summary, $success, $log) = tool_assignmentupgrade_upgrade_assignment($assignmentid); $current += 1; - echo $renderer->heading(get_string('upgradeprogress', 'tool_assignmentupgrade', array('current'=>$current, 'total'=>$total)), 3); + $params = array('current'=>$current, 'total'=>$total); + echo $renderer->heading(get_string('upgradeprogress', 'tool_assignmentupgrade', $params), 3); echo $renderer->convert_assignment_result($summary, $success, $log); } diff --git a/admin/tool/assignmentupgrade/index.php b/admin/tool/assignmentupgrade/index.php index 71ed56f4444..d9e554df5fa 100644 --- a/admin/tool/assignmentupgrade/index.php +++ b/admin/tool/assignmentupgrade/index.php @@ -37,7 +37,7 @@ require_once(dirname(__FILE__) . '/../../../config.php'); require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php'); -// admin_externalpage_setup calls require_login and checks moodle/site:config +// This calls require_login and checks moodle/site:config. admin_externalpage_setup('assignmentupgrade'); $renderer = $PAGE->get_renderer('tool_assignmentupgrade'); diff --git a/admin/tool/assignmentupgrade/listnotupgraded.php b/admin/tool/assignmentupgrade/listnotupgraded.php index 9d68c262fe6..048ded5b492 100644 --- a/admin/tool/assignmentupgrade/listnotupgraded.php +++ b/admin/tool/assignmentupgrade/listnotupgraded.php @@ -29,7 +29,7 @@ require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradable require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentsbatchform.php'); require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/paginationform.php'); -// admin_externalpage_setup calls require_login and checks moodle/site:config +// This calls require_login and checks moodle/site:config. admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('listnotupgraded')); $PAGE->navbar->add(get_string('listnotupgraded', 'tool_assignmentupgrade')); @@ -57,4 +57,3 @@ if ($data && $data->selectedassignments != '' || $data && isset($data->upgradeal echo $renderer->assignment_list_page($assignments, $batchform, $paginationform); } - diff --git a/admin/tool/assignmentupgrade/locallib.php b/admin/tool/assignmentupgrade/locallib.php index 6ea1883a4d3..27db50940b7 100644 --- a/admin/tool/assignmentupgrade/locallib.php +++ b/admin/tool/assignmentupgrade/locallib.php @@ -51,17 +51,24 @@ class tool_assignmentupgrade_batchoperationconfirm implements renderable { * Constructor for this class * @param stdClass $data - The data from the previous batch form */ - function __construct($data) { + public function __construct($data) { if (isset($data->upgradeselected)) { - $this->continuemessage = get_string('upgradeselectedcount', 'tool_assignmentupgrade', count(explode(',', $data->selectedassignments))); - $this->continueurl = new moodle_url('/admin/tool/assignmentupgrade/batchupgrade.php', array('upgradeselected'=>'1', 'confirm'=>'1', 'sesskey'=>sesskey(), 'selected'=>$data->selectedassignments)); + $this->continuemessage = get_string('upgradeselectedcount', + 'tool_assignmentupgrade', + count(explode(',', $data->selectedassignments))); + $urlparams = array('upgradeselected'=>'1', + 'confirm'=>'1', + 'sesskey'=>sesskey(), + 'selected'=>$data->selectedassignments); + $this->continueurl = new moodle_url('/admin/tool/assignmentupgrade/batchupgrade.php', $urlparams); } else if (isset($data->upgradeall)) { if (!tool_assignmentupgrade_any_upgradable_assignments()) { $this->continuemessage = get_string('noassignmentstoupgrade', 'tool_assignmentupgrade'); $this->continueurl = ''; } else { $this->continuemessage = get_string('upgradeallconfirm', 'tool_assignmentupgrade'); - $this->continueurl = new moodle_url('/admin/tool/assignmentupgrade/batchupgrade.php', array('upgradeall'=>'1', 'confirm'=>'1', 'sesskey'=>sesskey())); + $urlparams = array('upgradeall'=>'1', 'confirm'=>'1', 'sesskey'=>sesskey()); + $this->continueurl = new moodle_url('/admin/tool/assignmentupgrade/batchupgrade.php', $urlparams); } } } @@ -86,7 +93,8 @@ class tool_assignmentupgrade_action { /** * Constructor to set the fields. * - * In order to create a new tool_assignmentupgrade_action instance you must use the tool_assignmentupgrade_action::make + * In order to create a new tool_assignmentupgrade_action instance you must use + * the tool_assignmentupgrade_action::make * method. * * @param string $name the name of this action. @@ -120,8 +128,13 @@ class tool_assignmentupgrade_action { function tool_assignmentupgrade_any_upgradable_assignments() { global $DB, $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); - // first find all the unique assignment types - $types = $DB->get_records_sql('SELECT plugin AS assignmenttype, value AS version FROM {config_plugins} WHERE name = ? AND plugin LIKE ?', array('version', 'assignment_%')); + // First find all the unique assignment types. + $types = $DB->get_records_sql('SELECT plugin AS assignmenttype, + value AS version + FROM {config_plugins} + WHERE + name = ? AND + plugin LIKE ?', array('version', 'assignment_%')); $upgradabletypes = array(); @@ -133,7 +146,7 @@ function tool_assignmentupgrade_any_upgradable_assignments() { } list($sql, $params) = $DB->get_in_or_equal($upgradabletypes); - $count = $DB->count_records_sql('SELECT COUNT(id) from {assignment} where assignmenttype ' . $sql, $params); + $count = $DB->count_records_sql('SELECT COUNT(id) FROM {assignment} WHERE assignmenttype ' . $sql, $params); return $count > 0; } @@ -145,8 +158,14 @@ function tool_assignmentupgrade_any_upgradable_assignments() { function tool_assignmentupgrade_load_all_upgradable_assignmentids() { global $DB, $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); - // first find all the unique assignment types - $types = $DB->get_records_sql('SELECT plugin AS assignmenttype, value AS version FROM {config_plugins} WHERE name = ? AND plugin LIKE ?', array('version', 'assignment_%')); + // First find all the unique assignment types. + $types = $DB->get_records_sql('SELECT + plugin AS assignmenttype, + value AS version + FROM {config_plugins} + WHERE + name = ? AND + plugin LIKE ?', array('version', 'assignment_%')); $upgradabletypes = array(); diff --git a/admin/tool/assignmentupgrade/module.js b/admin/tool/assignmentupgrade/module.js index 7c170f18a7f..933408a5f14 100644 --- a/admin/tool/assignmentupgrade/module.js +++ b/admin/tool/assignmentupgrade/module.js @@ -1,4 +1,3 @@ - M.tool_assignmentupgrade = { init_upgrade_table: function(Y) { diff --git a/admin/tool/assignmentupgrade/paginationform.php b/admin/tool/assignmentupgrade/paginationform.php index 3efb8d4d508..e4c9028e854 100644 --- a/admin/tool/assignmentupgrade/paginationform.php +++ b/admin/tool/assignmentupgrade/paginationform.php @@ -24,9 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); - -/** Include formslib.php */ -require_once ($CFG->libdir.'/formslib.php'); +require_once($CFG->libdir.'/formslib.php'); /** * Assignment upgrade table display options @@ -39,20 +37,20 @@ class tool_assignmentupgrade_pagination_form extends moodleform { /** * Define this form - called from the parent constructor */ - function definition() { + public function definition() { $mform = $this->_form; $instance = $this->_customdata; $mform->addElement('header', 'general', get_string('assignmentsperpage', 'tool_assignmentupgrade')); - // visible elements + // Visible elements. $options = array(10=>'10', 20=>'20', 50=>'50', 100=>'100'); $mform->addElement('select', 'perpage', get_string('assignmentsperpage', 'assign'), $options); - // hidden params + // Hidden params. $mform->addElement('hidden', 'action', 'saveoptions'); $mform->setType('action', PARAM_ALPHA); - // buttons + // Buttons. $this->add_action_buttons(false, get_string('updatetable', 'tool_assignmentupgrade')); } } diff --git a/admin/tool/assignmentupgrade/renderer.php b/admin/tool/assignmentupgrade/renderer.php index 29192d76e6c..28112320055 100644 --- a/admin/tool/assignmentupgrade/renderer.php +++ b/admin/tool/assignmentupgrade/renderer.php @@ -100,7 +100,9 @@ class tool_assignmentupgrade_renderer extends plugin_renderer_base { $output = ''; if ($confirm->continueurl) { - $output .= $this->output->confirm($confirm->continuemessage, $confirm->continueurl, tool_assignmentupgrade_url('listnotupgraded')); + $output .= $this->output->confirm($confirm->continuemessage, + $confirm->continueurl, + tool_assignmentupgrade_url('listnotupgraded')); } else { $output .= $this->output->box($confirm->continuemessage); $output .= $this->output->continue_button(tool_assignmentupgrade_url('listnotupgraded')); @@ -115,7 +117,9 @@ class tool_assignmentupgrade_renderer extends plugin_renderer_base { * @param tool_assignmentupgrade_pagination_form $paginationform Form which contains the preferences for paginating the table * @return string html to output. */ - public function assignment_list_page(tool_assignmentupgrade_assignments_table $assignments, tool_assignmentupgrade_batchoperations_form $batchform, tool_assignmentupgrade_pagination_form $paginationform) { + public function assignment_list_page(tool_assignmentupgrade_assignments_table $assignments, + tool_assignmentupgrade_batchoperations_form $batchform, + tool_assignmentupgrade_pagination_form $paginationform) { $output = ''; $output .= $this->header(); $this->page->requires->js_init_call('M.tool_assignmentupgrade.init_upgrade_table', array()); @@ -161,7 +165,8 @@ class tool_assignmentupgrade_renderer extends plugin_renderer_base { $output .= $this->container(get_string('conversionfailed', 'tool_assignmentupgrade', $log)); } else { $output .= $this->container(get_string('upgradeassignmentsuccess', 'tool_assignmentupgrade')); - $output .= $this->container(html_writer::link(new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid)) ,get_string('viewcourse', 'tool_assignmentupgrade'))); + $url = new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid)); + $output .= $this->container(html_writer::link($url, get_string('viewcourse', 'tool_assignmentupgrade'))); } $output .= $this->container_end(); diff --git a/admin/tool/assignmentupgrade/settings.php b/admin/tool/assignmentupgrade/settings.php index a637e3825cb..1a919227e8b 100644 --- a/admin/tool/assignmentupgrade/settings.php +++ b/admin/tool/assignmentupgrade/settings.php @@ -24,8 +24,9 @@ defined('MOODLE_INTERNAL') || die; -if ($hassiteconfig) { // needs this condition or there is error on login page +if ($hassiteconfig) { + // Needs this condition or there is error on login page. $ADMIN->add('root', new admin_externalpage('assignmentupgrade', get_string('pluginname', 'tool_assignmentupgrade'), new moodle_url('/admin/tool/assignmentupgrade/index.php'))); -} \ No newline at end of file +} diff --git a/admin/tool/assignmentupgrade/upgradableassignmentsbatchform.php b/admin/tool/assignmentupgrade/upgradableassignmentsbatchform.php index 105530ab648..a9aeb587565 100644 --- a/admin/tool/assignmentupgrade/upgradableassignmentsbatchform.php +++ b/admin/tool/assignmentupgrade/upgradableassignmentsbatchform.php @@ -24,12 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); - -/** Include formslib.php */ -require_once ($CFG->libdir.'/formslib.php'); +require_once($CFG->libdir.'/formslib.php'); /** - * Assignment upgrade batch operations form + * Assignment upgrade batch operations form. * * @package tool_assignmentupgrade * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -37,14 +35,14 @@ require_once ($CFG->libdir.'/formslib.php'); */ class tool_assignmentupgrade_batchoperations_form extends moodleform { /** - * Define this form - is called from parent constructor + * Define this form - is called from parent constructor. */ - function definition() { + public function definition() { $mform = $this->_form; $instance = $this->_customdata; $mform->addElement('header', 'general', get_string('batchoperations', 'tool_assignmentupgrade')); - // visible elements + // Visible elements. $mform->addElement('hidden', 'selectedassignments', '', array('class'=>'selectedassignments')); $mform->addElement('submit', 'upgradeselected', get_string('upgradeselected', 'tool_assignmentupgrade')); diff --git a/admin/tool/assignmentupgrade/upgradableassignmentstable.php b/admin/tool/assignmentupgrade/upgradableassignmentstable.php index 307a8c95f61..a7851b93d29 100644 --- a/admin/tool/assignmentupgrade/upgradableassignmentstable.php +++ b/admin/tool/assignmentupgrade/upgradableassignmentstable.php @@ -36,6 +36,7 @@ require_once($CFG->dirroot.'/mod/assign/locallib.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class tool_assignmentupgrade_assignments_table extends table_sql implements renderable { + /** @var int $perpage */ private $perpage = 10; /** @var int $rownum (global index of current row in table) */ @@ -46,12 +47,13 @@ class tool_assignmentupgrade_assignments_table extends table_sql implements rend public $anyupgradableassignments = false; /** - * This table loads a list of the old assignment instances and tests them to see if they can be upgraded + * This table loads a list of the old assignment instances and tests them to see + * if they can be upgraded * * @param int $perpage How many per page * @param int $rowoffset The starting row for pagination */ - function __construct($perpage, $rowoffset=0) { + public function __construct($perpage, $rowoffset=0) { global $PAGE; parent::__construct('tool_assignmentupgrade_assignments'); $this->perpage = $perpage; @@ -61,12 +63,17 @@ class tool_assignmentupgrade_assignments_table extends table_sql implements rend $this->anyupgradableassignments = tool_assignmentupgrade_any_upgradable_assignments(); - // do some business - then set the sql + // Do some business - then set the sql. if ($rowoffset) { $this->rownum = $rowoffset - 1; } - $fields = 'a.id as id, a.name as name, a.assignmenttype as type, c.shortname as courseshortname, c.id as courseid, COUNT(s.id) as submissioncount'; + $fields = 'a.id as id, + a.name as name, + a.assignmenttype as type, + c.shortname as courseshortname, + c.id as courseid, + COUNT(s.id) as submissioncount'; $from = '{assignment} a JOIN {course} c ON a.course = c.id ' . ' LEFT JOIN {assignment_submissions} s ON a.id = s.assignment'; @@ -80,7 +87,10 @@ class tool_assignmentupgrade_assignments_table extends table_sql implements rend $headers = array(); $columns[] = 'select'; - $headers[] = get_string('select', 'tool_assignmentupgrade') . '
'; + $headers[] = get_string('select', 'tool_assignmentupgrade') . + '
' . + '' . + '
'; $columns[] = 'upgradable'; $headers[] = get_string('upgradable', 'tool_assignmentupgrade'); $columns[] = 'id'; @@ -94,7 +104,7 @@ class tool_assignmentupgrade_assignments_table extends table_sql implements rend $columns[] = 'submissioncount'; $headers[] = get_string('submissions', 'tool_assignmentupgrade'); - // set the columns + // Set the columns. $this->define_columns($columns); $this->define_headers($headers); $this->no_sorting('upgradable'); @@ -106,7 +116,7 @@ class tool_assignmentupgrade_assignments_table extends table_sql implements rend * * @return int The number of rows per page */ - function get_rows_per_page() { + public function get_rows_per_page() { return $this->perpage; } @@ -116,9 +126,9 @@ class tool_assignmentupgrade_assignments_table extends table_sql implements rend * @param stdClass $row * @return string */ - function col_name(stdClass $row) { - return html_writer::link(new moodle_url('/mod/assignment/view.php', - array('a' => $row->id)), $row->name); + public function col_name(stdClass $row) { + $url = new moodle_url('/mod/assignment/view.php', array('a' => $row->id)); + return html_writer::link($url, $row->name); } @@ -128,10 +138,11 @@ class tool_assignmentupgrade_assignments_table extends table_sql implements rend * @param stdClass $row (contains cached result from previous upgradable check) * @return string */ - function col_upgradable(stdClass $row) { + public function col_upgradable(stdClass $row) { if ($row->upgradable) { - return html_writer::link(new moodle_url('/admin/tool/assignmentupgrade/upgradesingleconfirm.php', - array('id' => $row->id, 'sesskey' => sesskey())), get_string('supported', 'tool_assignmentupgrade')); + $urlparams = array('id' => $row->id, 'sesskey' => sesskey()); + $url = new moodle_url('/admin/tool/assignmentupgrade/upgradesingleconfirm.php', $urlparams); + return html_writer::link($url, get_string('supported', 'tool_assignmentupgrade')); } else { return get_string('notsupported', 'tool_assignmentupgrade'); } @@ -143,7 +154,7 @@ class tool_assignmentupgrade_assignments_table extends table_sql implements rend * @param stdClass $row * @return string */ - function col_select(stdClass $row) { + public function col_select(stdClass $row) { global $CFG; $version = get_config('assignment_' . $row->type, 'version'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); diff --git a/admin/tool/assignmentupgrade/upgradesingle.php b/admin/tool/assignmentupgrade/upgradesingle.php index 67f24b0cd46..5a5679a0ce1 100644 --- a/admin/tool/assignmentupgrade/upgradesingle.php +++ b/admin/tool/assignmentupgrade/upgradesingle.php @@ -30,8 +30,11 @@ require_sesskey(); $assignmentid = required_param('id', PARAM_INT); -// admin_externalpage_setup calls require_login and checks moodle/site:config -admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('upgradesingle', array('id' => $assignmentid))); +// This calls require_login and checks moodle/site:config. +admin_externalpage_setup('assignmentupgrade', + '', + array(), + tool_assignmentupgrade_url('upgradesingle', array('id' => $assignmentid))); $PAGE->navbar->add(get_string('upgradesingle', 'tool_assignmentupgrade')); $renderer = $PAGE->get_renderer('tool_assignmentupgrade'); diff --git a/admin/tool/assignmentupgrade/upgradesingleconfirm.php b/admin/tool/assignmentupgrade/upgradesingleconfirm.php index 143ebf111c6..88be9a57188 100644 --- a/admin/tool/assignmentupgrade/upgradesingleconfirm.php +++ b/admin/tool/assignmentupgrade/upgradesingleconfirm.php @@ -30,8 +30,11 @@ require_sesskey(); $assignmentid = required_param('id', PARAM_INT); -// admin_externalpage_setup calls require_login and checks moodle/site:config -admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('upgradesingle', array('id' => $assignmentid))); +// This calls require_login and checks moodle/site:config. +admin_externalpage_setup('assignmentupgrade', + '', + array(), + tool_assignmentupgrade_url('upgradesingle', array('id' => $assignmentid))); $PAGE->navbar->add(get_string('upgradesingle', 'tool_assignmentupgrade')); $renderer = $PAGE->get_renderer('tool_assignmentupgrade'); diff --git a/mod/assign/adminlib.php b/mod/assign/adminlib.php index a84c4cbcd82..2a78c0ac4a7 100644 --- a/mod/assign/adminlib.php +++ b/mod/assign/adminlib.php @@ -24,7 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -/** Include adminlib.php */ require_once($CFG->libdir . '/adminlib.php'); /** @@ -46,8 +45,10 @@ class assign_admin_page_manage_assign_plugins extends admin_externalpage { */ public function __construct($subtype) { $this->subtype = $subtype; - parent::__construct('manage' . $subtype . 'plugins', get_string('manage' . $subtype . 'plugins', 'assign'), - new moodle_url('/mod/assign/adminmanageplugins.php', array('subtype'=>$subtype))); + $url = new moodle_url('/mod/assign/adminmanageplugins.php', array('subtype'=>$subtype)); + parent::__construct('manage' . $subtype . 'plugins', + get_string('manage' . $subtype . 'plugins', 'assign'), + $url); } /** @@ -124,7 +125,9 @@ class assign_plugin_manager { if (!$idx) { $idx = 0; } - while (array_key_exists($idx, $result)) $idx +=1; + while (array_key_exists($idx, $result)) { + $idx +=1; + } $result[$idx] = $name; } ksort($result); @@ -158,7 +161,6 @@ class assign_plugin_manager { */ private function view_plugins_table() { global $OUTPUT, $CFG; - /** Include tablelib.php */ require_once($CFG->libdir . '/tablelib.php'); // Set up the table. @@ -174,7 +176,6 @@ class assign_plugin_manager { $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); $table->setup(); - $plugins = $this->get_sorted_plugins_list(); $shortsubtype = substr($this->subtype, strlen('assign')); @@ -208,7 +209,8 @@ class assign_plugin_manager { } else { $row[] = ' '; } - if ($row[1] != '' && file_exists($CFG->dirroot . '/mod/assign/' . $shortsubtype . '/' . $plugin . '/settings.php')) { + $exists = file_exists($CFG->dirroot . '/mod/assign/' . $shortsubtype . '/' . $plugin . '/settings.php'); + if ($row[1] != '' && $exists) { $row[] = html_writer::link(new moodle_url('/admin/settings.php', array('section' => $this->subtype . '_' . $plugin)), get_string('settings')); } else { @@ -217,7 +219,6 @@ class assign_plugin_manager { $table->add_data($row); } - $table->finish_output(); $this->view_footer(); } @@ -273,32 +274,34 @@ class assign_plugin_manager { $this->error = $OUTPUT->notification(get_string('errordeletingconfig', 'admin', $this->subtype . '_' . $plugin)); } - - // Should be covered by the previous function - but just in case + // Should be covered by the previous function - but just in case. unset_config('disabled', $this->subtype . '_' . $plugin); unset_config('sortorder', $this->subtype . '_' . $plugin); - // delete the plugin specific config settings + // Delete the plugin specific config settings. $DB->delete_records('assign_plugin_config', array('plugin'=>$plugin, 'subtype'=>$this->subtype)); - // Then the tables themselves + // Then the tables themselves. $shortsubtype = substr($this->subtype, strlen('assign')); - drop_plugin_tables($this->subtype . '_' . $plugin, $CFG->dirroot . '/mod/assign/' . $shortsubtype . '/' .$plugin. '/db/install.xml', false); + $installxml = $CFG->dirroot . '/mod/assign/' . $shortsubtype . '/' . $plugin . '/db/install.xml'; + drop_plugin_tables($this->subtype . '_' . $plugin, + $installxml, + false); - // Remove event handlers and dequeue pending events + // Remove event handlers and dequeue pending events. events_uninstall($this->subtype . '_' . $plugin); - // the page to display + // The page to display. return 'plugindeleted'; } else { - // the page to display + // The page to display. return 'confirmdelete'; } } /** - * Show the page that gives the details of the plugin that was just deleted + * Show the page that gives the details of the plugin that was just deleted. * * @param string $plugin - The plugin that was just deleted * @return None @@ -306,15 +309,18 @@ class assign_plugin_manager { private function view_plugin_deleted($plugin) { global $OUTPUT; $this->view_header(); - echo $OUTPUT->heading(get_string('deletingplugin', 'assign', get_string('pluginname', $this->subtype . '_' . $plugin))); + $pluginname = get_string('pluginname', $this->subtype . '_' . $plugin); + echo $OUTPUT->heading(get_string('deletingplugin', 'assign', $pluginname)); echo $this->error; - echo $OUTPUT->notification(get_string('plugindeletefiles', 'moodle', array('name'=>get_string('pluginname', $this->subtype . '_' . $plugin), 'directory'=>('/mod/assign/' . $this->subtype . '/'.$plugin)))); + $messageparams = array('name'=>$pluginname, + 'directory'=>('/mod/assign/' . $this->subtype . '/'.$plugin)); + echo $OUTPUT->notification(get_string('plugindeletefiles', 'moodle', $messageparams)); echo $OUTPUT->continue_button($this->pageurl); $this->view_footer(); } /** - * Show the page that asks the user to confirm they want to delete a plugin + * Show the page that asks the user to confirm they want to delete a plugin. * * @param string $plugin - The plugin that will be deleted * @return None @@ -322,9 +328,12 @@ class assign_plugin_manager { private function view_confirm_delete($plugin) { global $OUTPUT; $this->view_header(); - echo $OUTPUT->heading(get_string('deletepluginareyousure', 'assign', get_string('pluginname', $this->subtype . '_' . $plugin))); - echo $OUTPUT->confirm(get_string('deletepluginareyousuremessage', 'assign', get_string('pluginname', $this->subtype . '_' . $plugin)), - new moodle_url($this->pageurl, array('action' => 'delete', 'plugin'=>$plugin, 'confirm' => 1)), + $pluginname = get_string('pluginname', $this->subtype . '_' . $plugin); + echo $OUTPUT->heading(get_string('deletepluginareyousure', 'assign', $pluginname)); + $urlparams = array('action' => 'delete', 'plugin'=>$plugin, 'confirm' => 1); + $confirmurl = new moodle_url($this->pageurl, $urlparams); + echo $OUTPUT->confirm(get_string('deletepluginareyousuremessage', 'assign', $pluginname), + $confirmurl, $this->pageurl); $this->view_footer(); } @@ -332,7 +341,7 @@ class assign_plugin_manager { /** - * Hide this plugin + * Hide this plugin. * * @param string $plugin - The plugin to hide * @return string The next page to display @@ -343,23 +352,22 @@ class assign_plugin_manager { } /** - * Change the order of this plugin + * Change the order of this plugin. * * @param string $plugintomove - The plugin to move * @param string $dir - up or down * @return string The next page to display */ public function move_plugin($plugintomove, $dir) { - // get a list of the current plugins + // Get a list of the current plugins. $plugins = $this->get_sorted_plugins_list(); $currentindex = 0; - // throw away the keys - + // Throw away the keys. $plugins = array_values($plugins); - // find this plugin in the list + // Find this plugin in the list. foreach ($plugins as $key => $plugin) { if ($plugin == $plugintomove) { $currentindex = $key; @@ -367,7 +375,7 @@ class assign_plugin_manager { } } - // make the switch + // Make the switch. if ($dir == 'up') { if ($currentindex > 0) { $tempplugin = $plugins[$currentindex - 1]; @@ -382,7 +390,7 @@ class assign_plugin_manager { } } - // save the new normal order + // Save the new normal order. foreach ($plugins as $key => $plugin) { set_config('sortorder', $key, $this->subtype . '_' . $plugin); } @@ -391,7 +399,7 @@ class assign_plugin_manager { /** - * Show this plugin + * Show this plugin. * * @param string $plugin - The plugin to show * @return string The next page to display @@ -403,7 +411,7 @@ class assign_plugin_manager { /** - * This is the entry point for this controller class + * This is the entry point for this controller class. * * @param string $action - The action to perform * @param string $plugin - Optional name of a plugin type to perform the action on @@ -416,7 +424,7 @@ class assign_plugin_manager { $this->check_permissions(); - // process + // Process. if ($action == 'delete' && $plugin != null) { $action = $this->delete_plugin($plugin); } else if ($action == 'hide' && $plugin != null) { @@ -429,8 +437,7 @@ class assign_plugin_manager { $action = $this->move_plugin($plugin, 'down'); } - - // view + // View. if ($action == 'confirmdelete' && $plugin != null) { $this->view_confirm_delete($plugin); } else if ($action == 'plugindeleted' && $plugin != null) { @@ -441,7 +448,7 @@ class assign_plugin_manager { } /** - * This function adds plugin pages to the navigation menu + * This function adds plugin pages to the navigation menu. * * @static * @param string $subtype - The type of plugin (submission or feedback) @@ -450,7 +457,10 @@ class assign_plugin_manager { * @param stdClass|plugininfo_mod $module - The handle to the current module * @return None */ - static function add_admin_assign_plugin_settings($subtype, part_of_admin_tree $admin, admin_settingpage $settings, $module) { + public static function add_admin_assign_plugin_settings($subtype, + part_of_admin_tree $admin, + admin_settingpage $settings, + $module) { global $CFG; $plugins = get_plugin_list_with_file($subtype, 'settings.php', false); @@ -462,8 +472,10 @@ class assign_plugin_manager { ksort($pluginsbyname); foreach ($pluginsbyname as $pluginname => $plugin) { - $settings = new admin_settingpage($subtype . '_'.$plugin, - $pluginname, 'moodle/site:config', $module->is_enabled() === false); + $settings = new admin_settingpage($subtype . '_' . $plugin, + $pluginname, + 'moodle/site:config', + $module->is_enabled() === false); if ($admin->fulltree) { $shortsubtype = substr($subtype, strlen('assign')); include($CFG->dirroot . "/mod/assign/$shortsubtype/$plugin/settings.php"); diff --git a/mod/assign/adminmanageplugins.php b/mod/assign/adminmanageplugins.php index 54a6ef34dcb..7ddcd715bf2 100644 --- a/mod/assign/adminmanageplugins.php +++ b/mod/assign/adminmanageplugins.php @@ -22,15 +22,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** Include config.php */ require_once(dirname(__FILE__) . '/../../config.php'); -/** Include adminlib.php */ require_once($CFG->dirroot.'/mod/assign/adminlib.php'); -// create the class for this controller +// Create the class for this controller. $pluginmanager = new assign_plugin_manager(required_param('subtype', PARAM_PLUGIN)); $PAGE->set_context(get_system_context()); -// execute the controller -$pluginmanager->execute(optional_param('action', null, PARAM_PLUGIN), optional_param('plugin', null, PARAM_PLUGIN)); +// Execute the controller. +$pluginmanager->execute(optional_param('action', null, PARAM_PLUGIN), + optional_param('plugin', null, PARAM_PLUGIN)); diff --git a/mod/assign/assignmentplugin.php b/mod/assign/assignmentplugin.php index 686bf0a41a2..264ddb01a94 100644 --- a/mod/assign/assignmentplugin.php +++ b/mod/assign/assignmentplugin.php @@ -34,7 +34,9 @@ defined('MOODLE_INTERNAL') || die(); */ abstract class assign_plugin { - /** @var assign $assignment the assignment record that contains the global settings for this assign instance */ + /** @var assign $assignment the assignment record that contains the global + * settings for this assign instance + */ protected $assignment; /** @var string $type assignment plugin type */ private $type = ''; @@ -73,7 +75,9 @@ abstract class assign_plugin { * @return bool */ public final function is_last() { - if ((count(get_plugin_list($this->get_subtype()))-1) == get_config($this->get_subtype() . '_' . $this->get_type(), 'sortorder')) { + $lastindex = count(get_plugin_list($this->get_subtype()))-1; + $currentindex = get_config($this->get_subtype() . '_' . $this->get_type(), 'sortorder'); + if ($lastindex == $currentindex) { return true; } @@ -123,7 +127,6 @@ abstract class assign_plugin { /** * What was the last error? * - * * @return string */ public final function get_error() { @@ -184,8 +187,9 @@ abstract class assign_plugin { /** * Save any custom data for this form submission * - * @param stdClass $submissionorgrade - assign_submission or assign_grade - * For submission plugins this is the submission data, for feedback plugins it is the grade data + * @param stdClass $submissionorgrade - assign_submission or assign_grade. + * For submission plugins this is the submission data, + * for feedback plugins it is the grade data * @param stdClass $data - the data submitted from the form * @return bool - on error the subtype should call set_error and return false. */ @@ -240,7 +244,8 @@ abstract class assign_plugin { * Get any additional fields for the submission/grading form for this assignment. * This function is retained for backwards compatibility - new plugins should override {@link get_form_elements_for_user()}. * - * @param mixed $submissionorgrade submission|grade - For submission plugins this is the submission data, for feedback plugins it is the grade data + * @param mixed $submissionorgrade submission|grade - For submission plugins this is the submission data, + * for feedback plugins it is the grade data * @param MoodleQuickForm $mform - This is the form * @param stdClass $data - This is the form data that can be modified for example by a filemanager element * @return boolean - true if we added anything to the form @@ -253,7 +258,8 @@ abstract class assign_plugin { * Should not output anything - return the result as a string so it can be consumed by webservices. * * @param stdClass $submissionorgrade assign_submission or assign_grade - * For submission plugins this is the submission data, for feedback plugins it is the grade data + * For submission plugins this is the submission data, + * for feedback plugins it is the grade data * @return string - return a string representation of the submission in full */ public function view(stdClass $submissionorgrade) { @@ -289,7 +295,9 @@ abstract class assign_plugin { public final function has_admin_settings() { global $CFG; - return file_exists($CFG->dirroot . '/mod/assign/' . substr($this->get_subtype(), strlen('assign')) . '/' . $this->get_type() . '/settings.php'); + $pluginroot = $CFG->dirroot . '/mod/assign/' . substr($this->get_subtype(), strlen('assign')) . '/' . $this->get_type(); + $settingsfile = $pluginroot . '/settings.php'; + return file_exists($settingsfile); } /** @@ -302,7 +310,11 @@ abstract class assign_plugin { public final function set_config($name, $value) { global $DB; - $current = $DB->get_record('assign_plugin_config', array('assignment'=>$this->assignment->get_instance()->id, 'subtype'=>$this->get_subtype(), 'plugin'=>$this->get_type(), 'name'=>$name), '*', IGNORE_MISSING); + $dbparams = array('assignment'=>$this->assignment->get_instance()->id, + 'subtype'=>$this->get_subtype(), + 'plugin'=>$this->get_type(), + 'name'=>$name); + $current = $DB->get_record('assign_plugin_config', $dbparams, '*', IGNORE_MISSING); if ($current) { $current->value = $value; @@ -334,14 +346,21 @@ abstract class assign_plugin { } $assignment = $this->assignment->get_instance(); if ($assignment) { - $result = $DB->get_record('assign_plugin_config', array('assignment'=>$assignment->id, 'subtype'=>$this->get_subtype(), 'plugin'=>$this->get_type(), 'name'=>$setting), '*', IGNORE_MISSING); + $dbparams = array('assignment'=>$assignment->id, + 'subtype'=>$this->get_subtype(), + 'plugin'=>$this->get_type(), + 'name'=>$setting); + $result = $DB->get_record('assign_plugin_config', $dbparams, '*', IGNORE_MISSING); if ($result) { return $result->value; } } return false; } - $results = $DB->get_records('assign_plugin_config', array('assignment'=>$this->assignment->get_instance()->id, 'subtype'=>$this->get_subtype(), 'plugin'=>$this->get_type())); + $dbparams = array('assignment'=>$this->assignment->get_instance()->id, + 'subtype'=>$this->get_subtype(), + 'plugin'=>$this->get_type()); + $results = $DB->get_records('assign_plugin_config', $dbparams); $config = new stdClass(); if (is_array($results)) { @@ -454,7 +473,8 @@ abstract class assign_plugin { * @return bool true or false - false will trigger a rollback */ public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) { - $log = $log . ' ' . get_string('upgradenotimplemented', 'mod_assign', array('type'=>$this->type, 'subtype'=>$this->get_subtype())); + $params = array('type'=>$this->type, 'subtype'=>$this->get_subtype()); + $log .= ' ' . get_string('upgradenotimplemented', 'mod_assign', $params); return false; } @@ -468,8 +488,13 @@ abstract class assign_plugin { * @param string $log Record upgrade messages in the log * @return boolean true or false - false will trigger a rollback */ - public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmissionorgrade, stdClass $submissionorgrade, & $log) { - $log = $log . ' ' . get_string('upgradenotimplemented', 'mod_assign', array('type'=>$this->type, 'subtype'=>$this->get_subtype())); + public function upgrade(context $oldcontext, + stdClass $oldassignment, + stdClass $oldsubmissionorgrade, + stdClass $submissionorgrade, + & $log) { + $params = array('type'=>$this->type, 'subtype'=>$this->get_subtype()); + $log = $log . ' ' . get_string('upgradenotimplemented', 'mod_assign', $params); return false; } @@ -480,7 +505,7 @@ abstract class assign_plugin { * @return string */ public function format_for_log(stdClass $submissionorgrade) { - // format the info for each submission plugin add_to_log + // Format the info for each submission plugin add_to_log. return ''; } @@ -533,7 +558,7 @@ abstract class assign_plugin { global $CFG, $DB, $USER; $urlbase = $CFG->wwwroot.'/pluginfile.php'; - // permission check on the itemid + // Permission check on the itemid. if ($this->get_subtype() == 'assignsubmission') { if ($itemid) { @@ -546,7 +571,7 @@ abstract class assign_plugin { } } } else { - // not supported for feedback plugins + // Not supported for feedback plugins. return null; } diff --git a/mod/assign/backup/moodle2/backup_assign_activity_task.class.php b/mod/assign/backup/moodle2/backup_assign_activity_task.class.php index 9f09426d5f9..9c3c967a1ca 100644 --- a/mod/assign/backup/moodle2/backup_assign_activity_task.class.php +++ b/mod/assign/backup/moodle2/backup_assign_activity_task.class.php @@ -25,7 +25,6 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/mod/assign/backup/moodle2/backup_assign_stepslib.php'); -//require_once($CFG->dirroot . '/mod/assign/backup/moodle2/backup_assign_settingslib.php'); /** * assign backup task that provides all the settings and steps to perform one complete backup of the activity @@ -40,7 +39,7 @@ class backup_assign_activity_task extends backup_activity_task { * Define (add) particular settings this activity can have */ protected function define_my_settings() { - // No particular settings for this activity + // No particular settings for this activity. } /** @@ -59,13 +58,11 @@ class backup_assign_activity_task extends backup_activity_task { static public function encode_content_links($content) { global $CFG; - $base = preg_quote($CFG->wwwroot,"/"); + $base = preg_quote($CFG->wwwroot, "/"); - // Link to the list of choices $search="/(".$base."\/mod\/assign\/index.php\?id\=)([0-9]+)/"; $content= preg_replace($search, '$@ASSIGNINDEX*$2@$', $content); - // Link to choice view by moduleid $search="/(".$base."\/mod\/assign\/view.php\?id\=)([0-9]+)/"; $content= preg_replace($search, '$@ASSIGNVIEWBYID*$2@$', $content); diff --git a/mod/assign/backup/moodle2/backup_assign_stepslib.php b/mod/assign/backup/moodle2/backup_assign_stepslib.php index cb4dd39de88..088e5fa3107 100644 --- a/mod/assign/backup/moodle2/backup_assign_stepslib.php +++ b/mod/assign/backup/moodle2/backup_assign_stepslib.php @@ -39,10 +39,10 @@ class backup_assign_activity_structure_step extends backup_activity_structure_st */ protected function define_structure() { - // To know if we are including userinfo + // To know if we are including userinfo. $userinfo = $this->get_setting_value('userinfo'); - // Define each element separated + // Define each element separated. $assign = new backup_nested_element('assign', array('id'), array('name', 'intro', @@ -93,7 +93,7 @@ class backup_assign_activity_structure_step extends backup_activity_structure_st 'name', 'value')); - // Build the tree + // Build the tree. $assign->add_child($submissions); $submissions->add_child($submission); @@ -102,10 +102,10 @@ class backup_assign_activity_structure_step extends backup_activity_structure_st $assign->add_child($pluginconfigs); $pluginconfigs->add_child($pluginconfig); - // Define sources. $assign->set_source_table('assign', array('id' => backup::VAR_ACTIVITYID)); - $pluginconfig->set_source_table('assign_plugin_config', array('assignment' => backup::VAR_PARENTID)); + $pluginconfig->set_source_table('assign_plugin_config', + array('assignment' => backup::VAR_PARENTID)); if ($userinfo) { $submission->set_source_table('assign_submission', @@ -119,17 +119,18 @@ class backup_assign_activity_structure_step extends backup_activity_structure_st $this->add_subplugin_structure('assignfeedback', $grade, true); } - // Define id annotations + // Define id annotations. $submission->annotate_ids('user', 'userid'); $submission->annotate_ids('group', 'groupid'); $grade->annotate_ids('user', 'userid'); $grade->annotate_ids('user', 'grader'); $assign->annotate_ids('grouping', 'teamsubmissiongroupingid'); - // Define file annotations - $assign->annotate_files('mod_assign', 'intro', null); // This file area hasn't itemid + // Define file annotations. + // This file area hasn't itemid. + $assign->annotate_files('mod_assign', 'intro', null); - // Return the root element (choice), wrapped into standard activity structure + // Return the root element (choice), wrapped into standard activity structure. return $this->prepare_activity_structure($assign); } diff --git a/mod/assign/backup/moodle2/restore_assign_activity_task.class.php b/mod/assign/backup/moodle2/restore_assign_activity_task.class.php index 900b1b8037d..d1080aa973e 100644 --- a/mod/assign/backup/moodle2/restore_assign_activity_task.class.php +++ b/mod/assign/backup/moodle2/restore_assign_activity_task.class.php @@ -36,23 +36,23 @@ require_once($CFG->dirroot . '/mod/assign/backup/moodle2/restore_assign_stepslib class restore_assign_activity_task extends restore_activity_task { /** - * Define (add) particular settings this activity can have + * Define (add) particular settings this activity can have. */ protected function define_my_settings() { - // No particular settings for this activity + // No particular settings for this activity. } /** - * Define (add) particular steps this activity can have + * Define (add) particular steps this activity can have. */ protected function define_my_steps() { - // Assign only has one structure step + // Assignment only has one structure step. $this->add_step(new restore_assign_activity_structure_step('assign_structure', 'assign.xml')); } /** * Define the contents in the activity that must be - * processed by the link decoder + * processed by the link decoder. * * @return array */ @@ -66,15 +66,19 @@ class restore_assign_activity_task extends restore_activity_task { /** * Define the decoding rules for links belonging - * to the activity to be executed by the link decoder + * to the activity to be executed by the link decoder. * * @return array of restore_decode_rule */ static public function define_decode_rules() { $rules = array(); - $rules[] = new restore_decode_rule('ASSIGNVIEWBYID', '/mod/assign/view.php?id=$1', 'course_module'); - $rules[] = new restore_decode_rule('ASSIGNINDEX', '/mod/assign/index.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('ASSIGNVIEWBYID', + '/mod/assign/view.php?id=$1', + 'course_module'); + $rules[] = new restore_decode_rule('ASSIGNINDEX', + '/mod/assign/index.php?id=$1', + 'course_module'); return $rules; @@ -84,7 +88,7 @@ class restore_assign_activity_task extends restore_activity_task { * Define the restore log rules that will be applied * by the {@link restore_logs_processor} when restoring * assign logs. It must return one array - * of {@link restore_log_rule} objects + * of {@link restore_log_rule} objects. * * @return array of restore_log_rule */ @@ -94,7 +98,6 @@ class restore_assign_activity_task extends restore_activity_task { $rules[] = new restore_log_rule('assign', 'add', 'view.php?id={course_module}', '{assign}'); $rules[] = new restore_log_rule('assign', 'update', 'view.php?id={course_module}', '{assign}'); $rules[] = new restore_log_rule('assign', 'view', 'view.php?id={course_module}', '{assign}'); - // more... return $rules; } diff --git a/mod/assign/backup/moodle2/restore_assign_stepslib.php b/mod/assign/backup/moodle2/restore_assign_stepslib.php index 6053447d03b..2a265dbed88 100644 --- a/mod/assign/backup/moodle2/restore_assign_stepslib.php +++ b/mod/assign/backup/moodle2/restore_assign_stepslib.php @@ -34,32 +34,36 @@ defined('MOODLE_INTERNAL') || die(); class restore_assign_activity_structure_step extends restore_activity_structure_step { /** - * Define the structure of the restore workflow + * Define the structure of the restore workflow. + * * @return restore_path_element $structure */ protected function define_structure() { $paths = array(); - // To know if we are including userinfo + // To know if we are including userinfo. $userinfo = $this->get_setting_value('userinfo'); - // Define each element separated + // Define each element separated. $paths[] = new restore_path_element('assign', '/activity/assign'); if ($userinfo) { - $submission = new restore_path_element('assign_submission', '/activity/assign/submissions/submission'); + $submission = new restore_path_element('assign_submission', + '/activity/assign/submissions/submission'); $paths[] = $submission; $this->add_subplugin_structure('assignsubmission', $submission); $grade = new restore_path_element('assign_grade', '/activity/assign/grades/grade'); $paths[] = $grade; $this->add_subplugin_structure('assignfeedback', $grade); } - $paths[] = new restore_path_element('assign_plugin_config', '/activity/assign/plugin_configs/plugin_config'); + $paths[] = new restore_path_element('assign_plugin_config', + '/activity/assign/plugin_configs/plugin_config'); return $this->prepare_activity_structure($paths); } /** - * Process an assign restore + * Process an assign restore. + * * @param object $data The data in object form * @return void */ @@ -74,7 +78,8 @@ class restore_assign_activity_structure_step extends restore_activity_structure_ $data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate); $data->duedate = $this->apply_date_offset($data->duedate); if (!empty($data->teamsubmissiongroupingid)) { - $data->teamsubmissiongroupingid = $this->get_mappingid('grouping', $data->teamsubmissiongroupingid); + $data->teamsubmissiongroupingid = $this->get_mappingid('grouping', + $data->teamsubmissiongroupingid); } else { $data->teamsubmissiongroupingid = 0; } @@ -89,7 +94,6 @@ class restore_assign_activity_structure_step extends restore_activity_structure_ $data->cutoffdate = $this->apply_date_offset($data->cutoffdate); } - $newitemid = $DB->insert_record('assign', $data); $this->apply_activity_instance($newitemid); @@ -122,7 +126,7 @@ class restore_assign_activity_structure_step extends restore_activity_structure_ $newitemid = $DB->insert_record('assign_submission', $data); // Note - the old contextid is required in order to be able to restore files stored in - // sub plugin file areas attached to the submissionid + // sub plugin file areas attached to the submissionid. $this->set_mapping('submission', $oldid, $newitemid, false, null, $this->task->get_old_contextid()); } @@ -152,7 +156,7 @@ class restore_assign_activity_structure_step extends restore_activity_structure_ $newitemid = $DB->insert_record('assign_grades', $data); // Note - the old contextid is required in order to be able to restore files stored in - // sub plugin file areas attached to the gradeid + // sub plugin file areas attached to the gradeid. $this->set_mapping('grade', $oldid, $newitemid, false, null, $this->task->get_old_contextid()); } @@ -170,7 +174,6 @@ class restore_assign_activity_structure_step extends restore_activity_structure_ $data->assignment = $this->get_new_parentid('assign'); $newitemid = $DB->insert_record('assign_plugin_config', $data); - } /** diff --git a/mod/assign/db/messages.php b/mod/assign/db/messages.php index a611f5f72ba..04e66a1715a 100644 --- a/mod/assign/db/messages.php +++ b/mod/assign/db/messages.php @@ -24,7 +24,7 @@ $messageproviders = array ( - // Ordinary assignment submissions + // Ordinary assignment submissions. 'assign_notification' => array( ) diff --git a/mod/assign/db/upgrade.php b/mod/assign/db/upgrade.php index 9b5405edef6..f64227939e5 100644 --- a/mod/assign/db/upgrade.php +++ b/mod/assign/db/upgrade.php @@ -36,7 +36,8 @@ function xmldb_assign_upgrade($oldversion) { // Define field to be added to assign. $table = new xmldb_table('assign'); - $field = new xmldb_field('sendlatenotifications', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'sendnotifications'); + $field = new xmldb_field('sendlatenotifications', XMLDB_TYPE_INTEGER, '2', null, + XMLDB_NOTNULL, null, '0', 'sendnotifications'); // Conditionally launch add field. if (!$dbman->field_exists($table, $field)) { @@ -54,7 +55,8 @@ function xmldb_assign_upgrade($oldversion) { // Define field requiresubmissionstatement to be added to assign. $table = new xmldb_table('assign'); - $field = new xmldb_field('requiresubmissionstatement', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'timemodified'); + $field = new xmldb_field('requiresubmissionstatement', XMLDB_TYPE_INTEGER, '2', null, + XMLDB_NOTNULL, null, '0', 'timemodified'); // Conditionally launch add field requiresubmissionstatement. @@ -70,7 +72,8 @@ function xmldb_assign_upgrade($oldversion) { // Define field to be added to assign. $table = new xmldb_table('assign'); - $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'timemodified'); + $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '2', null, + XMLDB_NOTNULL, null, '0', 'timemodified'); // Conditionally launch add field. if (!$dbman->field_exists($table, $field)) { @@ -106,11 +109,12 @@ function xmldb_assign_upgrade($oldversion) { $dbman->drop_field($table, $field); } - // Define field extensionduedate to be added to assign_grades + // Define field extensionduedate to be added to assign_grades. $table = new xmldb_table('assign_grades'); - $field = new xmldb_field('extensionduedate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'mailed'); + $field = new xmldb_field('extensionduedate', XMLDB_TYPE_INTEGER, '10', null, + XMLDB_NOTNULL, null, '0', 'mailed'); - // Conditionally launch add field extensionduedate + // Conditionally launch add field extensionduedate. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } @@ -143,13 +147,16 @@ function xmldb_assign_upgrade($oldversion) { if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - $index = new xmldb_index('teamsubmissiongroupingid', XMLDB_INDEX_NOTUNIQUE, array('teamsubmissiongroupingid')); + $index = new xmldb_index('teamsubmissiongroupingid', + XMLDB_INDEX_NOTUNIQUE, + array('teamsubmissiongroupingid')); // Conditionally launch add index. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } $table = new xmldb_table('assign_submission'); - $field = new xmldb_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'status'); + $field = new xmldb_field('groupid', XMLDB_TYPE_INTEGER, '10', null, + XMLDB_NOTNULL, null, '0', 'status'); // Conditionally launch add field. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); @@ -158,48 +165,48 @@ function xmldb_assign_upgrade($oldversion) { } if ($oldversion < 2012082400) { - // Define table assign_user_mapping to be created + // Define table assign_user_mapping to be created. $table = new xmldb_table('assign_user_mapping'); - // Adding fields to table assign_user_mapping + // Adding fields to table assign_user_mapping. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('assignment', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - // Adding keys to table assign_user_mapping + // Adding keys to table assign_user_mapping. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('assignment', XMLDB_KEY_FOREIGN, array('assignment'), 'assign', array('id')); $table->add_key('user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - // Conditionally launch create table for assign_user_mapping + // Conditionally launch create table for assign_user_mapping. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } - // Define field blindmarking to be added to assign + // Define field blindmarking to be added to assign. $table = new xmldb_table('assign'); - $field = new xmldb_field('blindmarking', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'teamsubmissiongroupingid'); + $field = new xmldb_field('blindmarking', XMLDB_TYPE_INTEGER, '2', null, + XMLDB_NOTNULL, null, '0', 'teamsubmissiongroupingid'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - // Define field revealidentities to be added to assign + // Define field revealidentities to be added to assign. $table = new xmldb_table('assign'); - $field = new xmldb_field('revealidentities', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'blindmarking'); + $field = new xmldb_field('revealidentities', XMLDB_TYPE_INTEGER, '2', null, + XMLDB_NOTNULL, null, '0', 'blindmarking'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - // assign savepoint reached + // Assignment savepoint reached. upgrade_mod_savepoint(true, 2012082400, 'assign'); } - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - + // Moodle v2.4.0 release upgrade line. + // Put any upgrade step following this. return true; } diff --git a/mod/assign/feedback/comments/backup/moodle2/backup_assignfeedback_comments_subplugin.class.php b/mod/assign/feedback/comments/backup/moodle2/backup_assignfeedback_comments_subplugin.class.php index 3faff44a9c8..d885b349713 100644 --- a/mod/assign/feedback/comments/backup/moodle2/backup_assignfeedback_comments_subplugin.class.php +++ b/mod/assign/feedback/comments/backup/moodle2/backup_assignfeedback_comments_subplugin.class.php @@ -25,9 +25,9 @@ defined('MOODLE_INTERNAL') || die(); /** - * Provides the information to backup comments feedback + * Provides the information to backup comments feedback. * - * This just records the text and format + * This just records the text and format. * * @package assignfeedback_comments * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -36,22 +36,25 @@ defined('MOODLE_INTERNAL') || die(); class backup_assignfeedback_comments_subplugin extends backup_subplugin { /** - * Returns the subplugin information to attach to submission element + * Returns the subplugin information to attach to submission element. * @return backup_subplugin_element */ protected function define_grade_subplugin_structure() { - // create XML elements - $subplugin = $this->get_subplugin_element(); // virtual optigroup element + // Create XML elements. + $subplugin = $this->get_subplugin_element(); $subpluginwrapper = new backup_nested_element($this->get_recommended_name()); - $subpluginelement = new backup_nested_element('feedback_comments', null, array('commenttext', 'commentformat', 'grade')); + $subpluginelement = new backup_nested_element('feedback_comments', + null, + array('commenttext', 'commentformat', 'grade')); - // connect XML elements into the tree + // Connect XML elements into the tree. $subplugin->add_child($subpluginwrapper); $subpluginwrapper->add_child($subpluginelement); - // set source to populate the data - $subpluginelement->set_source_table('assignfeedback_comments', array('grade' => backup::VAR_PARENTID)); + // Set source to populate the data. + $subpluginelement->set_source_table('assignfeedback_comments', + array('grade' => backup::VAR_PARENTID)); return $subplugin; } diff --git a/mod/assign/feedback/comments/backup/moodle2/restore_assignfeedback_comments_subplugin.class.php b/mod/assign/feedback/comments/backup/moodle2/restore_assignfeedback_comments_subplugin.class.php index 7e38515c064..1efd24e79a8 100644 --- a/mod/assign/feedback/comments/backup/moodle2/restore_assignfeedback_comments_subplugin.class.php +++ b/mod/assign/feedback/comments/backup/moodle2/restore_assignfeedback_comments_subplugin.class.php @@ -15,7 +15,8 @@ // along with Moodle. If not, see . /** - * restore subplugin class that provides the necessary information needed to restore one assign_submission subplugin. + * Restore subplugin class that provides the necessary information needed to restore + * one assign_submission subplugin. * * @package assignfeedback_comments * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -25,7 +26,8 @@ defined('MOODLE_INTERNAL') || die(); /** - * restore subplugin class that provides the necessary information needed to restore one assignfeedback subplugin. + * Restore subplugin class that provides the necessary information needed to restore + * one assignfeedback subplugin. * * @package assignfeedback_comments * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -42,14 +44,16 @@ class restore_assignfeedback_comments_subplugin extends restore_subplugin { $paths = array(); $elename = $this->get_namefor('grade'); - $elepath = $this->get_pathfor('/feedback_comments'); // we used get_recommended_name() so this works + // We used get_recommended_name() so this works. + $elepath = $this->get_pathfor('/feedback_comments'); + $paths[] = new restore_path_element($elename, $elepath); - return $paths; // And we return the interesting paths + return $paths; } /** - * Processes one feedback_comments element + * Processes one feedback_comments element. * @param mixed $data */ public function process_assignfeedback_comments_grade($data) { @@ -58,7 +62,8 @@ class restore_assignfeedback_comments_subplugin extends restore_subplugin { $data = (object)$data; $data->assignment = $this->get_new_parentid('assign'); $oldgradeid = $data->grade; - // the mapping is set in the restore for the core assign activity. When a grade node is processed + // The mapping is set in the restore for the core assign activity + // when a grade node is processed. $data->grade = $this->get_mappingid('grade', $data->grade); $DB->insert_record('assignfeedback_comments', $data); diff --git a/mod/assign/feedback/comments/db/install.php b/mod/assign/feedback/comments/db/install.php index f8c093b5eba..0376340edf8 100644 --- a/mod/assign/feedback/comments/db/install.php +++ b/mod/assign/feedback/comments/db/install.php @@ -31,13 +31,11 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_assignfeedback_comments_install() { global $CFG; - // do the install require_once($CFG->dirroot . '/mod/assign/adminlib.php'); - // set the correct initial order for the plugins + // Set the correct initial order for the plugins. $pluginmanager = new assign_plugin_manager('assignfeedback'); $pluginmanager->move_plugin('comments', 'up'); - // do the upgrades return true; } diff --git a/mod/assign/feedback/comments/db/upgrade.php b/mod/assign/feedback/comments/db/upgrade.php index d9ec10a68f7..ee433e4b329 100644 --- a/mod/assign/feedback/comments/db/upgrade.php +++ b/mod/assign/feedback/comments/db/upgrade.php @@ -28,14 +28,12 @@ * @return bool */ function xmldb_assignfeedback_comments_upgrade($oldversion) { - // do the upgrades - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this + // Do the upgrades. + // Moodle v2.3.0 release upgrade line. + // Put any upgrade step following this. + // Moodle v2.4.0 release upgrade line. + // Put any upgrade step following this. return true; } diff --git a/mod/assign/feedback/comments/locallib.php b/mod/assign/feedback/comments/locallib.php index 7dcff1e3141..2c56aa73ea8 100644 --- a/mod/assign/feedback/comments/locallib.php +++ b/mod/assign/feedback/comments/locallib.php @@ -17,16 +17,15 @@ /** * This file contains the definition for the library class for comment feedback plugin * - * * @package assignfeedback_comments * @copyright 2012 NetSpot {@link http://www.netspot.com.au} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); +defined('MOODLE_INTERNAL') || die(); /** - * library class for comment feedback plugin extending feedback plugin base class + * Library class for comment feedback plugin extending feedback plugin base class. * * @package assignfeedback_comments * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -34,19 +33,20 @@ */ class assign_feedback_comments extends assign_feedback_plugin { - /** - * Get the name of the online comment feedback plugin - * @return string - */ + /** + * Get the name of the online comment feedback plugin. + * @return string + */ public function get_name() { return get_string('pluginname', 'assignfeedback_comments'); } /** - * Get the feedback comment from the database + * Get the feedback comment from the database. * * @param int $gradeid - * @return stdClass|false The feedback comments for the given grade if it exists. False if it doesn't. + * @return stdClass|false The feedback comments for the given grade if it exists. + * False if it doesn't. */ public function get_feedback_comments($gradeid) { global $DB; @@ -54,7 +54,7 @@ class assign_feedback_comments extends assign_feedback_plugin { } /** - * Get quickgrading form elements as html + * Get quickgrading form elements as html. * * @param int $userid The user id in the table this quickgrading element relates to * @param mixed $grade - The grade data - may be null if there are no grades for this user (yet) @@ -69,10 +69,14 @@ class assign_feedback_comments extends assign_feedback_plugin { } } - return html_writer::tag('label', get_string('pluginname', 'assignfeedback_comments'), - array('for'=>'quickgrade_comments_' . $userid, 'class'=>'accesshide')) - . html_writer::tag('textarea', $commenttext, - array('name'=>'quickgrade_comments_' . $userid, 'id'=>'quickgrade_comments_' . $userid, 'class'=>'quickgrade')); + $pluginname = get_string('pluginname', 'assignfeedback_comments'); + $labeloptions = array('for'=>'quickgrade_comments_' . $userid, + 'class'=>'accesshide'); + $textareaoptions = array('name'=>'quickgrade_comments_' . $userid, + 'id'=>'quickgrade_comments_' . $userid, + 'class'=>'quickgrade'); + return html_writer::tag('label', $pluginname, $labeloptions) . + html_writer::tag('textarea', $commenttext, $textareaoptions); } /** @@ -95,7 +99,7 @@ class assign_feedback_comments extends assign_feedback_plugin { /** - * Override to indicate a plugin supports quickgrading + * Override to indicate a plugin supports quickgrading. * * @return boolean - True if the plugin supports quickgrading */ @@ -104,7 +108,7 @@ class assign_feedback_comments extends assign_feedback_plugin { } /** - * Return a list of the text fields that can be imported/exported by this plugin + * Return a list of the text fields that can be imported/exported by this plugin. * * @return array An array of field names and descriptions. (name=>description, ...) */ @@ -113,7 +117,7 @@ class assign_feedback_comments extends assign_feedback_plugin { } /** - * Get the saved text content from the editor + * Get the saved text content from the editor. * * @param string $name * @param int $gradeid @@ -131,7 +135,7 @@ class assign_feedback_comments extends assign_feedback_plugin { } /** - * Get the saved text content from the editor + * Get the saved text content from the editor. * * @param string $name * @param string $value @@ -160,7 +164,7 @@ class assign_feedback_comments extends assign_feedback_plugin { } /** - * Save quickgrading changes + * Save quickgrading changes. * * @param int $userid The user id in the table this quickgrading element relates to * @param stdClass $grade The grade @@ -204,7 +208,7 @@ class assign_feedback_comments extends assign_feedback_plugin { } /** - * Saving the comment content into dtabase + * Saving the comment content into database. * * @param stdClass $grade * @param stdClass $data @@ -228,7 +232,7 @@ class assign_feedback_comments extends assign_feedback_plugin { } /** - * display the comment in the feedback table + * Display the comment in the feedback table. * * @param stdClass $grade * @param bool $showviewlink Set to true to show a link to view the full feedback @@ -237,10 +241,12 @@ class assign_feedback_comments extends assign_feedback_plugin { public function view_summary(stdClass $grade, & $showviewlink) { $feedbackcomments = $this->get_feedback_comments($grade->id); if ($feedbackcomments) { - $text = format_text($feedbackcomments->commenttext, $feedbackcomments->commentformat, array('context' => $this->assignment->get_context())); + $text = format_text($feedbackcomments->commenttext, + $feedbackcomments->commentformat, + array('context' => $this->assignment->get_context())); $short = shorten_text($text, 140); - // show the view all link if the text has been shortened + // Show the view all link if the text has been shortened. $showviewlink = $short != $text; return $short; } @@ -248,7 +254,7 @@ class assign_feedback_comments extends assign_feedback_plugin { } /** - * display the comment in the feedback table + * Display the comment in the feedback table. * * @param stdClass $grade * @return string @@ -256,7 +262,9 @@ class assign_feedback_comments extends assign_feedback_plugin { public function view(stdClass $grade) { $feedbackcomments = $this->get_feedback_comments($grade->id); if ($feedbackcomments) { - return format_text($feedbackcomments->commenttext, $feedbackcomments->commentformat, array('context' => $this->assignment->get_context())); + return format_text($feedbackcomments->commenttext, + $feedbackcomments->commentformat, + array('context' => $this->assignment->get_context())); } return ''; } @@ -287,7 +295,6 @@ class assign_feedback_comments extends assign_feedback_plugin { * @return bool was it a success? (false will trigger a rollback) */ public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) { - // first upgrade settings (nothing to do) return true; } @@ -301,7 +308,11 @@ class assign_feedback_comments extends assign_feedback_plugin { * @param string $log Record upgrade messages in the log * @return bool true or false - false will trigger a rollback */ - public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $grade, & $log) { + public function upgrade(context $oldcontext, + stdClass $oldassignment, + stdClass $oldsubmission, + stdClass $grade, + & $log) { global $DB; $feedbackcomments = new stdClass(); @@ -361,13 +372,14 @@ class assign_feedback_comments extends assign_feedback_plugin { */ public function delete_instance() { global $DB; - // will throw exception on failure - $DB->delete_records('assignfeedback_comments', array('assignment'=>$this->assignment->get_instance()->id)); + // Will throw exception on failure. + $DB->delete_records('assignfeedback_comments', + array('assignment'=>$this->assignment->get_instance()->id)); return true; } /** - * Returns true if there are no feedback comments for the given grade + * Returns true if there are no feedback comments for the given grade. * * @param stdClass $grade * @return bool diff --git a/mod/assign/feedback/file/backup/moodle2/backup_assignfeedback_file_subplugin.class.php b/mod/assign/feedback/file/backup/moodle2/backup_assignfeedback_file_subplugin.class.php index 497a7c14c78..04bfafe615a 100644 --- a/mod/assign/feedback/file/backup/moodle2/backup_assignfeedback_file_subplugin.class.php +++ b/mod/assign/feedback/file/backup/moodle2/backup_assignfeedback_file_subplugin.class.php @@ -24,9 +24,9 @@ defined('MOODLE_INTERNAL') || die(); /** - * Provides the information to backup feedback files + * Provides the information to backup feedback files. * - * This just adds its filearea to the annotations and records the number of files + * This just adds its filearea to the annotations and records the number of files. * * @package assignfeedback_file * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -40,19 +40,19 @@ class backup_assignfeedback_file_subplugin extends backup_subplugin { */ protected function define_grade_subplugin_structure() { - // create XML elements - $subplugin = $this->get_subplugin_element(); // virtual optigroup element + // Create XML elements. + $subplugin = $this->get_subplugin_element(); $subpluginwrapper = new backup_nested_element($this->get_recommended_name()); $subpluginelement = new backup_nested_element('feedback_file', null, array('numfiles', 'grade')); - // connect XML elements into the tree + // Connect XML elements into the tree. $subplugin->add_child($subpluginwrapper); $subpluginwrapper->add_child($subpluginelement); - // set source to populate the data + // Set source to populate the data. $subpluginelement->set_source_table('assignfeedback_file', array('grade' => backup::VAR_PARENTID)); - - $subpluginelement->annotate_files('assignfeedback_file', 'feedback_files', 'grade');// The parent is the grade + // The parent is the grade. + $subpluginelement->annotate_files('assignfeedback_file', 'feedback_files', 'grade'); return $subplugin; } diff --git a/mod/assign/feedback/file/backup/moodle2/restore_assignfeedback_file_subplugin.class.php b/mod/assign/feedback/file/backup/moodle2/restore_assignfeedback_file_subplugin.class.php index 3ce98ed6fec..df258d3cccb 100644 --- a/mod/assign/feedback/file/backup/moodle2/restore_assignfeedback_file_subplugin.class.php +++ b/mod/assign/feedback/file/backup/moodle2/restore_assignfeedback_file_subplugin.class.php @@ -24,7 +24,8 @@ defined('MOODLE_INTERNAL') || die(); /** - * restore subplugin class that provides the necessary information needed to restore one assign_feedback subplugin. + * Restore subplugin class that provides the necessary information needed + * to restore one assign_feedback subplugin. * * @package assignfeedback_file * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -41,10 +42,11 @@ class restore_assignfeedback_file_subplugin extends restore_subplugin { $paths = array(); $elename = $this->get_namefor('grade'); - $elepath = $this->get_pathfor('/feedback_file'); // we used get_recommended_name() so this works + // We used get_recommended_name() so this works. + $elepath = $this->get_pathfor('/feedback_file'); $paths[] = new restore_path_element($elename, $elepath); - return $paths; // And we return the interesting paths + return $paths; } /** @@ -57,7 +59,8 @@ class restore_assignfeedback_file_subplugin extends restore_subplugin { $data = (object)$data; $data->assignment = $this->get_new_parentid('assign'); $oldgradeid = $data->grade; - // the mapping is set in the restore for the core assign activity. When a grade node is processed + // The mapping is set in the restore for the core assign activity + // when a grade node is processed. $data->grade = $this->get_mappingid('grade', $data->grade); $DB->insert_record('assignfeedback_file', $data); diff --git a/mod/assign/feedback/file/db/install.php b/mod/assign/feedback/file/db/install.php index 65c302f366e..929c3785c18 100644 --- a/mod/assign/feedback/file/db/install.php +++ b/mod/assign/feedback/file/db/install.php @@ -25,7 +25,6 @@ defined('MOODLE_INTERNAL') || die(); - /** * Code run after the assignfeedback_file module database tables have been created. * Moves the feedback file plugin down @@ -35,15 +34,12 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_assignfeedback_file_install() { global $CFG; - // do the install - require_once($CFG->dirroot . '/mod/assign/adminlib.php'); - // set the correct initial order for the plugins - $pluginmanager = new assign_plugin_manager('assignfeedback'); + // Set the correct initial order for the plugins. + $pluginmanager = new assign_plugin_manager('assignfeedback'); $pluginmanager->move_plugin('file', 'down'); - // do the upgrades return true; } diff --git a/mod/assign/feedback/file/db/upgrade.php b/mod/assign/feedback/file/db/upgrade.php index 4aa3a27712c..88945d84397 100644 --- a/mod/assign/feedback/file/db/upgrade.php +++ b/mod/assign/feedback/file/db/upgrade.php @@ -28,14 +28,12 @@ * @return bool */ function xmldb_assignfeedback_file_upgrade($oldversion) { - // do the upgrades - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this + // Do the upgrades. + // Moodle v2.3.0 release upgrade line. + // Put any upgrade step following this. + // Moodle v2.4.0 release upgrade line. + // Put any upgrade step following this. return true; } diff --git a/mod/assign/feedback/file/importzipform.php b/mod/assign/feedback/file/importzipform.php index a5aad69b0db..33e75020315 100644 --- a/mod/assign/feedback/file/importzipform.php +++ b/mod/assign/feedback/file/importzipform.php @@ -39,7 +39,7 @@ class assignfeedback_file_import_zip_form extends moodleform implements renderab /** * Create this grade import form */ - function definition() { + public function definition() { global $CFG, $PAGE; $mform = $this->_form; diff --git a/mod/assign/feedback/file/lib.php b/mod/assign/feedback/file/lib.php index 87ba684b80c..6ae9635fc54 100644 --- a/mod/assign/feedback/file/lib.php +++ b/mod/assign/feedback/file/lib.php @@ -34,7 +34,12 @@ defined('MOODLE_INTERNAL') || die(); * @param bool $forcedownload * @return bool false if file not found, does not return if found - just send the file */ -function assignfeedback_file_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload) { +function assignfeedback_file_pluginfile($course, + $cm, + context $context, + $filearea, + $args, + $forcedownload) { global $USER, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -46,7 +51,6 @@ function assignfeedback_file_pluginfile($course, $cm, context $context, $fileare $record = $DB->get_record('assign_grades', array('id'=>$itemid), 'userid,assignment', MUST_EXIST); $userid = $record->userid; - if (!$assign = $DB->get_record('assign', array('id'=>$cm->instance))) { return false; } @@ -55,8 +59,7 @@ function assignfeedback_file_pluginfile($course, $cm, context $context, $fileare return false; } - - // check is users feedback or has grading permission + // Check is users feedback or has grading permission. if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) { return false; } @@ -69,5 +72,6 @@ function assignfeedback_file_pluginfile($course, $cm, context $context, $fileare if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { return false; } - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + // Download MUST be forced - security! + send_stored_file($file, 0, 0, true); } diff --git a/mod/assign/feedback/file/locallib.php b/mod/assign/feedback/file/locallib.php index 6ed295eca93..d9f1c47630e 100644 --- a/mod/assign/feedback/file/locallib.php +++ b/mod/assign/feedback/file/locallib.php @@ -24,9 +24,8 @@ */ defined('MOODLE_INTERNAL') || die(); -/** - * File areas for file feedback assignment - */ + +// File areas for file feedback assignment. define('ASSIGNFEEDBACK_FILE_FILEAREA', 'feedback_files'); define('ASSIGNFEEDBACK_FILE_BATCH_FILEAREA', 'feedback_files_batch'); define('ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA', 'feedback_files_import'); @@ -35,7 +34,7 @@ define('ASSIGNFEEDBACK_FILE_MAXSUMMARYUSERS', 5); define('ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME', 120); /** - * library class for file feedback plugin extending feedback plugin base class + * Library class for file feedback plugin extending feedback plugin base class. * * @package asignfeedback_file * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -44,7 +43,8 @@ define('ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME', 120); class assign_feedback_file extends assign_feedback_plugin { /** - * Get the name of the file feedback plugin + * Get the name of the file feedback plugin. + * * @return string */ public function get_name() { @@ -52,7 +52,7 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Get file feedback information from the database + * Get file feedback information from the database. * * @param int $gradeid * @return mixed @@ -63,21 +63,22 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * File format options + * File format options. + * * @return array */ private function get_file_options() { global $COURSE; $fileoptions = array('subdirs'=>1, - 'maxbytes'=>$COURSE->maxbytes, - 'accepted_types'=>'*', - 'return_types'=>FILE_INTERNAL); + 'maxbytes'=>$COURSE->maxbytes, + 'accepted_types'=>'*', + 'return_types'=>FILE_INTERNAL); return $fileoptions; } /** - * Copy all the files from one file area to another + * Copy all the files from one file area to another. * * @param file_storage $fs - The source context id * @param int $fromcontextid - The source context id @@ -110,7 +111,8 @@ class assign_feedback_file extends assign_feedback_plugin { foreach ($files as $file) { if ($file->is_directory() and $file->get_filepath() === '/') { // We need a way to mark the age of each draft area. - // By not copying the root dir we force it to be created automatically with current timestamp. + // By not copying the root dir we force it to be created + // automatically with current timestamp. continue; } $newfile = $fs->create_file_from_storedfile($newfilerecord, $file); @@ -120,7 +122,7 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Get form elements for grading form + * Get form elements for grading form. * * @param stdClass $grade * @param MoodleQuickForm $mform @@ -148,7 +150,7 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Count the number of files + * Count the number of files. * * @param int $gradeid * @param string $area @@ -157,13 +159,18 @@ class assign_feedback_file extends assign_feedback_plugin { private function count_files($gradeid, $area) { $fs = get_file_storage(); - $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignfeedback_file', $area, $gradeid, "id", false); + $files = $fs->get_area_files($this->assignment->get_context()->id, + 'assignfeedback_file', + $area, + $gradeid, + 'id', + false); return count($files); } /** - * Update the number of files in the file area + * Update the number of files in the file area. * * @param stdClass $grade The grade record * @return bool - true if the value was saved @@ -185,7 +192,7 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Save the feedback files + * Save the feedback files. * * @param stdClass $grade * @param stdClass $data @@ -213,48 +220,57 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Display the list of files in the feedback status table + * Display the list of files in the feedback status table. * * @param stdClass $grade * @param bool $showviewlink - Set to true to show a link to see the full list of files * @return string */ public function view_summary(stdClass $grade, & $showviewlink) { + $count = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); - // show a view all link if the number of files is over this limit + + // Show a view all link if the number of files is over this limit. $showviewlink = $count > ASSIGNFEEDBACK_FILE_MAXSUMMARYFILES; if ($count <= ASSIGNFEEDBACK_FILE_MAXSUMMARYFILES) { - return $this->assignment->render_area_files('assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id); + return $this->assignment->render_area_files('assignfeedback_file', + ASSIGNFEEDBACK_FILE_FILEAREA, + $grade->id); } else { return get_string('countfiles', 'assignfeedback_file', $count); } } /** - * Display the list of files in the feedback status table + * Display the list of files in the feedback status table. + * * @param stdClass $grade * @return string */ public function view(stdClass $grade) { - return $this->assignment->render_area_files('assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id); + return $this->assignment->render_area_files('assignfeedback_file', + ASSIGNFEEDBACK_FILE_FILEAREA, + $grade->id); } /** - * The assignment has been deleted - cleanup + * The assignment has been deleted - cleanup. * * @return bool */ public function delete_instance() { global $DB; - // will throw exception on failure - $DB->delete_records('assignfeedback_file', array('assignment'=>$this->assignment->get_instance()->id)); + // Will throw exception on failure. + $DB->delete_records('assignfeedback_file', + array('assignment'=>$this->assignment->get_instance()->id)); return true; } /** - * Return true if there are no feedback files + * Return true if there are no feedback files. + * * @param stdClass $grade */ public function is_empty(stdClass $grade) { @@ -262,7 +278,8 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Get file areas returns a list of areas this plugin stores files + * Get file areas returns a list of areas this plugin stores files. + * * @return array - An array of fileareas (keys) and descriptions (values) */ public function get_file_areas() { @@ -278,7 +295,6 @@ class assign_feedback_file extends assign_feedback_plugin { * @return bool True if upgrade is possible */ public function can_upgrade($type, $version) { - if (($type == 'upload' || $type == 'uploadsingle') && $version >= 2011112900) { return true; } @@ -286,7 +302,7 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Upgrade the settings from the old assignment to the new plugin based one + * Upgrade the settings from the old assignment to the new plugin based one. * * @param context $oldcontext - the context for the old assignment * @param stdClass $oldassignment - the data for the old assignment @@ -294,12 +310,12 @@ class assign_feedback_file extends assign_feedback_plugin { * @return bool was it a success? (false will trigger a rollback) */ public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) { - // first upgrade settings (nothing to do) + // First upgrade settings (nothing to do). return true; } /** - * Upgrade the feedback from the old assignment to the new one + * Upgrade the feedback from the old assignment to the new one. * * @param context $oldcontext - the database for the old assignment context * @param stdClass $oldassignment The data record for the old assignment @@ -308,21 +324,24 @@ class assign_feedback_file extends assign_feedback_plugin { * @param string $log Record upgrade messages in the log * @return bool true or false - false will trigger a rollback */ - public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $grade, & $log) { + public function upgrade(context $oldcontext, + stdClass $oldassignment, + stdClass $oldsubmission, + stdClass $grade, + & $log) { global $DB; - // now copy the area files + // Now copy the area files. $this->assignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'response', $oldsubmission->id, - // New file area $this->assignment->get_context()->id, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id); - // now count them! + // Now count them! $filefeedback = new stdClass(); $filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); $filefeedback->grade = $grade->id; @@ -335,8 +354,8 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Return a list of the batch grading operations performed by this plugin - * This plugin supports batch upload files and upload zip + * Return a list of the batch grading operations performed by this plugin. + * This plugin supports batch upload files and upload zip. * * @return array The list of batch grading operations */ @@ -345,7 +364,7 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Upload files and send them to multiple users + * Upload files and send them to multiple users. * * @param array $users - An array of user ids * @return string - The response html @@ -366,17 +385,19 @@ class assign_feedback_file extends assign_feedback_plugin { $usercount = 0; foreach ($users as $userid) { if ($usercount >= ASSIGNFEEDBACK_FILE_MAXSUMMARYUSERS) { - $usershtml .= get_string('moreusers', 'assignfeedback_file', count($users) - ASSIGNFEEDBACK_FILE_MAXSUMMARYUSERS); + $moreuserscount = count($users) - ASSIGNFEEDBACK_FILE_MAXSUMMARYUSERS; + $usershtml .= get_string('moreusers', 'assignfeedback_file', $moreuserscount); break; } $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST); - $usershtml .= $this->assignment->get_renderer()->render(new assign_user_summary($user, - $this->assignment->get_course()->id, - has_capability('moodle/site:viewfullnames', - $this->assignment->get_course_context()), - $this->assignment->is_blind_marking(), - $this->assignment->get_uniqueid_for_user($user->id))); + $usersummary = new assign_user_summary($user, + $this->assignment->get_course()->id, + has_capability('moodle/site:viewfullnames', + $this->assignment->get_course_context()), + $this->assignment->is_blind_marking(), + $this->assignment->get_uniqueid_for_user($user->id)); + $usershtml .= $this->assignment->get_renderer()->render($usersummary); $usercount += 1; } @@ -416,11 +437,13 @@ class assign_feedback_file extends assign_feedback_plugin { $filefeedback = $this->get_file_feedback($grade->id); if ($filefeedback) { - $filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); + $filefeedback->numfiles = $this->count_files($grade->id, + ASSIGNFEEDBACK_FILE_FILEAREA); $DB->update_record('assignfeedback_file', $filefeedback); } else { $filefeedback = new stdClass(); - $filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); + $filefeedback->numfiles = $this->count_files($grade->id, + ASSIGNFEEDBACK_FILE_FILEAREA); $filefeedback->grade = $grade->id; $filefeedback->assignment = $this->assignment->get_instance()->id; $DB->insert_record('assignfeedback_file', $filefeedback); @@ -439,12 +462,13 @@ class assign_feedback_file extends assign_feedback_plugin { return; } else { + $header = new assign_header($this->assignment->get_instance(), + $this->assignment->get_context(), + false, + $this->assignment->get_course_module()->id, + get_string('batchuploadfiles', 'assignfeedback_file')); $o = ''; - $o .= $this->assignment->get_renderer()->render(new assign_header($this->assignment->get_instance(), - $this->assignment->get_context(), - false, - $this->assignment->get_course_module()->id, - get_string('batchuploadfiles', 'assignfeedback_file'))); + $o .= $this->assignment->get_renderer()->render($header); $o .= $this->assignment->get_renderer()->render(new assign_form('batchuploadfiles', $mform)); $o .= $this->assignment->get_renderer()->render_footer(); } @@ -453,7 +477,7 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * User has chosen a custom grading batch operation and selected some users + * User has chosen a custom grading batch operation and selected some users. * * @param string $action - The chosen action * @param array $users - An array of user ids @@ -468,7 +492,7 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * View the upload zip form + * View the upload zip form. * * @return string - The html response */ @@ -480,23 +504,25 @@ class assign_feedback_file extends assign_feedback_plugin { require_once($CFG->dirroot . '/mod/assign/feedback/file/importziplib.php'); require_once($CFG->dirroot . '/mod/assign/feedback/file/importzipform.php'); - $mform = new assignfeedback_file_upload_zip_form(null, - array('context'=>$this->assignment->get_context(), - 'cm'=>$this->assignment->get_course_module()->id)); + $formparams = array('context'=>$this->assignment->get_context(), + 'cm'=>$this->assignment->get_course_module()->id); + $mform = new assignfeedback_file_upload_zip_form(null, $formparams); $o = ''; $confirm = optional_param('confirm', 0, PARAM_BOOL); $renderer = $this->assignment->get_renderer(); + // Delete any existing files. $importer = new assignfeedback_file_zip_importer(); $contextid = $this->assignment->get_context()->id; if ($mform->is_cancelled()) { $importer->delete_import_files($contextid); - redirect(new moodle_url('view.php', - array('id'=>$this->assignment->get_course_module()->id, - 'action'=>'grading'))); + $urlparams = array('id'=>$this->assignment->get_course_module()->id, + 'action'=>'grading'); + $url = new moodle_url('view.php', $urlparams); + redirect($url); return; } else if ($confirm) { $params = array('assignment'=>$this->assignment, 'importer'=>$importer); @@ -504,9 +530,10 @@ class assign_feedback_file extends assign_feedback_plugin { $mform = new assignfeedback_file_import_zip_form(null, $params); if ($mform->is_cancelled()) { $importer->delete_import_files($contextid); - redirect(new moodle_url('view.php', - array('id'=>$this->assignment->get_course_module()->id, - 'action'=>'grading'))); + $urlparams = array('id'=>$this->assignment->get_course_module()->id, + 'action'=>'grading'); + $url = new moodle_url('view.php', $urlparams); + redirect($url); return; } @@ -528,21 +555,23 @@ class assign_feedback_file extends assign_feedback_plugin { $mform = new assignfeedback_file_import_zip_form(null, $params); - $o .= $renderer->render(new assign_header($this->assignment->get_instance(), - $this->assignment->get_context(), - false, - $this->assignment->get_course_module()->id, - get_string('confirmuploadzip', 'assignfeedback_file'))); + $header = new assign_header($this->assignment->get_instance(), + $this->assignment->get_context(), + false, + $this->assignment->get_course_module()->id, + get_string('confirmuploadzip', 'assignfeedback_file')); + $o .= $renderer->render($header); $o .= $renderer->render(new assign_form('confirmimportzip', $mform)); $o .= $renderer->render_footer(); } else { - $o .= $renderer->render(new assign_header($this->assignment->get_instance(), - $this->assignment->get_context(), - false, - $this->assignment->get_course_module()->id, - get_string('uploadzip', 'assignfeedback_file'))); + $header = new assign_header($this->assignment->get_instance(), + $this->assignment->get_context(), + false, + $this->assignment->get_course_module()->id, + get_string('uploadzip', 'assignfeedback_file')); + $o .= $renderer->render($header); $o .= $renderer->render(new assign_form('uploadfeedbackzip', $mform)); $o .= $renderer->render_footer(); } @@ -551,7 +580,8 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Called by the assignment module when someone chooses something from the grading navigation or batch operations list + * Called by the assignment module when someone chooses something from the + * grading navigation or batch operations list. * * @param string $action - The page to view * @return string - The html response @@ -569,8 +599,8 @@ class assign_feedback_file extends assign_feedback_plugin { } /** - * Return a list of the grading actions performed by this plugin - * This plugin supports upload zip + * Return a list of the grading actions performed by this plugin. + * This plugin supports upload zip. * * @return array The list of grading actions */ diff --git a/mod/assign/feedbackplugin.php b/mod/assign/feedbackplugin.php index 292f314918d..6d793f47a00 100644 --- a/mod/assign/feedbackplugin.php +++ b/mod/assign/feedbackplugin.php @@ -17,7 +17,6 @@ /** * This file contains the function for feedback_plugin abstract class * - * * @package mod_assign * @copyright 2012 NetSpot {@link http://www.netspot.com.au} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -25,7 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -/** Include assignmentplugin.php */ require_once($CFG->dirroot.'/mod/assign/assignmentplugin.php'); /** @@ -38,7 +36,7 @@ require_once($CFG->dirroot.'/mod/assign/assignmentplugin.php'); abstract class assign_feedback_plugin extends assign_plugin { /** - * return subtype name of the plugin + * Return subtype name of the plugin. * * @return string */ @@ -48,7 +46,7 @@ abstract class assign_feedback_plugin extends assign_plugin { /** * If this plugin adds to the gradebook comments field, it must specify the format - * of the comment + * of the comment. * * (From weblib.php) * define('FORMAT_MOODLE', '0'); // Does all sorts of transformations and filtering @@ -69,7 +67,7 @@ abstract class assign_feedback_plugin extends assign_plugin { /** * If this plugin adds to the gradebook comments field, it must format the text - * of the comment + * of the comment. * * Only one feedback plugin can push comments to the gradebook and that is chosen by the assignment * settings page. @@ -82,7 +80,7 @@ abstract class assign_feedback_plugin extends assign_plugin { } /** - * Override to indicate a plugin supports quickgrading + * Override to indicate a plugin supports quickgrading. * * @return boolean - True if the plugin supports quickgrading */ @@ -91,11 +89,13 @@ abstract class assign_feedback_plugin extends assign_plugin { } /** - * Get quickgrading form elements as html + * Get quickgrading form elements as html. * * @param int $userid The user id in the table this quickgrading element relates to - * @param mixed $grade grade or null - The grade data. May be null if there are no grades for this user (yet) - * @return mixed - A html string containing the html form elements required for quickgrading or false to indicate this plugin does not support quickgrading + * @param mixed $grade grade or null - The grade data. + * May be null if there are no grades for this user (yet) + * @return mixed - A html string containing the html form elements required for + * quickgrading or false to indicate this plugin does not support quickgrading */ public function get_quickgrading_html($userid, $grade) { return false; @@ -113,7 +113,7 @@ abstract class assign_feedback_plugin extends assign_plugin { } /** - * Save quickgrading changes + * Save quickgrading changes. * * @param int $userid The user id in the table this quickgrading element relates to * @param stdClass $grade The grade @@ -124,19 +124,21 @@ abstract class assign_feedback_plugin extends assign_plugin { } /** - * Return a list of the batch grading operations supported by this plugin + * Return a list of the batch grading operations supported by this plugin. * - * @return array - An array of action and description strings. The action will be passed to grading_batch_operation. + * @return array - An array of action and description strings. + * The action will be passed to grading_batch_operation. */ public function get_grading_batch_operations() { return array(); } /** - * Return a list of the grading actions supported by this plugin + * Return a list of the grading actions supported by this plugin. * * A grading action is a page that is not specific to a user but to the whole assignment. - * @return array - An array of action and description strings. The action will be passed to grading_action. + * @return array - An array of action and description strings. + * The action will be passed to grading_action. */ public function get_grading_actions() { return array(); diff --git a/mod/assign/gradeform.php b/mod/assign/gradeform.php index 366d5d8b0e0..bff82defe10 100644 --- a/mod/assign/gradeform.php +++ b/mod/assign/gradeform.php @@ -25,11 +25,8 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -/** Include formslib.php */ -require_once ($CFG->libdir.'/formslib.php'); -/** Include locallib.php */ +require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); -/** Required for advanced grading */ require_once('HTML/QuickForm/input.php'); /** @@ -44,13 +41,13 @@ class mod_assign_grade_form extends moodleform { private $assignment; /** - * Define the form - called by parent constructor + * Define the form - called by parent constructor. */ - function definition() { + public function definition() { $mform = $this->_form; list($assignment, $data, $params) = $this->_customdata; - // visible elements + // Visible elements. $this->assignment = $assignment; $assignment->add_grade_form_elements($mform, $data, $params); @@ -61,7 +58,8 @@ class mod_assign_grade_form extends moodleform { /** * This is required so when using "Save and next", each form is not defaulted to the previous form. - * Giving each form a unique identitifer is enough to prevent this (include the rownum in the form name). + * Giving each form a unique identitifer is enough to prevent this + * (include the rownum in the form name). * * @return string - The unique identifier for this form. */ @@ -75,25 +73,26 @@ class mod_assign_grade_form extends moodleform { * @param array $data * @param array $files */ - function validation($data, $files) { + public function validation($data, $files) { global $DB; $errors = parent::validation($data, $files); - // advanced grading + $instance = $this->assignment->get_instance(); + // Advanced grading. if (!array_key_exists('grade', $data)) { return $errors; } - if ($this->assignment->get_instance()->grade > 0) { + if ($instance->grade > 0) { if (unformat_float($data['grade']) === null && (!empty($data['grade']))) { $errors['grade'] = get_string('invalidfloatforgrade', 'assign', $data['grade']); - } else if (unformat_float($data['grade']) > $this->assignment->get_instance()->grade) { - $errors['grade'] = get_string('gradeabovemaximum', 'assign', $this->assignment->get_instance()->grade); + } else if (unformat_float($data['grade']) > $instance->grade) { + $errors['grade'] = get_string('gradeabovemaximum', 'assign', $instance->grade); } else if (unformat_float($data['grade']) < 0) { $errors['grade'] = get_string('gradebelowzero', 'assign'); } } else { - // this is a scale - if ($scale = $DB->get_record('scale', array('id'=>-($this->assignment->get_instance()->grade)))) { + // This is a scale. + if ($scale = $DB->get_record('scale', array('id'=>-($instance->grade)))) { $scaleoptions = make_menu_from_list($scale->scale); if (!array_key_exists((int)$data['grade'], $scaleoptions)) { $errors['grade'] = get_string('invalidgradeforscale', 'assign'); @@ -102,5 +101,4 @@ class mod_assign_grade_form extends moodleform { } return $errors; } - } diff --git a/mod/assign/gradingbatchoperationsform.php b/mod/assign/gradingbatchoperationsform.php index e2a72841851..637e0034ee8 100644 --- a/mod/assign/gradingbatchoperationsform.php +++ b/mod/assign/gradingbatchoperationsform.php @@ -24,10 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); - -/** Include formslib.php */ -require_once ($CFG->libdir.'/formslib.php'); -/** Include locallib.php */ +require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); /** @@ -39,13 +36,13 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php'); */ class mod_assign_grading_batch_operations_form extends moodleform { /** - * Define this form - called by the parent constructor + * Define this form - called by the parent constructor. */ - function definition() { + public function definition() { $mform = $this->_form; $instance = $this->_customdata; - // visible elements + // Visible elements. $options = array(); $options['lock'] = get_string('locksubmissions', 'assign'); $options['unlock'] = get_string('unlocksubmissions', 'assign'); @@ -59,7 +56,8 @@ class mod_assign_grading_batch_operations_form extends moodleform { foreach ($instance['feedbackplugins'] as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled()) { foreach ($plugin->get_grading_batch_operations() as $action => $description) { - $options['plugingradingbatchoperation_' . $plugin->get_type() . '_' . $action] = $description; + $operationkey = 'plugingradingbatchoperation_' . $plugin->get_type() . '_' . $action; + $options[$operationkey] = $description; } } } @@ -72,9 +70,8 @@ class mod_assign_grading_batch_operations_form extends moodleform { $objs = array(); $objs[] =& $mform->createElement('select', 'operation', get_string('chooseoperation', 'assign'), $options); $objs[] =& $mform->createElement('submit', 'submit', get_string('go')); - $mform->addElement('group', 'actionsgrp', get_string('batchoperationsdescription', 'assign'), $objs, ' ', false); - + $batchdescription = get_string('batchoperationsdescription', 'assign'); + $mform->addElement('group', 'actionsgrp', $batchdescription, $objs, ' ', false); } - } diff --git a/mod/assign/gradingoptionsform.php b/mod/assign/gradingoptionsform.php index 8eb7ce3b3ac..b8c38e61213 100644 --- a/mod/assign/gradingoptionsform.php +++ b/mod/assign/gradingoptionsform.php @@ -25,9 +25,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -/** Include formslib.php */ -require_once ($CFG->libdir.'/formslib.php'); -/** Include locallib.php */ +require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); /** @@ -39,16 +37,16 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php'); */ class mod_assign_grading_options_form extends moodleform { /** - * Define this form - called from the parent constructor + * Define this form - called from the parent constructor. */ - function definition() { + public function definition() { $mform = $this->_form; $instance = $this->_customdata; $dirtyclass = array('class'=>'ignoredirty'); $mform->addElement('header', 'general', get_string('gradingoptions', 'assign')); - // visible elements - $options = array(-1=>get_string('all'),10=>'10', 20=>'20', 50=>'50', 100=>'100'); + // Visible elements. + $options = array(-1=>get_string('all'), 10=>'10', 20=>'20', 50=>'50', 100=>'100'); $mform->addElement('select', 'perpage', get_string('assignmentsperpage', 'assign'), $options, $dirtyclass); $options = array('' => get_string('filternone', 'assign'), ASSIGN_FILTER_SUBMITTED => get_string('filtersubmitted', 'assign'), @@ -57,14 +55,14 @@ class mod_assign_grading_options_form extends moodleform { $mform->addElement('select', 'filter', get_string('filter', 'assign'), $options, $dirtyclass); } - // quickgrading + // Quickgrading. if ($instance['showquickgrading']) { $mform->addElement('checkbox', 'quickgrading', get_string('quickgrading', 'assign'), '', $dirtyclass); $mform->addHelpButton('quickgrading', 'quickgrading', 'assign'); $mform->setDefault('quickgrading', $instance['quickgrading']); } - // hidden params + // Hidden params. $mform->addElement('hidden', 'contextid', $instance['contextid']); $mform->setType('contextid', PARAM_INT); $mform->addElement('hidden', 'id', $instance['cm']); @@ -74,7 +72,7 @@ class mod_assign_grading_options_form extends moodleform { $mform->addElement('hidden', 'action', 'saveoptions'); $mform->setType('action', PARAM_ALPHA); - // buttons + // Buttons. $this->add_action_buttons(false, get_string('updatetable', 'assign')); } } diff --git a/mod/assign/gradingtable.php b/mod/assign/gradingtable.php index c565d7bfe4e..5cf6cc498c1 100644 --- a/mod/assign/gradingtable.php +++ b/mod/assign/gradingtable.php @@ -72,7 +72,12 @@ class assign_grading_table extends table_sql implements renderable { * @param int $rowoffset For showing a subsequent page of results * @param bool $quickgrading Is this table wrapped in a quickgrading form? */ - public function __construct(assign $assignment, $perpage, $filter, $rowoffset, $quickgrading, $downloadfilename = null) { + public function __construct(assign $assignment, + $perpage, + $filter, + $rowoffset, + $quickgrading, + $downloadfilename = null) { global $CFG, $PAGE, $DB; parent::__construct('mod_assign_grading'); $this->assignment = $assignment; @@ -91,10 +96,11 @@ class assign_grading_table extends table_sql implements renderable { $this->quickgrading = $quickgrading; $this->output = $PAGE->get_renderer('mod_assign'); - $this->define_baseurl(new moodle_url($CFG->wwwroot . '/mod/assign/view.php', array('action'=>'grading', 'id'=>$assignment->get_course_module()->id))); - - // do some business - then set the sql + $urlparams = array('action'=>'grading', 'id'=>$assignment->get_course_module()->id); + $url = new moodle_url($CFG->wwwroot . '/mod/assign/view.php', $urlparams); + $this->define_baseurl($url); + // Do some business - then set the sql. $currentgroup = groups_get_activity_group($assignment->get_course_module(), true); if ($rowoffset) { @@ -103,7 +109,7 @@ class assign_grading_table extends table_sql implements renderable { $users = array_keys( $assignment->list_participants($currentgroup, true)); if (count($users) == 0) { - // insert a record that will never match to the sql is still valid. + // Insert a record that will never match to the sql is still valid. $users[] = -1; } @@ -138,7 +144,8 @@ class assign_grading_table extends table_sql implements renderable { $where .= ' AND s.timecreated > 0 '; } if ($filter == ASSIGN_FILTER_REQUIRE_GRADING) { - $where .= ' AND (s.timemodified > g.timemodified OR (s.timemodified IS NOT NULL AND g.timemodified IS NULL))'; + $where .= ' AND (s.timemodified > g.timemodified OR + (s.timemodified IS NOT NULL AND g.timemodified IS NULL))'; } if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) { $userfilter = (int) array_pop(explode('=', $filter)); @@ -181,13 +188,13 @@ class assign_grading_table extends table_sql implements renderable { $headers[] = get_string('recordid', 'assign'); } - // Submission status + // Submission status. if ($assignment->is_any_submission_plugin_enabled()) { $columns[] = 'status'; $headers[] = get_string('status'); } - // Team submission columns + // Team submission columns. if ($assignment->get_instance()->teamsubmission) { $columns[] = 'team'; $headers[] = get_string('submissionteam', 'assign'); @@ -196,7 +203,7 @@ class assign_grading_table extends table_sql implements renderable { $headers[] = get_string('teamsubmissionstatus', 'assign'); } - // Grade + // Grade. $columns[] = 'grade'; $headers[] = get_string('grade'); if ($this->is_downloading()) { @@ -215,7 +222,7 @@ class assign_grading_table extends table_sql implements renderable { $headers[] = get_string('edit'); } - // Submission plugins + // Submission plugins. if ($assignment->is_any_submission_plugin_enabled()) { $columns[] = 'timesubmitted'; $headers[] = get_string('lastmodifiedsubmission', 'assign'); @@ -241,11 +248,11 @@ class assign_grading_table extends table_sql implements renderable { } } - // time marked + // Time marked. $columns[] = 'timemarked'; $headers[] = get_string('lastmodifiedgrade', 'assign'); - // Feedback plugins + // Feedback plugins. foreach ($this->assignment->get_feedback_plugins() as $plugin) { if ($this->is_downloading()) { if ($plugin->is_visible() && $plugin->is_enabled()) { @@ -271,17 +278,21 @@ class assign_grading_table extends table_sql implements renderable { $headers[] = get_string('finalgrade', 'grades'); } - // load the grading info for all users - $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users); - $this->hasgrantextension = has_capability('mod/assign:grantextension', $this->assignment->get_context()); + // Load the grading info for all users. + $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, + 'mod', + 'assign', + $this->assignment->get_instance()->id, + $users); + $this->hasgrantextension = has_capability('mod/assign:grantextension', + $this->assignment->get_context()); if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) { $columns[] = 'outcomes'; $headers[] = get_string('outcomes', 'grades'); } - - // set the columns + // Set the columns. $this->define_columns($columns); $this->define_headers($headers); // We require at least one unique column for the sort. @@ -318,12 +329,12 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Before adding each row to the table make sure rownum is incremented + * Before adding each row to the table make sure rownum is incremented. * * @param array $row row of data from db used to make one row of the table. * @return array one row for the table */ - function format_row($row) { + public function format_row($row) { if ($this->rownum < 0) { $this->rownum = $this->currpage * $this->pagesize; } else { @@ -334,31 +345,32 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Add a column with an ID that uniquely identifies this user in this assignment + * Add a column with an ID that uniquely identifies this user in this assignment. * * @return string */ - function col_recordid(stdClass $row) { - return get_string('hiddenuser', 'assign') . $this->assignment->get_uniqueid_for_user($row->userid); - } + public function col_recordid(stdClass $row) { + return get_string('hiddenuser', 'assign') . + $this->assignment->get_uniqueid_for_user($row->userid); + } /** - * Add the userid to the row class so it can be updated via ajax + * Add the userid to the row class so it can be updated via ajax. * * @param stdClass $row The row of data * @return string The row class */ - function get_row_class($row) { + public function get_row_class($row) { return 'user' . $row->userid; } /** - * Return the number of rows to display on a single page + * Return the number of rows to display on a single page. * * @return int The number of rows per page */ - function get_rows_per_page() { + public function get_rows_per_page() { return $this->perpage; } @@ -372,7 +384,8 @@ class assign_grading_table extends table_sql implements renderable { global $DB; if (empty($this->scale)) { - $this->scale = $DB->get_record('scale', array('id'=>-($this->assignment->get_instance()->grade))); + $dbparams = array('id'=>-($this->assignment->get_instance()->grade)); + $this->scale = $DB->get_record('scale', $dbparams); } if (!empty($this->scale->scale)) { @@ -390,7 +403,7 @@ class assign_grading_table extends table_sql implements renderable { * @param int $modified Timestamp showing when the grade was last modified * @return string The formatted grade */ - function display_grade($grade, $editable, $userid, $modified) { + public function display_grade($grade, $editable, $userid, $modified) { if ($this->is_downloading()) { if ($this->assignment->get_instance()->grade >= 0) { if ($grade == -1 || $grade === null) { @@ -410,12 +423,12 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Get the team info for this user + * Get the team info for this user. * * @param stdClass $row * @return string The team name */ - function col_team(stdClass $row) { + public function col_team(stdClass $row) { $submission = false; $group = false; $this->get_group_and_submission($row->id, $group, $submission); @@ -432,7 +445,7 @@ class assign_grading_table extends table_sql implements renderable { * @param int $groupid The groupid (returned) * @param mixed $submission The stdClass submission or false (returned) */ - function get_group_and_submission($userid, &$group, &$submission) { + public function get_group_and_submission($userid, &$group, &$submission) { $group = false; if (isset($this->submissiongroups[$userid])) { $group = $this->submissiongroups[$userid]; @@ -456,12 +469,12 @@ class assign_grading_table extends table_sql implements renderable { /** - * Get the team status for this user + * Get the team status for this user. * * @param stdClass $row * @return string The team name */ - function col_teamstatus(stdClass $row) { + public function col_teamstatus(stdClass $row) { $submission = false; $group = false; $this->get_group_and_submission($row->id, $group, $submission); @@ -475,14 +488,14 @@ class assign_grading_table extends table_sql implements renderable { /** - * Format a list of outcomes + * Format a list of outcomes. * * @param stdClass $row * @return string */ - function col_outcomes(stdClass $row) { + public function col_outcomes(stdClass $row) { $outcomes = ''; - foreach($this->gradinginfo->outcomes as $index=>$outcome) { + foreach ($this->gradinginfo->outcomes as $index => $outcome) { $options = make_grades_menu(-$outcome->scaleid); $options[0] = get_string('nooutcome', 'grades'); @@ -498,7 +511,8 @@ class assign_grading_table extends table_sql implements renderable { $select .= ''; $outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome'); } else { - $outcomes .= $this->output->container($outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade], 'outcome'); + $name = $outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade]; + $outcomes .= $this->output->container($name, 'outcome'); } } @@ -507,12 +521,12 @@ class assign_grading_table extends table_sql implements renderable { /** - * Format a user picture for display + * Format a user picture for display. * * @param stdClass $row * @return string */ - function col_picture(stdClass $row) { + public function col_picture(stdClass $row) { if ($row->picture) { return $this->output->user_picture($row); } @@ -520,12 +534,12 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Format a user record for display (link to profile) + * Format a user record for display (link to profile). * * @param stdClass $row * @return string */ - function col_fullname($row) { + public function col_fullname($row) { if (!$this->is_downloading()) { $courseid = $this->assignment->get_course()->id; $link= new moodle_url('/user/view.php', array('id' =>$row->id, 'course'=>$courseid)); @@ -536,19 +550,24 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Insert a checkbox for selecting the current row for batch operations + * Insert a checkbox for selecting the current row for batch operations. * * @param stdClass $row * @return string */ - function col_select(stdClass $row) { - return ' - '; + public function col_select(stdClass $row) { + $selectcol = ''; + $selectcol .= ''; + return $selectcol; } /** - * Return a users grades from the listing of all grade data for this assignment + * Return a users grades from the listing of all grade data for this assignment. * * @param int $userid * @return mixed stdClass or false @@ -561,7 +580,7 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Format a column of data for display + * Format a column of data for display. * * @param stdClass $row * @return string @@ -571,12 +590,12 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Format a column of data for display + * Format a column of data for display. * * @param stdClass $row * @return string */ - function col_grade(stdClass $row) { + public function col_grade(stdClass $row) { $o = ''; $link = ''; @@ -587,27 +606,34 @@ class assign_grading_table extends table_sql implements renderable { if (!$this->is_downloading()) { $name = fullname($row); if ($this->assignment->is_blind_marking()) { - $name = get_string('hiddenuser', 'assign') . $this->assignment->get_uniqueid_for_user($row->userid); + $name = get_string('hiddenuser', 'assign') . + $this->assignment->get_uniqueid_for_user($row->userid); } - $icon = $this->output->pix_icon('gradefeedback', get_string('gradeuser', 'assign', $name), 'mod_assign'); - $url = new moodle_url('/mod/assign/view.php', - array('id' => $this->assignment->get_course_module()->id, - 'rownum'=>$this->rownum,'action'=>'grade')); + $icon = $this->output->pix_icon('gradefeedback', + get_string('gradeuser', 'assign', $name), + 'mod_assign'); + $urlparams = array('id' => $this->assignment->get_course_module()->id, + 'rownum'=>$this->rownum, + 'action'=>'grade'); + $url = new moodle_url('/mod/assign/view.php', $urlparams); $link = $this->output->action_link($url, $icon); $separator = $this->output->spacer(array(), true); } - $grade = $this->display_grade($row->grade, $this->quickgrading && !$gradingdisabled, $row->userid, $row->timemarked); + $grade = $this->display_grade($row->grade, + $this->quickgrading && !$gradingdisabled, + $row->userid, + $row->timemarked); return $link . $separator . $grade; } /** - * Format a column of data for display + * Format a column of data for display. * * @param stdClass $row * @return string */ - function col_finalgrade(stdClass $row) { + public function col_finalgrade(stdClass $row) { $o = ''; $grade = $this->get_gradebook_data_for_user($row->userid); @@ -619,15 +645,15 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Format a column of data for display + * Format a column of data for display. * * @param stdClass $row * @return string */ - function col_timemarked(stdClass $row) { + public function col_timemarked(stdClass $row) { $o = '-'; - if ($row->timemarked && $row->grade !== NULL && $row->grade >= 0) { + if ($row->timemarked && $row->grade !== null && $row->grade >= 0) { $o = userdate($row->timemarked); } @@ -635,12 +661,12 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Format a column of data for display + * Format a column of data for display. * * @param stdClass $row * @return string */ - function col_timesubmitted(stdClass $row) { + public function col_timesubmitted(stdClass $row) { $o = '-'; if ($row->timesubmitted) { @@ -656,38 +682,48 @@ class assign_grading_table extends table_sql implements renderable { * @param stdClass $row * @return string */ - function col_status(stdClass $row) { + public function col_status(stdClass $row) { $o = ''; + $instance = $this->assignment->get_instance(); + if ($this->assignment->is_any_submission_plugin_enabled()) { $o .= $this->output->container(get_string('submissionstatus_' . $row->status, 'assign'), array('class'=>'submissionstatus' .$row->status)); - if ($this->assignment->get_instance()->duedate && $row->timesubmitted > $this->assignment->get_instance()->duedate) { - if (!$row->extensionduedate || $row->timesubmitted > $row->extensionduedate) { - $latemessage = get_string('submittedlateshort', 'assign', - format_time($row->timesubmitted - $this->assignment->get_instance()->duedate)); + if ($instance->duedate && + $row->timesubmitted > $instance->duedate) { + if (!$row->extensionduedate || + $row->timesubmitted > $row->extensionduedate) { + $usertime = format_time($row->timesubmitted - $instance->duedate); + $latemessage = get_string('submittedlateshort', + 'assign', + $usertime); $o .= $this->output->container($latemessage, 'latesubmission'); } } if ($row->locked) { - $o .= $this->output->container(get_string('submissionslockedshort', 'assign'), 'lockedsubmission'); + $lockedstr = get_string('submissionslockedshort', 'assign'); + $o .= $this->output->container($lockedstr, 'lockedsubmission'); } - if ($row->grade !== NULL && $row->grade >= 0) { + if ($row->grade !== null && $row->grade >= 0) { $o .= $this->output->container(get_string('graded', 'assign'), 'submissiongraded'); } if (!$row->timesubmitted) { $now = time(); - $due = $this->assignment->get_instance()->duedate; + $due = $instance->duedate; if ($row->extensionduedate) { $due = $row->extensionduedate; } if ($due && ($now > $due)) { - $o .= $this->output->container(get_string('overdue', 'assign', format_time($now - $due)), 'overduesubmission'); + $overduestr = get_string('overdue', 'assign', format_time($now - $due)); + $o .= $this->output->container($overduestr, 'overduesubmission'); } } if ($row->extensionduedate) { - $o .= $this->output->container(get_string('userextensiondate', 'assign', userdate($row->extensionduedate)), 'extensiondate'); + $userdate = userdate($row->extensionduedate); + $extensionstr = get_string('userextensiondate', 'assign', $userdate); + $o .= $this->output->container($extensionstr, 'extensiondate'); } } @@ -699,23 +735,25 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Format a column of data for display + * Format a column of data for display. * * @param stdClass $row * @return string */ - function col_userid(stdClass $row) { + public function col_userid(stdClass $row) { $edit = ''; $actions = array(); - $url = new moodle_url('/mod/assign/view.php', - array('id' => $this->assignment->get_course_module()->id, - 'rownum'=>$this->rownum,'action'=>'grade')); + $urlparams = array('id'=>$this->assignment->get_course_module()->id, + 'rownum'=>$this->rownum, + 'action'=>'grade'); + $url = new moodle_url('/mod/assign/view.php', $urlparams); + if (!$row->grade) { - $description = get_string('grade'); - }else{ - $description = get_string('updategrade','assign'); + $description = get_string('grade'); + } else { + $description = get_string('updategrade', 'assign'); } $actions[$url->out(false)] = $description; @@ -726,43 +764,48 @@ class assign_grading_table extends table_sql implements renderable { !$this->assignment->get_instance()->submissiondrafts) { if (!$row->locked) { - $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id, - 'userid'=>$row->id, - 'action'=>'lock', - 'sesskey'=>sesskey(), - 'page'=>$this->currpage)); + $urlparams = array('id' => $this->assignment->get_course_module()->id, + 'userid'=>$row->id, + 'action'=>'lock', + 'sesskey'=>sesskey(), + 'page'=>$this->currpage); + $url = new moodle_url('/mod/assign/view.php', $urlparams); + $description = get_string('preventsubmissionsshort', 'assign'); $actions[$url->out(false)] = $description; } else { - $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id, - 'userid'=>$row->id, - 'action'=>'unlock', - 'sesskey'=>sesskey(), - 'page'=>$this->currpage)); + $urlparams = array('id' => $this->assignment->get_course_module()->id, + 'userid'=>$row->id, + 'action'=>'unlock', + 'sesskey'=>sesskey(), + 'page'=>$this->currpage); + $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('allowsubmissionsshort', 'assign'); - $actions[$url->out(false)] = $description; + $actions[$url->out(false)] = $description; } } if (($this->assignment->get_instance()->duedate || $this->assignment->get_instance()->cutoffdate) && $this->hasgrantextension) { - $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id, - 'userid'=>$row->id, - 'action'=>'grantextension', - 'sesskey'=>sesskey(), - 'page'=>$this->currpage)); + $urlparams = array('id' => $this->assignment->get_course_module()->id, + 'userid'=>$row->id, + 'action'=>'grantextension', + 'sesskey'=>sesskey(), + 'page'=>$this->currpage); + $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('grantextension', 'assign'); $actions[$url->out(false)] = $description; - } } - if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED && $this->assignment->get_instance()->submissiondrafts) { - $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id, - 'userid'=>$row->id, - 'action'=>'reverttodraft', - 'sesskey'=>sesskey(), - 'page'=>$this->currpage)); + if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED && + $this->assignment->get_instance()->submissiondrafts) { + $urlparams = array('id' => $this->assignment->get_course_module()->id, + 'userid'=>$row->id, + 'action'=>'reverttodraft', + 'sesskey'=>sesskey(), + 'page'=>$this->currpage); + $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('reverttodraftshort', 'assign'); $actions[$url->out(false)] = $description; } @@ -802,28 +845,33 @@ class assign_grading_table extends table_sql implements renderable { * * @param assign_plugin $plugin Submission plugin or feedback plugin * @param stdClass $item Submission or grade - * @param string $returnaction The return action to pass to the view_submission page (the current page) - * @param string $returnparams The return params to pass to the view_submission page (the current page) + * @param string $returnaction The return action to pass to the + * view_submission page (the current page) + * @param string $returnparams The return params to pass to the view_submission + * page (the current page) * @return string The summary with an optional link */ - private function format_plugin_summary_with_link(assign_plugin $plugin, stdClass $item, $returnaction, $returnparams) { + private function format_plugin_summary_with_link(assign_plugin $plugin, + stdClass $item, + $returnaction, + $returnparams) { $link = ''; $showviewlink = false; $summary = $plugin->view_summary($item, $showviewlink); $separator = ''; if ($showviewlink) { - $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($plugin->get_subtype(), strlen('assign')), 'mod_assign')); - $link = $this->output->action_link( - new moodle_url('/mod/assign/view.php', - array('id' => $this->assignment->get_course_module()->id, + $viewstr = get_string('view' . substr($plugin->get_subtype(), strlen('assign')), 'assign'); + $icon = $this->output->pix_icon('t/preview', $viewstr); + $urlparams = array('id' => $this->assignment->get_course_module()->id, 'sid'=>$item->id, 'gid'=>$item->id, 'plugin'=>$plugin->get_type(), 'action'=>'viewplugin' . $plugin->get_subtype(), 'returnaction'=>$returnaction, - 'returnparams'=>http_build_query($returnparams))), - $icon); + 'returnparams'=>http_build_query($returnparams)); + $url = new moodle_url('/mod/assign/view.php', $urlparams); + $link = $this->output->action_link($url, $icon); $separator = $this->output->spacer(array(), true); } @@ -832,13 +880,13 @@ class assign_grading_table extends table_sql implements renderable { /** - * Format the submission and feedback columns + * Format the submission and feedback columns. * * @param string $colname The column name * @param stdClass $row The submission row * @return mixed string or NULL */ - function other_cols($colname, $row){ + public function other_cols($colname, $row) { $plugincache = $this->plugincache[$colname]; $plugin = $plugincache[0]; @@ -858,7 +906,10 @@ class assign_grading_table extends table_sql implements renderable { if (isset($field)) { return $plugin->get_editor_text($field, $submission->id); } - return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array()); + return $this->format_plugin_summary_with_link($plugin, + $submission, + 'grading', + array()); } } else if ($row->submissionid) { if (isset($field)) { @@ -870,7 +921,10 @@ class assign_grading_table extends table_sql implements renderable { $submission->timemodified = $row->timesubmitted; $submission->assignment = $this->assignment->get_instance()->id; $submission->userid = $row->userid; - return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array()); + return $this->format_plugin_summary_with_link($plugin, + $submission, + 'grading', + array()); } } else { $grade = null; @@ -891,7 +945,10 @@ class assign_grading_table extends table_sql implements renderable { if ($this->quickgrading && $plugin->supports_quickgrading()) { return $plugin->get_quickgrading_html($row->userid, $grade); } else if ($grade) { - return $this->format_plugin_summary_with_link($plugin, $grade, 'grading', array()); + return $this->format_plugin_summary_with_link($plugin, + $grade, + 'grading', + array()); } } } @@ -899,12 +956,12 @@ class assign_grading_table extends table_sql implements renderable { } /** - * Using the current filtering and sorting - load all rows and return a single column from them + * Using the current filtering and sorting - load all rows and return a single column from them. * * @param string $columnname The name of the raw column data * @return array of data */ - function get_column_data($columnname) { + public function get_column_data($columnname) { $this->setup(); $this->currpage = 0; $this->query_db($this->tablemaxrows); @@ -914,83 +971,65 @@ class assign_grading_table extends table_sql implements renderable { } return $result; } - /** - * Using the current filtering and sorting - load a single row and return a single column from it - * - * @param int $rownumber The rownumber to load - * @param string $columnname The name of the raw column data - * @param bool $lastrow Set to true if this is the last row in the table - * @return mixed string or false - */ - function get_cell_data($rownumber, $columnname, $lastrow) { - $this->setup(); - $this->currpage = $rownumber; - $this->query_db(1); - if ($rownumber == $this->totalrows-1) { - $lastrow = true; - } - foreach ($this->rawdata as $row) { - return $row->$columnname; - } - return false; - } /** - * Return things to the renderer + * Return things to the renderer. * * @return string the assignment name */ - function get_assignment_name() { + public function get_assignment_name() { return $this->assignment->get_instance()->name; } /** - * Return things to the renderer + * Return things to the renderer. * * @return int the course module id */ - function get_course_module_id() { + public function get_course_module_id() { return $this->assignment->get_course_module()->id; } /** - * Return things to the renderer + * Return things to the renderer. * * @return int the course id */ - function get_course_id() { + public function get_course_id() { return $this->assignment->get_course()->id; } /** - * Return things to the renderer + * Return things to the renderer. * * @return stdClass The course context */ - function get_course_context() { + public function get_course_context() { return $this->assignment->get_course_context(); } /** - * Return things to the renderer + * Return things to the renderer. * * @return bool Does this assignment accept submissions */ - function submissions_enabled() { + public function submissions_enabled() { return $this->assignment->is_any_submission_plugin_enabled(); } /** - * Return things to the renderer + * Return things to the renderer. * * @return bool Can this user view all grades (the gradebook) */ - function can_view_all_grades() { - return has_capability('gradereport/grader:view', $this->assignment->get_course_context()) && has_capability('moodle/grade:viewall', $this->assignment->get_course_context()); + public function can_view_all_grades() { + $context = $this->assignment->get_course_context(); + return has_capability('gradereport/grader:view', $context) && + has_capability('moodle/grade:viewall', $context); } /** - * Override the table show_hide_link to not show for select column + * Override the table show_hide_link to not show for select column. * * @param string $column the column name, index into various names. * @param int $index numerical index of the column. diff --git a/mod/assign/index.php b/mod/assign/index.php index 3b407407872..f072009bbf2 100644 --- a/mod/assign/index.php +++ b/mod/assign/index.php @@ -32,9 +32,9 @@ require_login($course); $PAGE->set_url('/mod/assign/index.php', array('id' => $id)); $PAGE->set_pagelayout('incourse'); -add_to_log($course->id, "assign", "view all", "index.php?id=$course->id", ""); +add_to_log($course->id, 'assign', 'view all', 'index.php?id=$course->id', ''); -// Print the header +// Print the header. $strplural = get_string("modulenameplural", "assign"); $PAGE->navbar->add($strplural); $PAGE->set_title($strplural); diff --git a/mod/assign/lib.php b/mod/assign/lib.php index ae530884c59..e2d7e01b872 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -15,7 +15,8 @@ // along with Moodle. If not, see . /** - * This file contains the moodle hooks for the assign module. It delegates most functions to the assignment class. + * This file contains the moodle hooks for the assign module. + * It delegates most functions to the assignment class. * * @package mod_assign * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -68,10 +69,14 @@ function assign_reset_userdata($data) { $status = array(); $params = array('courseid'=>$data->courseid); $sql = "SELECT a.id FROM {assign} a WHERE a.course=:courseid"; - $course = $DB->get_record('course', array('id'=> $data->courseid), '*', MUST_EXIST); - if ($assigns = $DB->get_records_sql($sql,$params)) { + $course = $DB->get_record('course', array('id'=>$data->courseid), '*', MUST_EXIST); + if ($assigns = $DB->get_records_sql($sql, $params)) { foreach ($assigns as $assign) { - $cm = get_coursemodule_from_instance('assign', $assign->id, $data->courseid, false, MUST_EXIST); + $cm = get_coursemodule_from_instance('assign', + $assign->id, + $data->courseid, + false, + MUST_EXIST); $context = context_module::instance($cm->id); $assignment = new assign($context, $cm, $course); $status = array_merge($status, $assignment->reset_userdata($data)); @@ -89,12 +94,12 @@ function assign_reset_userdata($data) { function assign_reset_gradebook($courseid, $type='') { global $CFG, $DB; - $params = array('moduletype'=>'assign','courseid'=>$courseid); + $params = array('moduletype'=>'assign', 'courseid'=>$courseid); $sql = 'SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid FROM {assign} a, {course_modules} cm, {modules} m WHERE m.name=:moduletype AND m.id=cm.module AND cm.instance=a.id AND a.course=:courseid'; - if ($assignments = $DB->get_records_sql($sql,$params)) { + if ($assignments = $DB->get_records_sql($sql, $params)) { foreach ($assignments as $assignment) { assign_grade_item_update($assignment, 'reset'); } @@ -108,7 +113,8 @@ function assign_reset_gradebook($courseid, $type='') { */ function assign_reset_course_form_definition(&$mform) { $mform->addElement('header', 'assignheader', get_string('modulenameplural', 'assign')); - $mform->addElement('advcheckbox', 'reset_assign_submissions', get_string('deleteallsubmissions','assign')); + $name = get_string('deleteallsubmissions', 'assign'); + $mform->addElement('advcheckbox', 'reset_assign_submissions', $name); } /** @@ -189,38 +195,40 @@ function assign_extend_settings_navigation(settings_navigation $settings, naviga $context = $cm->context; $course = $PAGE->course; - if (!$course) { return; } + // Link to gradebook. + if (has_capability('gradereport/grader:view', $cm->context) && + has_capability('moodle/grade:viewall', $cm->context)) { + $link = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id)); + $linkname = get_string('viewgradebook', 'assign'); + $node = $navref->add($linkname, $link, navigation_node::TYPE_SETTING); + } - // Link to gradebook - if (has_capability('gradereport/grader:view', $cm->context) && has_capability('moodle/grade:viewall', $cm->context)) { - $link = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id)); - $node = $navref->add(get_string('viewgradebook', 'assign'), $link, navigation_node::TYPE_SETTING); - } + // Link to download all submissions. + if (has_capability('mod/assign:grade', $context)) { + $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id, 'action'=>'grading')); + $node = $navref->add(get_string('viewgrading', 'assign'), $link, navigation_node::TYPE_SETTING); - // Link to download all submissions - if (has_capability('mod/assign:grade', $context)) { - $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id,'action'=>'grading')); - $node = $navref->add(get_string('viewgrading', 'assign'), $link, navigation_node::TYPE_SETTING); + $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id, 'action'=>'downloadall')); + $node = $navref->add(get_string('downloadall', 'assign'), $link, navigation_node::TYPE_SETTING); + } - $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id,'action'=>'downloadall')); - $node = $navref->add(get_string('downloadall', 'assign'), $link, navigation_node::TYPE_SETTING); - } + if (has_capability('mod/assign:revealidentities', $context)) { + $dbparams = array('id'=>$cm->instance); + $assignment = $DB->get_record('assign', $dbparams, 'blindmarking, revealidentities'); - if (has_capability('mod/assign:revealidentities', $context)) { - $assignment = $DB->get_record('assign', array('id'=>$cm->instance), 'blindmarking, revealidentities'); - - if ($assignment && $assignment->blindmarking && !$assignment->revealidentities) { - $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id,'action'=>'revealidentities')); - $node = $navref->add(get_string('revealidentities', 'assign'), $link, navigation_node::TYPE_SETTING); - } - } + if ($assignment && $assignment->blindmarking && !$assignment->revealidentities) { + $urlparams = array('id' => $cm->id, 'action'=>'revealidentities'); + $url = new moodle_url('/mod/assign/view.php', $urlparams); + $linkname = get_string('revealidentities', 'assign'); + $node = $navref->add($linkname, $url, navigation_node::TYPE_SETTING); + } + } } - /** * Add a get_coursemodule_info function in case any assignment type wants to add 'extra' information * for the course (see resource). @@ -229,13 +237,15 @@ function assign_extend_settings_navigation(settings_navigation $settings, naviga * when printing this activity in a course listing. See get_array_of_activities() in course/lib.php. * * @param stdClass $coursemodule The coursemodule object (record). - * @return cached_cm_info An object on information that the courses will know about (most noticeably, an icon). + * @return cached_cm_info An object on information that the courses + * will know about (most noticeably, an icon). */ function assign_get_coursemodule_info($coursemodule) { global $CFG, $DB; - if (! $assignment = $DB->get_record('assign', array('id'=>$coursemodule->instance), - 'id, name, alwaysshowdescription, allowsubmissionsfromdate, intro, introformat')) { + $dbparams = array('id'=>$coursemodule->instance); + $fields = 'id, name, alwaysshowdescription, allowsubmissionsfromdate, intro, introformat'; + if (! $assignment = $DB->get_record('assign', $dbparams, $fields)) { return false; } @@ -250,7 +260,6 @@ function assign_get_coursemodule_info($coursemodule) { return $result; } - /** * Return a list of page types * @param string $pagetype current page type @@ -279,13 +288,13 @@ function assign_print_overview($courses, &$htmlarray) { return array(); } - if (!$assignments = get_all_instances_in_courses('assign',$courses)) { + if (!$assignments = get_all_instances_in_courses('assign', $courses)) { return; } $assignmentids = array(); - // Do assignment_base::isopen() here without loading the whole thing for speed + // Do assignment_base::isopen() here without loading the whole thing for speed. foreach ($assignments as $key => $assignment) { $time = time(); $isopen = false; @@ -305,8 +314,8 @@ function assign_print_overview($courses, &$htmlarray) { } } - if (empty($assignmentids)){ - // no assignments to look at - we're done + if (empty($assignmentids)) { + // No assignments to look at - we're done. return true; } @@ -320,19 +329,27 @@ function assign_print_overview($courses, &$htmlarray) { $strnotsubmittedyet = get_string('notsubmittedyet', 'assign'); $strsubmitted = get_string('submitted', 'assign'); $strassignment = get_string('modulename', 'assign'); - $strreviewed = get_string('reviewed','assign'); + $strreviewed = get_string('reviewed', 'assign'); - - // NOTE: we do all possible database work here *outside* of the loop to ensure this scales - // + // We do all possible database work here *outside* of the loop to ensure this scales. list($sqlassignmentids, $assignmentidparams) = $DB->get_in_or_equal($assignmentids); - // build up and array of unmarked submissions indexed by assignment id/ userid - // for use where the user has grading rights on assignment - $rs = $DB->get_recordset_sql("SELECT s.assignment as assignment, s.userid as userid, s.id as id, s.status as status, g.timemodified as timegraded - FROM {assign_submission} s LEFT JOIN {assign_grades} g ON s.userid = g.userid and s.assignment = g.assignment - WHERE g.timemodified = 0 OR s.timemodified > g.timemodified - AND s.assignment $sqlassignmentids", $assignmentidparams); + // Build up and array of unmarked submissions indexed by assignment id/ userid + // for use where the user has grading rights on assignment. + $rs = $DB->get_recordset_sql('SELECT + s.assignment as assignment, + s.userid as userid, + s.id as id, + s.status as status, + g.timemodified as timegraded + FROM {assign_submission} s + LEFT JOIN {assign_grades} g ON + s.userid = g.userid AND + s.assignment = g.assignment + WHERE + g.timemodified = 0 OR + s.timemodified > g.timemodified AND + s.assignment ' . $sqlassignmentids, $assignmentidparams); $unmarkedsubmissions = array(); foreach ($rs as $rd) { @@ -340,39 +357,60 @@ function assign_print_overview($courses, &$htmlarray) { } $rs->close(); - - // get all user submissions, indexed by assignment id - $mysubmissions = $DB->get_records_sql("SELECT a.id AS assignment, a.nosubmissions AS nosubmissions, g.timemodified AS timemarked, g.grader AS grader, g.grade AS grade, s.status AS status - FROM {assign} a LEFT JOIN {assign_grades} g ON g.assignment = a.id AND g.userid = ? LEFT JOIN {assign_submission} s ON s.assignment = a.id AND s.userid = ? - AND a.id $sqlassignmentids", array_merge(array($USER->id, $USER->id), $assignmentidparams)); + // Get all user submissions, indexed by assignment id. + $dbparams = array_merge(array($USER->id, $USER->id), $assignmentidparams); + $mysubmissions = $DB->get_records_sql('SELECT + a.id AS assignment, + a.nosubmissions AS nosubmissions, + g.timemodified AS timemarked, + g.grader AS grader, + g.grade AS grade, + s.status AS status + FROM {assign} a + LEFT JOIN {assign_grades} g ON + g.assignment = a.id AND + g.userid = ? + LEFT JOIN {assign_submission} s ON + s.assignment = a.id AND + s.userid = ? AND + a.id ' . $sqlassignmentids, $dbparams); foreach ($assignments as $assignment) { - // Do not show assignments that are not open + // Do not show assignments that are not open. if (!in_array($assignment->id, $assignmentids)) { continue; } - $str = '
'; + $dimmedclass = ''; + if (!$assignment->visible) { + $dimmedclass = ' class="dimmed"'; + } + $href = $CFG->wwwroot . '/mod/assign/view.php?id=' . $assignment->coursemodule; + $str = '
' . + '
' . + $strassignment . ': '. + '' . + format_string($assignment->name) . + '
'; if ($assignment->duedate) { - $str .= '
'.$strduedate.': '.userdate($assignment->duedate).'
'; + $userdate = userdate($assignment->duedate); + $str .= '
' . $strduedate . ': ' . $userdate . '
'; } else { - $str .= '
'.$strduedateno.'
'; + $str .= '
' . $strduedateno . '
'; } if ($assignment->cutoffdate) { if ($assignment->cutoffdate == $assignment->duedate) { - $str .= '
'.$strnolatesubmissions.'
'; + $str .= '
' . $strnolatesubmissions . '
'; } else { - $str .= '
'.$strcutoffdate.': '.userdate($assignment->cutoffdate).'
'; + $userdate = userdate($assignment->cutoffdate); + $str .= '
' . $strcutoffdate . ': ' . $userdate . '
'; } } $context = context_module::instance($assignment->coursemodule); if (has_capability('mod/assign:grade', $context)) { - - // count how many people can submit - $submissions = 0; // init + // Count how many people can submit. + $submissions = 0; if ($students = get_enrolled_users($context, 'mod/assign:view', 0, 'u.id')) { foreach ($students as $student) { if (isset($unmarkedsubmissions[$assignment->id][$student->id])) { @@ -382,18 +420,23 @@ function assign_print_overview($courses, &$htmlarray) { } if ($submissions) { - $link = new moodle_url('/mod/assign/view.php', array('id'=>$assignment->coursemodule, 'action'=>'grading')); - $str .= ''; + $urlparams = array('id'=>$assignment->coursemodule, 'action'=>'grading'); + $url = new moodle_url('/mod/assign/view.php', $urlparams); + $str .= ''; } - } if (has_capability('mod/assign:submit', $context)) { + } + if (has_capability('mod/assign:submit', $context)) { $str .= '
'; $str .= get_string('mysubmission', 'assign'); $submission = $mysubmissions[$assignment->id]; if ($submission->nosubmissions) { - $str .= get_string('offline', 'assign'); - } else if(!$submission->status || $submission->status == 'draft'){ - $str .= $strnotsubmittedyet; - }else { + $str .= get_string('offline', 'assign'); + } else if (!$submission->status || $submission->status == 'draft') { + $str .= $strnotsubmittedyet; + } else { $str .= get_string('submissionstatus_' . $submission->status, 'assign'); } if (!$submission->grade || $submission->grade < 0) { @@ -403,7 +446,7 @@ function assign_print_overview($courses, &$htmlarray) { } $str .= '
'; } - $str .= '
'; + $str .= '
'; if (empty($htmlarray[$assignment->course]['assign'])) { $htmlarray[$assignment->course]['assign'] = $str; } else { @@ -423,9 +466,10 @@ function assign_print_overview($courses, &$htmlarray) { function assign_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; - // do not use log table if possible, it may be huge + // Do not use log table if possible, it may be huge. - if (!$submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid, asb.userid, + $dbparams = array($timestart, $course->id, 'assign'); + if (!$submissions = $DB->get_records_sql('SELECT asb.id, asb.timemodified, cm.id AS cmid, asb.userid, u.firstname, u.lastname, u.email, u.picture FROM {assign_submission} asb JOIN {assign} a ON a.id = asb.assignment @@ -434,18 +478,18 @@ function assign_print_recent_activity($course, $viewfullnames, $timestart) { JOIN {user} u ON u.id = asb.userid WHERE asb.timemodified > ? AND a.course = ? AND - md.name = 'assign' - ORDER BY asb.timemodified ASC", array($timestart, $course->id))) { + md.name = ? + ORDER BY asb.timemodified ASC', $dbparams)) { return false; } - $modinfo = get_fast_modinfo($course); // no need pass this by reference as the return object already being cached + $modinfo = get_fast_modinfo($course); $show = array(); $grader = array(); $showrecentsubmissions = get_config('mod_assign', 'showrecentsubmissions'); - foreach($submissions as $submission) { + foreach ($submissions as $submission) { if (!array_key_exists($submission->cmid, $modinfo->get_cms())) { continue; } @@ -459,10 +503,11 @@ function assign_print_recent_activity($course, $viewfullnames, $timestart) { } $context = context_module::instance($submission->cmid); - // the act of sumbitting of assignment may be considered private - only graders will see it if specified + // The act of submitting of assignment may be considered private - + // only graders will see it if specified. if (empty($showrecentsubmissions)) { if (!array_key_exists($cm->id, $grader)) { - $grader[$cm->id] = has_capability('moodle/grade:viewall',$context); + $grader[$cm->id] = has_capability('moodle/grade:viewall', $context); } if (!$grader[$cm->id]) { continue; @@ -471,17 +516,19 @@ function assign_print_recent_activity($course, $viewfullnames, $timestart) { $groupmode = groups_get_activity_groupmode($cm, $course); - if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { + if ($groupmode == SEPARATEGROUPS && + !has_capability('moodle/site:accessallgroups', $context)) { if (isguestuser()) { - // shortcut - guest user does not belong into any group + // Shortcut - guest user does not belong into any group. continue; } if (is_null($modinfo->get_groups())) { - $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo + // Load all my groups and cache it in modinfo. + $modinfo->groups = groups_get_user_groups($course->id); } - // this will be slow - show only users that share group with me in this cm + // This will be slow - show only users that share group with me in this cm. if (empty($modinfo->groups[$cm->id])) { continue; } @@ -506,14 +553,19 @@ function assign_print_recent_activity($course, $viewfullnames, $timestart) { foreach ($show as $submission) { $cm = $modinfo->get_cm($submission->cmid); $link = $CFG->wwwroot.'/mod/assign/view.php?id='.$cm->id; - print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames); + print_recent_activity_note($submission->timemodified, + $submission, + $cm->name, + $link, + false, + $viewfullnames); } return true; } /** - * Returns all assignments since a given time + * Returns all assignments since a given time. * * @param array $activities The activity information is returned in this array * @param int $index The current index in the activities array @@ -524,7 +576,13 @@ function assign_print_recent_activity($course, $viewfullnames, $timestart) { * @param int $groupid Optional group id * @return void */ -function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) { +function assign_get_recent_mod_activity(&$activities, + &$index, + $timestart, + $courseid, + $cmid, + $userid=0, + $groupid=0) { global $CFG, $COURSE, $USER, $DB; if ($COURSE->id == $courseid) { @@ -533,24 +591,24 @@ function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $cour $course = $DB->get_record('course', array('id'=>$courseid)); } - $modinfo = get_fast_modinfo($course); // no need pass this by reference as the return object already being cached + $modinfo = get_fast_modinfo($course); $cm = $modinfo->get_cm($cmid); $params = array(); if ($userid) { - $userselect = "AND u.id = :userid"; + $userselect = 'AND u.id = :userid'; $params['userid'] = $userid; } else { - $userselect = ""; + $userselect = ''; } if ($groupid) { - $groupselect = "AND gm.groupid = :groupid"; - $groupjoin = "JOIN {groups_members} gm ON gm.userid=u.id"; + $groupselect = 'AND gm.groupid = :groupid'; + $groupjoin = 'JOIN {groups_members} gm ON gm.userid=u.id'; $params['groupid'] = $groupid; } else { - $groupselect = ""; - $groupjoin = ""; + $groupselect = ''; + $groupjoin = ''; } $params['cminstance'] = $cm->instance; @@ -558,15 +616,16 @@ function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $cour $userfields = user_picture::fields('u', null, 'userid'); - if (!$submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified, + if (!$submissions = $DB->get_records_sql('SELECT asb.id, asb.timemodified, $userfields FROM {assign_submission} asb JOIN {assign} a ON a.id = asb.assignment JOIN {user} u ON u.id = asb.userid $groupjoin - WHERE asb.timemodified > :timestart AND a.id = :cminstance - $userselect $groupselect - ORDER BY asb.timemodified ASC", $params)) { + WHERE asb.timemodified > :timestart AND + a.id = :cminstance + ' . $userselect . ' ' . $groupselect . + ' ORDER BY asb.timemodified ASC', $params)) { return; } @@ -577,7 +636,8 @@ function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $cour $viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context); if (is_null($modinfo->get_groups())) { - $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo + // Load all my groups and cache it in modinfo. + $modinfo->groups = groups_get_user_groups($course->id); } $showrecentsubmissions = get_config('mod_assign', 'showrecentsubmissions'); @@ -586,12 +646,13 @@ function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $cour if (is_array($usersgroups)) { $usersgroups = array_keys($usersgroups); } - foreach($submissions as $submission) { + foreach ($submissions as $submission) { if ($submission->userid == $USER->id) { $show[] = $submission; continue; } - // the act of submitting of assignment may be considered private - only graders will see it if specified + // The act of submitting of assignment may be considered private - + // only graders will see it if specified. if (empty($showrecentsubmissions)) { if (!$grader) { continue; @@ -600,11 +661,11 @@ function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $cour if ($groupmode == SEPARATEGROUPS and !$accessallgroups) { if (isguestuser()) { - // shortcut - guest user does not belong into any group + // Shortcut - guest user does not belong into any group. continue; } - // this will be slow - show only users that share group with me in this cm + // This will be slow - show only users that share group with me in this cm. if (empty($modinfo->groups[$cm->id])) { continue; } @@ -625,14 +686,13 @@ function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $cour if ($grader) { require_once($CFG->libdir.'/gradelib.php'); $userids = array(); - foreach ($show as $id=>$submission) { + foreach ($show as $id => $submission) { $userids[] = $submission->userid; - } $grades = grade_get_grades($courseid, 'mod', 'assign', $cm->instance, $userids); } - $aname = format_string($cm->name,true); + $aname = format_string($cm->name, true); foreach ($show as $submission) { $activity = new stdClass(); @@ -649,7 +709,8 @@ function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $cour $userfields = explode(',', user_picture::fields()); foreach ($userfields as $userfield) { if ($userfield == 'id') { - $activity->user->{$userfield} = $submission->userid; // aliased in SQL above + // Aliased in SQL above. + $activity->user->{$userfield} = $submission->userid; } else { $activity->user->{$userfield} = $submission->{$userfield}; } @@ -671,21 +732,23 @@ function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $cour * @param bool $detail * @param array $modnames */ -function assign_print_recent_mod_activity($activity, $courseid, $detail, $modnames) { +function assign_print_recent_mod_activity($activity, $courseid, $detail, $modnames) { global $CFG, $OUTPUT; echo ''; - echo "
"; + echo '
'; echo $OUTPUT->user_picture($activity->user); - echo ""; + echo ''; if ($detail) { $modname = $modnames[$activity->type]; echo '
'; - echo "pix_url('icon', 'assign') . "\" ". - "class=\"icon\" alt=\"$modname\">"; - echo "wwwroot/mod/assign/view.php?id={$activity->cmid}\">{$activity->name}"; + echo '' . $modname . ''; + echo ''; + echo $activity->name; + echo ''; echo '
'; } @@ -697,15 +760,15 @@ function assign_print_recent_mod_activity($activity, $courseid, $detail, $modnam } echo ''; - echo "
"; + echo ''; } /** - * Checks if a scale is being used by an assignment + * Checks if a scale is being used by an assignment. * * This is used by the backup code to decide whether to back up a scale * @param int $assignmentid @@ -716,7 +779,7 @@ function assign_scale_used($assignmentid, $scaleid) { global $DB; $return = false; - $rec = $DB->get_record('assign', array('id'=>$assignmentid,'grade'=>-$scaleid)); + $rec = $DB->get_record('assign', array('id'=>$assignmentid, 'grade'=>-$scaleid)); if (!empty($rec) && !empty($scaleid)) { $return = true; @@ -743,8 +806,8 @@ function assign_scale_used_anywhere($scaleid) { } /** - * function to list the actions that correspond to a view of this module - * This is used by the participation report + * List the actions that correspond to a view of this module. + * This is used by the participation report. * @return array */ function assign_get_view_actions() { @@ -752,8 +815,8 @@ function assign_get_view_actions() { } /** - * function to list the actions that correspond to a post of this module - * This is used by the participation report + * List the actions that correspond to a post of this module. + * This is used by the participation report. * @return array */ function assign_get_post_actions() { @@ -761,7 +824,7 @@ function assign_get_post_actions() { } /** - * Call cron on the assign module + * Call cron on the assign module. */ function assign_cron() { global $CFG; @@ -796,17 +859,20 @@ function assign_cron() { * @return array Array of capability strings */ function assign_get_extra_capabilities() { - return array('gradereport/grader:view', 'moodle/grade:viewall', 'moodle/site:viewfullnames', 'moodle/site:config'); + return array('gradereport/grader:view', + 'moodle/grade:viewall', + 'moodle/site:viewfullnames', + 'moodle/site:config'); } /** - * Create grade item for given assignment + * Create grade item for given assignment. * * @param stdClass $assign record with extra cmidnumber * @param array $grades optional array/object of grade(s); 'reset' means reset grades in gradebook * @return int 0 if ok, error code otherwise */ -function assign_grade_item_update($assign, $grades=NULL) { +function assign_grade_item_update($assign, $grades=null) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); @@ -826,15 +892,23 @@ function assign_grade_item_update($assign, $grades=NULL) { $params['scaleid'] = -$assign->grade; } else { - $params['gradetype'] = GRADE_TYPE_TEXT; // allow text comments only + // Allow text comments only. + $params['gradetype'] = GRADE_TYPE_TEXT; } if ($grades === 'reset') { $params['reset'] = true; - $grades = NULL; + $grades = null; } - return grade_update('mod/assign', $assign->courseid, 'mod', 'assign', $assign->id, 0, $grades, $params); + return grade_update('mod/assign', + $assign->courseid, + 'mod', + 'assign', + $assign->id, + 0, + $grades, + $params); } /** @@ -846,6 +920,7 @@ function assign_grade_item_update($assign, $grades=NULL) { */ function assign_get_user_grades($assign, $userid=0) { global $CFG; + require_once($CFG->dirroot . '/mod/assign/locallib.php'); $cm = get_coursemodule_from_instance('assign', $assign->id, 0, false, MUST_EXIST); @@ -856,7 +931,7 @@ function assign_get_user_grades($assign, $userid=0) { } /** - * Update activity grades + * Update activity grades. * * @param stdClass $assign database record * @param int $userid specific user only, 0 means all @@ -870,7 +945,7 @@ function assign_update_grades($assign, $userid=0, $nullifnone=true) { assign_grade_item_update($assign); } else if ($grades = assign_get_user_grades($assign, $userid)) { - foreach($grades as $k=>$v) { + foreach ($grades as $k => $v) { if ($v->rawgrade == -1) { $grades[$k]->rawgrade = null; } @@ -883,7 +958,7 @@ function assign_update_grades($assign, $userid=0, $nullifnone=true) { } /** - * List the file areas that can be browsed + * List the file areas that can be browsed. * * @param stdClass $course * @param stdClass $cm @@ -932,7 +1007,15 @@ function assign_get_file_areas($course, $cm, $context) { * @param string $filename * @return object file_info instance or null if not found */ -function assign_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) { +function assign_get_file_info($browser, + $areas, + $course, + $cm, + $context, + $filearea, + $itemid, + $filepath, + $filename) { global $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -944,7 +1027,7 @@ function assign_get_file_info($browser, $areas, $course, $cm, $context, $fileare $filepath = is_null($filepath) ? '/' : $filepath; $filename = is_null($filename) ? '.' : $filename; - // need to find the plugin this belongs to + // Need to find the plugin this belongs to. $assignment = new assign($context, $cm, $course); $pluginowner = null; foreach ($assignment->get_submission_plugins() as $plugin) { @@ -979,18 +1062,19 @@ function assign_get_file_info($browser, $areas, $course, $cm, $context, $fileare } /** - * Prints the complete info about a user's interaction with an assignment + * Prints the complete info about a user's interaction with an assignment. * * @param stdClass $course * @param stdClass $user * @param stdClass $coursemodule * @param stdClass $assign the database assign record * - * This prints the submission summary and feedback summary for this student + * This prints the submission summary and feedback summary for this student. */ function assign_user_complete($course, $user, $coursemodule, $assign) { global $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); + $context = context_module::instance($coursemodule->id); $assignment = new assign($context, $coursemodule, $course); @@ -999,7 +1083,7 @@ function assign_user_complete($course, $user, $coursemodule, $assign) { } /** - * Print the grade information for the assignment for this user + * Print the grade information for the assignment for this user. * * @param stdClass $course * @param stdClass $user @@ -1041,14 +1125,15 @@ function assign_user_outline($course, $user, $coursemodule, $assignment) { * @return bool True if completed, false if not, $type if conditions not set. */ function assign_get_completion_state($course, $cm, $userid, $type) { - global $CFG,$DB; + global $CFG, $DB; require_once($CFG->dirroot . '/mod/assign/locallib.php'); $assign = new assign(null, $cm, $course); // If completion option is enabled, evaluate it and return true/false. if ($assign->get_instance()->completionsubmit) { - $submission = $DB->get_record('assign_submission', array('assignment'=>$assign->get_instance()->id, 'userid'=>$userid), '*', IGNORE_MISSING); + $dbparams = array('assignment'=>$assign->get_instance()->id, 'userid'=>$userid); + $submission = $DB->get_record('assign_submission', $dbparams, '*', IGNORE_MISSING); return $submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED; } else { // Completion option is not enabled so just return $type. diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 9971cd04059..aa1a8d85e8d 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -26,42 +26,26 @@ defined('MOODLE_INTERNAL') || die(); -/** - * Assignment submission statuses - */ -define('ASSIGN_SUBMISSION_STATUS_DRAFT', 'draft'); // student thinks it is a draft -define('ASSIGN_SUBMISSION_STATUS_SUBMITTED', 'submitted'); // student thinks it is finished +// Assignment submission statuses. +define('ASSIGN_SUBMISSION_STATUS_DRAFT', 'draft'); +define('ASSIGN_SUBMISSION_STATUS_SUBMITTED', 'submitted'); -/** - * Search filters for grading page - */ +// Search filters for grading page. define('ASSIGN_FILTER_SUBMITTED', 'submitted'); define('ASSIGN_FILTER_SINGLE_USER', 'singleuser'); define('ASSIGN_FILTER_REQUIRE_GRADING', 'require_grading'); -/** Include accesslib.php */ -require_once($CFG->libdir.'/accesslib.php'); -/** Include formslib.php */ -require_once($CFG->libdir.'/formslib.php'); -/** Include repository/lib.php */ +require_once($CFG->libdir . '/accesslib.php'); +require_once($CFG->libdir . '/formslib.php'); require_once($CFG->dirroot . '/repository/lib.php'); -/** Include local mod_form.php */ -require_once($CFG->dirroot.'/mod/assign/mod_form.php'); -/** gradelib.php */ -require_once($CFG->libdir.'/gradelib.php'); -/** grading lib.php */ -require_once($CFG->dirroot.'/grade/grading/lib.php'); -/** Include feedbackplugin.php */ -require_once($CFG->dirroot.'/mod/assign/feedbackplugin.php'); -/** Include submissionplugin.php */ -require_once($CFG->dirroot.'/mod/assign/submissionplugin.php'); -/** Include renderable.php */ -require_once($CFG->dirroot.'/mod/assign/renderable.php'); -/** Include gradingtable.php */ -require_once($CFG->dirroot.'/mod/assign/gradingtable.php'); -/** Include eventslib.php */ -require_once($CFG->libdir.'/eventslib.php'); -/** Include portfolio caller.php */ +require_once($CFG->dirroot . '/mod/assign/mod_form.php'); +require_once($CFG->libdir . '/gradelib.php'); +require_once($CFG->dirroot . '/grade/grading/lib.php'); +require_once($CFG->dirroot . '/mod/assign/feedbackplugin.php'); +require_once($CFG->dirroot . '/mod/assign/submissionplugin.php'); +require_once($CFG->dirroot . '/mod/assign/renderable.php'); +require_once($CFG->dirroot . '/mod/assign/gradingtable.php'); +require_once($CFG->libdir . '/eventslib.php'); require_once($CFG->libdir . '/portfolio/caller.php'); /** @@ -73,12 +57,12 @@ require_once($CFG->libdir . '/portfolio/caller.php'); */ class assign { - /** @var stdClass the assignment record that contains the global settings for this assign instance */ private $instance; - /** @var context the context of the course module for this assign instance (or just the course if we are - creating a new one) */ + /** @var context the context of the course module for this assign instance + * (or just the course if we are creating a new one) + */ private $context; /** @var stdClass the course this assign instance belongs to */ @@ -87,15 +71,15 @@ class assign { /** @var stdClass the admin config for all assign instances */ private $adminconfig; - /** @var assign_renderer the custom renderer for this module */ private $output; /** @var stdClass the course module for this assign instance */ private $coursemodule; - /** @var array cache for things like the coursemodule name or the scale menu - only lives for a single - request */ + /** @var array cache for things like the coursemodule name or the scale menu - + * only lives for a single request. + */ private $cache; /** @var array list of the installed submission plugins */ @@ -104,7 +88,9 @@ class assign { /** @var array list of the installed feedback plugins */ private $feedbackplugins; - /** @var string action to be used to return to this page (without repeating any form submissions etc.) */ + /** @var string action to be used to return to this page + * (without repeating any form submissions etc). + */ private $returnaction = 'view'; /** @var array params to be used to return to this page */ @@ -117,11 +103,15 @@ class assign { private static $modulenameplural = null; /** - * Constructor for the base assign class + * Constructor for the base assign class. * - * @param mixed $coursemodulecontext context|null the course module context (or the course context if the coursemodule has not been created yet) - * @param mixed $coursemodule the current course module if it was already loaded - otherwise this class will load one from the context as required - * @param mixed $course the current course if it was already loaded - otherwise this class will load one from the context as required + * @param mixed $coursemodulecontext context|null the course module context + * (or the course context if the coursemodule has not been + * created yet). + * @param mixed $coursemodule the current course module if it was already loaded, + * otherwise this class will load one from the context as required. + * @param mixed $course the current course if it was already loaded, + * otherwise this class will load one from the context as required. */ public function __construct($coursemodulecontext, $coursemodule, $course) { global $PAGE; @@ -129,17 +119,20 @@ class assign { $this->context = $coursemodulecontext; $this->coursemodule = $coursemodule; $this->course = $course; - $this->cache = array(); // temporary cache only lives for a single request - used to reduce db lookups + + // Temporary cache only lives for a single request - used to reduce db lookups. + $this->cache = array(); $this->submissionplugins = $this->load_plugins('assignsubmission'); $this->feedbackplugins = $this->load_plugins('assignfeedback'); } /** - * Set the action and parameters that can be used to return to the current page + * Set the action and parameters that can be used to return to the current page. * * @param string $action The action for the current page - * @param array $params An array of name value pairs which form the parameters to return to the current page + * @param array $params An array of name value pairs which form the parameters + * to return to the current page. * @return void */ public function register_return_link($action, $params) { @@ -148,7 +141,8 @@ class assign { } /** - * Return an action that can be used to get back to the current page + * Return an action that can be used to get back to the current page. + * * @return string action */ public function get_return_action() { @@ -156,7 +150,8 @@ class assign { } /** - * Based on the current assignment settings should we display the intro + * Based on the current assignment settings should we display the intro. + * * @return bool showintro */ private function show_intro() { @@ -168,7 +163,8 @@ class assign { } /** - * Return a list of parameters that can be used to get back to the current page + * Return a list of parameters that can be used to get back to the current page. + * * @return array params */ public function get_return_params() { @@ -176,7 +172,8 @@ class assign { } /** - * Set the submitted form data + * Set the submitted form data. + * * @param stdClass $data The form data (instance) */ public function set_instance(stdClass $data) { @@ -184,7 +181,8 @@ class assign { } /** - * Set the context + * Set the context. + * * @param context $context The new context */ public function set_context(context $context) { @@ -192,7 +190,8 @@ class assign { } /** - * Set the course data + * Set the course data. + * * @param stdClass $course The course data */ public function set_course(stdClass $course) { @@ -200,7 +199,8 @@ class assign { } /** - * get list of feedback plugins installed + * Get list of feedback plugins installed. + * * @return array */ public function get_feedback_plugins() { @@ -208,7 +208,8 @@ class assign { } /** - * get list of submission plugins installed + * Get list of submission plugins installed. + * * @return array */ public function get_submission_plugins() { @@ -239,7 +240,8 @@ class assign { } /** - * get a specific submission plugin by its type + * Get a specific submission plugin by its type. + * * @param string $subtype assignsubmission | assignfeedback * @param string $type * @return mixed assign_plugin|null @@ -260,7 +262,8 @@ class assign { } /** - * Get a feedback plugin by type + * Get a feedback plugin by type. + * * @param string $type - The type of plugin e.g comments * @return mixed assign_feedback_plugin|null */ @@ -269,7 +272,8 @@ class assign { } /** - * Get a submission plugin by type + * Get a submission plugin by type. + * * @param string $type - The type of plugin e.g comments * @return mixed assign_submission_plugin|null */ @@ -278,7 +282,8 @@ class assign { } /** - * Load the plugins from the sub folders under subtype + * Load the plugins from the sub folders under subtype. + * * @param string $subtype - either submission or feedback * @return array - The sorted list of plugins */ @@ -299,7 +304,9 @@ class assign { if ($plugin instanceof assign_plugin) { $idx = $plugin->get_sort_order(); - while (array_key_exists($idx, $result)) $idx +=1; + while (array_key_exists($idx, $result)) { + $idx +=1; + } $result[$idx] = $plugin; } } @@ -313,6 +320,7 @@ class assign { * * The assignment is displayed differently depending on your role, * the settings for the assignment and the status of the assignment. + * * @param string $action The current action if any. * @return void */ @@ -346,7 +354,7 @@ class assign { $action = $this->process_grading_batch_operation($mform); } else if ($action == 'submitgrade') { if (optional_param('saveandshownext', null, PARAM_RAW)) { - //save and show next + // Save and show next. $action = 'grade'; if ($this->process_save_grade($mform)) { $action = 'nextgrade'; @@ -354,16 +362,16 @@ class assign { } else if (optional_param('nosaveandprevious', null, PARAM_RAW)) { $action = 'previousgrade'; } else if (optional_param('nosaveandnext', null, PARAM_RAW)) { - //show next button + // Show next button. $action = 'nextgrade'; } else if (optional_param('savegrade', null, PARAM_RAW)) { - //save changes button + // Save changes button. $action = 'grade'; if ($this->process_save_grade($mform)) { $action = 'grading'; } } else { - //cancel button + // Cancel button. $action = 'grading'; } } else if ($action == 'quickgrade') { @@ -426,9 +434,8 @@ class assign { return $o; } - /** - * Add this instance to the database + * Add this instance to the database. * * @param stdClass $formdata The data submitted from the form * @param bool $callplugins This is used to skip the plugin code @@ -440,7 +447,7 @@ class assign { $err = ''; - // add the database record + // Add the database record. $update = new stdClass(); $update->name = $formdata->name; $update->timemodified = time(); @@ -466,11 +473,11 @@ class assign { $returnid = $DB->insert_record('assign', $update); $this->instance = $DB->get_record('assign', array('id'=>$returnid), '*', MUST_EXIST); - // cache the course record + // Cache the course record. $this->course = $DB->get_record('course', array('id'=>$formdata->course), '*', MUST_EXIST); if ($callplugins) { - // call save_settings hook for submission plugins + // Call save_settings hook for submission plugins. foreach ($this->submissionplugins as $plugin) { if (!$this->update_plugin_instance($plugin, $formdata)) { print_error($plugin->get_error()); @@ -484,10 +491,9 @@ class assign { } } - // in the case of upgrades the coursemodule has not been set so we need to wait before calling these two - // TODO: add event to the calendar + // In the case of upgrades the coursemodule has not been set, + // so we need to wait before calling these two. $this->update_calendar($formdata->coursemodule); - // TODO: add the item in the gradebook $this->update_gradebook(false, $formdata->coursemodule); } @@ -501,18 +507,26 @@ class assign { } /** - * Delete all grades from the gradebook for this assignment + * Delete all grades from the gradebook for this assignment. * * @return bool */ private function delete_grades() { global $CFG; - return grade_update('mod/assign', $this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, 0, NULL, array('deleted'=>1)) == GRADE_UPDATE_OK; + $result = grade_update('mod/assign', + $this->get_course()->id, + 'mod', + 'assign', + $this->get_instance()->id, + 0, + null, + array('deleted'=>1)); + return $result == GRADE_UPDATE_OK; } /** - * Delete this instance from the database + * Delete this instance from the database. * * @return bool false if an error occurs */ @@ -533,38 +547,37 @@ class assign { } } - // delete files associated with this assignment + // Delete files associated with this assignment. $fs = get_file_storage(); if (! $fs->delete_area_files($this->context->id) ) { $result = false; } - // delete_records will throw an exception if it fails - so no need for error checking here - + // Delete_records will throw an exception if it fails - so no need for error checking here. $DB->delete_records('assign_submission', array('assignment'=>$this->get_instance()->id)); $DB->delete_records('assign_grades', array('assignment'=>$this->get_instance()->id)); $DB->delete_records('assign_plugin_config', array('assignment'=>$this->get_instance()->id)); - // delete items from the gradebook + // Delete items from the gradebook. if (! $this->delete_grades()) { $result = false; } - // delete the instance + // Delete the instance. $DB->delete_records('assign', array('id'=>$this->get_instance()->id)); return $result; } /** - * Actual implementation of the reset course functionality, delete all the - * assignment submissions for course $data->courseid. - * - * @param $data the data submitted from the reset course. - * @return array status array - */ + * Actual implementation of the reset course functionality, delete all the + * assignment submissions for course $data->courseid. + * + * @param $data the data submitted from the reset course. + * @return array status array + */ public function reset_userdata($data) { - global $CFG,$DB; + global $CFG, $DB; $componentstr = get_string('modulenameplural', 'assign'); $status = array(); @@ -582,7 +595,7 @@ class assign { if (!$plugin->delete_instance()) { $status[] = array('component'=>$componentstr, - 'item'=>get_string('deleteallsubmissions','assign'), + 'item'=>get_string('deleteallsubmissions', 'assign'), 'error'=>$plugin->get_error()); } } @@ -597,22 +610,24 @@ class assign { if (!$plugin->delete_instance()) { $status[] = array('component'=>$componentstr, - 'item'=>get_string('deleteallsubmissions','assign'), + 'item'=>get_string('deleteallsubmissions', 'assign'), 'error'=>$plugin->get_error()); } } - $assignssql = "SELECT a.id + $assignssql = 'SELECT a.id FROM {assign} a - WHERE a.course=:course"; - $params = array ("course" => $data->courseid); + WHERE a.course=:course'; + $params = array('course'=>$data->courseid); $DB->delete_records_select('assign_submission', "assignment IN ($assignssql)", $params); + $status[] = array('component'=>$componentstr, - 'item'=>get_string('deleteallsubmissions','assign'), + 'item'=>get_string('deleteallsubmissions', 'assign'), 'error'=>false); - if (empty($data->reset_gradebook_grades)) { + if (!empty($data->reset_gradebook_grades)) { + $DB->delete_records_select('assign_grades', "assignment IN ($assignssql)", $params); // Remove all grades from gradebook. require_once($CFG->dirroot.'/mod/assign/lib.php'); assign_reset_gradebook($data->courseid); @@ -621,7 +636,7 @@ class assign { // Updating dates - shift may be negative too. if ($data->timeshift) { shift_course_mod_dates('assign', - array('duedate', 'allowsubmissionsfromdate','cutoffdate'), + array('duedate', 'allowsubmissionsfromdate', 'cutoffdate'), $data->timeshift, $data->courseid); $status[] = array('component'=>$componentstr, @@ -633,7 +648,7 @@ class assign { } /** - * Update the settings for a single plugin + * Update the settings for a single plugin. * * @param assign_plugin $plugin The plugin to update * @param stdClass $formdata The form data @@ -656,15 +671,15 @@ class assign { } /** - * Update the gradebook information for this assignment + * Update the gradebook information for this assignment. * * @param bool $reset If true, will reset all grades in the gradbook for this assignment * @param int $coursemoduleid This is required because it might not exist in the database yet * @return bool */ public function update_gradebook($reset, $coursemoduleid) { - global $CFG; - /** Include lib.php */ + global $CFG; + require_once($CFG->dirroot.'/mod/assign/lib.php'); $assign = clone $this->get_instance(); $assign->cmidnumber = $coursemoduleid; @@ -676,7 +691,8 @@ class assign { return assign_grade_item_update($assign, $param); } - /** Load and cache the admin config for this module + /** + * Load and cache the admin config for this module. * * @return stdClass the plugin config */ @@ -688,54 +704,58 @@ class assign { return $this->adminconfig; } - /** - * Update the calendar entries for this assignment + * Update the calendar entries for this assignment. * - * @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet + * @param int $coursemoduleid - Required to pass this in because it might + * not exist in the database yet. * @return bool */ public function update_calendar($coursemoduleid) { global $DB, $CFG; require_once($CFG->dirroot.'/calendar/lib.php'); - // special case for add_instance as the coursemodule has not been set yet. + // Special case for add_instance as the coursemodule has not been set yet. + $instance = $this->get_instance(); - if ($this->get_instance()->duedate) { + if ($instance->duedate) { $event = new stdClass(); - if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assign', 'instance'=>$this->get_instance()->id))) { + $params = array('modulename'=>'assign', 'instance'=>$instance->id); + $event->id = $DB->get_field('event', + 'id', + $params); - $event->name = $this->get_instance()->name; - - $event->description = format_module_intro('assign', $this->get_instance(), $coursemoduleid); - $event->timestart = $this->get_instance()->duedate; + if ($event->id) { + $event->name = $instance->name; + $event->description = format_module_intro('assign', $instance, $coursemoduleid); + $event->timestart = $instance->duedate; $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { $event = new stdClass(); - $event->name = $this->get_instance()->name; - $event->description = format_module_intro('assign', $this->get_instance(), $coursemoduleid); - $event->courseid = $this->get_instance()->course; + $event->name = $instance->name; + $event->description = format_module_intro('assign', $instance, $coursemoduleid); + $event->courseid = $instance->course; $event->groupid = 0; $event->userid = 0; $event->modulename = 'assign'; - $event->instance = $this->get_instance()->id; + $event->instance = $instance->id; $event->eventtype = 'due'; - $event->timestart = $this->get_instance()->duedate; + $event->timestart = $instance->duedate; $event->timeduration = 0; calendar_event::create($event); } } else { - $DB->delete_records('event', array('modulename'=>'assign', 'instance'=>$this->get_instance()->id)); + $DB->delete_records('event', array('modulename'=>'assign', 'instance'=>$instance->id)); } } /** - * Update this instance in the database + * Update this instance in the database. * * @param stdClass $formdata - the data submitted from the form * @return bool false if an error occurs @@ -768,9 +788,9 @@ class assign { $result = $DB->update_record('assign', $update); $this->instance = $DB->get_record('assign', array('id'=>$update->id), '*', MUST_EXIST); - // load the assignment so the plugins have access to it + // Load the assignment so the plugins have access to it. - // call save_settings hook for submission plugins + // Call save_settings hook for submission plugins. foreach ($this->submissionplugins as $plugin) { if (!$this->update_plugin_instance($plugin, $formdata)) { print_error($plugin->get_error()); @@ -784,13 +804,7 @@ class assign { } } - - // update the database record - - - // update all the calendar events $this->update_calendar($this->get_course_module()->id); - $this->update_gradebook(false, $this->get_course_module()->id); $update = new stdClass(); @@ -798,15 +812,11 @@ class assign { $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1: 0; $DB->update_record('assign', $update); - - - - return $result; } /** - * add elements in grading plugin form + * Add elements in grading plugin form. * * @param mixed $grade stdClass|null * @param MoodleQuickForm $mform @@ -828,20 +838,22 @@ class assign { /** - * Add one plugins settings to edit plugin form + * Add one plugins settings to edit plugin form. * * @param assign_plugin $plugin The plugin to add the settings from - * @param MoodleQuickForm $mform The form to add the configuration settings to. This form is modified directly (not returned) + * @param MoodleQuickForm $mform The form to add the configuration settings to. + * This form is modified directly (not returned). * @return void */ private function add_plugin_settings(assign_plugin $plugin, MoodleQuickForm $mform) { global $CFG; if ($plugin->is_visible()) { - // enabled - //tied disableIf rule to this select element - $mform->addElement('selectyesno', $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled', $plugin->get_name()); - $mform->addHelpButton($plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled', 'enabled', $plugin->get_subtype() . '_' . $plugin->get_type()); - + $mform->addElement('selectyesno', + $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled', + $plugin->get_name()); + $mform->addHelpButton($plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled', + 'enabled', + $plugin->get_subtype() . '_' . $plugin->get_type()); $default = get_config($plugin->get_subtype() . '_' . $plugin->get_type(), 'default'); if ($plugin->get_config('enabled') !== false) { @@ -852,14 +864,13 @@ class assign { $plugin->get_settings($mform); } - } - /** - * Add settings to edit plugin form + * Add settings to edit plugin form. * - * @param MoodleQuickForm $mform The form to add the configuration settings to. This form is modified directly (not returned) + * @param MoodleQuickForm $mform The form to add the configuration settings to. + * This form is modified directly (not returned). * @return void */ public function add_all_plugin_settings(MoodleQuickForm $mform) { @@ -879,6 +890,7 @@ class assign { * Allow each plugin an opportunity to update the defaultvalues * passed in to the settings form (needed to set up draft areas for * editor and filemanager elements) + * * @param array $defaultvalues */ public function plugin_data_preprocessing(&$defaultvalues) { @@ -940,21 +952,25 @@ class assign { return $this->instance; } if ($this->get_course_module()) { - $this->instance = $DB->get_record('assign', array('id' => $this->get_course_module()->instance), '*', MUST_EXIST); + $params = array('id' => $this->get_course_module()->instance); + $this->instance = $DB->get_record('assign', $params, '*', MUST_EXIST); } if (!$this->instance) { - throw new coding_exception('Improper use of the assignment class. Cannot load the assignment record.'); + throw new coding_exception('Improper use of the assignment class. ' . + 'Cannot load the assignment record.'); } return $this->instance; } /** - * Get the context of the current course + * Get the context of the current course. + * * @return mixed context|null The course context */ public function get_course_context() { if (!$this->context && !$this->course) { - throw new coding_exception('Improper use of the assignment class. Cannot load the course context.'); + throw new coding_exception('Improper use of the assignment class. ' . + 'Cannot load the course context.'); } if ($this->context) { return $this->context->get_course_context(); @@ -965,7 +981,7 @@ class assign { /** - * Get the current course module + * Get the current course module. * * @return mixed stdClass|null The course module */ @@ -978,14 +994,18 @@ class assign { } if ($this->context->contextlevel == CONTEXT_MODULE) { - $this->coursemodule = get_coursemodule_from_id('assign', $this->context->instanceid, 0, false, MUST_EXIST); + $this->coursemodule = get_coursemodule_from_id('assign', + $this->context->instanceid, + 0, + false, + MUST_EXIST); return $this->coursemodule; } return null; } /** - * Get context module + * Get context module. * * @return context */ @@ -994,11 +1014,13 @@ class assign { } /** - * Get the current course + * Get the current course. + * * @return mixed stdClass|null The course */ public function get_course() { global $DB; + if ($this->course) { return $this->course; } @@ -1006,12 +1028,14 @@ class assign { if (!$this->context) { return null; } - $this->course = $DB->get_record('course', array('id' => $this->get_course_context()->instanceid), '*', MUST_EXIST); + $params = array('id' => $this->get_course_context()->instanceid); + $this->course = $DB->get_record('course', $params, '*', MUST_EXIST); + return $this->course; } /** - * Return a grade in user-friendly form, whether it's a scale or not + * Return a grade in user-friendly form, whether it's a scale or not. * * @param mixed $grade int|null * @param boolean $editing Are we allowing changes to this grade? @@ -1027,18 +1051,27 @@ class assign { $o = ''; if ($this->get_instance()->grade >= 0) { - // Normal number + // Normal number. if ($editing && $this->get_instance()->grade > 0) { if ($grade < 0) { $displaygrade = ''; } else { $displaygrade = format_float($grade); } - $o .= ''; - $o .= ''; - $o .= ' / ' . format_float($this->get_instance()->grade,2); - $o .= ''; + $o .= ''; + $o .= ''; + $o .= ' / ' . format_float($this->get_instance()->grade, 2); + $o .= ''; return $o; } else { $o .= ''; @@ -1046,13 +1079,15 @@ class assign { $o .= '-'; return $o; } else { - $o .= format_float(($grade),2) .' / '. format_float($this->get_instance()->grade,2); + $o .= format_float($grade, 2) . + ' / ' . + format_float($this->get_instance()->grade, 2); return $o; } } } else { - // Scale + // Scale. if (empty($this->cache['scale'])) { if ($scale = $DB->get_record('scale', array('id'=>-($this->get_instance()->grade)))) { $this->cache['scale'] = make_menu_from_list($scale->scale); @@ -1062,7 +1097,10 @@ class assign { } } if ($editing) { - $o .= ''; + $o .= ''; $o .= ''; - $o .= ''; + $o .= ''; return $o; } else { $scaleid = (int)$grade; @@ -1088,7 +1128,8 @@ class assign { } /** - * Load a list of users enrolled in the current course with the specified permission and group (0 for no group) + * Load a list of users enrolled in the current course with the specified permission and group. + * 0 for no group. * * @param int $currentgroup * @param bool $idsonly @@ -1096,20 +1137,23 @@ class assign { */ public function list_participants($currentgroup, $idsonly) { if ($idsonly) { - return get_enrolled_users($this->context, "mod/assign:submit", $currentgroup, 'u.id'); + return get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, 'u.id'); } else { - return get_enrolled_users($this->context, "mod/assign:submit", $currentgroup); + return get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup); } } /** - * Load a count of valid teams for this assignment + * Load a count of valid teams for this assignment. * * @return int number of valid teams */ public function count_teams() { - $groups = groups_get_all_groups($this->get_course()->id, 0, $this->get_instance()->teamsubmissiongroupingid, 'g.id'); + $groups = groups_get_all_groups($this->get_course()->id, + 0, + $this->get_instance()->teamsubmissiongroupingid, + 'g.id'); $count = count($groups); // See if there are any users in the default group. @@ -1121,13 +1165,14 @@ class assign { } /** - * Load a count of users enrolled in the current course with the specified permission and group (0 for no group) + * Load a count of users enrolled in the current course with the specified permission and group. + * 0 for no group. * * @param int $currentgroup * @return int number of matching users */ public function count_participants($currentgroup) { - return count_enrolled_users($this->context, "mod/assign:submit", $currentgroup); + return count_enrolled_users($this->context, 'mod/assign:submit', $currentgroup); } /** @@ -1167,7 +1212,7 @@ class assign { } /** - * Load a count of grades + * Load a count of grades. * * @return int number of grades */ @@ -1192,7 +1237,7 @@ class assign { } /** - * Load a count of submissions + * Load a count of submissions. * * @return int number of submissions */ @@ -1234,7 +1279,7 @@ class assign { } /** - * Load a count of submissions with a specified status + * Load a count of submissions with a specified status. * * @param string $status The submission status - should match one of the constants * @return int number of matching submissions @@ -1272,7 +1317,7 @@ class assign { /** * Utility function to get the userid for every row in the grading table - * so the order can be frozen while we iterate it + * so the order can be frozen while we iterate it. * * @return array An array of userids */ @@ -1285,74 +1330,51 @@ class assign { return $useridlist; } - /** - * Utility function get the userid based on the row number of the grading table. - * This takes into account any active filters on the table. + * Generate zip file from array of given files. * - * @param int $num The row number of the user - * @param bool $last This is set to true if this is the last user in the table - * @return mixed The user id of the matching user or false if there was an error + * @param array $filesforzipping - array of files to pass into archive_to_pathname. + * This array is indexed by the final file name and each + * element in the array is an instance of a stored_file object. + * @return path of temp file - note this returned file does + * not have a .zip extension - it is a temp file. */ - private function get_userid_for_row($num, $last) { - if (!array_key_exists('userid_for_row', $this->cache)) { - $this->cache['userid_for_row'] = array(); + private function pack_files($filesforzipping) { + global $CFG; + // Create path for new zip file. + $tempzip = tempnam($CFG->tempdir . '/', 'assignment_'); + // Zip files. + $zipper = new zip_packer(); + if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) { + return $tempzip; } - if (array_key_exists($num, $this->cache['userid_for_row'])) { - list($userid, $last) = $this->cache['userid_for_row'][$num]; - return $userid; - } - - $filter = get_user_preferences('assign_filter', ''); - $table = new assign_grading_table($this, 0, $filter, 0, false); - - $userid = $table->get_cell_data($num, 'userid', $last); - - $this->cache['userid_for_row'][$num] = array($userid, $last); - return $userid; - } - - /** - * Generate zip file from array of given files - * - * @param array $filesforzipping - array of files to pass into archive_to_pathname - this array is indexed by the final file name and each element in the array is an instance of a stored_file object - * @return path of temp file - note this returned file does not have a .zip extension - it is a temp file. - */ - private function pack_files($filesforzipping) { - global $CFG; - //create path for new zip file. - $tempzip = tempnam($CFG->tempdir.'/', 'assignment_'); - //zip files - $zipper = new zip_packer(); - if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) { - return $tempzip; - } - return false; + return false; } /** * Finds all assignment notifications that have yet to be mailed out, and mails them. * - * Cron function to be run periodically according to the moodle cron + * Cron function to be run periodically according to the moodle cron. * * @return bool */ - static function cron() { + public static function cron() { global $DB; - // only ever send a max of one days worth of updates + // Only ever send a max of one days worth of updates. $yesterday = time() - (24 * 3600); $timenow = time(); // Collect all submissions from the past 24 hours that require mailing. - $sql = "SELECT s.*, a.course, a.name, a.blindmarking, a.revealidentities, + $sql = 'SELECT s.*, a.course, a.name, a.blindmarking, a.revealidentities, g.*, g.id as gradeid, g.timemodified as lastmodified FROM {assign} a JOIN {assign_grades} g ON g.assignment = a.id LEFT JOIN {assign_submission} s ON s.assignment = a.id AND s.userid = g.userid WHERE g.timemodified >= :yesterday AND g.timemodified <= :today AND - g.mailed = 0"; + g.mailed = 0'; + $params = array('yesterday' => $yesterday, 'today' => $timenow); $submissions = $DB->get_records_sql($sql, $params); @@ -1368,16 +1390,19 @@ class assign { foreach ($submissions as $submission) { $courseids[] = $submission->course; } - // Filter out duplicates + + // Filter out duplicates. $courseids = array_unique($courseids); $ctxselect = context_helper::get_preload_record_columns_sql('ctx'); list($courseidsql, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED); - $sql = "SELECT c.*, {$ctxselect} - FROM {course} c + $sql = 'SELECT c.*, ' . $ctxselect . + ' FROM {course} c LEFT JOIN {context} ctx ON ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel - WHERE c.id {$courseidsql}"; + WHERE c.id ' . $courseidsql; + $params['contextlevel'] = CONTEXT_COURSE; $courses = $DB->get_records_sql($sql, $params); + // Clean up... this could go on for a while. unset($courseids); unset($ctxselect); @@ -1387,20 +1412,20 @@ class assign { // Simple array we'll use for caching modules. $modcache = array(); - // Message students about new feedback + // Message students about new feedback. foreach ($submissions as $submission) { mtrace("Processing assignment submission $submission->id ..."); - // do not cache user lookups - could be too many - if (!$user = $DB->get_record("user", array("id"=>$submission->userid))) { - mtrace("Could not find user $submission->userid"); + // Do not cache user lookups - could be too many. + if (!$user = $DB->get_record('user', array('id'=>$submission->userid))) { + mtrace('Could not find user ' . $submission->userid); continue; } - // use a cache to prevent the same DB queries happening over and over + // Use a cache to prevent the same DB queries happening over and over. if (!array_key_exists($submission->course, $courses)) { - mtrace("Could not find course $submission->course"); + mtrace('Could not find course ' . $submission->course); continue; } $course = $courses[$submission->course]; @@ -1413,37 +1438,40 @@ class assign { // mail is customised for the receiver. cron_setup_user($user, $course); - // context lookups are already cached + // Context lookups are already cached. $coursecontext = context_course::instance($course->id); if (!is_enrolled($coursecontext, $user->id)) { - $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext)); - mtrace(fullname($user)." not an active participant in " . $courseshortname); + $courseshortname = format_string($course->shortname, + true, + array('context' => $coursecontext)); + mtrace(fullname($user) . ' not an active participant in ' . $courseshortname); continue; } - if (!$grader = $DB->get_record("user", array("id"=>$submission->grader))) { - mtrace("Could not find grader $submission->grader"); + if (!$grader = $DB->get_record('user', array('id'=>$submission->grader))) { + mtrace('Could not find grader ' . $submission->grader); continue; } if (!array_key_exists($submission->assignment, $modcache)) { - if (! $mod = get_coursemodule_from_instance("assign", $submission->assignment, $course->id)) { - mtrace("Could not find course module for assignment id $submission->assignment"); + $mod = get_coursemodule_from_instance('assign', $submission->assignment, $course->id); + if (empty($mod)) { + mtrace('Could not find course module for assignment id ' . $submission->assignment); continue; } $modcache[$submission->assignment] = $mod; } else { $mod = $modcache[$submission->assignment]; } - // context lookups are already cached + // Context lookups are already cached. $contextmodule = context_module::instance($mod->id); if (!$mod->visible) { - // Hold mail notification for hidden assignments until later + // Hold mail notification for hidden assignments until later. continue; } - // need to send this to the student + // Need to send this to the student. $messagetype = 'feedbackavailable'; $eventtype = 'assign_notification'; $updatetime = $submission->lastmodified; @@ -1453,9 +1481,18 @@ class assign { if ($submission->blindmarking && !$submission->revealidentities) { $uniqueid = self::get_uniqueid_for_user_static($submission->assignment, $user->id); } - self::send_assignment_notification($grader, $user, $messagetype, $eventtype, $updatetime, - $mod, $contextmodule, $course, $modulename, $submission->name, - $submission->blindmarking && !$submission->revealidentities, + $showusers = $submission->blindmarking && !$submission->revealidentities; + self::send_assignment_notification($grader, + $user, + $messagetype, + $eventtype, + $updatetime, + $mod, + $contextmodule, + $course, + $modulename, + $submission->name, + $showusers, $uniqueid); $grade = new stdClass(); @@ -1469,7 +1506,7 @@ class assign { cron_setup_user(); - // Free up memory just to be sure + // Free up memory just to be sure. unset($courses); unset($modcache); @@ -1477,7 +1514,7 @@ class assign { } /** - * Update a grade in the grade table for the assignment and in the gradebook + * Update a grade in the grade table for the assignment and in the gradebook. * * @param stdClass $grade a grade record keyed on id * @return bool true for success @@ -1497,7 +1534,7 @@ class assign { return false; } } else { - // this is a scale + // This is a scale. if ($scale = $DB->get_record('scale', array('id' => -($this->get_instance()->grade)))) { $scaleoptions = make_menu_from_list($scale->scale); if (!array_key_exists((int) $grade->grade, $scaleoptions)) { @@ -1515,10 +1552,11 @@ class assign { } /** - * View the grant extension date page + * View the grant extension date page. * * Uses url parameters 'userid' * or from parameter 'selectedusers' + * * @param moodleform $mform - Used for validation of the submitted data * @return string */ @@ -1545,18 +1583,20 @@ class assign { } else { $data->batchusers = $batchusers; } - $o .= $this->get_renderer()->render(new assign_header($this->get_instance(), - $this->get_context(), - $this->show_intro(), - $this->get_course_module()->id, - get_string('grantextension', 'assign'))); + $header = new assign_header($this->get_instance(), + $this->get_context(), + $this->show_intro(), + $this->get_course_module()->id, + get_string('grantextension', 'assign')); + $o .= $this->get_renderer()->render($header); if (!$mform) { - $mform = new mod_assign_extension_form(null, array($this->get_course_module()->id, - $userid, - $batchusers, - $this->get_instance(), - $data)); + $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->view_footer(); @@ -1564,7 +1604,7 @@ class assign { } /** - * Get a list of the users in the same group as this user + * Get a list of the users in the same group as this user. * * @param int $groupid The id of the group whose members we want or 0 for the default group * @param bool $onlyids Whether to retrieve only the user id's @@ -1595,14 +1635,15 @@ class assign { } /** - * Get a list of the users in the same group as this user that have not submitted the assignment + * Get a list of the users in the same group as this user that have not submitted the assignment. * * @param int $groupid The id of the group whose members we want or 0 for the default group * @param bool $onlyids Whether to retrieve only the user id's * @return array The users (possibly id's only) */ public function get_submission_group_members_who_have_not_submitted($groupid, $onlyids) { - if (!$this->get_instance()->teamsubmission || !$this->get_instance()->requireallteammemberssubmit) { + $instance = $this->get_instance(); + if (!$instance->teamsubmission || !$instance->requireallteammemberssubmit) { return array(); } $members = $this->get_submission_group_members($groupid, $onlyids); @@ -1613,7 +1654,8 @@ class assign { unset($members[$id]); } else { if ($this->is_blind_marking()) { - $members[$id]->alias = get_string('hiddenuser', 'assign') . $this->get_uniqueid_for_user($id); + $members[$id]->alias = get_string('hiddenuser', 'assign') . + $this->get_uniqueid_for_user($id); } } } @@ -1621,12 +1663,11 @@ class assign { } /** - * Load the group submission object for a particular user, optionally creating it if required - * - * This will create the user submission and the group submission if required + * Load the group submission object for a particular user, optionally creating it if required. * * @param int $userid The id of the user whose submission we want - * @param int $groupid The id of the group for this user - may be 0 in which case it is determined from the userid + * @param int $groupid The id of the group for this user - may be 0 in which + * case it is determined from the userid. * @param bool $create If set to true a new submission object will be created in the database * @return stdClass The submission */ @@ -1647,10 +1688,10 @@ class assign { if (!$submission) { $submission = new stdClass(); - $submission->assignment = $this->get_instance()->id; - $submission->userid = $userid; - $submission->groupid = 0; - $submission->timecreated = time(); + $submission->assignment = $this->get_instance()->id; + $submission->userid = $userid; + $submission->groupid = 0; + $submission->timecreated = time(); $submission->timemodified = $submission->timecreated; if ($this->get_instance()->submissiondrafts) { @@ -1670,9 +1711,9 @@ class assign { } if ($create) { $submission = new stdClass(); - $submission->assignment = $this->get_instance()->id; - $submission->userid = 0; - $submission->groupid = $groupid; + $submission->assignment = $this->get_instance()->id; + $submission->userid = 0; + $submission->groupid = $groupid; $submission->timecreated = time(); $submission->timemodified = $submission->timecreated; @@ -1724,7 +1765,7 @@ class assign { continue; } - $timedue = $cms[$cm->id]->duedate; + $timedue = $cms[$cm->id]->duedate; $sectionname = ''; if ($usesections && $cm->sectionnum) { @@ -1768,7 +1809,7 @@ class assign { /** * View a page rendered by a plugin. * - * Uses url parameters 'pluginaction', 'pluginsubtype', 'plugin', and 'id' + * Uses url parameters 'pluginaction', 'pluginsubtype', 'plugin', and 'id'. * * @return string */ @@ -1801,7 +1842,8 @@ class assign { * @return mixed The group or false */ public function get_submission_group($userid) { - $groups = groups_get_all_groups($this->get_course()->id, $userid, $this->get_instance()->teamsubmissiongroupingid); + $grouping = $this->get_instance()->teamsubmissiongroupingid; + $groups = groups_get_all_groups($this->get_course()->id, $userid, $grouping); if (count($groups) != 1) { return false; } @@ -1810,8 +1852,10 @@ class assign { /** - * display the submission that is used by a plugin - * Uses url parameters 'sid', 'gid' and 'plugin' + * Display the submission that is used by a plugin. + * + * Uses url parameters 'sid', 'gid' and 'plugin'. + * * @param string $pluginsubtype * @return string */ @@ -1831,7 +1875,7 @@ class assign { } $item = $this->get_submission($submissionid); - // permissions + // Check permissions. if ($item->userid != $USER->id) { require_capability('mod/assign:grade', $this->context); } @@ -1847,14 +1891,15 @@ class assign { $this->get_return_action(), $this->get_return_params())); - $this->add_to_log('view submission', get_string('viewsubmissionforuser', 'assign', $item->userid)); + $logmessage = get_string('viewsubmissionforuser', 'assign', $item->userid); + $this->add_to_log('view submission', $logmessage); } else { $plugin = $this->get_feedback_plugin_by_type($plugintype); if ($gradeid <= 0) { throw new coding_exception('Grade id should not be 0'); } $item = $this->get_grade($gradeid); - // permissions + // Check permissions. if ($item->userid != $USER->id) { require_capability('mod/assign:grade', $this->context); } @@ -1869,10 +1914,10 @@ class assign { $this->get_course_module()->id, $this->get_return_action(), $this->get_return_params())); - $this->add_to_log('view feedback', get_string('viewfeedbackforuser', 'assign', $item->userid)); + $logmessage = get_string('viewfeedbackforuser', 'assign', $item->userid); + $this->add_to_log('view feedback', $logmessage); } - $o .= $this->view_return_links(); $o .= $this->view_footer(); @@ -1880,7 +1925,7 @@ class assign { } /** - * render the content in editor that is often used by plugin + * Render the content in editor that is often used by plugin. * * @param string $filearea * @param int $submissionid @@ -1899,21 +1944,33 @@ class assign { $text = $plugin->get_editor_text($editor, $submissionid); $format = $plugin->get_editor_format($editor, $submissionid); - $finaltext = file_rewrite_pluginfile_urls($text, 'pluginfile.php', $this->get_context()->id, $component, $filearea, $submissionid); - $result .= format_text($finaltext, $format, array('overflowdiv' => true, 'context' => $this->get_context())); - - + $finaltext = file_rewrite_pluginfile_urls($text, + 'pluginfile.php', + $this->get_context()->id, + $component, + $filearea, + $submissionid); + $params = array('overflowdiv' => true, 'context' => $this->get_context()); + $result .= format_text($finaltext, $format, $params); if ($CFG->enableportfolios) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); - $button->set_callback_options('assign_portfolio_caller', array('cmid' => $this->get_course_module()->id, - 'sid' => $submissionid, 'plugin' => $plugintype, 'editor' => $editor, 'area'=>$filearea), - 'mod_assign'); + $portfolioparams = array('cmid' => $this->get_course_module()->id, + 'sid' => $submissionid, + 'plugin' => $plugintype, + 'editor' => $editor, + 'area'=>$filearea); + $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign'); $fs = get_file_storage(); - if ($files = $fs->get_area_files($this->context->id, $component,$filearea, $submissionid, "timemodified", false)) { + if ($files = $fs->get_area_files($this->context->id, + $component, + $filearea, + $submissionid, + 'timemodified', + false)) { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); @@ -1924,7 +1981,7 @@ class assign { } /** - * Display a grading error + * Display a grading error. * * @param string $message - The description of the result * @return string @@ -1936,13 +1993,14 @@ class assign { $this->show_intro(), $this->get_course_module()->id, get_string('quickgradingresult', 'assign'))); - $o .= $this->get_renderer()->render(new assign_quickgrading_result($message, $this->get_course_module()->id)); + $gradingresult = new assign_quickgrading_result($message, $this->get_course_module()->id); + $o .= $this->get_renderer()->render($gradingresult); $o .= $this->view_footer(); return $o; } /** - * Display the page footer + * Display the page footer. * * @return string */ @@ -1951,12 +2009,12 @@ class assign { } /** - * Does this user have grade permission for this assignment + * Does this user have grade permission for this assignment? * * @return bool */ private function can_grade() { - // Permissions check + // Permissions check. if (!has_capability('mod/assign:grade', $this->context)) { return false; } @@ -1965,12 +2023,12 @@ class assign { } /** - * Download a zip file of all assignment submissions + * Download a zip file of all assignment submissions. * * @return void */ private function download_submissions() { - global $CFG,$DB; + global $CFG, $DB; // More efficient to load this here. require_once($CFG->libdir.'/filelib.php'); @@ -1992,9 +2050,9 @@ class assign { } // Construct the zip file name. - $filename = clean_filename($this->get_course()->shortname.'-'. - $this->get_instance()->name.'-'. - $groupname.$this->get_course_module()->id.".zip"); + $filename = clean_filename($this->get_course()->shortname . '-' . + $this->get_instance()->name . '-' . + $groupname.$this->get_course_module()->id . '.zip'); // Get all the files for each student. foreach ($students as $student) { @@ -2018,11 +2076,11 @@ class assign { } if ($this->is_blind_marking()) { - $prefix = clean_filename(str_replace('_', ' ', $groupname . get_string('participant', 'assign')) . - "_" . $this->get_uniqueid_for_user($userid) . "_"); + $prefix = str_replace('_', ' ', $groupname . get_string('participant', 'assign')); + $prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($userid) . '_'); } else { - $prefix = clean_filename(str_replace('_', ' ', $groupname . fullname($student)) . - "_" . $this->get_uniqueid_for_user($userid) . "_"); + $prefix = str_replace('_', ' ', $groupname . fullname($student)); + $prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($userid) . '_'); } if ($submission) { @@ -2032,7 +2090,12 @@ class assign { foreach ($pluginfiles as $zipfilename => $file) { $subtype = $plugin->get_subtype(); $type = $plugin->get_type(); - $prefixedfilename = $prefix . $subtype . '_' . $type . '_' . $zipfilename; + $prefixedfilename = clean_filename($prefix . + $subtype . + '_' . + $type . + '_' . + $zipfilename); $filesforzipping[$prefixedfilename] = $file; } } @@ -2063,7 +2126,7 @@ class assign { } /** - * Util function to add a message to the log + * Util function to add a message to the log. * * @param string $action The current action * @param string $info A detailed description of the change. But no more than 255 characters. @@ -2078,11 +2141,17 @@ class assign { $fullurl .= '&' . $url; } - add_to_log($this->get_course()->id, 'assign', $action, $fullurl, $info, $this->get_course_module()->id, $USER->id); + add_to_log($this->get_course()->id, + 'assign', + $action, + $fullurl, + $info, + $this->get_course_module()->id, + $USER->id); } /** - * Lazy load the page renderer and expose the renderer to plugins + * Lazy load the page renderer and expose the renderer to plugins. * * @return assign_renderer */ @@ -2096,14 +2165,15 @@ class assign { } /** - * Load the submission object for a particular user, optionally creating it if required + * Load the submission object for a particular user, optionally creating it if required. * * For team assignments there are 2 submissions - the student submission and the team submission * All files are associated with the team submission but the status of the students contribution is * recorded separately. * * @param int $userid The id of the user whose submission we want or 0 in which case USER->id is used - * @param bool $create optional Defaults to false. If set to true a new submission object will be created in the database + * @param bool $create optional - defaults to false. If set to true a new submission object + * will be created in the database. * @return stdClass The submission */ public function get_user_submission($userid, $create) { @@ -2134,7 +2204,7 @@ class assign { } /** - * Load the submission object from it's id + * Load the submission object from it's id. * * @param int $submissionid The id of the submission we want * @return stdClass The submission @@ -2142,11 +2212,12 @@ class assign { private function get_submission($submissionid) { global $DB; - return $DB->get_record('assign_submission', array('assignment'=>$this->get_instance()->id, 'id'=>$submissionid), '*', MUST_EXIST); + $params = array('assignment'=>$this->get_instance()->id, 'id'=>$submissionid); + return $DB->get_record('assign_submission', $params, '*', MUST_EXIST); } /** - * This will retrieve a grade object from the db, optionally creating it if required + * This will retrieve a grade object from the db, optionally creating it if required. * * @param int $userid The user we are grading * @param bool $create If true the grade will be created if it does not exist @@ -2159,7 +2230,7 @@ class assign { $userid = $USER->id; } - // if the userid is not null then use userid + // If the userid is not null then use userid. $grade = $DB->get_record('assign_grades', array('assignment'=>$this->get_instance()->id, 'userid'=>$userid)); if ($grade) { @@ -2183,7 +2254,7 @@ class assign { } /** - * This will retrieve a grade object from the db + * This will retrieve a grade object from the db. * * @param int $gradeid The id of the grade * @return stdClass The grade record @@ -2191,11 +2262,12 @@ class assign { private function get_grade($gradeid) { global $DB; - return $DB->get_record('assign_grades', array('assignment'=>$this->get_instance()->id, 'id'=>$gradeid), '*', MUST_EXIST); + $params = array('assignment'=>$this->get_instance()->id, 'id'=>$gradeid); + return $DB->get_record('assign_grades', $params, '*', MUST_EXIST); } /** - * Print the grading page for a single user submission + * Print the grading page for a single user submission. * * @param moodleform $mform * @param int $offset @@ -2205,15 +2277,19 @@ class assign { global $DB, $CFG; $o = ''; + $instance = $this->get_instance(); - // Include grade form require_once($CFG->dirroot . '/mod/assign/gradeform.php'); - // Need submit permission to submit an assignment + // Need submit permission to submit an assignment. require_capability('mod/assign:grade', $this->context); - $o .= $this->get_renderer()->render(new assign_header($this->get_instance(), - $this->get_context(), false, $this->get_course_module()->id,get_string('grading', 'assign'))); + $header = new assign_header($instance, + $this->get_context(), + false, + $this->get_course_module()->id, + get_string('grading', 'assign')); + $o .= $this->get_renderer()->render($header); $rownum = required_param('rownum', PARAM_INT) + $offset; $useridlist = optional_param('useridlist', '', PARAM_TEXT); @@ -2232,19 +2308,20 @@ class assign { } $user = $DB->get_record('user', array('id' => $userid)); if ($user) { - $o .= $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))); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); + $usersummary = new assign_user_summary($user, + $this->get_course()->id, + $viewfullnames, + $this->is_blind_marking(), + $this->get_uniqueid_for_user($user->id)); + $o .= $this->get_renderer()->render($usersummary); } $submission = $this->get_user_submission($userid, false); $submissiongroup = null; $submissiongroupmemberswhohavenotsubmitted = array(); $teamsubmission = null; $notsubmitted = array(); - if ($this->get_instance()->teamsubmission) { + if ($instance->teamsubmission) { $teamsubmission = $this->get_group_submission($userid, 0, false); $submissiongroup = $this->get_submission_group($userid); $groupid = 0; @@ -2255,7 +2332,7 @@ class assign { } - // get the current grade + // Get the current grade. $grade = $this->get_user_grade($userid, false); if ($this->can_view_submission($userid)) { $gradelocked = ($grade && $grade->locked) || $this->grading_disabled($userid); @@ -2266,52 +2343,57 @@ class assign { $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled()); if ($teamsubmission) { - $showsubmit = $showedit && $teamsubmission && ($teamsubmission->status == ASSIGN_SUBMISSION_STATUS_DRAFT); + $showsubmit = $showedit && + $teamsubmission && + ($teamsubmission->status == ASSIGN_SUBMISSION_STATUS_DRAFT); } else { - $showsubmit = $showedit && $submission && ($submission->status == ASSIGN_SUBMISSION_STATUS_DRAFT); + $showsubmit = $showedit && + $submission && + ($submission->status == ASSIGN_SUBMISSION_STATUS_DRAFT); } if (!$this->get_instance()->submissiondrafts) { $showsubmit = false; } $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); - $o .= $this->get_renderer()->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate, - $this->get_instance()->alwaysshowdescription, - $submission, - $this->get_instance()->teamsubmission, - $teamsubmission, - $submissiongroup, - $notsubmitted, - $this->is_any_submission_plugin_enabled(), - $gradelocked, - $this->is_graded($userid), - $this->get_instance()->duedate, - $this->get_instance()->cutoffdate, - $this->get_submission_plugins(), - $this->get_return_action(), - $this->get_return_params(), - $this->get_course_module()->id, - $this->get_course()->id, - assign_submission_status::GRADER_VIEW, - $showedit, - $showsubmit, - $viewfullnames, - $extensionduedate, - $this->get_context(), - $this->is_blind_marking(), - '')); + $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate, + $instance->alwaysshowdescription, + $submission, + $instance->teamsubmission, + $teamsubmission, + $submissiongroup, + $notsubmitted, + $this->is_any_submission_plugin_enabled(), + $gradelocked, + $this->is_graded($userid), + $instance->duedate, + $instance->cutoffdate, + $this->get_submission_plugins(), + $this->get_return_action(), + $this->get_return_params(), + $this->get_course_module()->id, + $this->get_course()->id, + assign_submission_status::GRADER_VIEW, + $showedit, + $showsubmit, + $viewfullnames, + $extensionduedate, + $this->get_context(), + $this->is_blind_marking(), + ''); + $o .= $this->get_renderer()->render($submissionstatus); } if ($grade) { $data = new stdClass(); - if ($grade->grade !== NULL && $grade->grade >= 0) { - $data->grade = format_float($grade->grade,2); + if ($grade->grade !== null && $grade->grade >= 0) { + $data->grade = format_float($grade->grade, 2); } } else { $data = new stdClass(); $data->grade = ''; } - // now show the grading form + // Now show the grading form. if (!$mform) { $pagination = array( 'rownum'=>$rownum, 'useridlist'=>$useridlist, 'last'=>$last); $formparams = array($this, $data, $pagination); @@ -2321,9 +2403,11 @@ class assign { '', array('class'=>'gradeform')); } - $o .= $this->get_renderer()->render(new assign_form('gradingform',$mform)); + $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform)); - $msg = get_string('viewgradingformforstudent', 'assign', array('id'=>$user->id, 'fullname'=>fullname($user))); + $msg = get_string('viewgradingformforstudent', + 'assign', + array('id'=>$user->id, 'fullname'=>fullname($user))); $this->add_to_log('view grading form', $msg); $o .= $this->view_footer(); @@ -2331,7 +2415,7 @@ class assign { } /** - * Show a confirmation page to make sure they want to release student identities + * Show a confirmation page to make sure they want to release student identities. * * @return string */ @@ -2341,55 +2425,61 @@ class assign { require_capability('mod/assign:revealidentities', $this->get_context()); $o = ''; - $o .= $this->get_renderer()->render(new assign_header($this->get_instance(), - $this->get_context(), false, $this->get_course_module()->id)); + $header = new assign_header($this->get_instance(), + $this->get_context(), + false, + $this->get_course_module()->id); + $o .= $this->get_renderer()->render($header); - $confirmurl = new moodle_url('/mod/assign/view.php', array('id'=>$this->get_course_module()->id, - 'action'=>'revealidentitiesconfirm', - 'sesskey'=>sesskey())); + $urlparams = array('id'=>$this->get_course_module()->id, + 'action'=>'revealidentitiesconfirm', + 'sesskey'=>sesskey()); + $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams); - $cancelurl = new moodle_url('/mod/assign/view.php', array('id'=>$this->get_course_module()->id, - 'action'=>'grading')); + $urlparams = array('id'=>$this->get_course_module()->id, + 'action'=>'grading'); + $cancelurl = new moodle_url('/mod/assign/view.php', $urlparams); - $o .= $this->get_renderer()->confirm(get_string('revealidentitiesconfirm', 'assign'), $confirmurl, $cancelurl); + $o .= $this->get_renderer()->confirm(get_string('revealidentitiesconfirm', 'assign'), + $confirmurl, + $cancelurl); $o .= $this->view_footer(); $this->add_to_log('view', get_string('viewrevealidentitiesconfirm', 'assign')); return $o; } - - - /** * View a link to go back to the previous page. Uses url parameters returnaction and returnparams. * * @return string */ private function view_return_links() { - - $returnaction = optional_param('returnaction','', PARAM_ALPHA); - $returnparams = optional_param('returnparams','', PARAM_TEXT); + $returnaction = optional_param('returnaction', '', PARAM_ALPHA); + $returnparams = optional_param('returnparams', '', PARAM_TEXT); $params = array(); parse_str($returnparams, $params); - $params = array_merge( array('id' => $this->get_course_module()->id, 'action' => $returnaction), $params); - - return $this->get_renderer()->single_button(new moodle_url('/mod/assign/view.php', $params), get_string('back'), 'get'); + $newparams = array('id' => $this->get_course_module()->id, 'action' => $returnaction); + $params = array_merge($newparams, $params); + $url = new moodle_url('/mod/assign/view.php', $params); + return $this->get_renderer()->single_button($url, get_string('back'), 'get'); } /** - * View the grading table of all submissions for this assignment + * View the grading table of all submissions for this assignment. * * @return string */ private function view_grading_table() { global $USER, $CFG; - // Include grading options form + + // Include grading options form. require_once($CFG->dirroot . '/mod/assign/gradingoptionsform.php'); require_once($CFG->dirroot . '/mod/assign/quickgradingform.php'); require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php'); $o = ''; + $cmid = $this->get_course_module()->id; $links = array(); if (has_capability('gradereport/grader:view', $this->get_course_context()) && @@ -2398,18 +2488,19 @@ class assign { $links[$gradebookurl] = get_string('viewgradebook', 'assign'); } if ($this->is_any_submission_plugin_enabled()) { - $downloadurl = '/mod/assign/view.php?id=' . $this->get_course_module()->id . '&action=downloadall'; + $downloadurl = '/mod/assign/view.php?id=' . $cmid . '&action=downloadall'; $links[$downloadurl] = get_string('downloadall', 'assign'); } - if ($this->is_blind_marking() && has_capability('mod/assign:revealidentities', $this->get_context())) { - $revealidentitiesurl = '/mod/assign/view.php?id=' . $this->get_course_module()->id . '&action=revealidentities'; + if ($this->is_blind_marking() && + has_capability('mod/assign:revealidentities', $this->get_context())) { + $revealidentitiesurl = '/mod/assign/view.php?id=' . $cmid . '&action=revealidentities'; $links[$revealidentitiesurl] = get_string('revealidentities', 'assign'); } foreach ($this->get_feedback_plugins() as $plugin) { if ($plugin->is_enabled() && $plugin->is_visible()) { foreach ($plugin->get_grading_actions() as $action => $description) { $url = '/mod/assign/view.php' . - '?id=' . $this->get_course_module()->id . + '?id=' . $cmid . '&plugin=' . $plugin->get_type() . '&pluginsubtype=assignfeedback' . '&action=viewpluginpage&pluginaction=' . $action; @@ -2433,24 +2524,32 @@ class assign { } $quickgrading = get_user_preferences('assign_quickgrading', false); - // print options for changing the filter and changing the number of results per page + // Print options for changing the filter and changing the number of results per page. + $gradingoptionsformparams = array('cm'=>$cmid, + 'contextid'=>$this->context->id, + 'userid'=>$USER->id, + 'submissionsenabled'=>$this->is_any_submission_plugin_enabled(), + 'showquickgrading'=>$showquickgrading, + 'quickgrading'=>$quickgrading); + + $classoptions = array('class'=>'gradingoptionsform'); $gradingoptionsform = new mod_assign_grading_options_form(null, - array('cm'=>$this->get_course_module()->id, - 'contextid'=>$this->context->id, - 'userid'=>$USER->id, - 'submissionsenabled'=>$this->is_any_submission_plugin_enabled(), - 'showquickgrading'=>$showquickgrading, - 'quickgrading'=>$quickgrading), - 'post', '', - array('class'=>'gradingoptionsform')); + $gradingoptionsformparams, + 'post', + '', + $classoptions); + + $batchformparams = array('cm'=>$cmid, + 'submissiondrafts'=>$this->get_instance()->submissiondrafts, + 'duedate'=>$this->get_instance()->duedate, + 'feedbackplugins'=>$this->get_feedback_plugins()); + $classoptions = array('class'=>'gradingbatchoperationsform'); $gradingbatchoperationsform = new mod_assign_grading_batch_operations_form(null, - array('cm'=>$this->get_course_module()->id, - 'submissiondrafts'=>$this->get_instance()->submissiondrafts, - 'duedate'=>$this->get_instance()->duedate, - 'feedbackplugins'=>$this->get_feedback_plugins()), - 'post', '', - array('class'=>'gradingbatchoperationsform')); + $batchformparams, + 'post', + '', + $classoptions); $gradingoptionsdata = new stdClass(); $gradingoptionsdata->perpage = $perpage; @@ -2458,35 +2557,51 @@ class assign { $gradingoptionsform->set_data($gradingoptionsdata); $actionformtext = $this->get_renderer()->render($gradingactions); - $o .= $this->get_renderer()->render(new assign_header($this->get_instance(), - $this->get_context(), false, $this->get_course_module()->id, get_string('grading', 'assign'), $actionformtext)); - $o .= groups_print_activity_menu($this->get_course_module(), $CFG->wwwroot . '/mod/assign/view.php?id=' . $this->get_course_module()->id.'&action=grading', true); + $header = new assign_header($this->get_instance(), + $this->get_context(), + false, + $this->get_course_module()->id, + get_string('grading', 'assign'), + $actionformtext); + $o .= $this->get_renderer()->render($header); - // plagiarism update status apearring in the grading book + $currenturl = $CFG->wwwroot . + '/mod/assign/view.php?id=' . + $this->get_course_module()->id . + '&action=grading'; + + $o .= groups_print_activity_menu($this->get_course_module(), $currenturl, true); + + // Plagiarism update status apearring in the grading book. if (!empty($CFG->enableplagiarism)) { - /** Include plagiarismlib.php */ require_once($CFG->libdir . '/plagiarismlib.php'); $o .= plagiarism_update_status($this->get_course(), $this->get_course_module()); } - // load and print the table of submissions + // Load and print the table of submissions. if ($showquickgrading && $quickgrading) { - $table = $this->get_renderer()->render(new assign_grading_table($this, $perpage, $filter, 0, true)); - $quickgradingform = new mod_assign_quick_grading_form(null, - array('cm'=>$this->get_course_module()->id, - 'gradingtable'=>$table)); + $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, true); + $table = $this->get_renderer()->render($gradingtable); + $quickformparams = array('cm'=>$this->get_course_module()->id, 'gradingtable'=>$table); + $quickgradingform = new mod_assign_quick_grading_form(null, $quickformparams); + $o .= $this->get_renderer()->render(new assign_form('quickgradingform', $quickgradingform)); } else { - $o .= $this->get_renderer()->render(new assign_grading_table($this, $perpage, $filter, 0, false)); + $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, false); + $o .= $this->get_renderer()->render($gradingtable); } $currentgroup = groups_get_activity_group($this->get_course_module(), true); $users = array_keys($this->list_participants($currentgroup, true)); if (count($users) != 0) { - // if no enrolled user in a course then don't display the batch operations feature - $o .= $this->get_renderer()->render(new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform)); + // If no enrolled user in a course then don't display the batch operations feature. + $assignform = new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform); + $o .= $this->get_renderer()->render($assignform); } - $o .= $this->get_renderer()->render(new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options')); + $assignform = new assign_form('gradingoptionsform', + $gradingoptionsform, + 'M.mod_assign.init_grading_options'); + $o .= $this->get_renderer()->render($assignform); return $o; } @@ -2499,21 +2614,23 @@ class assign { global $CFG; $o = ''; - // Need submit permission to submit an assignment + // Need submit permission to submit an assignment. require_capability('mod/assign:grade', $this->context); require_once($CFG->dirroot . '/mod/assign/gradeform.php'); - // only load this if it is + // Only load this if it is. $o .= $this->view_grading_table(); $o .= $this->view_footer(); - $this->add_to_log('view submission grading table', get_string('viewsubmissiongradingtable', 'assign')); + + $logmessage = get_string('viewsubmissiongradingtable', 'assign'); + $this->add_to_log('view submission grading table', $logmessage); return $o; } /** - * Capture the output of the plagiarism plugins disclosures and return it as a string + * Capture the output of the plagiarism plugins disclosures and return it as a string. * * @return void */ @@ -2522,7 +2639,6 @@ class assign { $o = ''; if (!empty($CFG->enableplagiarism)) { - /** Include plagiarismlib.php */ require_once($CFG->libdir . '/plagiarismlib.php'); $o .= plagiarism_print_disclosure($this->get_course_module()->id); @@ -2532,7 +2648,7 @@ class assign { } /** - * message for students when assignment submissions have been closed + * Message for students when assignment submissions have been closed. * * @return string */ @@ -2540,14 +2656,15 @@ class assign { global $CFG; $o = ''; - // Need submit permission to submit an assignment + // Need submit permission to submit an assignment. require_capability('mod/assign:submit', $this->context); - $o .= $this->get_renderer()->render(new assign_header($this->get_instance(), - $this->get_context(), - $this->show_intro(), - $this->get_course_module()->id, - get_string('editsubmission', 'assign'))); + $header = new assign_header($this->get_instance(), + $this->get_context(), + $this->show_intro(), + $this->get_course_module()->id, + get_string('editsubmission', 'assign')); + $o .= $this->get_renderer()->render($header); $o .= $this->get_renderer()->notification(get_string('submissionsclosed', 'assign')); @@ -2561,16 +2678,16 @@ class assign { * View edit submissions page. * * @param moodleform $mform - * @param array $notices A list of notices to display at the top of the edit submission form (e.g. from plugins). + * @param array $notices A list of notices to display at the top of the + * edit submission form (e.g. from plugins). * @return void */ private function view_edit_submission_page($mform, $notices) { global $CFG; $o = ''; - // Include submission form require_once($CFG->dirroot . '/mod/assign/submission_form.php'); - // Need submit permission to submit an assignment + // Need submit permission to submit an assignment. require_capability('mod/assign:submit', $this->context); if (!$this->submissions_open()) { @@ -2592,7 +2709,7 @@ class assign { $o .= $this->get_renderer()->notification($notice); } - $o .= $this->get_renderer()->render(new assign_form('editsubmissionform',$mform)); + $o .= $this->get_renderer()->render(new assign_form('editsubmissionform', $mform)); $o .= $this->view_footer(); $this->add_to_log('view submit assignment form', get_string('viewownsubmissionform', 'assign')); @@ -2601,7 +2718,7 @@ class assign { } /** - * See if this assignment has a grade yet + * See if this assignment has a grade yet. * * @param int $userid * @return bool @@ -2609,14 +2726,13 @@ class assign { private function is_graded($userid) { $grade = $this->get_user_grade($userid, false); if ($grade) { - return ($grade->grade !== NULL && $grade->grade >= 0); + return ($grade->grade !== null && $grade->grade >= 0); } return false; } - /** - * Perform an access check to see if the current $USER can view this users submission + * Perform an access check to see if the current $USER can view this users submission. * * @param int $userid * @return bool @@ -2627,13 +2743,13 @@ class assign { if (!is_enrolled($this->get_course_context(), $userid)) { return false; } - if ($userid == $USER->id && !has_capability('mod/assign:submit', $this->context)) { - return false; + if ($userid == $USER->id && has_capability('mod/assign:submit', $this->context)) { + return true; } - if ($userid != $USER->id && !has_capability('mod/assign:grade', $this->context)) { - return false; + if (has_capability('mod/assign:grade', $this->context)) { + return true; } - return true; + return false; } /** @@ -2662,6 +2778,7 @@ class assign { /** * Ask the user to confirm they want to perform this batch operation + * * @param moodleform $mform Set to a grading batch operations form * @return string - the page to view after processing these actions */ @@ -2670,17 +2787,19 @@ class assign { require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php'); require_sesskey(); + $batchformparams = array('cm'=>$this->get_course_module()->id, + 'submissiondrafts'=>$this->get_instance()->submissiondrafts, + 'duedate'=>$this->get_instance()->duedate, + 'feedbackplugins'=>$this->get_feedback_plugins()); + $formclasses = array('class'=>'gradingbatchoperationsform'); $mform = new mod_assign_grading_batch_operations_form(null, - array('cm'=>$this->get_course_module()->id, - 'submissiondrafts'=>$this->get_instance()->submissiondrafts, - 'duedate'=>$this->get_instance()->duedate, - 'feedbackplugins'=>$this->get_feedback_plugins()), + $batchformparams, 'post', '', - array('class'=>'gradingbatchoperationsform')); + $formclasses); if ($data = $mform->get_data()) { - // get the list of users + // Get the list of users. $users = $data->selectedusers; $userlist = explode(',', $users); @@ -2715,7 +2834,8 @@ class assign { } /** - * Ask the user to confirm they want to submit their work for grading + * Ask the user to confirm they want to submit their work for grading. + * * @param $mform moodleform - null unless form validation has failed * @return string */ @@ -2724,7 +2844,7 @@ class assign { require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php'); - // Check that all of the submission plugins are ready for this submission + // Check that all of the submission plugins are ready for this submission. $notifications = array(); $submission = $this->get_user_submission($USER->id, false); $plugins = $this->get_submission_plugins(); @@ -2756,17 +2876,21 @@ class assign { } $o = ''; $o .= $this->get_renderer()->header(); - $o .= $this->get_renderer()->render(new assign_submit_for_grading_page($notifications, $this->get_course_module()->id, $mform)); + $submitforgradingpage = new assign_submit_for_grading_page($notifications, + $this->get_course_module()->id, + $mform); + $o .= $this->get_renderer()->render($submitforgradingpage); $o .= $this->view_footer(); - $this->add_to_log('view confirm submit assignment form', get_string('viewownsubmissionform', 'assign')); + $logmessage = get_string('viewownsubmissionform', 'assign'); + $this->add_to_log('view confirm submit assignment form', $logmessage); return $o; } /** * Print 2 tables of information with no action links - - * the submission summary and the grading summary + * the submission summary and the grading summary. * * @param stdClass $user the user to print the report for * @param bool $showlinks - Return plain text or links to the profile @@ -2775,6 +2899,7 @@ class assign { public function view_student_summary($user, $showlinks) { global $CFG, $DB, $PAGE; + $instance = $this->get_instance(); $grade = $this->get_user_grade($user->id, false); $submission = $this->get_user_submission($user->id, false); $o = ''; @@ -2782,7 +2907,7 @@ class assign { $teamsubmission = null; $submissiongroup = null; $notsubmitted = array(); - if ($this->get_instance()->teamsubmission) { + if ($instance->teamsubmission) { $teamsubmission = $this->get_group_submission($user->id, 0, false); $submissiongroup = $this->get_submission_group($user->id); $groupid = 0; @@ -2794,8 +2919,12 @@ class assign { if ($this->can_view_submission($user->id)) { $showedit = has_capability('mod/assign:submit', $this->context) && - $this->submissions_open($user->id) && ($this->is_any_submission_plugin_enabled()) && $showlinks; + $this->submissions_open($user->id) && + ($this->is_any_submission_plugin_enabled()) && + $showlinks; + $gradelocked = ($grade && $grade->locked) || $this->grading_disabled($user->id); + // Grading criteria preview. $gradingmanager = get_grading_manager($this->context, 'mod_assign', 'submissions'); $gradingcontrollerpreview = ''; @@ -2821,18 +2950,19 @@ class assign { $extensionduedate = $grade->extensionduedate; } $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); - $o .= $this->get_renderer()->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate, - $this->get_instance()->alwaysshowdescription, + + $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate, + $instance->alwaysshowdescription, $submission, - $this->get_instance()->teamsubmission, + $instance->teamsubmission, $teamsubmission, $submissiongroup, $notsubmitted, $this->is_any_submission_plugin_enabled(), $gradelocked, $this->is_graded($user->id), - $this->get_instance()->duedate, - $this->get_instance()->cutoffdate, + $instance->duedate, + $instance->cutoffdate, $this->get_submission_plugins(), $this->get_return_action(), $this->get_return_params(), @@ -2845,7 +2975,8 @@ class assign { $extensionduedate, $this->get_context(), $this->is_blind_marking(), - $gradingcontrollerpreview)); + $gradingcontrollerpreview); + $o .= $this->get_renderer()->render($submissionstatus); require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->dirroot.'/grade/grading/lib.php'); @@ -2853,13 +2984,13 @@ class assign { $gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', - $this->get_instance()->id, + $instance->id, $user->id); $gradingitem = $gradinginfo->items[0]; $gradebookgrade = $gradingitem->grades[$user->id]; - // check to see if all feedback plugins are empty + // Check to see if all feedback plugins are empty. $emptyplugins = true; if ($grade) { foreach ($this->get_feedback_plugins() as $plugin) { @@ -2871,7 +3002,6 @@ class assign { } } - if (!($gradebookgrade->hidden) && ($gradebookgrade->grade !== null || !$emptyplugins)) { $gradefordisplay = ''; @@ -2879,11 +3009,12 @@ class assign { if ($controller = $gradingmanager->get_active_controller()) { $controller->set_grade_range(make_grades_menu($this->get_instance()->grade)); + $cangrade = has_capability('mod/assign:grade', $this->get_context()); $gradefordisplay = $controller->render_grade($PAGE, $grade->id, $gradingitem, $gradebookgrade->str_long_grade, - has_capability('mod/assign:grade', $this->get_context())); + $cangrade); } else { $gradefordisplay = $this->display_grade($gradebookgrade->grade, false); } @@ -2915,36 +3046,40 @@ class assign { private function view_submission_page() { global $CFG, $DB, $USER, $PAGE; + $instance = $this->get_instance(); + $o = ''; - $o .= $this->get_renderer()->render(new assign_header($this->get_instance(), + $o .= $this->get_renderer()->render(new assign_header($instance, $this->get_context(), $this->show_intro(), $this->get_course_module()->id)); if ($this->can_grade()) { - if ($this->get_instance()->teamsubmission) { + $draft = ASSIGN_SUBMISSION_STATUS_DRAFT; + $submitted = ASSIGN_SUBMISSION_STATUS_SUBMITTED; + if ($instance->teamsubmission) { $summary = new assign_grading_summary($this->count_teams(), - $this->get_instance()->submissiondrafts, - $this->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_DRAFT), + $instance->submissiondrafts, + $this->count_submissions_with_status($draft), $this->is_any_submission_plugin_enabled(), - $this->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED), - $this->get_instance()->cutoffdate, - $this->get_instance()->duedate, + $this->count_submissions_with_status($submitted), + $instance->cutoffdate, + $instance->duedate, $this->get_course_module()->id, $this->count_submissions_need_grading(), - $this->get_instance()->teamsubmission); + $instance->teamsubmission); $o .= $this->get_renderer()->render($summary); } else { $summary = new assign_grading_summary($this->count_participants(0), - $this->get_instance()->submissiondrafts, - $this->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_DRAFT), + $instance->submissiondrafts, + $this->count_submissions_with_status($draft), $this->is_any_submission_plugin_enabled(), - $this->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED), - $this->get_instance()->cutoffdate, - $this->get_instance()->duedate, + $this->count_submissions_with_status($submitted), + $instance->cutoffdate, + $instance->duedate, $this->get_course_module()->id, $this->count_submissions_need_grading(), - $this->get_instance()->teamsubmission); + $instance->teamsubmission); $o .= $this->get_renderer()->render($summary); } } @@ -2955,29 +3090,25 @@ class assign { $o .= $this->view_student_summary($USER, true); } - $o .= $this->view_footer(); $this->add_to_log('view', get_string('viewownsubmissionstatus', 'assign')); return $o; } /** - * convert the final raw grade(s) in the grading table for the gradebook + * Convert the final raw grade(s) in the grading table for the gradebook. * * @param stdClass $grade * @return array */ private function convert_grade_for_gradebook(stdClass $grade) { $gradebookgrade = array(); - // trying to match those array keys in grade update function in gradelib.php - // with keys in th database table assign_grades - // starting around line 262 if ($grade->grade >= 0) { $gradebookgrade['rawgrade'] = $grade->grade; } $gradebookgrade['userid'] = $grade->userid; $gradebookgrade['usermodified'] = $grade->grader; - $gradebookgrade['datesubmitted'] = NULL; + $gradebookgrade['datesubmitted'] = null; $gradebookgrade['dategraded'] = $grade->timemodified; if (isset($grade->feedbackformat)) { $gradebookgrade['feedbackformat'] = $grade->feedbackformat; @@ -2990,7 +3121,7 @@ class assign { } /** - * convert submission details for the gradebook + * Convert submission details for the gradebook. * * @param stdClass $submission * @return array @@ -2998,7 +3129,6 @@ class assign { private function convert_submission_for_gradebook(stdClass $submission) { $gradebookgrade = array(); - $gradebookgrade['userid'] = $submission->userid; $gradebookgrade['usermodified'] = $submission->userid; $gradebookgrade['datesubmitted'] = $submission->timemodified; @@ -3007,19 +3137,20 @@ class assign { } /** - * update grades in the gradebook + * Update grades in the gradebook. * * @param mixed $submission stdClass|null * @param mixed $grade stdClass|null * @return bool */ - private function gradebook_item_update($submission=NULL, $grade=NULL) { + private function gradebook_item_update($submission=null, $grade=null) { - // Do not push grade to gradebook if blind marking is active as the gradebook would reveal the students. + // Do not push grade to gradebook if blind marking is active as + // the gradebook would reveal the students. if ($this->is_blind_marking()) { return false; } - if ($submission != NULL) { + if ($submission != null) { if ($submission->userid == 0) { // This is a group submission update. $team = groups_get_members($submission->groupid, 'u.id'); @@ -3048,7 +3179,7 @@ class assign { } /** - * update team submission + * Update team submission. * * @param stdClass $submission * @param int $userid @@ -3107,7 +3238,7 @@ class assign { /** - * update grades in the gradebook based on submission time + * Update grades in the gradebook based on submission time. * * @param stdClass $submission * @param int $userid @@ -3190,7 +3321,7 @@ class assign { if ($submission) { if ($this->get_instance()->submissiondrafts && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) { - // drafts are tracked and the student has submitted the assignment + // Drafts are tracked and the student has submitted the assignment. return false; } } @@ -3208,7 +3339,8 @@ class assign { } /** - * render the files in file area + * Render the files in file area. + * * @param string $component * @param string $area * @param int $submissionid @@ -3219,28 +3351,33 @@ class assign { $fs = get_file_storage(); $browser = get_file_browser(); - $files = $fs->get_area_files($this->get_context()->id, $component, $area , $submissionid , "timemodified", false); + $files = $fs->get_area_files($this->get_context()->id, + $component, + $area, + $submissionid, + 'timemodified', + false); return $this->get_renderer()->assign_files($this->context, $submissionid, $area, $component); } /** - * Returns a list of teachers that should be grading given submission + * Returns a list of teachers that should be grading given submission. * * @param int $userid * @return array */ private function get_graders($userid) { - //potential graders - $potentialgraders = get_enrolled_users($this->context, "mod/assign:grade"); + $potentialgraders = get_enrolled_users($this->context, 'mod/assign:grade'); $graders = array(); - if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) { // Separate groups are being used - if ($groups = groups_get_all_groups($this->get_course()->id, $userid)) { // Try to find all groups + if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) { + if ($groups = groups_get_all_groups($this->get_course()->id, $userid)) { foreach ($groups as $group) { foreach ($potentialgraders as $grader) { if ($grader->id == $userid) { - continue; // do not send self + // Do not send self. + continue; } if (groups_is_member($group->id, $grader->id)) { $graders[$grader->id] = $grader; @@ -3248,10 +3385,11 @@ class assign { } } } else { - // user not in group, try to find graders without group + // User not in group, try to find graders without group. foreach ($potentialgraders as $grader) { if ($grader->id == $userid) { - continue; // do not send self + // Do not send self. + continue; } if (!groups_has_membership($this->get_course_module(), $grader->id)) { $graders[$grader->id] = $grader; @@ -3261,9 +3399,10 @@ class assign { } else { foreach ($potentialgraders as $grader) { if ($grader->id == $userid) { - continue; // do not send self + // Do not send self. + continue; } - // must be enrolled + // Must be enrolled. if (is_enrolled($this->get_course_context(), $grader->id)) { $graders[$grader->id] = $grader; } @@ -3273,7 +3412,7 @@ class assign { } /** - * Format a notification for plain text + * Format a notification for plain text. * * @param string $messagetype * @param stdClass $info @@ -3282,18 +3421,26 @@ class assign { * @param string $modulename * @param string $assignmentname */ - private static function format_notification_message_text($messagetype, $info, $course, $context, $modulename, $assignmentname) { - $posttext = format_string($course->shortname, true, array('context' => $context->get_course_context())).' -> '. - $modulename.' -> '. - format_string($assignmentname, true, array('context' => $context))."\n"; - $posttext .= '---------------------------------------------------------------------'."\n"; - $posttext .= get_string($messagetype . 'text', "assign", $info)."\n"; + private static function format_notification_message_text($messagetype, + $info, + $course, + $context, + $modulename, + $assignmentname) { + $formatparams = array('context' => $context->get_course_context()); + $posttext = format_string($course->shortname, true, $formatparams) . + ' -> ' . + $modulename . + ' -> ' . + format_string($assignmentname, true, $formatparams) . "\n"; + $posttext .= '---------------------------------------------------------------------' . "\n"; + $posttext .= get_string($messagetype . 'text', 'assign', $info)."\n"; $posttext .= "\n---------------------------------------------------------------------\n"; return $posttext; } /** - * Format a notification for HTML + * Format a notification for HTML. * * @param string $messagetype * @param stdClass $info @@ -3304,20 +3451,33 @@ class assign { * @param string $assignmentname * @param stdClass $info */ - private static function format_notification_message_html($messagetype, $info, $course, $context, $modulename, $coursemodule, $assignmentname) { + private static function format_notification_message_html($messagetype, + $info, + $course, + $context, + $modulename, + $coursemodule, + $assignmentname) { global $CFG; - $posthtml = '

'. - ''.format_string($course->shortname, true, array('context' => $context->get_course_context())).' ->'. - ''.$modulename.' ->'. - ''.format_string($assignmentname, true, array('context' => $context)).'

'; + $formatparams = array('context' => $context->get_course_context()); + $posthtml = '

' . + '' . + format_string($course->shortname, true, $formatparams) . + ' ->' . + '' . + $modulename . + ' ->' . + '' . + format_string($assignmentname, true, $formatparams) . + '

'; $posthtml .= '
'; - $posthtml .= '

'.get_string($messagetype . 'html', 'assign', $info).'

'; + $posthtml .= '

' . get_string($messagetype . 'html', 'assign', $info) . '

'; $posthtml .= '

'; return $posthtml; } /** - * Message someone about something (static so it can be called from cron) + * Message someone about something (static so it can be called from cron). * * @param stdClass $userfrom * @param stdClass $userto @@ -3331,9 +3491,17 @@ class assign { * @param string $assignmentname * @return void */ - public static function send_assignment_notification($userfrom, $userto, $messagetype, $eventtype, - $updatetime, $coursemodule, $context, $course, - $modulename, $assignmentname, $blindmarking, + public static function send_assignment_notification($userfrom, + $userto, + $messagetype, + $eventtype, + $updatetime, + $coursemodule, + $context, + $course, + $modulename, + $assignmentname, + $blindmarking, $uniqueidforuser) { global $CFG; @@ -3343,13 +3511,27 @@ class assign { } else { $info->username = fullname($userfrom, true); } - $info->assignment = format_string($assignmentname,true, array('context'=>$context)); + $info->assignment = format_string($assignmentname, true, array('context'=>$context)); $info->url = $CFG->wwwroot.'/mod/assign/view.php?id='.$coursemodule->id; $info->timeupdated = userdate($updatetime, get_string('strftimerecentfull')); $postsubject = get_string($messagetype . 'small', 'assign', $info); - $posttext = self::format_notification_message_text($messagetype, $info, $course, $context, $modulename, $assignmentname); - $posthtml = ($userto->mailformat == 1) ? self::format_notification_message_html($messagetype, $info, $course, $context, $modulename, $coursemodule, $assignmentname) : ''; + $posttext = self::format_notification_message_text($messagetype, + $info, + $course, + $context, + $modulename, + $assignmentname); + $posthtml = ''; + if ($userto->mailformat == 1) { + $posthtml = self::format_notification_message_html($messagetype, + $info, + $course, + $context, + $modulename, + $coursemodule, + $assignmentname); + } $eventdata = new stdClass(); $eventdata->modulename = 'assign'; @@ -3371,7 +3553,7 @@ class assign { } /** - * Message someone about something + * Message someone about something. * * @param stdClass $userfrom * @param stdClass $userto @@ -3380,16 +3562,27 @@ class assign { * @param int $updatetime * @return void */ - public function send_notification($userfrom, $userto, $messagetype, $eventtype, $updatetime) { - self::send_assignment_notification($userfrom, $userto, $messagetype, $eventtype, - $updatetime, $this->get_course_module(), $this->get_context(), - $this->get_course(), $this->get_module_name(), - $this->get_instance()->name, $this->is_blind_marking(), + public function send_notification($userfrom, + $userto, + $messagetype, + $eventtype, + $updatetime) { + self::send_assignment_notification($userfrom, + $userto, + $messagetype, + $eventtype, + $updatetime, + $this->get_course_module(), + $this->get_context(), + $this->get_course(), + $this->get_module_name(), + $this->get_instance()->name, + $this->is_blind_marking(), $this->get_uniqueid_for_user($userfrom->id)); } /** - * Notify student upon successful submission + * Notify student upon successful submission. * * @param stdClass $submission * @return void @@ -3399,7 +3592,7 @@ class assign { $adminconfig = $this->get_admin_config(); if (empty($adminconfig->submissionreceipts)) { - // No need to do anything + // No need to do anything. return; } if ($submission->userid) { @@ -3407,11 +3600,15 @@ class assign { } else { $user = $USER; } - $this->send_notification($user, $user, 'submissionreceipt', 'assign_notification', $submission->timemodified); + $this->send_notification($user, + $user, + 'submissionreceipt', + 'assign_notification', + $submission->timemodified); } /** - * Send notifications to graders upon student submissions + * Send notifications to graders upon student submissions. * * @param stdClass $submission * @return void @@ -3419,9 +3616,12 @@ class assign { private function notify_graders(stdClass $submission) { global $DB, $USER; - $late = $this->get_instance()->duedate && ($this->get_instance()->duedate < time()); + $instance = $this->get_instance(); - if (!$this->get_instance()->sendnotifications && !($late && $this->get_instance()->sendlatenotifications)) { // No need to do anything + $late = $instance->duedate && ($instance->duedate < time()); + + if (!$instance->sendnotifications && !($late && $instance->sendlatenotifications)) { + // No need to do anything. return; } @@ -3432,29 +3632,35 @@ class assign { } if ($teachers = $this->get_graders($user->id)) { foreach ($teachers as $teacher) { - $this->send_notification($user, $teacher, 'gradersubmissionupdated', 'assign_notification', $submission->timemodified); + $this->send_notification($user, + $teacher, + 'gradersubmissionupdated', + 'assign_notification', + $submission->timemodified); } } } /** - * assignment submission is processed before grading + * Assignment submission is processed before grading. * - * @param $mform If validation failed when submitting this form - this is the moodleform - it can be null + * @param $mform If validation failed when submitting this form - this is the moodleform. + * It can be null. * @return bool Return false if the validation fails. This affects which page is displayed next. */ private function process_submit_for_grading($mform) { global $USER, $CFG; - // Need submit permission to submit an assignment + // Need submit permission to submit an assignment. require_capability('mod/assign:submit', $this->context); require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php'); require_sesskey(); + $instance = $this->get_instance(); $data = new stdClass(); $adminconfig = $this->get_admin_config(); $requiresubmissionstatement = (!empty($adminconfig->requiresubmissionstatement) || - $this->get_instance()->requiresubmissionstatement) && + $instance->requiresubmissionstatement) && !empty($adminconfig->submissionstatement); $submissionstatement = ''; @@ -3474,32 +3680,36 @@ class assign { if ($mform->get_data() == false) { return false; } - if ($this->get_instance()->teamsubmission) { + if ($instance->teamsubmission) { $submission = $this->get_group_submission($USER->id, 0, true); } else { $submission = $this->get_user_submission($USER->id, true); } if ($submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) { - // Give each submission plugin a chance to process the submission + // Give each submission plugin a chance to process the submission. $plugins = $this->get_submission_plugins(); foreach ($plugins as $plugin) { $plugin->submit_for_grading(); } $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; - $this->update_submission($submission, $USER->id, true, $this->get_instance()->teamsubmission); + $this->update_submission($submission, $USER->id, true, $instance->teamsubmission); $completion = new completion_info($this->get_course()); - if ($completion->is_enabled($this->get_course_module()) && $this->get_instance()->completionsubmit) { + if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) { $completion->update_state($this->get_course_module(), COMPLETION_COMPLETE, $USER->id); } if (isset($data->submissionstatement)) { - $this->add_to_log('submission statement accepted', get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER))); + $logmessage = get_string('submissionstatementacceptedlog', + 'mod_assign', + fullname($USER)); + $this->add_to_log('submission statement accepted', $logmessage); } $this->add_to_log('submit for grading', $this->format_submission_for_log($submission)); $this->notify_graders($submission); $this->notify_student_submission_receipt($submission); + // Trigger assessable_submitted event on submission. $eventdata = new stdClass(); $eventdata->modulename = 'assign'; @@ -3507,9 +3717,7 @@ class assign { $eventdata->itemid = $submission->id; $eventdata->courseid = $this->get_course()->id; $eventdata->userid = $USER->id; - $eventdata->params = array( - 'submission_editable' => false, - ); + $eventdata->params = array( 'submission_editable' => false); events_trigger('assessable_submitted', $eventdata); } } @@ -3517,7 +3725,7 @@ class assign { } /** - * save the extension date for a single user + * Save the extension date for a single user. * * @param int $userid The user id * @param mixed $extensionduedate Either an integer date or null @@ -3539,7 +3747,7 @@ class assign { } /** - * save extension date + * Save extension date. * * @param moodleform $mform The submitted form * @return boolean @@ -3586,17 +3794,17 @@ class assign { /** - * save quick grades + * Save quick grades. * * @return string The result of the save operation */ private function process_save_quick_grades() { global $USER, $DB, $CFG; - // Need grade permission + // Need grade permission. require_capability('mod/assign:grade', $this->context); - // make sure advanced grading is disabled + // Make sure advanced grading is disabled. $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions'); $controller = $gradingmanager->get_active_controller(); if (!empty($controller)) { @@ -3604,28 +3812,32 @@ class assign { } $users = array(); - // first check all the last modified values + // First check all the last modified values. $currentgroup = groups_get_activity_group($this->get_course_module(), true); $participants = $this->list_participants($currentgroup, true); - // gets a list of possible users and look for values based upon that. + // Gets a list of possible users and look for values based upon that. foreach ($participants as $userid => $unused) { $modified = optional_param('grademodified_' . $userid, -1, PARAM_INT); // Gather the userid, updated grade and last modified value. $record = new stdClass(); $record->userid = $userid; - $gradevalue = optional_param('quickgrade_' . $userid, '', PARAM_TEXT); - if($modified >= 0) { + if ($modified >= 0) { $record->grade = unformat_float(optional_param('quickgrade_' . $record->userid, -1, PARAM_TEXT)); } $record->lastmodified = $modified; - $record->gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, array($userid)); + $record->gradinginfo = grade_get_grades($this->get_course()->id, + 'mod', + 'assign', + $this->get_instance()->id, + array($userid)); $users[$userid] = $record; } list($userids, $params) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED); $params['assignment'] = $this->get_instance()->id; - // check them all for currency + + // Check them all for currency. $sql = 'SELECT u.id as userid, g.grade as grade, g.timemodified as lastmodified FROM {user} u LEFT JOIN {assign_grades} g ON u.id = g.userid AND g.assignment = :assignment @@ -3637,20 +3849,21 @@ class assign { $modified = $users[(int)$current->userid]; $grade = $this->get_user_grade($modified->userid, false); - // check to see if the outcomes were modified + // Check to see if the outcomes were modified. if ($CFG->enableoutcomes) { foreach ($modified->gradinginfo->outcomes as $outcomeid => $outcome) { $oldoutcome = $outcome->grades[$modified->userid]->grade; - $newoutcome = optional_param('outcome_' . $outcomeid . '_' . $modified->userid, -1, PARAM_FLOAT); + $paramname = 'outcome_' . $outcomeid . '_' . $modified->userid; + $newoutcome = optional_param($paramname, -1, PARAM_FLOAT); if ($oldoutcome != $newoutcome) { - // can't check modified time for outcomes because it is not reported + // Can't check modified time for outcomes because it is not reported. $modifiedusers[$modified->userid] = $modified; continue; } } } - // let plugins participate + // Let plugins participate. foreach ($this->feedbackplugins as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->supports_quickgrading()) { if ($plugin->is_quickgrading_modified($modified->userid, $grade)) { @@ -3664,23 +3877,22 @@ class assign { } } - - if (($current->grade < 0 || $current->grade === NULL) && - ($modified->grade < 0 || $modified->grade === NULL)) { - // different ways to indicate no grade + if (($current->grade < 0 || $current->grade === null) && + ($modified->grade < 0 || $modified->grade === null)) { + // Different ways to indicate no grade. continue; } - // Treat 0 and null as different values + // Treat 0 and null as different values. if ($current->grade !== null) { $current->grade = floatval($current->grade); } if ($current->grade !== $modified->grade) { - // grade changed + // Grade changed. if ($this->grading_disabled($modified->userid)) { continue; } if ((int)$current->lastmodified > (int)$modified->lastmodified) { - // error - record has been modified since viewing the page + // Error - record has been modified since viewing the page. return get_string('errorrecordmodified', 'assign'); } else { $modifiedusers[$modified->userid] = $modified; @@ -3693,13 +3905,13 @@ class assign { $adminconfig = $this->get_admin_config(); $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook; - // ok - ready to process the updates + // Ok - ready to process the updates. foreach ($modifiedusers as $userid => $modified) { $grade = $this->get_user_grade($userid, true); $grade->grade= grade_floatval(unformat_float($modified->grade)); $grade->grader= $USER->id; - // save plugins data + // Save plugins data. foreach ($this->feedbackplugins as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->supports_quickgrading()) { $plugin->save_quickgrading_changes($userid, $grade); @@ -3713,18 +3925,25 @@ class assign { $this->update_grade($grade); - // save outcomes + // Save outcomes. if ($CFG->enableoutcomes) { $data = array(); foreach ($modified->gradinginfo->outcomes as $outcomeid => $outcome) { $oldoutcome = $outcome->grades[$modified->userid]->grade; - $newoutcome = optional_param('outcome_' . $outcomeid . '_' . $modified->userid, -1, PARAM_INT); + $paramname = 'outcome_' . $outcomeid . '_' . $modified->userid; + $newoutcome = optional_param($paramname, -1, PARAM_INT); if ($oldoutcome != $newoutcome) { $data[$outcomeid] = $newoutcome; } } if (count($data) > 0) { - grade_update_outcomes('mod/assign', $this->course->id, 'mod', 'assign', $this->get_instance()->id, $userid, $data); + grade_update_outcomes('mod/assign', + $this->course->id, + 'mod', + 'assign', + $this->get_instance()->id, + $userid, + $data); } } @@ -3735,7 +3954,7 @@ class assign { } /** - * Reveal student identities to markers (and the gradebook) + * Reveal student identities to markers (and the gradebook). * * @return void */ @@ -3774,7 +3993,7 @@ class assign { $grade->feedbacktext = $plugin->text_for_gradebook($grade); $grade->feedbackformat = $plugin->format_for_gradebook($grade); } - $this->gradebook_item_update(NULL, $grade); + $this->gradebook_item_update(null, $grade); } $this->add_to_log('reveal identities', get_string('revealidentities', 'assign')); @@ -3782,24 +4001,26 @@ class assign { /** - * save grading options + * Save grading options. * * @return void */ private function process_save_grading_options() { global $USER, $CFG; - // Include grading options form + // Include grading options form. require_once($CFG->dirroot . '/mod/assign/gradingoptionsform.php'); - // Need submit permission to submit an assignment + // Need submit permission to submit an assignment. require_capability('mod/assign:grade', $this->context); - $mform = new mod_assign_grading_options_form(null, array('cm'=>$this->get_course_module()->id, - 'contextid'=>$this->context->id, - 'userid'=>$USER->id, - 'submissionsenabled'=>$this->is_any_submission_plugin_enabled(), - 'showquickgrading'=>false)); + $gradingoptionsparams = array('cm'=>$this->get_course_module()->id, + 'contextid'=>$this->context->id, + 'userid'=>$USER->id, + 'submissionsenabled'=>$this->is_any_submission_plugin_enabled(), + 'showquickgrading'=>false); + + $mform = new mod_assign_grading_options_form(null, $gradingoptionsparams); if ($formdata = $mform->get_data()) { set_user_preference('assign_perpage', $formdata->perpage); if (isset($formdata->filter)) { @@ -3808,14 +4029,14 @@ class assign { } } - /** - * Take a grade object and print a short summary for the log file. - * The size limit for the log file is 255 characters, so be careful not - * to include too much information. - * - * @param stdClass $grade - * @return string - */ + /** + * Take a grade object and print a short summary for the log file. + * The size limit for the log file is 255 characters, so be careful not + * to include too much information. + * + * @param stdClass $grade + * @return string + */ public function format_grade_for_log(stdClass $grade) { global $DB; @@ -3846,26 +4067,26 @@ class assign { */ private function format_submission_for_log(stdClass $submission) { $info = ''; - $info .= get_string('submissionstatus', 'assign') . ': ' . get_string('submissionstatus_' . $submission->status, 'assign') . '.
'; - // format_for_log here iterating every single log INFO from either submission or grade in every assignment plugin + $info .= get_string('submissionstatus', 'assign') . + ': ' . + get_string('submissionstatus_' . $submission->status, 'assign') . + '.
'; foreach ($this->submissionplugins as $plugin) { if ($plugin->is_enabled() && $plugin->is_visible()) { - - - $info .= "
" . $plugin->format_for_log($submission); + $info .= '
' . $plugin->format_for_log($submission); } } - return $info; } /** - * save assignment submission + * Save assignment submission. * * @param moodleform $mform - * @param array $notices Any error messages that should be shown to the user at the top of the edit submission form. + * @param array $notices Any error messages that should be shown + * to the user at the top of the edit submission form. * @return bool */ private function process_save_submission(&$mform, &$notices) { @@ -3877,6 +4098,7 @@ class assign { // Need submit permission to submit an assignment. require_capability('mod/assign:submit', $this->context); require_sesskey(); + $instance = $this->get_instance(); $data = new stdClass(); $mform = new mod_assign_submission_form(null, array($this, $data)); @@ -3884,24 +4106,25 @@ class assign { return true; } if ($data = $mform->get_data()) { - if ($this->get_instance()->teamsubmission) { + if ($instance->teamsubmission) { $submission = $this->get_group_submission($USER->id, 0, true); } else { $submission = $this->get_user_submission($USER->id, true); } - if ($this->get_instance()->submissiondrafts) { + if ($instance->submissiondrafts) { $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT; } else { $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } - $grade = $this->get_user_grade($USER->id, false); // get the grade to check if it is locked + $grade = $this->get_user_grade($USER->id, false); + + // Get the grade to check if it is locked. if ($grade && $grade->locked) { print_error('submissionslocked', 'assign'); return true; } - $allempty = true; $pluginerror = false; foreach ($this->submissionplugins as $plugin) { @@ -3922,11 +4145,14 @@ class assign { return false; } - $this->update_submission($submission, $USER->id, true, $this->get_instance()->teamsubmission); + $this->update_submission($submission, $USER->id, true, $instance->teamsubmission); - // Logging + // Logging. if (isset($data->submissionstatement)) { - $this->add_to_log('submission statement accepted', get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER))); + $logmessage = get_string('submissionstatementacceptedlog', + 'mod_assign', + fullname($USER)); + $this->add_to_log('submission statement accepted', $logmessage); } $this->add_to_log('submit', $this->format_submission_for_log($submission)); @@ -3935,11 +4161,11 @@ class assign { $complete = COMPLETION_COMPLETE; } $completion = new completion_info($this->get_course()); - if ($completion->is_enabled($this->get_course_module()) && $this->get_instance()->completionsubmit) { + if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) { $completion->update_state($this->get_course_module(), $complete, $USER->id); } - if (!$this->get_instance()->submissiondrafts) { + if (!$instance->submissiondrafts) { $this->notify_student_submission_receipt($submission); $this->notify_graders($submission); // Trigger assessable_submitted event on submission. @@ -3961,7 +4187,7 @@ class assign { /** - * Determine if this users grade is locked or overridden + * Determine if this users grade is locked or overridden. * * @param int $userid - The student userid * @return bool $gradingdisabled @@ -3969,7 +4195,11 @@ class assign { public function grading_disabled($userid) { global $CFG; - $gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, array($userid)); + $gradinginfo = grade_get_grades($this->get_course()->id, + 'mod', + 'assign', + $this->get_instance()->id, + array($userid)); if (!$gradinginfo) { return false; } @@ -3977,14 +4207,15 @@ class assign { if (!isset($gradinginfo->items[0]->grades[$userid])) { return false; } - $gradingdisabled = $gradinginfo->items[0]->grades[$userid]->locked || $gradinginfo->items[0]->grades[$userid]->overridden; + $gradingdisabled = $gradinginfo->items[0]->grades[$userid]->locked || + $gradinginfo->items[0]->grades[$userid]->overridden; return $gradingdisabled; } /** - * Get an instance of a grading form if advanced grading is enabled - * This is specific to the assignment, marker and student + * Get an instance of a grading form if advanced grading is enabled. + * This is specific to the assignment, marker and student. * * @param int $userid - The student userid * @param bool $gradingdisabled @@ -4007,10 +4238,12 @@ class assign { $itemid = $grade->id; } if ($gradingdisabled && $itemid) { - $gradinginstance = ($controller->get_current_instance($USER->id, $itemid)); + $gradinginstance = $controller->get_current_instance($USER->id, $itemid); } else if (!$gradingdisabled) { $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT); - $gradinginstance = ($controller->get_or_create_instance($instanceid, $USER->id, $itemid)); + $gradinginstance = $controller->get_or_create_instance($instanceid, + $USER->id, + $itemid); } } else { $advancedgradingwarning = $controller->form_unavailable_notification(); @@ -4023,7 +4256,7 @@ class assign { } /** - * add elements to grade form + * Add elements to grade form. * * @param MoodleQuickForm $mform * @param stdClass $data @@ -4040,21 +4273,25 @@ class assign { $userid = $useridlist[$rownum]; $grade = $this->get_user_grade($userid, false); - // add advanced grading + // Add advanced grading. $gradingdisabled = $this->grading_disabled($userid); $gradinginstance = $this->get_grading_instance($userid, $gradingdisabled); if ($gradinginstance) { - $gradingelement = $mform->addElement('grading', 'advancedgrading', get_string('grade').':', array('gradinginstance' => $gradinginstance)); + $gradingelement = $mform->addElement('grading', + 'advancedgrading', + get_string('grade').':', + array('gradinginstance' => $gradinginstance)); if ($gradingdisabled) { $gradingelement->freeze(); } else { $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id()); } } else { - // use simple direct grading + // Use simple direct grading. if ($this->get_instance()->grade > 0) { - $gradingelement = $mform->addElement('text', 'grade', get_string('gradeoutof', 'assign',$this->get_instance()->grade)); + $name = get_string('gradeoutof', 'assign', $this->get_instance()->grade); + $gradingelement = $mform->addElement('text', 'grade', $name); $mform->addHelpButton('grade', 'gradeoutofhelp', 'assign'); $mform->setType('grade', PARAM_TEXT); if ($gradingdisabled) { @@ -4063,7 +4300,7 @@ class assign { } else { $grademenu = make_grades_menu($this->get_instance()->grade); if (count($grademenu) > 0) { - $gradingelement = $mform->addElement('select', 'grade', get_string('grade').':', $grademenu); + $gradingelement = $mform->addElement('select', 'grade', get_string('grade') . ':', $grademenu); // The grade is already formatted with format_float so it needs to be converted back to an integer. if (!empty($data->grade)) { @@ -4083,38 +4320,49 @@ class assign { $this->get_instance()->id, $userid); if (!empty($CFG->enableoutcomes)) { - foreach($gradinginfo->outcomes as $index=>$outcome) { + foreach ($gradinginfo->outcomes as $index => $outcome) { $options = make_grades_menu(-$outcome->scaleid); if ($outcome->grades[$userid]->locked) { $options[0] = get_string('nooutcome', 'grades'); - $mform->addElement('static', 'outcome_'.$index.'['.$userid.']', $outcome->name.':', - $options[$outcome->grades[$userid]->grade]); + $mform->addElement('static', + 'outcome_' . $index . '[' . $userid . ']', + $outcome->name . ':', + $options[$outcome->grades[$userid]->grade]); } else { $options[''] = get_string('nooutcome', 'grades'); - $attributes = array('id' => 'menuoutcome_'.$index ); - $mform->addElement('select', 'outcome_'.$index.'['.$userid.']', $outcome->name.':', $options, $attributes ); - $mform->setType('outcome_'.$index.'['.$userid.']', PARAM_INT); - $mform->setDefault('outcome_'.$index.'['.$userid.']', $outcome->grades[$userid]->grade ); + $attributes = array('id' => 'menuoutcome_' . $index ); + $mform->addElement('select', + 'outcome_' . $index . '[' . $userid . ']', + $outcome->name.':', + $options, + $attributes); + $mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT); + $mform->setDefault('outcome_' . $index . '[' . $userid . ']', + $outcome->grades[$userid]->grade); } } } - if (has_all_capabilities(array('gradereport/grader:view', 'moodle/grade:viewall'), $this->get_course_context())) { - $gradestring = $this->get_renderer()->action_link(new moodle_url('/grade/report/grader/index.php', - array('id'=>$this->get_course()->id)), - $gradinginfo->items[0]->grades[$userid]->str_grade); + $capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall'); + if (has_all_capabilities($capabilitylist, $this->get_course_context())) { + $urlparams = array('id'=>$this->get_course()->id); + $url = new moodle_url('/grade/report/grader/index.php', $urlparams); + $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade; + $gradestring = $this->get_renderer()->action_link($url, $usergrade); } else { $gradestring = $gradinginfo->items[0]->grades[$userid]->str_grade; } - $mform->addElement('static', 'finalgrade', get_string('currentgrade', 'assign').':', $gradestring); + $name = get_string('currentgrade', 'assign') . ':' . $gradestring; + $mform->addElement('static', 'finalgrade', $name); - - $mform->addElement('static', 'progress', '', get_string('gradingstudentprogress', 'assign', array('index'=>$rownum+1, 'count'=>count($useridlist)))); + $strparams = array('index'=>$rownum+1, 'count'=>count($useridlist)); + $name = get_string('gradingstudentprogress', 'assign', $strparams); + $mform->addElement('static', 'progress', '', $name); // Let feedback plugins add elements to the grading form. $this->add_plugin_grade_elements($grade, $mform, $data, $userid); - // hidden params + // Hidden params. $mform->addElement('hidden', 'id', $this->get_course_module()->id); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'rownum', $rownum); @@ -4133,11 +4381,12 @@ class assign { $mform->addElement('hidden', 'action', 'submitgrade'); $mform->setType('action', PARAM_ALPHA); - $buttonarray=array(); - $buttonarray[] = $mform->createElement('submit', 'savegrade', get_string('savechanges', 'assign')); + $name = get_string('savechanges', 'assign'); + $buttonarray[] = $mform->createElement('submit', 'savegrade', $name); if (!$last) { - $buttonarray[] = $mform->createElement('submit', 'saveandshownext', get_string('savenext','assign')); + $name = get_string('savenext', 'assign'); + $buttonarray[] = $mform->createElement('submit', 'saveandshownext', $name); } $buttonarray[] = $mform->createElement('cancel', 'cancelbutton', get_string('cancel')); $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); @@ -4145,20 +4394,21 @@ class assign { $buttonarray=array(); if ($rownum > 0) { - $buttonarray[] = $mform->createElement('submit', 'nosaveandprevious', get_string('previous','assign')); + $name = get_string('previous', 'assign'); + $buttonarray[] = $mform->createElement('submit', 'nosaveandprevious', $name); } if (!$last) { - $buttonarray[] = $mform->createElement('submit', 'nosaveandnext', get_string('nosavebutnext', 'assign')); + $name = get_string('nosavebutnext', 'assign'); + $buttonarray[] = $mform->createElement('submit', 'nosaveandnext', $name); } if (!empty($buttonarray)) { $mform->addGroup($buttonarray, 'navar', '', array(' '), false); } } - /** - * add elements in submission plugin form + * Add elements in submission plugin form. * * @param mixed $submission stdClass|null * @param MoodleQuickForm $mform @@ -4166,7 +4416,10 @@ class assign { * @param int $userid The current userid (same as $USER->id) * @return void */ - private function add_plugin_submission_elements($submission, MoodleQuickForm $mform, stdClass $data, $userid) { + private function add_plugin_submission_elements($submission, + MoodleQuickForm $mform, + stdClass $data, + $userid) { foreach ($this->submissionplugins as $plugin) { if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions()) { $mform->addElement('header', 'header_' . $plugin->get_type(), $plugin->get_name()); @@ -4178,7 +4431,7 @@ class assign { } /** - * check if feedback plugins installed are enabled + * Check if feedback plugins installed are enabled. * * @return bool */ @@ -4198,7 +4451,7 @@ class assign { } /** - * check if submission plugins installed are enabled + * Check if submission plugins installed are enabled. * * @return bool */ @@ -4218,7 +4471,7 @@ class assign { } /** - * add elements to submission form + * Add elements to submission form. * @param MoodleQuickForm $mform * @param stdClass $data * @return void @@ -4254,18 +4507,16 @@ class assign { $this->add_plugin_submission_elements($submission, $mform, $data, $USER->id); - // hidden params + // Hidden params. $mform->addElement('hidden', 'id', $this->get_course_module()->id); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'action', 'savesubmission'); $mform->setType('action', PARAM_TEXT); - // buttons - } /** - * revert to draft + * Revert to draft. * Uses url parameter userid * * @param int $userid @@ -4274,7 +4525,7 @@ class assign { private function process_revert_to_draft($userid = 0) { global $DB, $USER; - // Need grade permission + // Need grade permission. require_capability('mod/assign:grade', $this->context); require_sesskey(); @@ -4302,23 +4553,27 @@ class assign { $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); $completion = new completion_info($this->get_course()); - if ($completion->is_enabled($this->get_course_module()) && $this->get_instance()->completionsubmit) { + if ($completion->is_enabled($this->get_course_module()) && + $this->get_instance()->completionsubmit) { $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid); } - $this->add_to_log('revert submission to draft', get_string('reverttodraftforstudent', 'assign', array('id'=>$user->id, 'fullname'=>fullname($user)))); - + $logmessage = get_string('reverttodraftforstudent', + 'assign', + array('id'=>$user->id, 'fullname'=>fullname($user))); + $this->add_to_log('revert submission to draft', $logmessage); } /** - * lock the process + * Lock the process. * Uses url parameter userid + * * @param int $userid * @return void */ private function process_lock($userid = 0) { global $USER, $DB; - // Need grade permission + // Need grade permission. require_capability('mod/assign:grade', $this->context); require_sesskey(); @@ -4333,11 +4588,14 @@ class assign { $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); - $this->add_to_log('lock submission', get_string('locksubmissionforstudent', 'assign', array('id'=>$user->id, 'fullname'=>fullname($user)))); + $logmessage = get_string('locksubmissionforstudent', + 'assign', + array('id'=>$user->id, 'fullname'=>fullname($user))); + $this->add_to_log('lock submission', $logmessage); } /** - * unlock the process + * Unlock the process. * * @param int $userid * @return void @@ -4345,7 +4603,7 @@ class assign { private function process_unlock($userid = 0) { global $USER, $DB; - // Need grade permission + // Need grade permission. require_capability('mod/assign:grade', $this->context); require_sesskey(); @@ -4360,11 +4618,14 @@ class assign { $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); - $this->add_to_log('unlock submission', get_string('unlocksubmissionforstudent', 'assign', array('id'=>$user->id, 'fullname'=>fullname($user)))); + $logmessage = get_string('unlocksubmissionforstudent', + 'assign', + array('id'=>$user->id, 'fullname'=>fullname($user))); + $this->add_to_log('unlock submission', $logmessage); } - /** - * Apply a grade from a grading form to a user (may be called multiple times for a group submission) + /** + * Apply a grade from a grading form to a user (may be called multiple times for a group submission). * * @param stdClass $formdata - the data from the form * @param int $userid - the user to apply the grade to @@ -4378,7 +4639,8 @@ class assign { $gradinginstance = $this->get_grading_instance($userid, $gradingdisabled); if (!$gradingdisabled) { if ($gradinginstance) { - $grade->grade = $gradinginstance->submit_and_get_grade($formdata->advancedgrading, $grade->id); + $grade->grade = $gradinginstance->submit_and_get_grade($formdata->advancedgrading, + $grade->id); } else { // Handle the case when grade is set to No Grade. if (isset($formdata->grade)) { @@ -4413,7 +4675,7 @@ class assign { /** - * save outcomes submitted from grading form + * Save outcomes submitted from grading form * * @param int $userid * @param stdClass $formdata @@ -4438,32 +4700,38 @@ class assign { $userid); if (!empty($gradinginfo->outcomes)) { - foreach($gradinginfo->outcomes as $index=>$oldoutcome) { + foreach ($gradinginfo->outcomes as $index => $oldoutcome) { $name = 'outcome_'.$index; - if (isset($formdata->{$name}[$userid]) and $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$userid]) { + if (isset($formdata->{$name}[$userid]) && + $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$userid]) { $data[$index] = $formdata->{$name}[$userid]; } } } if (count($data) > 0) { - grade_update_outcomes('mod/assign', $this->course->id, 'mod', 'assign', $this->get_instance()->id, $userid, $data); + grade_update_outcomes('mod/assign', + $this->course->id, + 'mod', + 'assign', + $this->get_instance()->id, + $userid, + $data); } - } /** - * save grade + * Save grade. * * @param moodleform $mform * @return bool - was the grade saved */ private function process_save_grade(&$mform) { global $CFG; - // Include grade form + // Include grade form. require_once($CFG->dirroot . '/mod/assign/gradeform.php'); - // Need submit permission to submit an assignment + // Need submit permission to submit an assignment. require_capability('mod/assign:grade', $this->context); require_sesskey(); @@ -4481,7 +4749,13 @@ class assign { } $data = new stdClass(); - $mform = new mod_assign_grade_form(null, array($this, $data, array('rownum'=>$rownum, 'useridlist'=>$useridlist, 'last'=>false)), 'post', '', array('class'=>'gradeform')); + + $gradeformparams = array('rownum'=>$rownum, 'useridlist'=>$useridlist, 'last'=>false); + $mform = new mod_assign_grade_form(null, + array($this, $data, $gradeformparams), + 'post', + '', + array('class'=>'gradeform')); if ($formdata = $mform->get_data()) { if ($this->get_instance()->teamsubmission && $formdata->applytoall) { @@ -4509,7 +4783,7 @@ class assign { } /** - * This function is a static wrapper around can_upgrade + * This function is a static wrapper around can_upgrade. * * @param string $type The plugin type * @param int $version The plugin version @@ -4521,8 +4795,8 @@ class assign { } /** - * This function returns true if it can upgrade an assignment from the 2.2 - * module. + * This function returns true if it can upgrade an assignment from the 2.2 module. + * * @param string $type The plugin type * @param int $version The plugin version * @return bool @@ -4558,14 +4832,26 @@ class assign { * @param int $newitemid The new submissionid (can be null e.g. intro) * @return int The number of files copied */ - public function copy_area_files_for_upgrade($oldcontextid, $oldcomponent, $oldfilearea, $olditemid, $newcontextid, $newcomponent, $newfilearea, $newitemid) { + public function copy_area_files_for_upgrade($oldcontextid, + $oldcomponent, + $oldfilearea, + $olditemid, + $newcontextid, + $newcomponent, + $newfilearea, + $newitemid) { // Note, this code is based on some code in filestorage - but that code - // deleted the old files (which we don't want) + // deleted the old files (which we don't want). $count = 0; $fs = get_file_storage(); - $oldfiles = $fs->get_area_files($oldcontextid, $oldcomponent, $oldfilearea, $olditemid, 'id', false); + $oldfiles = $fs->get_area_files($oldcontextid, + $oldcomponent, + $oldfilearea, + $olditemid, + 'id', + false); foreach ($oldfiles as $oldfile) { $filerecord = new stdClass(); $filerecord->contextid = $newcontextid; @@ -4580,7 +4866,7 @@ class assign { } /** - * Get an upto date list of user grades and feedback for the gradebook + * Get an upto date list of user grades and feedback for the gradebook. * * @param int $userid int or 0 for all users * @return array of grade data formated for the gradebook api @@ -4601,7 +4887,7 @@ class assign { $gradebookpluginname = $adminconfig->feedback_plugin_for_gradebook; $gradebookplugin = null; - // find the gradebook plugin + // Find the gradebook plugin. foreach ($this->feedbackplugins as $plugin) { if ($plugin->is_enabled() && $plugin->is_visible()) { if (('assignfeedback_' . $plugin->get_type()) == $gradebookpluginname) { @@ -4615,16 +4901,22 @@ class assign { $where = ' WHERE u.id != ? '; } - $graderesults = $DB->get_recordset_sql('SELECT u.id as userid, s.timemodified as datesubmitted, g.grade as rawgrade, g.timemodified as dategraded, g.grader as usermodified - FROM {user} u - LEFT JOIN {assign_submission} s ON u.id = s.userid and s.assignment = ? - JOIN {assign_grades} g ON u.id = g.userid and g.assignment = ? - ' . $where, array($assignmentid, $assignmentid, $userid)); - + $graderesults = $DB->get_recordset_sql('SELECT + u.id as userid, + s.timemodified as datesubmitted, + g.grade as rawgrade, + g.timemodified as dategraded, + g.grader as usermodified + FROM {user} u + LEFT JOIN {assign_submission} s + ON u.id = s.userid and s.assignment = ? + JOIN {assign_grades} g + ON u.id = g.userid and g.assignment = ?' . + $where, array($assignmentid, $assignmentid, $userid)); foreach ($graderesults as $result) { $gradebookgrade = clone $result; - // now get the feedback + // Now get the feedback. if ($gradebookplugin) { $grade = $this->get_user_grade($result->userid, false); if ($grade) { @@ -4650,7 +4942,7 @@ class assign { } /** - * Foreach participant in the course - assign them a random id + * Foreach participant in the course - assign them a random id. * * @param int $assignid The assignid to lookup */ @@ -4663,13 +4955,17 @@ class assign { $currentgroup = groups_get_activity_group($cm, true); $users = get_enrolled_users($context, "mod/assign:submit", $currentgroup, 'u.id'); - // shuffle the users + // Shuffle the users. shuffle($users); $record = new stdClass(); $record->assignment = $assignid; foreach ($users as $user) { - if (!$DB->get_record('assign_user_mapping', array('assignment'=>$assignid, 'userid'=>$user->id), 'id')) { + $record = $DB->get_record('assign_user_mapping', + array('assignment'=>$assignid, 'userid'=>$user->id), + 'id'); + if (!$record) { + $record = new stdClass(); $record->userid = $user->id; $DB->insert_record('assign_user_mapping', $record); } @@ -4677,7 +4973,7 @@ class assign { } /** - * Lookup this user id and return the unique id for this assignment + * Lookup this user id and return the unique id for this assignment. * * @param int $userid The userid to lookup * @return int The unique id @@ -4686,16 +4982,18 @@ class assign { global $DB; // Search for a record. - if ($record = $DB->get_record('assign_user_mapping', array('assignment'=>$assignid, 'userid'=>$userid), 'id')) { + $params = array('assignment'=>$assignid, 'userid'=>$userid); + if ($record = $DB->get_record('assign_user_mapping', $params, 'id')) { return $record->id; } // Be a little smart about this - there is no record for the current user. - // We should ensure any unallocated ids for the current participant list are distrubited randomly + // We should ensure any unallocated ids for the current participant + // list are distrubited randomly. self::allocate_unique_ids($assignid); // Retry the search for a record. - if ($record = $DB->get_record('assign_user_mapping', array('assignment'=>$assignid, 'userid'=>$userid), 'id')) { + if ($record = $DB->get_record('assign_user_mapping', $params, 'id')) { return $record->id; } @@ -4708,7 +5006,7 @@ class assign { } /** - * Call the static version of this function + * Call the static version of this function. * * @param int $uniqueid The uniqueid to lookup * @return int The user id or false if they don't exist @@ -4718,7 +5016,7 @@ class assign { } /** - * Lookup this unique id and return the user id for this assignment + * Lookup this unique id and return the user id for this assignment. * * @param int $assignid The id of the assignment this user mapping is in * @param int $uniqueid The uniqueid to lookup @@ -4741,7 +5039,7 @@ class assign { } /** - * portfolio caller class for mod_assign. + * Portfolio caller class for mod_assign. * * @package mod_assign * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -4770,9 +5068,9 @@ class assign_portfolio_caller extends portfolio_module_caller_base { /** @var string callback arg - the name of the editor field we export */ protected $editor; - /** - * callback arg for a single file export - */ + /** + * Callback arg for a single file export. + */ public static function expected_callbackargs() { return array( 'cmid' => true, @@ -4782,25 +5080,26 @@ class assign_portfolio_caller extends portfolio_module_caller_base { 'fileid' => false, 'plugin' => false, 'editor' => false, - ); + ); } /** - * the constructor + * The constructor. + * * @param array $callbackargs */ - function __construct($callbackargs) { + public function __construct($callbackargs) { parent::__construct($callbackargs); $this->cm = get_coursemodule_from_id('assign', $this->cmid, 0, false, MUST_EXIST); } /** - * - * Load data needed for the portfolio export + * Load data needed for the portfolio export. * * If the assignment type implements portfolio_load_data(), the processing is delegated * to it. Otherwise, the caller must provide either fileid (to export single file) or - * submissionid and filearea (to export all data attached to the given submission file area) via callback arguments. + * submissionid and filearea (to export all data attached to the given submission file area) + * via callback arguments. * * @throws portfolio_caller_exception */ @@ -4815,15 +5114,21 @@ class assign_portfolio_caller extends portfolio_module_caller_base { } - // export either an area of files or a single file (see function for more detail) - // the first arg is an id or null. If it is an id, the rest of the args are ignored - // if it is null, the rest of the args are used to load a list of files from get_areafiles - $this->set_file_and_format_data($this->fileid, $context->id, $this->component, $this->area, $this->sid, 'timemodified', false); + // Export either an area of files or a single file (see function for more detail). + // The first arg is an id or null. If it is an id, the rest of the args are ignored. + // If it is null, the rest of the args are used to load a list of files from get_areafiles. + $this->set_file_and_format_data($this->fileid, + $context->id, + $this->component, + $this->area, + $this->sid, + 'timemodified', + false); } /** - * prepares the package up before control is passed to the portfolio plugin. + * Prepares the package up before control is passed to the portfolio plugin. * * @throws portfolio_caller_exception * @return mixed @@ -4841,9 +5146,15 @@ class assign_portfolio_caller extends portfolio_module_caller_base { $format = $plugin->get_editor_format($this->editor, $this->sid); $html = format_text($text, $format, $options); - $html = portfolio_rewrite_pluginfile_urls($html, $context->id, 'mod_assign', $this->area, $this->sid, $this->exporter->get('format')); + $html = portfolio_rewrite_pluginfile_urls($html, + $context->id, + 'mod_assign', + $this->area, + $this->sid, + $this->exporter->get('format')); - if (in_array($this->exporter->get('formatclass'), array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_RICHHTML))) { + $exporterclass = $this->exporter->get('formatclass'); + if (in_array($exporterclass, array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_RICHHTML))) { if ($files = $this->exporter->get('caller')->get('multifiles')) { foreach ($files as $file) { $this->exporter->copy_existing_file($file); @@ -4852,7 +5163,10 @@ class assign_portfolio_caller extends portfolio_module_caller_base { return $this->exporter->write_new_file($html, 'assignment.html', !empty($files)); } else if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { $leapwriter = $this->exporter->get('format')->leap2a_writer(); - $entry = new portfolio_format_leap2a_entry($this->area . $this->cmid, print_context_name($context), 'resource', $html); + $entry = new portfolio_format_leap2a_entry($this->area . $this->cmid, + print_context_name($context), + 'resource', + $html); $entry->add_category('web', 'resource_type'); $entry->author = $this->user; @@ -4863,23 +5177,26 @@ class assign_portfolio_caller extends portfolio_module_caller_base { $this->exporter->copy_existing_file($file); } } - return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true); + return $this->exporter->write_new_file($leapwriter->to_xml(), + $this->exporter->get('format')->manifest_name(), + true); } else { debugging('invalid format class: ' . $this->exporter->get('formatclass')); } } - if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { $leapwriter = $this->exporter->get('format')->leap2a_writer(); $files = array(); if ($this->singlefile) { $files[] = $this->singlefile; - } elseif ($this->multifiles) { + } else if ($this->multifiles) { $files = $this->multifiles; } else { - throw new portfolio_caller_exception('invalidpreparepackagefile', 'portfolio', $this->get_return_url()); + throw new portfolio_caller_exception('invalidpreparepackagefile', + 'portfolio', + $this->get_return_url()); } $entryids = array(); @@ -4894,18 +5211,22 @@ class assign_portfolio_caller extends portfolio_module_caller_base { $baseid = 'assign' . $this->cmid . $this->area; $context = context_module::instance($this->cmid); - // if we have multiple files, they should be grouped together into a folder - $entry = new portfolio_format_leap2a_entry($baseid . 'group', print_context_name($context), 'selection'); + // If we have multiple files, they should be grouped together into a folder. + $entry = new portfolio_format_leap2a_entry($baseid . 'group', + print_context_name($context), + 'selection'); $leapwriter->add_entry($entry); $leapwriter->make_selection($entry, $entryids, 'Folder'); } - return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true); + return $this->exporter->write_new_file($leapwriter->to_xml(), + $this->exporter->get('format')->manifest_name(), + true); } return $this->prepare_package_file(); } /** - * fetch the plugin by its type + * Fetch the plugin by its type. * * @return assign_submission_plugin */ @@ -4924,9 +5245,8 @@ class assign_portfolio_caller extends portfolio_module_caller_base { } /** - * get sha1 file - * calculate a sha1 has of either a single file or a list - * of files based on the data set by load_data + * Calculate a sha1 has of either a single file or a list + * of files based on the data set by load_data. * * @return string */ @@ -4937,20 +5257,24 @@ class assign_portfolio_caller extends portfolio_module_caller_base { $options = portfolio_format_text_options(); $options->context = context_module::instance($this->cmid); - $textsha1 = sha1(format_text($plugin->get_editor_text($this->editor, $this->sid), - $plugin->get_editor_format($this->editor, $this->sid), $options)); + $text = format_text($plugin->get_editor_text($this->editor, $this->sid), + $plugin->get_editor_format($this->editor, $this->sid), + $options); + $textsha1 = sha1($text); $filesha1 = ''; try { $filesha1 = $this->get_sha1_file(); - } catch (portfolio_caller_exception $e) {} // no files + } catch (portfolio_caller_exception $e) { + // No files. + } return sha1($textsha1 . $filesha1); } return $this->get_sha1_file(); } /** - * calculate the time to transfer either a single file or a list - * of files based on the data set by load_data + * Calculate the time to transfer either a single file or a list + * of files based on the data set by load_data. * * @return int */ @@ -4959,7 +5283,7 @@ class assign_portfolio_caller extends portfolio_module_caller_base { } /** - * checking the permissions + * Checking the permissions. * * @return bool */ @@ -4969,7 +5293,7 @@ class assign_portfolio_caller extends portfolio_module_caller_base { } /** - * display a module name + * Display a module name. * * @return string */ @@ -4978,12 +5302,11 @@ class assign_portfolio_caller extends portfolio_module_caller_base { } /** - * return array of formats supported by this portfolio call back + * Return array of formats supported by this portfolio call back. + * * @return array */ public static function base_supported_formats() { - return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A); - } } diff --git a/mod/assign/mod_form.php b/mod/assign/mod_form.php index 45d6c6d8582..70bc77b4412 100644 --- a/mod/assign/mod_form.php +++ b/mod/assign/mod_form.php @@ -24,10 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); - -/** Include moodleform_mod.php */ -require_once ($CFG->dirroot.'/course/moodleform_mod.php'); -/** Include locallib.php */ +require_once($CFG->dirroot.'/course/moodleform_mod.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); /** @@ -44,7 +41,7 @@ class mod_assign_mod_form extends moodleform_mod { * * @return void */ - function definition() { + public function definition() { global $CFG, $DB, $PAGE; $mform = $this->_form; @@ -70,49 +67,71 @@ class mod_assign_mod_form extends moodleform_mod { if (!$ctx) { $ctx = context_course::instance($this->current->course); } - $assignment->set_course($DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST)); + $course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST); + $assignment->set_course($course); } $config = get_config('assign'); $mform->addElement('header', 'general', get_string('settings', 'assign')); - $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'), array('optional'=>true)); + + $name = get_string('allowsubmissionsfromdate', 'assign'); + $options = array('optional'=>true); + $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options); $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign'); $mform->setDefault('allowsubmissionsfromdate', time()); - $mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'assign'), array('optional'=>true)); + + $name = get_string('duedate', 'assign'); + $mform->addElement('date_time_selector', 'duedate', $name, array('optional'=>true)); $mform->addHelpButton('duedate', 'duedate', 'assign'); $mform->setDefault('duedate', time()+7*24*3600); - $mform->addElement('date_time_selector', 'cutoffdate', get_string('cutoffdate', 'assign'), array('optional'=>true)); + + $name = get_string('cutoffdate', 'assign'); + $mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional'=>true)); $mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign'); $mform->setDefault('cutoffdate', time()+7*24*3600); - $mform->addElement('selectyesno', 'alwaysshowdescription', get_string('alwaysshowdescription', 'assign')); + + $name = get_string('alwaysshowdescription', 'assign'); + $mform->addElement('selectyesno', 'alwaysshowdescription', $name); $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign'); $mform->setDefault('alwaysshowdescription', 1); - $mform->addElement('selectyesno', 'submissiondrafts', get_string('submissiondrafts', 'assign')); + + $name = get_string('submissiondrafts', 'assign'); + $mform->addElement('selectyesno', 'submissiondrafts', $name); $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign'); $mform->setDefault('submissiondrafts', 0); - // submission statement + if (empty($config->submissionstatement)) { $mform->addElement('hidden', 'requiresubmissionstatement', 0); } else if (empty($config->requiresubmissionstatement)) { - $mform->addElement('selectyesno', 'requiresubmissionstatement', get_string('requiresubmissionstatement', 'assign')); + $name = get_string('requiresubmissionstatement', 'assign'); + $mform->addElement('selectyesno', 'requiresubmissionstatement', $name); $mform->setDefault('requiresubmissionstatement', 0); - $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatementassignment', 'assign'); + $mform->addHelpButton('requiresubmissionstatement', + 'requiresubmissionstatementassignment', + 'assign'); } else { $mform->addElement('hidden', 'requiresubmissionstatement', 1); } - $mform->addElement('selectyesno', 'sendnotifications', get_string('sendnotifications', 'assign')); + $name = get_string('sendnotifications', 'assign'); + $mform->addElement('selectyesno', 'sendnotifications', $name); $mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign'); $mform->setDefault('sendnotifications', 1); - $mform->addElement('selectyesno', 'sendlatenotifications', get_string('sendlatenotifications', 'assign')); + + $name = get_string('sendlatenotifications', 'assign'); + $mform->addElement('selectyesno', 'sendlatenotifications', $name); $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign'); $mform->setDefault('sendlatenotifications', 1); $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1); - $mform->addElement('selectyesno', 'teamsubmission', get_string('teamsubmission', 'assign')); + + $name = get_string('teamsubmission', 'assign'); + $mform->addElement('selectyesno', 'teamsubmission', $name); $mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign'); $mform->setDefault('teamsubmission', 0); - $mform->addElement('selectyesno', 'requireallteammemberssubmit', get_string('requireallteammemberssubmit', 'assign')); + + $name = get_string('requireallteammemberssubmit', 'assign'); + $mform->addElement('selectyesno', 'requireallteammemberssubmit', $name); $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign'); $mform->setDefault('requireallteammemberssubmit', 0); $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0); @@ -124,22 +143,23 @@ class mod_assign_mod_form extends moodleform_mod { foreach ($groupings as $grouping) { $options[$grouping->id] = $grouping->name; } - $mform->addElement('select', 'teamsubmissiongroupingid', get_string('teamsubmissiongroupingid', 'assign'), $options); + + $name = get_string('teamsubmissiongroupingid', 'assign'); + $mform->addElement('select', 'teamsubmissiongroupingid', $name, $options); $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign'); $mform->setDefault('teamsubmissiongroupingid', 0); $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0); - $mform->addElement('selectyesno', 'blindmarking', get_string('blindmarking', 'assign')); + $name = get_string('blindmarking', 'assign'); + $mform->addElement('selectyesno', 'blindmarking', $name); $mform->addHelpButton('blindmarking', 'blindmarking', 'assign'); $mform->setDefault('blindmarking', 0); if ($assignment->has_submissions_or_grades() ) { $mform->freeze('blindmarking'); } - - // plagiarism enabling form + // Plagiarism enabling form. if (!empty($CFG->enableplagiarism)) { - /** Include plagiarismlib.php */ require_once($CFG->libdir . '/plagiarismlib.php'); plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign'); } @@ -151,7 +171,13 @@ class mod_assign_mod_form extends moodleform_mod { $this->add_action_buttons(); // Add warning popup/noscript tag, if grades are changed by user. - if ($mform->elementExists('grade') && !empty($this->_instance) && $DB->record_exists_select('assign_grades', 'assignment = ? AND grade <> -1', array($this->_instance))) { + $hasgrade = false; + if (!empty($this->_instance)) { + $hasgrade = $DB->record_exists_select('assign_grades', + 'assignment = ? AND grade <> -1', + array($this->_instance)); + } + if ($mform->elementExists('grade') && $hasgrade) { $module = array( 'name' => 'mod_assign', 'fullpath' => '/mod/assign/module.js', @@ -160,8 +186,12 @@ class mod_assign_mod_form extends moodleform_mod { ); $PAGE->requires->js_init_call('M.mod_assign.init_grade_change', null, false, $module); - // Add noscript tag in case - $noscriptwarning = $mform->createElement('static', 'warning', null, html_writer::tag('noscript', get_string('changegradewarning', 'mod_assign'))); + // Add noscript tag in case. + $noscriptwarning = $mform->createElement('static', + 'warning', + null, + html_writer::tag('noscript', + get_string('changegradewarning', 'mod_assign'))); $mform->insertElementBefore($noscriptwarning, 'grade'); } } @@ -171,7 +201,7 @@ class mod_assign_mod_form extends moodleform_mod { * @param array $data * @param array $files */ - function validation($data, $files) { + public function validation($data, $files) { $errors = parent::validation($data, $files); if ($data['allowsubmissionsfromdate'] && $data['duedate']) { @@ -198,7 +228,7 @@ class mod_assign_mod_form extends moodleform_mod { * (needed to set up draft areas for editor and filemanager elements) * @param array $defaultvalues */ - function data_preprocessing(&$defaultvalues) { + public function data_preprocessing(&$defaultvalues) { global $DB; $ctx = null; @@ -211,19 +241,20 @@ class mod_assign_mod_form extends moodleform_mod { if (!$ctx) { $ctx = context_course::instance($this->current->course); } - $assignment->set_course($DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST)); + $course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST); + $assignment->set_course($course); } $assignment->plugin_data_preprocessing($defaultvalues); } - function add_completion_rules() { + public function add_completion_rules() { $mform =& $this->_form; $mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'assign')); return array('completionsubmit'); } - function completion_rule_enabled($data) { + public function completion_rule_enabled($data) { return !empty($data['completionsubmit']); } diff --git a/mod/assign/module.js b/mod/assign/module.js index 12c3eb05cf0..a1618b76fe8 100644 --- a/mod/assign/module.js +++ b/mod/assign/module.js @@ -16,7 +16,6 @@ M.mod_assign.init_tree = function(Y, expand_all, htmlid) { }); }; - M.mod_assign.init_grading_table = function(Y) { Y.use('node', function(Y) { checkboxes = Y.all('td.c0 input'); @@ -92,7 +91,6 @@ M.mod_assign.init_grading_table = function(Y) { } }); - Y.use('node-menunav', function(Y) { var menus = Y.all('.gradingtable .actionmenu'); @@ -103,13 +101,8 @@ M.mod_assign.init_grading_table = function(Y) { submenus.each(function (n) { n.removeClass('yui3-loading'); }); - }, "#" + menu.getAttribute('id')); - - }); - - }); var quickgrade = Y.all('.gradingtable .quickgrade'); quickgrade.each(function(quick) { @@ -209,6 +202,4 @@ M.mod_assign.init_plugin_summary = function(Y, subtype, type, submissionid) { } }); } - - } diff --git a/mod/assign/quickgradingform.php b/mod/assign/quickgradingform.php index 9382582d80b..2e93df7b054 100644 --- a/mod/assign/quickgradingform.php +++ b/mod/assign/quickgradingform.php @@ -25,9 +25,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -/** Include formslib.php */ -require_once ($CFG->libdir.'/formslib.php'); -/** Include locallib.php */ +require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); /** @@ -41,21 +39,22 @@ class mod_assign_quick_grading_form extends moodleform { /** * Define this form - called from the parent constructor */ - function definition() { + public function definition() { $mform = $this->_form; $instance = $this->_customdata; - // visible elements + // Visible elements. $mform->addElement('html', $instance['gradingtable']); - // hidden params + // Hidden params. $mform->addElement('hidden', 'id', $instance['cm']); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'action', 'quickgrade'); $mform->setType('action', PARAM_ALPHA); - // buttons - $mform->addElement('submit', 'savequickgrades', get_string('saveallquickgradingchanges', 'assign')); + // Buttons. + $savemessage = get_string('saveallquickgradingchanges', 'assign'); + $mform->addElement('submit', 'savequickgrades', $savemessage); } } diff --git a/mod/assign/renderable.php b/mod/assign/renderable.php index 2875b78e7ec..02b7c3519e0 100644 --- a/mod/assign/renderable.php +++ b/mod/assign/renderable.php @@ -31,12 +31,12 @@ defined('MOODLE_INTERNAL') || die(); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class assign_submit_for_grading_page implements renderable { - /** @var array $notifications is a list of notification messages returned from the plugins*/ - var $notifications = array(); + /** @var array $notifications is a list of notification messages returned from the plugins */ + public $notifications = array(); /** @var int $coursemoduleid */ - var $coursemoduleid = 0; + public $coursemoduleid = 0; /** @var moodleform $confirmform */ - var $confirmform = null; + public $confirmform = null; /** * Constructor @@ -59,9 +59,9 @@ class assign_submit_for_grading_page implements renderable { */ class assign_quickgrading_result implements renderable { /** @var string $message is the message to display to the user */ - var $message = ''; + public $message = ''; /** @var int $coursemoduleid */ - var $coursemoduleid = 0; + public $coursemoduleid = 0; /** * Constructor @@ -82,11 +82,11 @@ class assign_quickgrading_result implements renderable { */ class assign_form implements renderable { /** @var moodleform $form is the edit submission form */ - var $form = null; + public $form = null; /** @var string $classname is the name of the class to assign to the container */ - var $classname = ''; + public $classname = ''; /** @var string $jsinitfunction is an optional js function to add to the page requires */ - var $jsinitfunction = ''; + public $jsinitfunction = ''; /** * Constructor @@ -102,7 +102,6 @@ class assign_form implements renderable { } - /** * Implements a renderable user summary * @package mod_assign @@ -110,7 +109,7 @@ class assign_form implements renderable { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class assign_user_summary implements renderable { - /** @var stdClass $user suitable for rendering with user_picture and fullname(). Must contain firstname, lastname, id and picture fields */ + /** @var stdClass $user suitable for rendering with user_picture and fullname(). */ public $user = null; /** @var int $courseid */ public $courseid; @@ -127,7 +126,11 @@ class assign_user_summary implements renderable { * @param int $courseid * @param bool $viewfullnames */ - public function __construct(stdClass $user, $courseid, $viewfullnames, $blindmarking, $uniqueidforuser) { + public function __construct(stdClass $user, + $courseid, + $viewfullnames, + $blindmarking, + $uniqueidforuser) { $this->user = $user; $this->courseid = $courseid; $this->viewfullnames = $viewfullnames; @@ -149,20 +152,20 @@ class assign_feedback_plugin_feedback implements renderable { const FULL = 20; /** @var assign_submission_plugin $plugin */ - var $plugin = null; + public $plugin = null; /** @var stdClass $grade */ - var $grade = null; + public $grade = null; /** @var string $view */ - var $view = self::SUMMARY; + public $view = self::SUMMARY; /** @var int $coursemoduleid */ - var $coursemoduleid = 0; + public $coursemoduleid = 0; /** @var string returnaction The action to take you back to the current page */ - var $returnaction = ''; + public $returnaction = ''; /** @var array returnparams The params to take you back to the current page */ - var $returnparams = array(); + public $returnparams = array(); /** - * feedback for a single plugin + * Feedback for a single plugin * * @param assign_feedback_plugin $plugin * @param stdClass $grade @@ -171,7 +174,12 @@ class assign_feedback_plugin_feedback implements renderable { * @param string $returnaction The action required to return to this page * @param array $returnparams The params required to return to this page */ - public function __construct(assign_feedback_plugin $plugin, stdClass $grade, $view, $coursemoduleid, $returnaction, $returnparams) { + public function __construct(assign_feedback_plugin $plugin, + stdClass $grade, + $view, + $coursemoduleid, + $returnaction, + $returnparams) { $this->plugin = $plugin; $this->grade = $grade; $this->view = $view; @@ -195,19 +203,17 @@ class assign_submission_plugin_submission implements renderable { const FULL = 20; /** @var assign_submission_plugin $plugin */ - var $plugin = null; + public $plugin = null; /** @var stdClass $submission */ - var $submission = null; + public $submission = null; /** @var string $view */ - var $view = self::SUMMARY; + public $view = self::SUMMARY; /** @var int $coursemoduleid */ - var $coursemoduleid = 0; + public $coursemoduleid = 0; /** @var string returnaction The action to take you back to the current page */ - var $returnaction = ''; + public $returnaction = ''; /** @var array returnparams The params to take you back to the current page */ - var $returnparams = array(); - - + public $returnparams = array(); /** * Constructor @@ -218,7 +224,12 @@ class assign_submission_plugin_submission implements renderable { * @param string $returnaction The action to return to the current page * @param array $returnparams The params to return to the current page */ - public function __construct(assign_submission_plugin $plugin, stdClass $submission, $view, $coursemoduleid, $returnaction, $returnparams) { + public function __construct(assign_submission_plugin $plugin, + stdClass $submission, + $view, + $coursemoduleid, + $returnaction, + $returnparams) { $this->plugin = $plugin; $this->submission = $submission; $this->view = $view; @@ -237,21 +248,21 @@ class assign_submission_plugin_submission implements renderable { class assign_feedback_status implements renderable { /** @var stding $gradefordisplay the student grade rendered into a format suitable for display */ - var $gradefordisplay = ''; + public $gradefordisplay = ''; /** @var mixed the graded date (may be null) */ - var $gradeddate = 0; + public $gradeddate = 0; /** @var mixed the grader (may be null) */ - var $grader = null; + public $grader = null; /** @var array feedbackplugins - array of feedback plugins */ - var $feedbackplugins = array(); + public $feedbackplugins = array(); /** @var stdClass assign_grade record */ - var $grade = null; + public $grade = null; /** @var int coursemoduleid */ - var $coursemoduleid = 0; + public $coursemoduleid = 0; /** @var string returnaction */ - var $returnaction = ''; + public $returnaction = ''; /** @var array returnparams */ - var $returnparams = array(); + public $returnparams = array(); /** * Constructor @@ -264,7 +275,14 @@ class assign_feedback_status implements renderable { * @param string $returnaction The action required to return to this page * @param array $returnparams The list of params required to return to this page */ - public function __construct($gradefordisplay, $gradeddate, $grader, $feedbackplugins, $grade, $coursemoduleid, $returnaction, $returnparams) { + public function __construct($gradefordisplay, + $gradeddate, + $grader, + $feedbackplugins, + $grade, + $coursemoduleid, + $returnaction, + $returnparams) { $this->gradefordisplay = $gradefordisplay; $this->gradeddate = $gradeddate; $this->grader = $grader; @@ -274,7 +292,6 @@ class assign_feedback_status implements renderable { $this->returnaction = $returnaction; $this->returnparams = $returnparams; } - } /** @@ -290,11 +307,11 @@ class assign_submission_status implements renderable { const GRADER_VIEW = 20; /** @var int allowsubmissionsfromdate */ - var $allowsubmissionsfromdate = 0; + public $allowsubmissionsfromdate = 0; /** @var bool alwaysshowdescription */ - var $alwaysshowdescription = false; + public $alwaysshowdescription = false; /** @var stdClass the submission info (may be null) */ - var $submission = null; + public $submission = null; /** @var boolean teamsubmissionenabled - true or false */ public $teamsubmissionenabled = false; /** @var stdClass teamsubmission the team submission info (may be null) */ @@ -304,45 +321,44 @@ class assign_submission_status implements renderable { /** @var array submissiongroupmemberswhoneedtosubmit list of users who still need to submit */ public $submissiongroupmemberswhoneedtosubmit = array(); /** @var bool submissionsenabled */ - var $submissionsenabled = false; + public $submissionsenabled = false; /** @var bool locked */ - var $locked = false; + public $locked = false; /** @var bool graded */ - var $graded = false; + public $graded = false; /** @var int duedate */ - var $duedate = 0; + public $duedate = 0; /** @var int cutoffdate */ public $cutoffdate = 0; /** @var array submissionplugins - the list of submission plugins */ - var $submissionplugins = array(); + public $submissionplugins = array(); /** @var string returnaction */ - var $returnaction = ''; + public $returnaction = ''; /** @var string returnparams */ - var $returnparams = array(); + public $returnparams = array(); /** @var int courseid */ public $courseid = 0; /** @var int coursemoduleid */ - var $coursemoduleid = 0; - /** @var int the view (assign_submission_status::STUDENT_VIEW OR assign_submission_status::GRADER_VIEW) */ - var $view = self::STUDENT_VIEW; + public $coursemoduleid = 0; + /** @var int the view (STUDENT_VIEW OR GRADER_VIEW) */ + public $view = self::STUDENT_VIEW; /** @var bool canviewfullnames */ public $canviewfullnames = false; /** @var bool canedit */ - var $canedit = false; + public $canedit = false; /** @var bool cansubmit */ - var $cansubmit = false; + public $cansubmit = false; /** @var int extensionduedate */ public $extensionduedate = 0; /** @var context context */ public $context = 0; /** @var bool blindmarking - Should we hide student identities from graders? */ public $blindmarking = false; - /** @var string gradingcontrollerpreview */ public $gradingcontrollerpreview = ''; /** - * constructor + * Constructor * * @param int $allowsubmissionsfromdate * @param bool $alwaysshowdescription @@ -369,12 +385,31 @@ class assign_submission_status implements renderable { * @param context $context - Any extension to the due date granted for this user * @param blindmarking $blindmarking - Should we hide student identities from graders? */ - public function __construct($allowsubmissionsfromdate, $alwaysshowdescription, $submission, - $teamsubmissionenabled, $teamsubmission, $submissiongroup, - $submissiongroupmemberswhoneedtosubmit, $submissionsenabled, - $locked, $graded, $duedate, $cutoffdate, $submissionplugins, $returnaction, $returnparams, - $coursemoduleid, $courseid, $view, $canedit, $cansubmit, $canviewfullnames, $extensionduedate, - $context, $blindmarking, $gradingcontrollerpreview) { + public function __construct($allowsubmissionsfromdate, + $alwaysshowdescription, + $submission, + $teamsubmissionenabled, + $teamsubmission, + $submissiongroup, + $submissiongroupmemberswhoneedtosubmit, + $submissionsenabled, + $locked, + $graded, + $duedate, + $cutoffdate, + $submissionplugins, + $returnaction, + $returnparams, + $coursemoduleid, + $courseid, + $view, + $canedit, + $cansubmit, + $canviewfullnames, + $extensionduedate, + $context, + $blindmarking, + $gradingcontrollerpreview) { $this->allowsubmissionsfromdate = $allowsubmissionsfromdate; $this->alwaysshowdescription = $alwaysshowdescription; $this->submission = $submission; @@ -412,29 +447,34 @@ class assign_submission_status implements renderable { */ class assign_header implements renderable { /** @var stdClass the assign record */ - var $assign = null; + public $assign = null; /** @var mixed context|null the context record */ - var $context = null; + public $context = null; /** @var bool $showintro - show or hide the intro */ - var $showintro = false; + public $showintro = false; /** @var int coursemoduleid - The course module id */ - var $coursemoduleid = 0; + public $coursemoduleid = 0; /** @var string $subpage optional subpage (extra level in the breadcrumbs) */ - var $subpage = ''; + public $subpage = ''; /** @var string $preface optional preface (text to show before the heading) */ - var $preface = ''; + public $preface = ''; /** * Constructor * * @param stdClass $assign - the assign database record - * @param mixed $context context|null the course module context (or the course context if the coursemodule has not been created yet) + * @param mixed $context context|null the course module context * @param bool $showintro - show or hide the intro * @param int $coursemoduleid - the course module id * @param string $subpage - an optional sub page in the navigation * @param string $preface - an optional preface to show before the heading */ - public function __construct(stdClass $assign, $context, $showintro, $coursemoduleid, $subpage='', $preface='') { + public function __construct(stdClass $assign, + $context, + $showintro, + $coursemoduleid, + $subpage='', + $preface='') { $this->assign = $assign; $this->context = $context; $this->showintro = $showintro; @@ -452,23 +492,23 @@ class assign_header implements renderable { */ class assign_grading_summary implements renderable { /** @var int participantcount - The number of users who can submit to this assignment */ - var $participantcount = 0; + public $participantcount = 0; /** @var bool submissiondraftsenabled - Allow submission drafts */ - var $submissiondraftsenabled = false; + public $submissiondraftsenabled = false; /** @var int submissiondraftscount - The number of submissions in draft status */ - var $submissiondraftscount = 0; + public $submissiondraftscount = 0; /** @var bool submissionsenabled - Allow submissions */ - var $submissionsenabled = false; + public $submissionsenabled = false; /** @var int submissionssubmittedcount - The number of submissions in submitted status */ - var $submissionssubmittedcount = 0; + public $submissionssubmittedcount = 0; /** @var int submissionsneedgradingcount - The number of submissions that need grading */ - var $submissionsneedgradingcount = 0; + public $submissionsneedgradingcount = 0; /** @var int duedate - The assignment due date (if one is set) */ - var $duedate = 0; + public $duedate = 0; /** @var int cutoffdate - The assignment cut off date (if one is set) */ - var $cutoffdate = 0; + public $cutoffdate = 0; /** @var int coursemoduleid - The assignment course module id */ - var $coursemoduleid = 0; + public $coursemoduleid = 0; /** @var boolean teamsubmission - Are team submissions enabled for this assignment */ public $teamsubmission = false; @@ -486,10 +526,16 @@ class assign_grading_summary implements renderable { * @param int $submissionsneedgradingcount * @param bool $teamsubmission */ - public function __construct($participantcount, $submissiondraftsenabled, - $submissiondraftscount, $submissionsenabled, - $submissionssubmittedcount, $cutoffdate, $duedate, - $coursemoduleid, $submissionsneedgradingcount, $teamsubmission) { + public function __construct($participantcount, + $submissiondraftsenabled, + $submissiondraftscount, + $submissionsenabled, + $submissionssubmittedcount, + $cutoffdate, + $duedate, + $coursemoduleid, + $submissionsneedgradingcount, + $teamsubmission) { $this->participantcount = $participantcount; $this->submissiondraftsenabled = $submissiondraftsenabled; $this->submissiondraftscount = $submissiondraftscount; @@ -501,7 +547,6 @@ class assign_grading_summary implements renderable { $this->submissionsneedgradingcount = $submissionsneedgradingcount; $this->teamsubmission = $teamsubmission; } - } /** @@ -572,7 +617,6 @@ class assign_files implements renderable { /** @var stdClass $course */ public $course; - /** * The constructor * @@ -590,17 +634,24 @@ class assign_files implements renderable { $fs = get_file_storage(); $this->dir = $fs->get_area_tree($this->context->id, $component, $filearea, $sid); - $files = $fs->get_area_files($this->context->id, $component, $filearea, $sid, "timemodified", false); + $files = $fs->get_area_files($this->context->id, + $component, + $filearea, + $sid, + 'timemodified', + false); if (!empty($CFG->enableportfolios)) { require_once($CFG->libdir . '/portfoliolib.php'); - if (count($files) >= 1 && has_capability('mod/assign:exportownsubmission', $this->context)) { + if (count($files) >= 1 && + has_capability('mod/assign:exportownsubmission', $this->context)) { $button = new portfolio_add_button(); + $callbackparams = array('cmid' => $this->cm->id, + 'sid' => $sid, + 'area' => $filearea, + 'component' => $component); $button->set_callback_options('assign_portfolio_caller', - array('cmid' => $this->cm->id, - 'sid' => $sid, - 'area' => $filearea, - 'component' => $component), + $callbackparams, 'mod_assign'); $button->reset_formats(); $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK); @@ -608,30 +659,31 @@ class assign_files implements renderable { } - // plagiarism check if it is enabled + // Plagiarism check if it is enabled. $output = ''; if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir . '/plagiarismlib.php'); - // for plagiarism_get_links + // For plagiarism_get_links. $assignment = new assign($this->context, null, null); foreach ($files as $file) { - $output .= plagiarism_get_links(array('userid' => $sid, - 'file' => $file, - 'cmid' => $this->cm->id, - 'course' => $this->course, - 'assignment' => $assignment->get_instance())); + $linkparams = array('userid' => $sid, + 'file' => $file, + 'cmid' => $this->cm->id, + 'course' => $this->course, + 'assignment' => $assignment->get_instance()); + $output .= plagiarism_get_links($linkparams); - $output .= '
'; + $output .= '
'; } } - $this->preprocess($this->dir, $filearea, $component); + $this->preprocess($this->dir, $filearea, $component); } /** - * preprocessing the file list to add the portfolio links if required + * Preprocessing the file list to add the portfolio links if required. * * @param array $dir * @param string $filearea @@ -648,14 +700,25 @@ class assign_files implements renderable { if (!empty($CFG->enableportfolios)) { $button = new portfolio_add_button(); if (has_capability('mod/assign:exportownsubmission', $this->context)) { + $portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id()); $button->set_callback_options('assign_portfolio_caller', - array('cmid' => $this->cm->id, 'fileid' => $file->get_id()), + $portfolioparams, 'mod_assign'); $button->set_format_by_file($file); $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } - $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$this->context->id.'/'.$component.'/'.$filearea.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true); + $path = '/' . + $this->context->id . + '/' . + $component . + '/' . + $filearea . + '/' . + $file->get_itemid() . + $file->get_filepath() . + $file->get_filename(); + $url = file_encode_url("$CFG->wwwroot/pluginfile.php", $path, true); $filename = $file->get_filename(); $file->fileurl = html_writer::link($url, $filename); } diff --git a/mod/assign/renderer.php b/mod/assign/renderer.php index ed1a972a0c0..cbf7a56cc9f 100644 --- a/mod/assign/renderer.php +++ b/mod/assign/renderer.php @@ -24,10 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -/** Include locallib.php */ require_once($CFG->dirroot . '/mod/assign/locallib.php'); - /** * A custom renderer class that extends the plugin_renderer_base and is used by the assign module. * @@ -38,7 +36,7 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php'); class mod_assign_renderer extends plugin_renderer_base { /** - * rendering assignment files + * Rendering assignment files * * @param context $context * @param int $userid @@ -51,7 +49,7 @@ class mod_assign_renderer extends plugin_renderer_base { } /** - * rendering assignment files + * Rendering assignment files * * @param assign_files $tree * @return string @@ -92,7 +90,8 @@ class mod_assign_renderer extends plugin_renderer_base { * @return string */ public function render_assign_quickgrading_result(assign_quickgrading_result $result) { - $url = new moodle_url('/mod/assign/view.php', array('id' => $result->coursemoduleid, 'action'=>'grading')); + $urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading'); + $url = new moodle_url('/mod/assign/view.php', $urlparams); $o = ''; $o .= $this->output->heading(get_string('quickgradingresult', 'assign'), 4); @@ -136,10 +135,9 @@ class mod_assign_renderer extends plugin_renderer_base { } else { $o .= $this->output->user_picture($summary->user); $o .= $this->output->spacer(array('width'=>30)); - $o .= $this->output->action_link(new moodle_url('/user/view.php', - array('id' => $summary->user->id, - 'course'=>$summary->courseid)), - fullname($summary->user, $summary->viewfullnames)); + $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid); + $url = new moodle_url('/user/view.php', $urlparams); + $o .= $this->output->action_link($url, fullname($summary->user, $summary->viewfullnames)); } $o .= $this->output->box_end(); $o .= $this->output->container_end(); @@ -162,7 +160,7 @@ class mod_assign_renderer extends plugin_renderer_base { $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid)); if (count($page->notifications)) { - // At least one of the submission plugins is not ready for submission + // At least one of the submission plugins is not ready for submission. $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4); @@ -172,17 +170,16 @@ class mod_assign_renderer extends plugin_renderer_base { $o .= $this->output->continue_button($cancelurl); } else { - // All submission plugins ready - show the confirmation form (may contain submission statement) + // All submission plugins ready - show the confirmation form. $o .= $this->moodleform($page->confirmform); } $o .= $this->output->container_end(); - return $o; } /** - * Page is done - render the footer + * Page is done - render the footer. * * @return void */ @@ -191,7 +188,7 @@ class mod_assign_renderer extends plugin_renderer_base { } /** - * render the header + * Render the header. * * @param assign_header $header * @return string @@ -210,7 +207,8 @@ class mod_assign_renderer extends plugin_renderer_base { if ($header->preface) { $o .= $header->preface; } - $o .= $this->output->heading(format_string($header->assign->name,false, array('context' => $header->context))); + $heading = format_string($header->assign->name, false, array('context' => $header->context)); + $o .= $this->output->heading($heading); if ($header->showintro) { $o .= $this->output->box_start('generalbox boxaligncenter', 'intro'); @@ -222,20 +220,20 @@ class mod_assign_renderer extends plugin_renderer_base { } /** - * render a table containing the current status of the grading process + * Render a table containing the current status of the grading process. * * @param assign_grading_summary $summary * @return string */ public function render_assign_grading_summary(assign_grading_summary $summary) { - // create a table for the data + // Create a table for the data. $o = ''; $o .= $this->output->container_start('gradingsummary'); $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3); $o .= $this->output->box_start('boxaligncenter gradingsummarytable'); $t = new html_table(); - // status + // Status. if ($summary->teamsubmission) { $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'), $summary->participantcount); @@ -244,13 +242,13 @@ class mod_assign_renderer extends plugin_renderer_base { $summary->participantcount); } - // drafts + // Drafts. if ($summary->submissiondraftsenabled) { $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'), $summary->submissiondraftscount); - } + } - // submitted for grading + // Submitted for grading. if ($summary->submissionsenabled) { $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'), $summary->submissionssubmittedcount); @@ -262,13 +260,12 @@ class mod_assign_renderer extends plugin_renderer_base { $time = time(); if ($summary->duedate) { - // due date - // submitted for grading + // Due date. $duedate = $summary->duedate; $this->add_table_row_tuple($t, get_string('duedate', 'assign'), userdate($duedate)); - // time remaining + // Time remaining. $due = ''; if ($duedate - $time <= 0) { $due = get_string('assignmentisdue', 'assign'); @@ -291,26 +288,25 @@ class mod_assign_renderer extends plugin_renderer_base { } - // all done - write the table + // All done - write the table. $o .= html_writer::table($t); $o .= $this->output->box_end(); - // link to the grading page + // Link to the grading page. $o .= $this->output->container_start('submissionlinks'); - $o .= $this->output->action_link(new moodle_url('/mod/assign/view.php', - array('id' => $summary->coursemoduleid, - 'action'=>'grading')), - get_string('viewgrading', 'assign')); + $urlparams = array('id' => $summary->coursemoduleid, 'action'=>'grading'); + $url = new moodle_url('/mod/assign/view.php', $urlparams); + $o .= $this->output->action_link($url, get_string('viewgrading', 'assign')); $o .= $this->output->container_end(); - // close the container and insert a spacer + // Close the container and insert a spacer. $o .= $this->output->container_end(); return $o; } /** - * render a table containing all the current grades and feedback + * Render a table containing all the current grades and feedback. * * @param assign_feedback_status $status * @return string @@ -324,12 +320,14 @@ class mod_assign_renderer extends plugin_renderer_base { $o .= $this->output->box_start('boxaligncenter feedbacktable'); $t = new html_table(); + // Grade. $row = new html_table_row(); $cell1 = new html_table_cell(get_string('grade')); $cell2 = new html_table_cell($status->gradefordisplay); $row->cells = array($cell1, $cell2); $t->data[] = $row; + // Grade date. $row = new html_table_row(); $cell1 = new html_table_cell(get_string('gradedon', 'assign')); $cell2 = new html_table_cell(userdate($status->gradeddate)); @@ -337,9 +335,13 @@ class mod_assign_renderer extends plugin_renderer_base { $t->data[] = $row; if ($status->grader) { + // Grader. $row = new html_table_row(); $cell1 = new html_table_cell(get_string('gradedby', 'assign')); - $cell2 = new html_table_cell($this->output->user_picture($status->grader) . $this->output->spacer(array('width'=>30)) . fullname($status->grader)); + $userdescription = $this->output->user_picture($status->grader) . + $this->output->spacer(array('width'=>30)) . + fullname($status->grader); + $cell2 = new html_table_cell($userdescription); $row->cells = array($cell1, $cell2); $t->data[] = $row; } @@ -353,14 +355,19 @@ class mod_assign_renderer extends plugin_renderer_base { $row = new html_table_row(); $cell1 = new html_table_cell($plugin->get_name()); - $pluginfeedback = new assign_feedback_plugin_feedback($plugin, $status->grade, assign_feedback_plugin_feedback::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams); + $displaymode = assign_feedback_plugin_feedback::SUMMARY; + $pluginfeedback = new assign_feedback_plugin_feedback($plugin, + $status->grade, + $displaymode, + $status->coursemoduleid, + $status->returnaction, + $status->returnparams); $cell2 = new html_table_cell($this->render($pluginfeedback)); $row->cells = array($cell1, $cell2); $t->data[] = $row; } } - $o .= html_writer::table($t); $o .= $this->output->box_end(); @@ -369,7 +376,7 @@ class mod_assign_renderer extends plugin_renderer_base { } /** - * render a table containing the current status of the submission + * Render a table containing the current status of the submission. * * @param assign_submission_status $status * @return string @@ -384,9 +391,11 @@ class mod_assign_renderer extends plugin_renderer_base { $time <= $status->allowsubmissionsfromdate) { $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates'); if ($status->alwaysshowdescription) { - $o .= get_string('allowsubmissionsfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate)); + $date = userdate($status->allowsubmissionsfromdate); + $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date); } else { - $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate)); + $date = userdate($status->allowsubmissionsfromdate); + $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date); } $o .= $this->output->box_end(); } @@ -411,7 +420,8 @@ class mod_assign_renderer extends plugin_renderer_base { $cell1 = new html_table_cell(get_string('submissionstatus', 'assign')); if (!$status->teamsubmissionenabled) { if ($status->submission) { - $cell2 = new html_table_cell(get_string('submissionstatus_' . $status->submission->status, 'assign')); + $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign'); + $cell2 = new html_table_cell($statusstr); $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status); } else { if (!$status->submissionsenabled) { @@ -426,7 +436,8 @@ class mod_assign_renderer extends plugin_renderer_base { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('submissionstatus', 'assign')); if ($status->teamsubmission) { - $submissionsummary = get_string('submissionstatus_' . $status->teamsubmission->status, 'assign'); + $teamstatus = $status->teamsubmission->status; + $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign'); $groupid = 0; if ($status->submissiongroup) { $groupid = $status->submissiongroup->id; @@ -435,16 +446,19 @@ class mod_assign_renderer extends plugin_renderer_base { $members = $status->submissiongroupmemberswhoneedtosubmit; $userslist = array(); foreach ($members as $member) { - $url = new moodle_url('/user/view.php', array('id' => $member->id, 'course'=>$status->courseid)); + $urlparams = array('id' => $member->id, 'course'=>$status->courseid); + $url = new moodle_url('/user/view.php', $urlparams); if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) { $userslist[] = $member->alias; } else { - $userslist[] = $this->output->action_link($url, fullname($member, $status->canviewfullnames)); + $fullname = fullname($member, $status->canviewfullnames); + $userslist[] = $this->output->action_link($url, $fullname); } } if (count($userslist) > 0) { $userstr = join(', ', $userslist); - $submissionsummary .= $this->output->container(get_string('userswhoneedtosubmit', 'assign', $userstr)); + $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr); + $submissionsummary .= $this->output->container($formatteduserstr); } $cell2 = new html_table_cell($submissionsummary); @@ -461,7 +475,7 @@ class mod_assign_renderer extends plugin_renderer_base { $t->data[] = $row; } - // status + // Is locked? if ($status->locked) { $row = new html_table_row(); $cell1 = new html_table_cell(); @@ -471,7 +485,7 @@ class mod_assign_renderer extends plugin_renderer_base { $t->data[] = $row; } - // grading status + // Grading status. $row = new html_table_row(); $cell1 = new html_table_cell(get_string('gradingstatus', 'assign')); @@ -485,9 +499,9 @@ class mod_assign_renderer extends plugin_renderer_base { $row->cells = array($cell1, $cell2); $t->data[] = $row; - $duedate = $status->duedate; if ($duedate > 0) { + // Due date. $row = new html_table_row(); $cell1 = new html_table_cell(get_string('duedate', 'assign')); $cell2 = new html_table_cell(userdate($duedate)); @@ -496,6 +510,7 @@ class mod_assign_renderer extends plugin_renderer_base { if ($status->view == assign_submission_status::GRADER_VIEW) { if ($status->cutoffdate) { + // Cut off date. $row = new html_table_row(); $cell1 = new html_table_cell(get_string('cutoffdate', 'assign')); $cell2 = new html_table_cell(userdate($status->cutoffdate)); @@ -505,6 +520,7 @@ class mod_assign_renderer extends plugin_renderer_base { } if ($status->extensionduedate) { + // Extension date. $row = new html_table_row(); $cell1 = new html_table_cell(get_string('extensionduedate', 'assign')); $cell2 = new html_table_cell(userdate($status->extensionduedate)); @@ -517,19 +533,27 @@ class mod_assign_renderer extends plugin_renderer_base { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('timeremaining', 'assign')); if ($duedate - $time <= 0) { - if (!$status->submission || $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) { + if (!$status->submission || + $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) { if ($status->submissionsenabled) { - $cell2 = new html_table_cell(get_string('overdue', 'assign', format_time($time - $duedate))); + $overduestr = get_string('overdue', 'assign', format_time($time - $duedate)); + $cell2 = new html_table_cell($overduestr); $cell2->attributes = array('class'=>'overdue'); } else { $cell2 = new html_table_cell(get_string('duedatereached', 'assign')); } } else { if ($status->submission->timemodified > $duedate) { - $cell2 = new html_table_cell(get_string('submittedlate', 'assign', format_time($status->submission->timemodified - $duedate))); + $latestr = get_string('submittedlate', + 'assign', + format_time($status->submission->timemodified - $duedate)); + $cell2 = new html_table_cell($latestr); $cell2->attributes = array('class'=>'latesubmission'); } else { - $cell2 = new html_table_cell(get_string('submittedearly', 'assign', format_time($status->submission->timemodified - $duedate))); + $earlystr = get_string('submittedearly', + 'assign', + format_time($status->submission->timemodified - $duedate)); + $cell2 = new html_table_cell($earlystr); $cell2->attributes = array('class'=>'earlysubmission'); } } @@ -582,9 +606,10 @@ class mod_assign_renderer extends plugin_renderer_base { $row = new html_table_row(); $cell1 = new html_table_cell($plugin->get_name()); + $displaymode = assign_submission_plugin_submission::SUMMARY; $pluginsubmission = new assign_submission_plugin_submission($plugin, $submission, - assign_submission_plugin_submission::SUMMARY, + $displaymode, $status->coursemoduleid, $status->returnaction, $status->returnparams); @@ -595,7 +620,6 @@ class mod_assign_renderer extends plugin_renderer_base { } } - $o .= html_writer::table($t); $o .= $this->output->box_end(); @@ -628,7 +652,7 @@ class mod_assign_renderer extends plugin_renderer_base { } /** - * render a submission plugin submission + * Render a submission plugin submission * * @param assign_submission_plugin_submission $submissionplugin * @return string @@ -638,9 +662,15 @@ class mod_assign_renderer extends plugin_renderer_base { if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) { $showviewlink = false; - $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, $showviewlink); + $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, + $showviewlink); + + $classsuffix = $submissionplugin->plugin->get_subtype() . + '_' . + $submissionplugin->plugin->get_type() . + '_' . + $submissionplugin->submission->id; - $classsuffix = $submissionplugin->plugin->get_subtype() . '_' . $submissionplugin->plugin->get_type() . '_' . $submissionplugin->submission->id; $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix); $link = ''; @@ -649,24 +679,26 @@ class mod_assign_renderer extends plugin_renderer_base { $icon = $this->output->pix_icon('t/preview', $previewstr); $expandstr = get_string('viewfull', 'assign'); - $classes = 'expandsummaryicon expand_' . $classsuffix; - $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, array('class'=>$classes)); + $options = array('class'=>'expandsummaryicon expand_' . $classsuffix); + $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options); $jsparams = array($submissionplugin->plugin->get_subtype(), $submissionplugin->plugin->get_type(), $submissionplugin->submission->id); + $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams); + $action = 'viewplugin' . $submissionplugin->plugin->get_subtype(); + $returnparams = http_build_query($submissionplugin->returnparams); $link .= ''; $link .= $this->output->spacer(array('width'=>15)); @@ -694,7 +726,7 @@ class mod_assign_renderer extends plugin_renderer_base { } /** - * render the grading table + * Render the grading table. * * @param assign_grading_table $table * @return string @@ -712,15 +744,15 @@ class mod_assign_renderer extends plugin_renderer_base { $this->page->requires->string_for_js('editaction', 'assign'); foreach ($table->plugingradingbatchoperations as $plugin => $operations) { foreach ($operations as $operation => $description) { - $this->page->requires->string_for_js('batchoperationconfirm' . $operation, 'assignfeedback_' . $plugin); + $this->page->requires->string_for_js('batchoperationconfirm' . $operation, + 'assignfeedback_' . $plugin); } } - // need to get from prefs $o .= $this->flexible_table($table, $table->get_rows_per_page(), true); $o .= $this->output->box_end(); return $o; - } + } /** * Render a feedback plugin feedback @@ -735,7 +767,11 @@ class mod_assign_renderer extends plugin_renderer_base { $showviewlink = false; $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink); - $classsuffix = $feedbackplugin->plugin->get_subtype() . '_' . $feedbackplugin->plugin->get_type() . '_' . $feedbackplugin->grade->id; + $classsuffix = $feedbackplugin->plugin->get_subtype() . + '_' . + $feedbackplugin->plugin->get_type() . + '_' . + $feedbackplugin->grade->id; $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix); $link = ''; @@ -744,24 +780,23 @@ class mod_assign_renderer extends plugin_renderer_base { $icon = $this->output->pix_icon('t/preview', $previewstr); $expandstr = get_string('viewfull', 'assign'); - $classes = 'expandsummaryicon expand_' . $classsuffix; - $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, array('class'=>$classes)); + $options = array('class'=>'expandsummaryicon expand_' . $classsuffix); + $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options); $jsparams = array($feedbackplugin->plugin->get_subtype(), $feedbackplugin->plugin->get_type(), $feedbackplugin->grade->id); $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams); + $urlparams = array('id' => $feedbackplugin->coursemoduleid, + 'gid'=>$feedbackplugin->grade->id, + 'plugin'=>$feedbackplugin->plugin->get_type(), + 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(), + 'returnaction'=>$feedbackplugin->returnaction, + 'returnparams'=>http_build_query($feedbackplugin->returnparams)); + $url = new moodle_url('/mod/assign/view.php', $urlparams); $link .= ''; $link .= $this->output->spacer(array('width'=>15)); @@ -866,20 +901,37 @@ class mod_assign_renderer extends plugin_renderer_base { $result = '
    '; foreach ($dir['subdirs'] as $subdir) { - $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon')); - $result .= '
  • '.$image.' '.s($subdir['dirname']).'
    '.$this->htmllize_tree($tree, $subdir).'
  • '; + $image = $this->output->pix_icon(file_folder_icon(), + $subdir['dirname'], + 'moodle', + array('class'=>'icon')); + $result .= '
  • ' . + '
    ' . $image . ' ' . s($subdir['dirname']) . '
    ' . + $this->htmllize_tree($tree, $subdir) . + '
  • '; } foreach ($dir['files'] as $file) { $filename = $file->get_filename(); if ($CFG->enableplagiarism) { require_once($CFG->libdir.'/plagiarismlib.php'); - $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course)); + $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), + 'file'=>$file, + 'cmid'=>$tree->cm->id, + 'course'=>$tree->course)); } else { - $plagiarsmlinks = ''; + $plagiarismlinks = ''; } - $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon')); - $result .= '
  • '.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'
  • '; + $image = $this->output->pix_icon(file_file_icon($file), + $filename, + 'moodle', + array('class'=>'icon')); + $result .= '
  • ' . + '
    ' . $image . ' ' . + $file->fileurl . ' ' . + $plagiarismlinks . + $file->portfoliobutton . '
    ' . + '
  • '; } $result .= '
'; @@ -892,7 +944,8 @@ class mod_assign_renderer extends plugin_renderer_base { * * @param flexible_table $table The table to render * @param int $rowsperpage How many assignments to render in a page - * @param bool $displaylinks - Whether to render links in the table (e.g. downloads would not enable this) + * @param bool $displaylinks - Whether to render links in the table + * (e.g. downloads would not enable this) * @return string HTML */ protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) { diff --git a/mod/assign/settings.php b/mod/assign/settings.php index f5ade68bce8..5ec54e45746 100644 --- a/mod/assign/settings.php +++ b/mod/assign/settings.php @@ -48,21 +48,42 @@ if ($ADMIN->fulltree) { } } - // The default here is feedback_comments (if it exists) + // The default here is feedback_comments (if it exists). + $name = new lang_string('feedbackplugin', 'mod_assign'); + $description = new lang_string('feedbackpluginforgradebook', 'mod_assign'); $settings->add(new admin_setting_configselect('assign/feedback_plugin_for_gradebook', - new lang_string('feedbackplugin', 'mod_assign'), - new lang_string('feedbackpluginforgradebook', 'mod_assign'), 'assignfeedback_comments', $menu)); + $name, + $description, + 'assignfeedback_comments', + $menu)); + + $name = new lang_string('showrecentsubmissions', 'mod_assign'); + $description = new lang_string('configshowrecentsubmissions', 'mod_assign'); $settings->add(new admin_setting_configcheckbox('assign/showrecentsubmissions', - new lang_string('showrecentsubmissions', 'mod_assign'), - new lang_string('configshowrecentsubmissions', 'mod_assign'), 0)); + $name, + $description, + 0)); + + $name = new lang_string('sendsubmissionreceipts', 'mod_assign'); + $description = new lang_string('sendsubmissionreceipts_help', 'mod_assign'); $settings->add(new admin_setting_configcheckbox('assign/submissionreceipts', - new lang_string('sendsubmissionreceipts', 'mod_assign'), - new lang_string('sendsubmissionreceipts_help', 'mod_assign'), 1)); + $name, + $description, + 1)); + + $name = new lang_string('submissionstatement', 'mod_assign'); + $description = new lang_string('submissionstatement_help', 'mod_assign'); + $default = get_string('submissionstatementdefault', 'mod_assign'); $settings->add(new admin_setting_configtextarea('assign/submissionstatement', - new lang_string('submissionstatement', 'mod_assign'), - new lang_string('submissionstatement_help', 'mod_assign'), get_string('submissionstatementdefault', 'mod_assign'))); + $name, + $description, + $default)); + + $name = new lang_string('requiresubmissionstatement', 'mod_assign'); + $description = new lang_string('requiresubmissionstatement_help', 'mod_assign'); $settings->add(new admin_setting_configcheckbox('assign/requiresubmissionstatement', - new lang_string('requiresubmissionstatement', 'mod_assign'), - new lang_string('requiresubmissionstatement_help', 'mod_assign'), 0)); + $name, + $description, + 0)); } diff --git a/mod/assign/submission/comments/db/install.php b/mod/assign/submission/comments/db/install.php index c05ac59474e..0c01febdb77 100644 --- a/mod/assign/submission/comments/db/install.php +++ b/mod/assign/submission/comments/db/install.php @@ -34,17 +34,12 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_assignsubmission_comments_install() { global $CFG; - // do the install - require_once($CFG->dirroot . '/mod/assign/adminlib.php'); - // set the correct initial order for the plugins + // Set the correct initial order for the plugins. $pluginmanager = new assign_plugin_manager('assignsubmission'); $pluginmanager->move_plugin('comments', 'down'); $pluginmanager->move_plugin('comments', 'down'); - // do the upgrades return true; - - } diff --git a/mod/assign/submission/comments/db/upgrade.php b/mod/assign/submission/comments/db/upgrade.php index 499d7811d6c..9c9881a758b 100644 --- a/mod/assign/submission/comments/db/upgrade.php +++ b/mod/assign/submission/comments/db/upgrade.php @@ -28,13 +28,11 @@ * @return bool */ function xmldb_assignsubmission_comments_upgrade($oldversion) { - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this + // Moodle v2.3.0 release upgrade line. + // Put any upgrade step following this. + // Moodle v2.4.0 release upgrade line. + // Put any upgrade step following this. return true; } diff --git a/mod/assign/submission/comments/locallib.php b/mod/assign/submission/comments/locallib.php index 513dca948ad..16364e2b6f5 100644 --- a/mod/assign/submission/comments/locallib.php +++ b/mod/assign/submission/comments/locallib.php @@ -24,13 +24,11 @@ defined('MOODLE_INTERNAL') || die(); - /** Include comment core lib.php */ require_once($CFG->dirroot . '/comment/lib.php'); - /** Include submissionplugin.php */ require_once($CFG->dirroot . '/mod/assign/submissionplugin.php'); /** - * library class for comment submission plugin extending submission plugin base class + * Library class for comment submission plugin extending submission plugin base class * * @package assignsubmission_comments * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -38,27 +36,27 @@ */ class assign_submission_comments extends assign_submission_plugin { - /** - * get the name of the online comment submission plugin - * @return string - */ + /** + * Get the name of the online comment submission plugin + * @return string + */ public function get_name() { return get_string('pluginname', 'assignsubmission_comments'); } - /** - * display AJAX based comment in the submission status table - * - * @param stdClass $submission - * @param bool $showviewlink - If the comments are long this is set to true so they can be shown in a separate page - * @return string - */ - public function view_summary(stdClass $submission, & $showviewlink) { + /** + * Display AJAX based comment in the submission status table + * + * @param stdClass $submission + * @param bool $showviewlink - If the comments are long this is + * set to true so they can be shown in a separate page + * @return string + */ + public function view_summary(stdClass $submission, & $showviewlink) { - // never show a link to view full submission + // Never show a link to view full submission. $showviewlink = false; - // need to used this init() otherwise it shows up undefined ! - // require js for commenting + // Need to used this init() otherwise it does not have the javascript includes. comment::init(); $options = new stdClass(); @@ -74,7 +72,6 @@ class assign_submission_comments extends assign_submission_plugin { $comment->set_view_permission(true); return $comment->output(true); - } /** @@ -87,7 +84,7 @@ class assign_submission_comments extends assign_submission_plugin { return true; } - /** + /** * Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type * and version. * @@ -104,7 +101,7 @@ class assign_submission_comments extends assign_submission_plugin { } - /** + /** * Upgrade the settings from the old assignment to the new plugin based one * * @param context $oldcontext - the context for the old assignment @@ -113,7 +110,7 @@ class assign_submission_comments extends assign_submission_plugin { * @return bool was it a success? (false will trigger a rollback) */ public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) { - // first upgrade settings (nothing to do) + // No settings to upgrade. return true; } @@ -127,12 +124,15 @@ class assign_submission_comments extends assign_submission_plugin { * @param string $log Record upgrade messages in the log * @return bool true or false - false will trigger a rollback */ - public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $submission, & $log) { + public function upgrade(context $oldcontext, + stdClass $oldassignment, + stdClass $oldsubmission, + stdClass $submission, + & $log) { if ($oldsubmission->data1 != '') { - // need to used this innit() otherwise it shows up undefined ! - // require js for commenting + // Need to used this init() otherwise it does not have the javascript includes. comment::init(); $options = new stdClass(); @@ -148,11 +148,9 @@ class assign_submission_comments extends assign_submission_plugin { $comment->add($oldsubmission->data1); $comment->set_view_permission(true); - return $comment->output(true); } - return true; } diff --git a/mod/assign/submission/file/backup/moodle2/backup_assignsubmission_file_subplugin.class.php b/mod/assign/submission/file/backup/moodle2/backup_assignsubmission_file_subplugin.class.php index cd131d13083..c969adf7d9b 100644 --- a/mod/assign/submission/file/backup/moodle2/backup_assignsubmission_file_subplugin.class.php +++ b/mod/assign/submission/file/backup/moodle2/backup_assignsubmission_file_subplugin.class.php @@ -36,25 +36,30 @@ defined('MOODLE_INTERNAL') || die(); class backup_assignsubmission_file_subplugin extends backup_subplugin { /** - * * Returns the subplugin information to attach to submission element * @return backup_subplugin_element */ protected function define_submission_subplugin_structure() { - // create XML elements - $subplugin = $this->get_subplugin_element(); // virtual optigroup element + // Create XML elements. + $subplugin = $this->get_subplugin_element(); $subpluginwrapper = new backup_nested_element($this->get_recommended_name()); - $subpluginelement = new backup_nested_element('submission_file', null, array('numfiles', 'submission')); + $subpluginelement = new backup_nested_element('submission_file', + null, + array('numfiles', 'submission')); - // connect XML elements into the tree + // Connect XML elements into the tree. $subplugin->add_child($subpluginwrapper); $subpluginwrapper->add_child($subpluginelement); - // set source to populate the data - $subpluginelement->set_source_table('assignsubmission_file', array('submission' => backup::VAR_PARENTID)); + // Set source to populate the data. + $subpluginelement->set_source_table('assignsubmission_file', + array('submission' => backup::VAR_PARENTID)); - $subpluginelement->annotate_files('assignsubmission_file', 'submission_files', 'submission');// The parent is the submission + // The parent is the submission. + $subpluginelement->annotate_files('assignsubmission_file', + 'submission_files', + 'submission'); return $subplugin; } diff --git a/mod/assign/submission/file/backup/moodle2/restore_assignsubmission_file_subplugin.class.php b/mod/assign/submission/file/backup/moodle2/restore_assignsubmission_file_subplugin.class.php index 92879c27e83..8f575e538a3 100644 --- a/mod/assign/submission/file/backup/moodle2/restore_assignsubmission_file_subplugin.class.php +++ b/mod/assign/submission/file/backup/moodle2/restore_assignsubmission_file_subplugin.class.php @@ -23,7 +23,8 @@ */ /** - * restore subplugin class that provides the necessary information needed to restore one assign_submission subplugin. + * restore subplugin class that provides the necessary information + * needed to restore one assign_submission subplugin. * * @package assignsubmission_file * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -40,10 +41,11 @@ class restore_assignsubmission_file_subplugin extends restore_subplugin { $paths = array(); $elename = $this->get_namefor('submission'); - $elepath = $this->get_pathfor('/submission_file'); // we used get_recommended_name() so this works + $elepath = $this->get_pathfor('/submission_file'); + // We used get_recommended_name() so this works. $paths[] = new restore_path_element($elename, $elepath); - return $paths; // And we return the interesting paths + return $paths; } /** @@ -57,12 +59,17 @@ class restore_assignsubmission_file_subplugin extends restore_subplugin { $data = (object)$data; $data->assignment = $this->get_new_parentid('assign'); $oldsubmissionid = $data->submission; - // the mapping is set in the restore for the core assign activity. When a submission node is processed + // The mapping is set in the restore for the core assign activity + // when a submission node is processed. $data->submission = $this->get_mappingid('submission', $data->submission); $DB->insert_record('assignsubmission_file', $data); - $this->add_related_files('assignsubmission_file', 'submission_files', 'submission', null, $oldsubmissionid); + $this->add_related_files('assignsubmission_file', + 'submission_files', + 'submission', + null, + $oldsubmissionid); } } diff --git a/mod/assign/submission/file/db/upgrade.php b/mod/assign/submission/file/db/upgrade.php index 87c15bb85ae..cacdb032e1a 100644 --- a/mod/assign/submission/file/db/upgrade.php +++ b/mod/assign/submission/file/db/upgrade.php @@ -28,13 +28,9 @@ * @return bool */ function xmldb_assignsubmission_file_upgrade($oldversion) { - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this + // Moodle v2.4.0 release upgrade line. + // Put any upgrade step following this. return true; } diff --git a/mod/assign/submission/file/lang/en/assignsubmission_file.php b/mod/assign/submission/file/lang/en/assignsubmission_file.php index cf1e3d525f1..69124e9e1a7 100644 --- a/mod/assign/submission/file/lang/en/assignsubmission_file.php +++ b/mod/assign/submission/file/lang/en/assignsubmission_file.php @@ -35,6 +35,7 @@ $string['maxfilessubmission'] = 'Maximum number of uploaded files'; $string['maxfilessubmission_help'] = 'If file submissions are enabled, each student will be able to upload up to this number of files for their submission.'; $string['maximumsubmissionsize'] = 'Maximum submission size'; $string['maximumsubmissionsize_help'] = 'Files uploaded by students may be up to this size.'; +$string['numfilesforlog'] = 'The number of file(s) : {$a} file(s).'; $string['pluginname'] = 'File submissions'; $string['siteuploadlimit'] = 'Site upload limit'; $string['submissionfilearea'] = 'Uploaded submission files'; diff --git a/mod/assign/submission/file/lib.php b/mod/assign/submission/file/lib.php index 36abc1b056c..8b58fe21894 100644 --- a/mod/assign/submission/file/lib.php +++ b/mod/assign/submission/file/lib.php @@ -34,7 +34,12 @@ defined('MOODLE_INTERNAL') || die(); * @param bool $forcedownload * @return bool false if file not found, does not return if found - just send the file */ -function assignsubmission_file_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload) { +function assignsubmission_file_pluginfile($course, + $cm, + context $context, + $filearea, + $args, + $forcedownload) { global $USER, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -43,7 +48,10 @@ function assignsubmission_file_pluginfile($course, $cm, context $context, $filea require_login($course, false, $cm); $itemid = (int)array_shift($args); - $record = $DB->get_record('assign_submission', array('id'=>$itemid), 'userid, assignment', MUST_EXIST); + $record = $DB->get_record('assign_submission', + array('id'=>$itemid), + 'userid, assignment', + MUST_EXIST); $userid = $record->userid; if (!$assign = $DB->get_record('assign', array('id'=>$cm->instance))) { @@ -54,7 +62,7 @@ function assignsubmission_file_pluginfile($course, $cm, context $context, $filea return false; } - // check is users submission or has grading permission + // Check if this is the current users submission or the user has grading permission. if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) { return false; } @@ -67,5 +75,7 @@ function assignsubmission_file_pluginfile($course, $cm, context $context, $filea if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { return false; } - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + + // Download MUST be forced - security! + send_stored_file($file, 0, 0, true); } diff --git a/mod/assign/submission/file/locallib.php b/mod/assign/submission/file/locallib.php index ed1e23471dc..a6c8e97413a 100644 --- a/mod/assign/submission/file/locallib.php +++ b/mod/assign/submission/file/locallib.php @@ -24,19 +24,17 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** Include eventslib.php */ require_once($CFG->libdir.'/eventslib.php'); defined('MOODLE_INTERNAL') || die(); -/** - * File areas for file submission assignment - */ + +// File areas for file submission assignment. define('ASSIGNSUBMISSION_FILE_MAXFILES', 20); define('ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES', 5); define('ASSIGNSUBMISSION_FILE_FILEAREA', 'submission_files'); /** - * library class for file submission plugin extending submission plugin base class + * Library class for file submission plugin extending submission plugin base class * * @package assignsubmission_file * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -77,19 +75,25 @@ class assign_submission_file extends assign_submission_plugin { $settings = array(); $options = array(); - for($i = 1; $i <= ASSIGNSUBMISSION_FILE_MAXFILES; $i++) { + for ($i = 1; $i <= ASSIGNSUBMISSION_FILE_MAXFILES; $i++) { $options[$i] = $i; } - $mform->addElement('select', 'assignsubmission_file_maxfiles', get_string('maxfilessubmission', 'assignsubmission_file'), $options); - $mform->addHelpButton('assignsubmission_file_maxfiles', 'maxfilessubmission', 'assignsubmission_file'); + $name = get_string('maxfilessubmission', 'assignsubmission_file'); + $mform->addElement('select', 'assignsubmission_file_maxfiles', $name, $options); + $mform->addHelpButton('assignsubmission_file_maxfiles', + 'maxfilessubmission', + 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_maxfiles', $defaultmaxfilesubmissions); $mform->disabledIf('assignsubmission_file_maxfiles', 'assignsubmission_file_enabled', 'eq', 0); - $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, get_config('assignsubmission_file', 'maxbytes')); + $choices = get_max_upload_sizes($CFG->maxbytes, + $COURSE->maxbytes, + get_config('assignsubmission_file', 'maxbytes')); // Remove the option for 0 bytes. unset($choices[0]); + if ($COURSE->maxbytes == 0) { $choices = array(0=>get_string('siteuploadlimit', 'assignsubmission_file')) + $choices; } else { @@ -101,10 +105,15 @@ class assign_submission_file extends assign_submission_plugin { 'options'=> $choices, 'default'=> $defaultmaxsubmissionsizebytes); - $mform->addElement('select', 'assignsubmission_file_maxsizebytes', get_string('maximumsubmissionsize', 'assignsubmission_file'), $choices); - $mform->addHelpButton('assignsubmission_file_maxsizebytes', 'maximumsubmissionsize', 'assignsubmission_file'); + $name = get_string('maximumsubmissionsize', 'assignsubmission_file'); + $mform->addElement('select', 'assignsubmission_file_maxsizebytes', $name, $choices); + $mform->addHelpButton('assignsubmission_file_maxsizebytes', + 'maximumsubmissionsize', + 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_maxsizebytes', $defaultmaxsubmissionsizebytes); - $mform->disabledIf('assignsubmission_file_maxsizebytes', 'assignsubmission_file_enabled', 'eq', 0); + $mform->disabledIf('assignsubmission_file_maxsizebytes', + 'assignsubmission_file_enabled', + 'eq', 0); } /** @@ -150,8 +159,13 @@ class assign_submission_file extends assign_submission_plugin { $fileoptions = $this->get_file_options(); $submissionid = $submission ? $submission->id : 0; - - $data = file_prepare_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submissionid); + $data = file_prepare_standard_filemanager($data, + 'files', + $fileoptions, + $this->assignment->get_context(), + 'assignsubmission_file', + ASSIGNSUBMISSION_FILE_FILEAREA, + $submissionid); $mform->addElement('filemanager', 'files_filemanager', '', null, $fileoptions); return true; } @@ -166,13 +180,19 @@ class assign_submission_file extends assign_submission_plugin { private function count_files($submissionid, $area) { $fs = get_file_storage(); - $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', $area, $submissionid, "id", false); + $files = $fs->get_area_files($this->assignment->get_context()->id, + 'assignsubmission_file', + $area, + $submissionid, + 'id', + false); return count($files); } /** - * Save the files and trigger plagiarism plugin, if enabled, to scan the uploaded files via events trigger + * Save the files and trigger plagiarism plugin, if enabled, + * to scan the uploaded files via events trigger * * @param stdClass $submission * @param stdClass $data @@ -183,19 +203,30 @@ class assign_submission_file extends assign_submission_plugin { $fileoptions = $this->get_file_options(); - - $data = file_postupdate_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); - + $data = file_postupdate_standard_filemanager($data, + 'files', + $fileoptions, + $this->assignment->get_context(), + 'assignsubmission_file', + ASSIGNSUBMISSION_FILE_FILEAREA, + $submission->id); $filesubmission = $this->get_file_submission($submission->id); - //plagiarism code event trigger when files are uploaded + // Plagiarism code event trigger when files are uploaded. $fs = get_file_storage(); - $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, "id", false); + $files = $fs->get_area_files($this->assignment->get_context()->id, + 'assignsubmission_file', + ASSIGNSUBMISSION_FILE_FILEAREA, + $submission->id, + 'id', + false); + $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); - // send files to event system - // Let Moodle know that an assessable file was uploaded (eg for plagiarism detection) + + // Send files to event system. + // This lets Moodle know that an assessable file was uploaded (eg for plagiarism detection). $eventdata = new stdClass(); $eventdata->modulename = 'assign'; $eventdata->cmid = $this->assignment->get_course_module()->id; @@ -203,19 +234,20 @@ class assign_submission_file extends assign_submission_plugin { $eventdata->courseid = $this->assignment->get_course()->id; $eventdata->userid = $USER->id; if ($count > 1) { - $eventdata->files = $files; // This is depreceated - please use pathnamehashes instead! + $eventdata->files = $files; } - $eventdata->file = $files; // This is depreceated - please use pathnamehashes instead! + $eventdata->file = $files; $eventdata->pathnamehashes = array_keys($files); events_trigger('assessable_file_uploaded', $eventdata); - if ($filesubmission) { - $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); + $filesubmission->numfiles = $this->count_files($submission->id, + ASSIGNSUBMISSION_FILE_FILEAREA); return $DB->update_record('assignsubmission_file', $filesubmission); } else { $filesubmission = new stdClass(); - $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); + $filesubmission->numfiles = $this->count_files($submission->id, + ASSIGNSUBMISSION_FILE_FILEAREA); $filesubmission->submission = $submission->id; $filesubmission->assignment = $this->assignment->get_instance()->id; return $DB->insert_record('assignsubmission_file', $filesubmission) > 0; @@ -232,7 +264,12 @@ class assign_submission_file extends assign_submission_plugin { $result = array(); $fs = get_file_storage(); - $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, "timemodified", false); + $files = $fs->get_area_files($this->assignment->get_context()->id, + 'assignsubmission_file', + ASSIGNSUBMISSION_FILE_FILEAREA, + $submission->id, + 'timemodified', + false); foreach ($files as $file) { $result[$file->get_filename()] = $file; @@ -250,10 +287,12 @@ class assign_submission_file extends assign_submission_plugin { public function view_summary(stdClass $submission, & $showviewlink) { $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); - // show we show a link to view all files for this plugin? + // Show we show a link to view all files for this plugin? $showviewlink = $count > ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES; if ($count <= ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES) { - return $this->assignment->render_area_files('assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); + return $this->assignment->render_area_files('assignsubmission_file', + ASSIGNSUBMISSION_FILE_FILEAREA, + $submission->id); } else { return get_string('countfiles', 'assignsubmission_file', $count); } @@ -266,7 +305,9 @@ class assign_submission_file extends assign_submission_plugin { * @return string */ public function view(stdClass $submission) { - return $this->assignment->render_area_files('assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); + return $this->assignment->render_area_files('assignsubmission_file', + ASSIGNSUBMISSION_FILE_FILEAREA, + $submission->id); } @@ -300,20 +341,16 @@ class assign_submission_file extends assign_submission_plugin { * @param string $log record log events here * @return bool Was it a success? (false will trigger rollback) */ - public function upgrade_settings(context $oldcontext,stdClass $oldassignment, & $log) { + public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) { if ($oldassignment->assignmenttype == 'uploadsingle') { $this->set_config('maxfilesubmissions', 1); $this->set_config('maxsubmissionsizebytes', $oldassignment->maxbytes); return true; - }else { - + } else { $this->set_config('maxfilesubmissions', $oldassignment->var1); $this->set_config('maxsubmissionsizebytes', $oldassignment->maxbytes); return true; } - - - } /** @@ -326,7 +363,11 @@ class assign_submission_file extends assign_submission_plugin { * @param string $log Record upgrade messages in the log * @return bool true or false - false will trigger a rollback */ - public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $submission, & $log) { + public function upgrade(context $oldcontext, + stdClass $oldassignment, + stdClass $oldsubmission, + stdClass $submission, + & $log) { global $DB; $filesubmission = new stdClass(); @@ -340,24 +381,16 @@ class assign_submission_file extends assign_submission_plugin { return false; } - - - - // now copy the area files + // Now copy the area files. $this->assignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'submission', $oldsubmission->id, - // New file area $this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); - - - - return true; } @@ -368,8 +401,9 @@ class assign_submission_file extends assign_submission_plugin { */ public function delete_instance() { global $DB; - // will throw exception on failure - $DB->delete_records('assignsubmission_file', array('assignment'=>$this->assignment->get_instance()->id)); + // Will throw exception on failure. + $DB->delete_records('assignsubmission_file', + array('assignment'=>$this->assignment->get_instance()->id)); return true; } @@ -378,16 +412,13 @@ class assign_submission_file extends assign_submission_plugin { * Formatting for log info * * @param stdClass $submission The submission - * * @return string */ public function format_for_log(stdClass $submission) { - // format the info for each submission plugin add_to_log + // Format the info for each submission plugin (will be added to log). $filecount = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); - $fileloginfo = ''; - $fileloginfo .= ' the number of file(s) : ' . $filecount . " file(s).
"; - return $fileloginfo; + return get_string('numfilesforlog', 'assignsubmission_file', $filecount); } /** diff --git a/mod/assign/submission/file/settings.php b/mod/assign/submission/file/settings.php index 1d2964d76bd..03bb2b5070f 100644 --- a/mod/assign/submission/file/settings.php +++ b/mod/assign/submission/file/settings.php @@ -23,13 +23,20 @@ */ -// Note this is on by default +// Note: This is on by default. $settings->add(new admin_setting_configcheckbox('assignsubmission_file/default', new lang_string('default', 'assignsubmission_file'), new lang_string('default_help', 'assignsubmission_file'), 1)); if (isset($CFG->maxbytes)) { - $settings->add(new admin_setting_configselect('assignsubmission_file/maxbytes', - new lang_string('maximumsubmissionsize', 'assignsubmission_file'), - new lang_string('configmaxbytes', 'assignsubmission_file'), 1048576, get_max_upload_sizes($CFG->maxbytes))); + + $name = new lang_string('maximumsubmissionsize', 'assignsubmission_file'); + $description = new lang_string('configmaxbytes', 'assignsubmission_file'); + + $element = new admin_setting_configselect('assignsubmission_file/maxbytes', + $name, + $description, + 1048576, + get_max_upload_sizes($CFG->maxbytes)); + $settings->add($element); } diff --git a/mod/assign/submission/onlinetext/backup/moodle2/backup_assignsubmission_onlinetext_subplugin.class.php b/mod/assign/submission/onlinetext/backup/moodle2/backup_assignsubmission_onlinetext_subplugin.class.php index 9cee43e52ae..4ccf749a9e5 100644 --- a/mod/assign/submission/onlinetext/backup/moodle2/backup_assignsubmission_onlinetext_subplugin.class.php +++ b/mod/assign/submission/onlinetext/backup/moodle2/backup_assignsubmission_onlinetext_subplugin.class.php @@ -36,25 +36,30 @@ defined('MOODLE_INTERNAL') || die(); class backup_assignsubmission_onlinetext_subplugin extends backup_subplugin { /** - * * Returns the subplugin information to attach to submission element + * * @return backup_subplugin_element */ protected function define_submission_subplugin_structure() { - // create XML elements - $subplugin = $this->get_subplugin_element(); // virtual optigroup element + // Create XML elements. + $subplugin = $this->get_subplugin_element(); $subpluginwrapper = new backup_nested_element($this->get_recommended_name()); - $subpluginelement = new backup_nested_element('submission_onlinetext', null, array('onlinetext', 'onlineformat', 'submission')); + $subpluginelement = new backup_nested_element('submission_onlinetext', + null, + array('onlinetext', 'onlineformat', 'submission')); - // connect XML elements into the tree + // Connect XML elements into the tree. $subplugin->add_child($subpluginwrapper); $subpluginwrapper->add_child($subpluginelement); - // set source to populate the data - $subpluginelement->set_source_table('assignsubmission_onlinetext', array('submission' => backup::VAR_PARENTID)); + // Set source to populate the data. + $subpluginelement->set_source_table('assignsubmission_onlinetext', + array('submission' => backup::VAR_PARENTID)); - $subpluginelement->annotate_files('assignsubmission_onlinetext', 'submissions_onlinetext', 'submission'); + $subpluginelement->annotate_files('assignsubmission_onlinetext', + 'submissions_onlinetext', + 'submission'); return $subplugin; } diff --git a/mod/assign/submission/onlinetext/backup/moodle2/restore_assignsubmission_onlinetext_subplugin.class.php b/mod/assign/submission/onlinetext/backup/moodle2/restore_assignsubmission_onlinetext_subplugin.class.php index 2316bd82e02..bfa234289c6 100644 --- a/mod/assign/submission/onlinetext/backup/moodle2/restore_assignsubmission_onlinetext_subplugin.class.php +++ b/mod/assign/submission/onlinetext/backup/moodle2/restore_assignsubmission_onlinetext_subplugin.class.php @@ -23,7 +23,8 @@ */ /** - * restore subplugin class that provides the necessary information needed to restore one assign_submission subplugin. + * restore subplugin class that provides the necessary information needed to restore + * one assign_submission subplugin. * * @package assignsubmission_onlinetext * @copyright 2012 NetSpot {@link http://www.netspot.com.au} @@ -32,7 +33,6 @@ class restore_assignsubmission_onlinetext_subplugin extends restore_subplugin { /** - * * Returns array the paths to be handled by the subplugin at assignment level * @return array */ @@ -41,10 +41,12 @@ class restore_assignsubmission_onlinetext_subplugin extends restore_subplugin { $paths = array(); $elename = $this->get_namefor('submission'); - $elepath = $this->get_pathfor('/submission_onlinetext'); // we used get_recommended_name() so this works + + // We used get_recommended_name() so this works. + $elepath = $this->get_pathfor('/submission_onlinetext'); $paths[] = new restore_path_element($elename, $elepath); - return $paths; // And we return the interesting paths + return $paths; } /** @@ -58,7 +60,8 @@ class restore_assignsubmission_onlinetext_subplugin extends restore_subplugin { $data = (object)$data; $data->assignment = $this->get_new_parentid('assign'); $oldsubmissionid = $data->submission; - // the mapping is set in the restore for the core assign activity. When a submission node is processed + // The mapping is set in the restore for the core assign activity + // when a submission node is processed. $data->submission = $this->get_mappingid('submission', $data->submission); $DB->insert_record('assignsubmission_onlinetext', $data); diff --git a/mod/assign/submission/onlinetext/db/install.php b/mod/assign/submission/onlinetext/db/install.php index 0e1d18b5104..26aa4e74eb7 100644 --- a/mod/assign/submission/onlinetext/db/install.php +++ b/mod/assign/submission/onlinetext/db/install.php @@ -32,20 +32,12 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_assignsubmission_onlinetext_install() { global $CFG; - // do the install - + // Set the correct initial order for the plugins. require_once($CFG->dirroot . '/mod/assign/adminlib.php'); - // set the correct initial order for the plugins $pluginmanager = new assign_plugin_manager('assignsubmission'); $pluginmanager->move_plugin('onlinetext', 'up'); $pluginmanager->move_plugin('onlinetext', 'up'); - // do the upgrades return true; - - - } - - diff --git a/mod/assign/submission/onlinetext/db/upgrade.php b/mod/assign/submission/onlinetext/db/upgrade.php index b93cd4ca445..980c24d1122 100644 --- a/mod/assign/submission/onlinetext/db/upgrade.php +++ b/mod/assign/submission/onlinetext/db/upgrade.php @@ -28,13 +28,11 @@ * @return bool */ function xmldb_assignsubmission_onlinetext_upgrade($oldversion) { - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this + // Moodle v2.3.0 release upgrade line. + // Put any upgrade step following this. + // Moodle v2.4.0 release upgrade line. + // Put any upgrade step following this. return true; } diff --git a/mod/assign/submission/onlinetext/lib.php b/mod/assign/submission/onlinetext/lib.php index 0b84cf83188..19e8e73394a 100644 --- a/mod/assign/submission/onlinetext/lib.php +++ b/mod/assign/submission/onlinetext/lib.php @@ -54,7 +54,7 @@ function assignsubmission_onlinetext_pluginfile($course, $cm, context $context, return false; } - // check is users submission or has grading permission + // Check is users submission or has grading permission. if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) { return false; } @@ -67,5 +67,7 @@ function assignsubmission_onlinetext_pluginfile($course, $cm, context $context, if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { return false; } - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + + // Download MUST be forced - security! + send_stored_file($file, 0, 0, true); } diff --git a/mod/assign/submission/onlinetext/locallib.php b/mod/assign/submission/onlinetext/locallib.php index 85f57a13728..d5c159b3f84 100644 --- a/mod/assign/submission/onlinetext/locallib.php +++ b/mod/assign/submission/onlinetext/locallib.php @@ -25,9 +25,7 @@ */ defined('MOODLE_INTERNAL') || die(); -/** - * File area for online text submission assignment - */ +// File area for online text submission assignment. define('ASSIGNSUBMISSION_ONLINETEXT_FILEAREA', 'submissions_onlinetext'); /** @@ -48,12 +46,12 @@ class assign_submission_onlinetext extends assign_submission_plugin { } - /** - * Get onlinetext submission information from the database - * - * @param int $submissionid - * @return mixed - */ + /** + * Get onlinetext submission information from the database + * + * @param int $submissionid + * @return mixed + */ private function get_onlinetext_submission($submissionid) { global $DB; @@ -90,8 +88,13 @@ class assign_submission_onlinetext extends assign_submission_plugin { } - - $data = file_prepare_standard_editor($data, 'onlinetext', $editoroptions, $this->assignment->get_context(), 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $submissionid); + $data = file_prepare_standard_editor($data, + 'onlinetext', + $editoroptions, + $this->assignment->get_context(), + 'assignsubmission_onlinetext', + ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, + $submissionid); $mform->addElement('editor', 'onlinetext_editor', '', null, $editoroptions); return true; } @@ -112,32 +115,51 @@ class assign_submission_onlinetext extends assign_submission_plugin { return $editoroptions; } - /** - * Save data to the database and trigger plagiarism plugin, if enabled, to scan the uploaded content via events trigger - * - * @param stdClass $submission - * @param stdClass $data - * @return bool - */ - public function save(stdClass $submission, stdClass $data) { + /** + * Save data to the database and trigger plagiarism plugin, + * if enabled, to scan the uploaded content via events trigger + * + * @param stdClass $submission + * @param stdClass $data + * @return bool + */ + public function save(stdClass $submission, stdClass $data) { global $USER, $DB; $editoroptions = $this->get_edit_options(); - $data = file_postupdate_standard_editor($data, 'onlinetext', $editoroptions, $this->assignment->get_context(), 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $submission->id); + $data = file_postupdate_standard_editor($data, + 'onlinetext', + $editoroptions, + $this->assignment->get_context(), + 'assignsubmission_onlinetext', + ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, + $submission->id); $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); + $text = format_text($data->onlinetext, + $data->onlinetext_editor['format'], + array('context'=>$this->assignment->get_context())); + $fs = get_file_storage(); - $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $submission->id, "id", false); - // Let Moodle know that an assessable content was uploaded (eg for plagiarism detection) + + $files = $fs->get_area_files($this->assignment->get_context()->id, + 'assignsubmission_onlinetext', + ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, + $submission->id, + 'id', + false); + + // Let Moodle know that an assessable content was uploaded (eg for plagiarism detection). $eventdata = new stdClass(); $eventdata->modulename = 'assign'; $eventdata->cmid = $this->assignment->get_course_module()->id; $eventdata->itemid = $submission->id; $eventdata->courseid = $this->assignment->get_course()->id; $eventdata->userid = $USER->id; - $eventdata->content = trim(format_text($data->onlinetext, $data->onlinetext_editor['format'], array('context'=>$this->assignment->get_context()))); + $eventdata->content = trim($text); + if ($files) { $eventdata->pathnamehashes = array_keys($files); } @@ -148,7 +170,6 @@ class assign_submission_onlinetext extends assign_submission_plugin { $onlinetextsubmission->onlinetext = $data->onlinetext; $onlinetextsubmission->onlineformat = $data->onlinetext_editor['format']; - return $DB->update_record('assignsubmission_onlinetext', $onlinetextsubmission); } else { @@ -160,8 +181,6 @@ class assign_submission_onlinetext extends assign_submission_plugin { $onlinetextsubmission->assignment = $this->assignment->get_instance()->id; return $DB->insert_record('assignsubmission_onlinetext', $onlinetextsubmission) > 0; } - - } /** @@ -206,8 +225,7 @@ class assign_submission_onlinetext extends assign_submission_plugin { } } - - return 0; + return 0; } @@ -222,7 +240,7 @@ class assign_submission_onlinetext extends assign_submission_plugin { global $CFG; $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); - // always show the view link + // Always show the view link. $showviewlink = true; if ($onlinetextsubmission) { @@ -234,16 +252,20 @@ class assign_submission_onlinetext extends assign_submission_plugin { $shorttext = shorten_text($text, 140); $plagiarismlinks = ''; + if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir . '/plagiarismlib.php'); + $plagiarismlinks .= plagiarism_get_links(array('userid' => $submission->userid, - 'content' => trim(format_text($onlinetextsubmission->onlinetext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context()))), + 'content' => trim($text), 'cmid' => $this->assignment->get_course_module()->id, 'course' => $this->assignment->get_course()->id, 'assignment' => $submission->assignment)); } if ($text != $shorttext) { - return $shorttext . $plagiarismlinks . get_string('numwords', 'assignsubmission_onlinetext', count_words($text)); + $wordcount = get_string('numwords', 'assignsubmission_onlinetext', count_words($text)); + + return $shorttext . $plagiarismlinks . $wordcount; } else { return $shorttext . $plagiarismlinks; } @@ -252,17 +274,22 @@ class assign_submission_onlinetext extends assign_submission_plugin { } /** - * Produce a list of files suitable for export that represent this submission + * Produce a list of files suitable for export that represent this submission. * * @param stdClass $submission - For this is the submission data * @return array - return an array of files indexed by filename */ public function get_files(stdClass $submission) { global $DB; + $files = array(); $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); + if ($onlinetextsubmission) { - $user = $DB->get_record("user", array("id"=>$submission->userid),'id,username,firstname,lastname', MUST_EXIST); + $user = $DB->get_record('user', + array('id'=>$submission->userid), + 'id,username,firstname,lastname', + MUST_EXIST); if (!$this->assignment->is_blind_marking()) { $filename = str_replace('_', '', fullname($user)) . '_' . @@ -277,13 +304,23 @@ class assign_submission_onlinetext extends assign_submission_plugin { } $finaltext = str_replace('@@PLUGINFILE@@/', $prefix, $onlinetextsubmission->onlinetext); - $submissioncontent = "". format_text($finaltext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context())). ""; //fetched from database - $files[get_string('onlinetextfilename', 'assignsubmission_onlinetext')] = array($submissioncontent); + $formattedtext = format_text($finaltext, + $onlinetextsubmission->onlineformat, + array('context'=>$this->assignment->get_context())); + $submissioncontent = ''. $formattedtext . ''; + + $filename = get_string('onlinetextfilename', 'assignsubmission_onlinetext'); + $files[$filename] = array($submissioncontent); $fs = get_file_storage(); - $fsfiles = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $submission->id, "timemodified", false); + $fsfiles = $fs->get_area_files($this->assignment->get_context()->id, + 'assignsubmission_onlinetext', + ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, + $submission->id, + 'timemodified', + false); foreach ($fsfiles as $file) { $files[$file->get_filename()] = $file; @@ -304,18 +341,21 @@ class assign_submission_onlinetext extends assign_submission_plugin { $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); - if ($onlinetextsubmission) { - // render for portfolio API - $result .= $this->assignment->render_editor_content(ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $onlinetextsubmission->submission, $this->get_type(), 'onlinetext', 'assignsubmission_onlinetext'); + // Render for portfolio API. + $result .= $this->assignment->render_editor_content(ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, + $onlinetextsubmission->submission, + $this->get_type(), + 'onlinetext', + 'assignsubmission_onlinetext'); } return $result; } - /** + /** * Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type and version. * * @param string $type old assignment subtype @@ -339,7 +379,7 @@ class assign_submission_onlinetext extends assign_submission_plugin { * @return bool Was it a success? */ public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) { - // first upgrade settings (nothing to do) + // No settings to upgrade. return true; } @@ -353,7 +393,11 @@ class assign_submission_onlinetext extends assign_submission_plugin { * @param string $log Record upgrade messages in the log * @return bool true or false - false will trigger a rollback */ - public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $submission, & $log) { + public function upgrade(context $oldcontext, + stdClass $oldassignment, + stdClass $oldsubmission, + stdClass $submission, + & $log) { global $DB; $onlinetextsubmission = new stdClass(); @@ -376,12 +420,11 @@ class assign_submission_onlinetext extends assign_submission_plugin { return false; } - // now copy the area files + // Now copy the area files. $this->assignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'submission', $oldsubmission->id, - // New file area $this->assignment->get_context()->id, 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, @@ -396,13 +439,15 @@ class assign_submission_onlinetext extends assign_submission_plugin { * @return string */ public function format_for_log(stdClass $submission) { - // format the info for each submission plugin add_to_log + // Format the info for each submission plugin (will be logged). $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); $onlinetextloginfo = ''; $text = format_text($onlinetextsubmission->onlinetext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context())); - $onlinetextloginfo .= get_string('numwordsforlog', 'assignsubmission_onlinetext', count_words($text)); + $onlinetextloginfo .= get_string('numwordsforlog', + 'assignsubmission_onlinetext', + count_words($text)); return $onlinetextloginfo; } @@ -414,8 +459,8 @@ class assign_submission_onlinetext extends assign_submission_plugin { */ public function delete_instance() { global $DB; - // will throw exception on failure - $DB->delete_records('assignsubmission_onlinetext', array('assignment'=>$this->assignment->get_instance()->id)); + $DB->delete_records('assignsubmission_onlinetext', + array('assignment'=>$this->assignment->get_instance()->id)); return true; } diff --git a/mod/assign/submission_form.php b/mod/assign/submission_form.php index 12e91de01e0..fc466697111 100644 --- a/mod/assign/submission_form.php +++ b/mod/assign/submission_form.php @@ -25,7 +25,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -/** Include locallib.php */ require_once($CFG->libdir . '/formslib.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -41,7 +40,7 @@ class mod_assign_submission_form extends moodleform { /** * Define this form - called by the parent constructor */ - function definition() { + public function definition() { $mform = $this->_form; list($assign, $data) = $this->_customdata; diff --git a/mod/assign/submissionconfirmform.php b/mod/assign/submissionconfirmform.php index 809f4036f95..2a7636c4012 100644 --- a/mod/assign/submissionconfirmform.php +++ b/mod/assign/submissionconfirmform.php @@ -24,10 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); - -/** Include formslib.php */ -require_once ($CFG->libdir.'/formslib.php'); -/** Include locallib.php */ +require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); /** @@ -41,10 +38,13 @@ class mod_assign_confirm_submission_form extends moodleform { /** * Define the form - called by parent constructor */ - function definition() { + public function definition() { $mform = $this->_form; - list($requiresubmissionstatement, $submissionstatement, $coursemoduleid, $data) = $this->_customdata; + list($requiresubmissionstatement, + $submissionstatement, + $coursemoduleid, + $data) = $this->_customdata; if ($requiresubmissionstatement) { $mform->addElement('checkbox', 'submissionstatement', '', ' ' . $submissionstatement); diff --git a/mod/assign/submissionplugin.php b/mod/assign/submissionplugin.php index 29462c9ee55..6f0d2512d45 100644 --- a/mod/assign/submissionplugin.php +++ b/mod/assign/submissionplugin.php @@ -12,7 +12,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . +// along with Moodle. If not, see . /** * This file contains the definition for the abstract class for submission_plugin diff --git a/mod/assign/upgradelib.php b/mod/assign/upgradelib.php index d8bb7c2ca9e..055457bef2c 100644 --- a/mod/assign/upgradelib.php +++ b/mod/assign/upgradelib.php @@ -24,12 +24,10 @@ defined('MOODLE_INTERNAL') || die(); -/** Include locallib.php */ require_once($CFG->dirroot.'/mod/assign/locallib.php'); -/** Include accesslib.php */ require_once($CFG->libdir.'/accesslib.php'); -/** +/* * The maximum amount of time to spend upgrading a single assignment. * This is intentionally generous (5 mins) as the effect of a timeout * for a legitimate upgrade would be quite harsh (roll back code will not run) @@ -54,25 +52,26 @@ class assign_upgrade_manager { * @return bool true or false */ public function upgrade_assignment($oldassignmentid, & $log) { - // steps to upgrade an assignment global $DB, $CFG, $USER; - // steps to upgrade an assignment + // Steps to upgrade an assignment. - // is the user the admin? admin check goes here + // Is the user the admin? admin check goes here. if (!is_siteadmin($USER->id)) { return false; } - // should we use a shutdown handler to rollback on timeout? @set_time_limit(ASSIGN_MAX_UPGRADE_TIME_SECS); - - // get the module details + // Get the module details. $oldmodule = $DB->get_record('modules', array('name'=>'assignment'), '*', MUST_EXIST); - $oldcoursemodule = $DB->get_record('course_modules', array('module'=>$oldmodule->id, 'instance'=>$oldassignmentid), '*', MUST_EXIST); + $params = array('module'=>$oldmodule->id, 'instance'=>$oldassignmentid); + $oldcoursemodule = $DB->get_record('course_modules', + $params, + '*', + MUST_EXIST); $oldcontext = context_module::instance($oldcoursemodule->id); - // first insert an assign instance to get the id + // First insert an assign instance to get the id. $oldassignment = $DB->get_record('assignment', array('id'=>$oldassignmentid), '*', MUST_EXIST); $oldversion = get_config('assignment_' . $oldassignment->assignmenttype, 'version'); @@ -107,36 +106,37 @@ class assign_upgrade_manager { return false; } - // now create a new coursemodule from the old one + // Now create a new coursemodule from the old one. $newmodule = $DB->get_record('modules', array('name'=>'assign'), '*', MUST_EXIST); - $newcoursemodule = $this->duplicate_course_module($oldcoursemodule, $newmodule->id, $newassignment->get_instance()->id); + $newcoursemodule = $this->duplicate_course_module($oldcoursemodule, + $newmodule->id, + $newassignment->get_instance()->id); if (!$newcoursemodule) { $log = get_string('couldnotcreatenewcoursemodule', 'mod_assign'); return false; } - // convert the base database tables (assignment, submission, grade) + // Convert the base database tables (assignment, submission, grade). - // these are used to store information in case a rollback is required + // These are used to store information in case a rollback is required. $gradingarea = null; $gradingdefinitions = null; $gradeidmap = array(); $completiondone = false; $gradesdone = false; - // from this point we want to rollback on failure + // From this point we want to rollback on failure. $rollback = false; try { $newassignment->set_context(context_module::instance($newcoursemodule->id)); - // the course module has now been created - time to update the core tables + // The course module has now been created - time to update the core tables. - // copy intro files + // Copy intro files. $newassignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'intro', 0, $newassignment->get_context()->id, 'mod_assign', 'intro', 0); - - // get the plugins to do their bit + // Get the plugins to do their bit. foreach ($newassignment->get_submission_plugins() as $plugin) { if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) { $plugin->enable(); @@ -158,16 +158,28 @@ class assign_upgrade_manager { } } - // see if there is advanced grading upgrades required - $gradingarea = $DB->get_record('grading_areas', array('contextid'=>$oldcontext->id, 'areaname'=>'submission'), '*', IGNORE_MISSING); + // See if there is advanced grading upgrades required. + $gradingarea = $DB->get_record('grading_areas', + array('contextid'=>$oldcontext->id, 'areaname'=>'submission'), + '*', + IGNORE_MISSING); if ($gradingarea) { - $DB->update_record('grading_areas', array('id'=>$gradingarea->id, 'contextid'=>$newassignment->get_context()->id, 'component'=>'mod_assign', 'areaname'=>'submissions')); - $gradingdefinitions = $DB->get_records('grading_definitions', array('areaid'=>$gradingarea->id)); + $params = array('id'=>$gradingarea->id, + 'contextid'=>$newassignment->get_context()->id, + 'component'=>'mod_assign', + 'areaname'=>'submissions'); + $DB->update_record('grading_areas', $params); + $gradingdefinitions = $DB->get_records('grading_definitions', + array('areaid'=>$gradingarea->id)); } - // upgrade completion data - $DB->set_field('course_modules_completion', 'coursemoduleid', $newcoursemodule->id, array('coursemoduleid'=>$oldcoursemodule->id)); - $allcriteria = $DB->get_records('course_completion_criteria', array('moduleinstance'=>$oldcoursemodule->id)); + // Upgrade completion data. + $DB->set_field('course_modules_completion', + 'coursemoduleid', + $newcoursemodule->id, + array('coursemoduleid'=>$oldcoursemodule->id)); + $allcriteria = $DB->get_records('course_completion_criteria', + array('moduleinstance'=>$oldcoursemodule->id)); foreach ($allcriteria as $criteria) { $criteria->module = 'assign'; $criteria->moduleinstance = $newcoursemodule->id; @@ -180,9 +192,9 @@ class assign_upgrade_manager { $DB->set_field('log', 'module', 'assign', $logparams); $DB->set_field('log', 'cmid', $newcoursemodule->id, $logparams); - - // copy all the submission data (and get plugins to do their bit) - $oldsubmissions = $DB->get_records('assignment_submissions', array('assignment'=>$oldassignmentid)); + // Copy all the submission data (and get plugins to do their bit). + $oldsubmissions = $DB->get_records('assignment_submissions', + array('assignment'=>$oldassignmentid)); foreach ($oldsubmissions as $oldsubmission) { $submission = new stdClass(); @@ -198,20 +210,23 @@ class assign_upgrade_manager { } foreach ($newassignment->get_submission_plugins() as $plugin) { if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) { - if (!$plugin->upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, $log)) { + if (!$plugin->upgrade($oldcontext, + $oldassignment, + $oldsubmission, + $submission, + $log)) { $rollback = true; } } } if ($oldsubmission->timemarked) { - // submission has been graded - create a grade record + // Submission has been graded - create a grade record. $grade = new stdClass(); $grade->assignment = $newassignment->get_instance()->id; $grade->userid = $oldsubmission->userid; $grade->grader = $oldsubmission->teacher; $grade->timemodified = $oldsubmission->timemarked; $grade->timecreated = $oldsubmission->timecreated; - // $grade->locked = $oldsubmission->locked; $grade->grade = $oldsubmission->grade; $grade->mailed = $oldsubmission->mailed; $grade->id = $DB->insert_record('assign_grades', $grade); @@ -220,19 +235,25 @@ class assign_upgrade_manager { $rollback = true; } - // copy any grading instances + // Copy any grading instances. if ($gradingarea) { $gradeidmap[$grade->id] = $oldsubmission->id; foreach ($gradingdefinitions as $definition) { - $DB->set_field('grading_instances', 'itemid', $grade->id, array('definitionid'=>$definition->id, 'itemid'=>$oldsubmission->id)); + $params = array('definitionid'=>$definition->id, + 'itemid'=>$oldsubmission->id); + $DB->set_field('grading_instances', 'itemid', $grade->id, $params); } } foreach ($newassignment->get_feedback_plugins() as $plugin) { if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) { - if (!$plugin->upgrade($oldcontext, $oldassignment, $oldsubmission, $grade, $log)) { + if (!$plugin->upgrade($oldcontext, + $oldassignment, + $oldsubmission, + $grade, + $log)) { $rollback = true; } } @@ -256,42 +277,53 @@ class assign_upgrade_manager { } if ($rollback) { - // roll back the grades changes + // Roll back the grades changes. if ($gradesdone) { // Reassociate grade_items from the new assign instance to the old assignment instance. $params = array('assignment', $oldassignment->id, 'assign', $newassignment->get_instance()->id); $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?'; $DB->execute($sql, $params); } - // roll back the completion changes + // Roll back the completion changes. if ($completiondone) { - $DB->set_field('course_modules_completion', 'coursemoduleid', $oldcoursemodule->id, array('coursemoduleid'=>$newcoursemodule->id)); - $allcriteria = $DB->get_records('course_completion_criteria', array('moduleinstance'=>$newcoursemodule->id)); + $DB->set_field('course_modules_completion', + 'coursemoduleid', + $oldcoursemodule->id, + array('coursemoduleid'=>$newcoursemodule->id)); + + $allcriteria = $DB->get_records('course_completion_criteria', + array('moduleinstance'=>$newcoursemodule->id)); foreach ($allcriteria as $criteria) { $criteria->module = 'assignment'; $criteria->moduleinstance = $oldcoursemodule->id; $DB->update_record('course_completion_criteria', $criteria); } } - // Roll back the log changes + // Roll back the log changes. $logparams = array('cmid' => $newcoursemodule->id, 'course' => $newcoursemodule->course); $DB->set_field('log', 'module', 'assignment', $logparams); $DB->set_field('log', 'cmid', $oldcoursemodule->id, $logparams); - // roll back the advanced grading update + // Roll back the advanced grading update. if ($gradingarea) { foreach ($gradeidmap as $newgradeid => $oldsubmissionid) { foreach ($gradingdefinitions as $definition) { - $DB->set_field('grading_instances', 'itemid', $oldsubmissionid, array('definitionid'=>$definition->id, 'itemid'=>$newgradeid)); + $DB->set_field('grading_instances', + 'itemid', + $oldsubmissionid, + array('definitionid'=>$definition->id, 'itemid'=>$newgradeid)); } } - $DB->update_record('grading_areas', array('id'=>$gradingarea->id, 'contextid'=>$oldcontext->id, 'component'=>'mod_assignment', 'areaname'=>'submission')); + $params = array('id'=>$gradingarea->id, + 'contextid'=>$oldcontext->id, + 'component'=>'mod_assignment', + 'areaname'=>'submission'); + $DB->update_record('grading_areas', $params); } $newassignment->delete_instance(); return false; } - // all is well, - // delete the old assignment (use object delete) + // Delete the old assignment (use object delete). $cm = get_coursemodule_from_id('', $oldcoursemodule->id, $oldcoursemodule->course); if ($cm) { $this->delete_course_module($cm); @@ -328,7 +360,7 @@ class assign_upgrade_manager { $newcm->completiongradeitemnumber = $cm->completiongradeitemnumber; $newcm->completionview = $cm->completionview; $newcm->completionexpected = $cm->completionexpected; - if(!empty($CFG->enableavailability)) { + if (!empty($CFG->enableavailability)) { $newcm->availablefrom = $cm->availablefrom; $newcm->availableuntil = $cm->availableuntil; $newcm->showavailability = $cm->showavailability; @@ -347,8 +379,8 @@ class assign_upgrade_manager { $newcm->section = course_add_cm_to_section($newcm->course, $newcm->id, $section->section); - // make sure visibility is set correctly (in particular in calendar) - // note: allow them to set it even without moodle/course:activityvisibility + // Make sure visibility is set correctly (in particular in calendar). + // Note: Allow them to set it even without moodle/course:activityvisibility. set_coursemodule_visible($newcm->id, $newcm->visible); return $newcm; @@ -382,7 +414,7 @@ class assign_upgrade_manager { echo $OUTPUT->notification("Could not delete the $cm->modname (instance)"); } - // remove all module files in case modules forget to do that + // Remove all module files in case modules forget to do that. $fs = get_file_storage(); $fs->delete_area_files($modcontext->id); diff --git a/mod/assign/version.php b/mod/assign/version.php index 10457b52ffd..683d9dbcab6 100644 --- a/mod/assign/version.php +++ b/mod/assign/version.php @@ -24,9 +24,9 @@ defined('MOODLE_INTERNAL') || die(); -$module->component = 'mod_assign'; // Full name of the plugin (used for diagnostics) -$module->version = 2012112900; // The current module version (Date: YYYYMMDDXX) -$module->requires = 2012112900; // Requires this Moodle version +$module->component = 'mod_assign'; // Full name of the plugin (used for diagnostics). +$module->version = 2012112900; // The current module version (Date: YYYYMMDDXX). +$module->requires = 2012112900; // Requires this Moodle version. $module->cron = 60; diff --git a/mod/assign/view.php b/mod/assign/view.php index 679a2a41c86..3be88b0e530 100644 --- a/mod/assign/view.php +++ b/mod/assign/view.php @@ -22,20 +22,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** config.php */ require_once('../../config.php'); -/** Include locallib.php */ require_once($CFG->dirroot . '/mod/assign/locallib.php'); -$id = required_param('id', PARAM_INT); // Course Module ID -$url = new moodle_url('/mod/assign/view.php', array('id' => $id)); // Base URL - -// get the request parameters +$id = required_param('id', PARAM_INT); +$url = new moodle_url('/mod/assign/view.php', array('id' => $id)); $cm = get_coursemodule_from_id('assign', $id, 0, false, MUST_EXIST); - $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); -// Auth require_login($course, true, $cm); $PAGE->set_url($url); @@ -43,11 +37,11 @@ $context = context_module::instance($cm->id); require_capability('mod/assign:view', $context); -$assign = new assign($context,$cm,$course); +$assign = new assign($context, $cm, $course); -// Mark as viewed $completion=new completion_info($course); $completion->set_module_viewed($cm); -// Get the assign to render the page +// Get the assign class to +// render the page. echo $assign->view(optional_param('action', '', PARAM_TEXT));