Skip to content
Browse files

MDL-31270 mod_assign: introducing the assignment module

* Includes an assignment upgrade tool to convert from the old mod_assignment.
* Hides mod_assignment on new installs
  • Loading branch information...
1 parent b21a1d4 commit bbd0e548c38e7addac1c8d655ffb622817585870 Damyon Wiese committed with danpoltawski May 3, 2012
Showing with 12,820 additions and 0 deletions.
  1. +45 −0 admin/tool/assignmentupgrade/batchupgrade.php
  2. +50 −0 admin/tool/assignmentupgrade/index.php
  3. +56 −0 admin/tool/assignmentupgrade/lang/en/tool_assignmentupgrade.php
  4. +59 −0 admin/tool/assignmentupgrade/lib.php
  5. +48 −0 admin/tool/assignmentupgrade/listnotupgraded.php
  6. +245 −0 admin/tool/assignmentupgrade/locallib.php
  7. +66 −0 admin/tool/assignmentupgrade/module.js
  8. +278 −0 admin/tool/assignmentupgrade/renderer.php
  9. +31 −0 admin/tool/assignmentupgrade/settings.php
  10. +11 −0 admin/tool/assignmentupgrade/styles.css
  11. +55 −0 admin/tool/assignmentupgrade/upgradableassignmentsbatchform.php
  12. +172 −0 admin/tool/assignmentupgrade/upgradableassignmentstable.php
  13. +46 −0 admin/tool/assignmentupgrade/upgradesingle.php
  14. +39 −0 admin/tool/assignmentupgrade/upgradesingleconfirm.php
  15. +29 −0 admin/tool/assignmentupgrade/version.php
  16. +480 −0 mod/assign/adminlib.php
  17. +36 −0 mod/assign/adminmanageplugins.php
  18. +525 −0 mod/assign/assignmentplugin.php
  19. +76 −0 mod/assign/backup/moodle2/backup_assign_activity_task.class.php
  20. +126 −0 mod/assign/backup/moodle2/backup_assign_stepslib.php
  21. +120 −0 mod/assign/backup/moodle2/restore_assign_activity_task.class.php
  22. +156 −0 mod/assign/backup/moodle2/restore_assign_stepslib.php
  23. +86 −0 mod/assign/db/access.php
  24. +32 −0 mod/assign/db/events.php
  25. +89 −0 mod/assign/db/install.xml
  26. +46 −0 mod/assign/db/log.php
  27. +31 −0 mod/assign/db/messages.php
  28. +25 −0 mod/assign/db/subplugins.php
  29. +34 −0 mod/assign/db/upgrade.php
  30. +58 −0 mod/assign/feedback/comments/backup/moodle2/backup_assignfeedback_comments_subplugin.class.php
  31. +66 −0 mod/assign/feedback/comments/backup/moodle2/restore_assignfeedback_comments_subplugin.class.php
  32. +27 −0 mod/assign/feedback/comments/db/access.php
  33. +43 −0 mod/assign/feedback/comments/db/install.php
  34. +22 −0 mod/assign/feedback/comments/db/install.xml
  35. +35 −0 mod/assign/feedback/comments/db/upgrade.php
  36. +29 −0 mod/assign/feedback/comments/lang/en/assignfeedback_comments.php
  37. +248 −0 mod/assign/feedback/comments/locallib.php
  38. +27 −0 mod/assign/feedback/comments/version.php
  39. +59 −0 mod/assign/feedback/file/backup/moodle2/backup_assignfeedback_file_subplugin.class.php
  40. +68 −0 mod/assign/feedback/file/backup/moodle2/restore_assignfeedback_file_subplugin.class.php
  41. +28 −0 mod/assign/feedback/file/db/access.php
  42. +50 −0 mod/assign/feedback/file/db/install.php
  43. +21 −0 mod/assign/feedback/file/db/install.xml
  44. +35 −0 mod/assign/feedback/file/db/upgrade.php
  45. +32 −0 mod/assign/feedback/file/lang/en/assignfeedback_file.php
  46. +73 −0 mod/assign/feedback/file/lib.php
  47. +264 −0 mod/assign/feedback/file/locallib.php
  48. +30 −0 mod/assign/feedback/file/version.php
  49. +84 −0 mod/assign/feedbackplugin.php
  50. +95 −0 mod/assign/gradeform.php
  51. +63 −0 mod/assign/gradingactionsform.php
  52. +67 −0 mod/assign/gradingbatchoperationsform.php
  53. +70 −0 mod/assign/gradingoptionsform.php
  54. +653 −0 mod/assign/gradingtable.php
  55. +66 −0 mod/assign/index.php
  56. +225 −0 mod/assign/lang/en/assign.php
  57. +932 −0 mod/assign/lib.php
  58. +2,911 −0 mod/assign/locallib.php
  59. +150 −0 mod/assign/mod_form.php
  60. +106 −0 mod/assign/module.js
  61. BIN mod/assign/pix/gradefeedback.gif
  62. BIN mod/assign/pix/icon.gif
  63. +281 −0 mod/assign/portfolio_callback.php
  64. +505 −0 mod/assign/renderable.php
  65. +641 −0 mod/assign/renderer.php
  66. +79 −0 mod/assign/settings.php
  67. +130 −0 mod/assign/styles.css
  68. +30 −0 mod/assign/submission/comments/db/access.php
  69. +50 −0 mod/assign/submission/comments/db/install.php
  70. +34 −0 mod/assign/submission/comments/db/upgrade.php
  71. +28 −0 mod/assign/submission/comments/lang/en/assignsubmission_comments.php
  72. +67 −0 mod/assign/submission/comments/lib.php
  73. +167 −0 mod/assign/submission/comments/locallib.php
  74. +29 −0 mod/assign/submission/comments/version.php
  75. +61 −0 mod/assign/submission/file/backup/moodle2/backup_assignsubmission_file_subplugin.class.php
  76. +68 −0 mod/assign/submission/file/backup/moodle2/restore_assignsubmission_file_subplugin.class.php
  77. +29 −0 mod/assign/submission/file/db/access.php
  78. +21 −0 mod/assign/submission/file/db/install.xml
  79. +34 −0 mod/assign/submission/file/db/upgrade.php
  80. +38 −0 mod/assign/submission/file/lang/en/assignsubmission_file.php
  81. +71 −0 mod/assign/submission/file/lib.php
  82. +405 −0 mod/assign/submission/file/locallib.php
  83. +29 −0 mod/assign/submission/file/settings.php
  84. +28 −0 mod/assign/submission/file/version.php
  85. +61 −0 ...ssign/submission/onlinetext/backup/moodle2/backup_assignsubmission_onlinetext_subplugin.class.php
  86. +69 −0 ...sign/submission/onlinetext/backup/moodle2/restore_assignsubmission_onlinetext_subplugin.class.php
  87. +29 −0 mod/assign/submission/onlinetext/db/access.php
  88. +51 −0 mod/assign/submission/onlinetext/db/install.php
  89. +22 −0 mod/assign/submission/onlinetext/db/install.xml
  90. +34 −0 mod/assign/submission/onlinetext/db/upgrade.php
Sorry, we could not display the entire diff because it was too big.
View
45 admin/tool/assignmentupgrade/batchupgrade.php
@@ -0,0 +1,45 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Script to show all the assignments that have not been upgraded after the main upgrade.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../../../config.php');
+require_once(dirname(__FILE__) . '/locallib.php');
+require_once(dirname(__FILE__) . '/upgradableassignmentstable.php');
+require_once(dirname(__FILE__) . '/upgradableassignmentsbatchform.php');
+require_once($CFG->libdir . '/adminlib.php');
+
+// admin_externalpage_setup calls require_login and checks moodle/site:config
+admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('batchupgrade'));
+$PAGE->navbar->add(get_string('batchupgrade', 'tool_assignmentupgrade'));
+
+$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
+
+$confirm = required_param('confirm', PARAM_BOOL);
+if (!$confirm) {
+ print_error('invalidrequest');
+ die();
+}
+$result = tool_assignmentupgrade_upgrade_multiple_assignments(optional_param('upgradeall', 0, PARAM_BOOL),
+ explode(',', optional_param('selected', '', PARAM_TEXT)));
+
+echo $renderer->convert_multiple_assignments_result($result);
View
50 admin/tool/assignmentupgrade/index.php
@@ -0,0 +1,50 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * This tool can upgrade old assignment activities to the new assignment activity type
+ *
+ * The upgrade can be done on any old assignment instance providing it is using one of the core
+ * assignment subtypes (online text, single upload, etc).
+ * The new assignment module was introduced in Moodle 2.3 and although it completely reproduces
+ * the features of the existing assignment type it wasn't designed to replace it entirely as there
+ * are many custom assignment types people use and it wouldn't be practical to try to convert them.
+ * Instead the existing assignment type will be left in core and people will be encouraged to
+ * use the new assignment type.
+ *
+ * This screen is the main entry-point to the plugin, it gives the admin a list
+ * of options available to them.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../../../config.php');
+require_once(dirname(__FILE__) . '/locallib.php');
+require_once($CFG->libdir . '/adminlib.php');
+
+// admin_externalpage_setup calls require_login and checks moodle/site:config
+admin_externalpage_setup('assignmentupgrade');
+
+$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
+
+$actions = array();
+
+$header = get_string('pluginname', 'tool_assignmentupgrade');
+$actions[] = tool_assignmentupgrade_action::make('listnotupgraded');
+
+echo $renderer->index_page($header, $actions);
View
56 admin/tool/assignmentupgrade/lang/en/tool_assignmentupgrade.php
@@ -0,0 +1,56 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Strings for the assignment upgrade tool
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['areyousure'] = 'Are you sure?';
+$string['areyousuremessage'] = 'Are you sure you want to upgrade the assignment "{$a->name}"?';
+$string['assignmentid'] = 'Assignment ID';
+$string['assignmentnotfound'] = 'Assignment could not be found (id={$a})';
+$string['assignmenttype'] = 'Assignment type';
+$string['backtoindex'] = 'Back to index';
+$string['batchoperations'] = 'Batch operations';
+$string['batchupgrade'] = 'Upgrade multiple assignments';
+$string['confirmbatchupgrade'] = 'Confirm batch upgrade assignments';
+$string['conversioncomplete'] = 'Assignment converted';
+$string['conversionfailed'] = 'The assignment conversion was not successful. The log from the upgrade was: <br />{$a}';
+$string['listnotupgraded'] = 'List assignments that have not been upgraded';
+$string['listnotupgraded_desc'] = 'You can upgrade individual assignments from here';
+$string['noassignmentstoupgrade'] = 'There are no assignments that require upgrading';
+$string['notsupported'] = '';
+$string['notupgradedintro'] = 'This page lists the assignments created with an older version of Moodle that have not been upgraded to the new assignment module in Moodle 2.3. Not all assignments can be upgraded - if they were created with a custom assignment subtype, then that subtype will need to be upgraded to the new assignment plugin format in order to complete the upgrade.';
+$string['notupgradedtitle'] = 'Assignments not upgraded';
+$string['pluginname'] = 'Assignment upgrade helper';
+$string['select'] = 'Select';
+$string['submissions'] = 'Submissions';
+$string['supported'] = 'Upgrade';
+$string['unknown'] = 'Unknown';
+$string['upgradeassignmentsummary'] = 'Upgrade assignment: {$a->name} (Course: {$a->shortname})';
+$string['upgradeassignmentsuccess'] = 'Result: Upgrade successful';
+$string['upgradeassignmentfailed'] = 'Result: Upgrade failed. The log from the upgrade was: <br/><div class="tool_assignmentupgrade_upgradelog">{$a->log}</div>';
+$string['upgradable'] = 'Upgradable';
+$string['upgradeselected'] = 'Upgrade selected assignments';
+$string['upgradeselectedcount'] = 'Upgrade {$a} selected assignments?';
+$string['upgradeall'] = 'Upgrade all assignments';
+$string['upgradeallconfirm'] = 'Upgrade all assignments?';
+$string['upgradesingle'] = 'Upgrade single assignment';
+$string['viewcourse'] = 'View the course with the converted assignment';
View
59 admin/tool/assignmentupgrade/lib.php
@@ -0,0 +1,59 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Lib functions (cron) to automatically complete the assignment module upgrade if it was not done all at once during the main upgrade.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+/**
+ * Standard cron function
+ */
+function tool_assignmentupgrade_cron() {
+ $settings = get_config('tool_assignmentupgrade');
+ if (empty($settings->cronenabled)) {
+ return;
+ }
+
+ mtrace('assignmentupgrade: tool_assignmentupgrade_cron() started at '. date('H:i:s'));
+ try {
+ tool_assignmentupgrade_process($settings);
+ } catch (Exception $e) {
+ mtrace('assignmentupgrade: tool_assignmentupgrade_cron() failed with an exception:');
+ mtrace($e->getMessage());
+ }
+ mtrace('assignmentupgrade: tool_assignmentupgrade_cron() finished at ' . date('H:i:s'));
+}
+
+/**
+ * This function does the cron process within the time range according to settings.
+ * This is not implemented yet
+ * @param stdClass $settings - not used
+ */
+function tool_assignmentupgrade_process($settings) {
+ global $CFG;
+ require_once(dirname(__FILE__) . '/locallib.php');
+
+ mtrace('assignmentupgrade: processing ...');
+
+ mtrace('assignmentupgrade: Done.');
+ return;
+}
View
48 admin/tool/assignmentupgrade/listnotupgraded.php
@@ -0,0 +1,48 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Script to show all the assignments that have not been upgraded after the main upgrade.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../../../config.php');
+require_once(dirname(__FILE__) . '/locallib.php');
+require_once(dirname(__FILE__) . '/upgradableassignmentstable.php');
+require_once(dirname(__FILE__) . '/upgradableassignmentsbatchform.php');
+require_once($CFG->libdir . '/adminlib.php');
+
+// admin_externalpage_setup 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'));
+
+$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
+
+$perpage = get_user_preferences('tool_assignmentupgrade_perpage', 5);
+$assignments = new tool_assignmentupgrade_assignments_table($perpage);
+
+$batchform = new tool_assignmentupgrade_batchoperations_form();
+$data = $batchform->get_data();
+if ($data && $data->selectedassignments != '' || $data && isset($data->upgradeall)) {
+ echo $renderer->confirm_batch_operation_page($data);
+} else {
+ echo $renderer->assignment_list_page($assignments, $batchform);
+}
+
+
View
245 admin/tool/assignmentupgrade/locallib.php
@@ -0,0 +1,245 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Assignment upgrade tool library functions
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Get the URL of a script within this plugin.
+ * @param string $script the script name, without .php. E.g. 'index'
+ * @param array $params URL parameters (optional)
+ * @return moodle_url
+ */
+function tool_assignmentupgrade_url($script, $params = array()) {
+ return new moodle_url('/admin/tool/assignmentupgrade/' . $script . '.php', $params);
+}
+
+/**
+ * Class to encapsulate the continue / cancel for batch operations
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class tool_assignmentupgrade_batchoperationconfirm implements renderable {
+ /** @var string $continuemessage The message to show above the continue cancel buttons */
+ public $continuemessage = '';
+ /** @var string $continueurl The url to load if the user clicks continue */
+ public $continueurl;
+
+ /**
+ * Constructor for this class
+ * @param stdClass $data - The data from the previous batch form
+ */
+ 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));
+ } 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()));
+ }
+ }
+ }
+}
+
+
+/**
+ * Class to encapsulate one of the functionalities that this plugin offers.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class tool_assignmentupgrade_action {
+ /** @var string the name of this action. */
+ public $name;
+ /** @var moodle_url the URL to launch this action. */
+ public $url;
+ /** @var string a description of this aciton. */
+ public $description;
+
+ /**
+ * Constructor to set the fields.
+ *
+ * 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.
+ * @param moodle_url $url the URL to launch this action.
+ * @param string $description a description of this aciton.
+ */
+ protected function __construct($name, moodle_url $url, $description) {
+ $this->name = $name;
+ $this->url = $url;
+ $this->description = $description;
+ }
+
+ /**
+ * Make an action with standard values.
+ * @param string $shortname internal name of the action. Used to get strings and build a URL.
+ * @param array $params any URL params required.
+ * @return tool_assignmentupgrade_action
+ */
+ public static function make($shortname, $params = array()) {
+ return new self(
+ get_string($shortname, 'tool_assignmentupgrade'),
+ tool_assignmentupgrade_url($shortname, $params),
+ get_string($shortname . '_desc', 'tool_assignmentupgrade'));
+ }
+}
+
+/**
+ * Determine if there are any assignments that can be upgraded
+ * @return boolean - Are there any assignments that can be upgraded
+ */
+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_%'));
+
+ $upgradabletypes = array();
+
+ foreach ($types as $assignment) {
+ $shorttype = substr($assignment->assignmenttype, strlen('assignment_'));
+ if (assign::can_upgrade_assignment($shorttype, $assignment->version)) {
+ $upgradabletypes[] = $shorttype;
+ }
+ }
+ $paramlist = '?';
+ foreach ($upgradabletypes as $index => $upgradabletype) {
+ if ($index > 0) {
+ $paramlist .= ', ?';
+ }
+ }
+
+ $record = $DB->get_record_sql('SELECT COUNT(id) as count from {assignment} where assignmenttype in (' . $paramlist . ')', $upgradabletypes);
+
+ return $record->count > 0;
+}
+
+/**
+ * Load a list of all the assignmentids that can be upgraded
+ * @return array of assignment ids
+ */
+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_%'));
+
+ $upgradabletypes = array();
+
+ foreach ($types as $assignment) {
+ $shorttype = substr($assignment->assignmenttype, strlen('assignment_'));
+ if (assign::can_upgrade_assignment($shorttype, $assignment->version)) {
+ $upgradabletypes[] = $shorttype;
+ }
+ }
+ $paramlist = '?';
+ foreach ($upgradabletypes as $index => $upgradabletype) {
+ if ($index > 0) {
+ $paramlist .= ', ?';
+ }
+ }
+
+ $records = $DB->get_records_sql('SELECT id from {assignment} where assignmenttype in (' . $paramlist . ')', $upgradabletypes);
+ $ids = array();
+ foreach ($records as $record) {
+ $ids[] = $record->id;
+ }
+
+ return $ids;
+}
+
+
+/**
+ * Convert a list of assignments from the old format to the new one.
+ * @param bool $upgradeall - Upgrade all possible assignments
+ * @param array $assignmentids An array of assignment ids to upgrade
+ * @return array of $entry['assignmentsummary' => (result from tool_assignmentupgrade_get_assignment)
+ * $entry['success'] => boolean
+ * $entry['log'] => string - upgrade log
+ */
+function tool_assignmentupgrade_upgrade_multiple_assignments($upgradeall, $assignmentids) {
+ global $CFG;
+ require_once($CFG->dirroot . '/mod/assign/locallib.php');
+ require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
+ $upgrades = array();
+
+ if ($upgradeall) {
+ $assignmentids = tool_assignmentupgrade_load_all_upgradable_assignmentids();
+ }
+
+ $assignment_upgrader = new assign_upgrade_manager();
+ foreach ($assignmentids as $assignmentid) {
+ $info = tool_assignmentupgrade_get_assignment($assignmentid);
+ if ($info) {
+ $log = '';
+ $success = $assignment_upgrader->upgrade_assignment($assignmentid, $log);
+ } else {
+ $success = false;
+ $log = get_string('assignmentnotfound', 'tool_assignmentupgrade', $assignmentid);
+ $info = new stdClass();
+ $info->name = get_string('unknown', 'tool_assignmentupgrade');
+ $info->shortname = get_string('unknown', 'tool_assignmentupgrade');
+ }
+
+ $upgrades[] = array('assignmentsummary'=>$info, 'success'=>$success, 'log'=>$log);
+ }
+ return $upgrades;
+}
+
+/**
+ * Convert a single assignment from the old format to the new one.
+ * @param stdClass $assignmentinfo An object containing information about this class
+ * @param string $log This gets appended to with the details of the conversion process
+ * @return boolean This is the overall result (true/false)
+ */
+function tool_assignmentupgrade_upgrade_assignment($assignmentinfo, &$log) {
+ global $CFG;
+ require_once($CFG->dirroot . '/mod/assign/locallib.php');
+ require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
+ $assignment_upgrader = new assign_upgrade_manager();
+ return $assignment_upgrader->upgrade_assignment($assignmentinfo->id, $log);
+}
+
+/**
+ * Get the information about a assignment to be upgraded.
+ * @param int $assignmentid the assignment id.
+ * @return stdClass the information about that assignment.
+ */
+function tool_assignmentupgrade_get_assignment($assignmentid) {
+ global $DB;
+ return $DB->get_record_sql("
+ SELECT a.id, a.name, c.shortname, c.id AS courseid
+ FROM {assignment} a
+ JOIN {course} c ON c.id = a.course
+ WHERE a.id = ?", array($assignmentid));
+}
+
View
66 admin/tool/assignmentupgrade/module.js
@@ -0,0 +1,66 @@
+
+M.tool_assignmentupgrade = {
+ init_upgrade_table: function(Y) {
+
+ Y.use('node', function(Y) {
+ checkboxes = Y.all('td.c0 input');
+ checkboxes.each(function(node) {
+ node.on('change', function(e) {
+ rowelement = e.currentTarget.get('parentNode').get('parentNode');
+ if (e.currentTarget.get('checked')) {
+ rowelement.setAttribute('class', 'selectedrow');
+ } else {
+ rowelement.setAttribute('class', 'unselectedrow');
+ }
+ });
+
+ rowelement = node.get('parentNode').get('parentNode');
+ if (node.get('checked')) {
+ rowelement.setAttribute('class', 'selectedrow');
+ } else {
+ rowelement.setAttribute('class', 'unselectedrow');
+ }
+ });
+ });
+
+ var selectall = Y.one('th.c0 input');
+ selectall.on('change', function(e) {
+ if (e.currentTarget.get('checked')) {
+ checkboxes = Y.all('td.c0 input');
+ checkboxes.each(function(node) {
+ rowelement = node.get('parentNode').get('parentNode');
+ node.set('checked', true);
+ rowelement.setAttribute('class', 'selectedrow');
+ });
+ } else {
+ checkboxes = Y.all('td.c0 input');
+ checkboxes.each(function(node) {
+ rowelement = node.get('parentNode').get('parentNode');
+ node.set('checked', false);
+ rowelement.setAttribute('class', 'unselectedrow');
+ });
+ }
+ });
+
+ var batchform = Y.one('.tool_assignmentupgrade_batchform form');
+ batchform.on('submit', function(e) {
+ checkboxes = Y.all('td.c0 input');
+ var selectedassignments = [];
+ checkboxes.each(function(node) {
+ if (node.get('checked')) {
+ selectedassignments[selectedassignments.length] = node.get('value');
+ }
+ });
+
+ operation = Y.one('#id_operation');
+ assignmentsinput = Y.one('input.selectedassignments');
+ assignmentsinput.set('value', selectedassignments.join(','));
+ if (selectedassignments.length == 0) {
+ alert(M.str.assign.noassignmentsselected);
+ e.preventDefault();
+ }
+ });
+
+
+ }
+}
View
278 admin/tool/assignmentupgrade/renderer.php
@@ -0,0 +1,278 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Defines the renderer for the assignment upgrade helper plugin.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Renderer for the assignment upgrade helper plugin.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class tool_assignmentupgrade_renderer extends plugin_renderer_base {
+
+ /**
+ * Render the index page.
+ * @param string $detected information about what sort of site was detected.
+ * @param array $actions list of actions to show on this page.
+ * @return string html to output.
+ */
+ public function index_page($detected, array $actions) {
+ $output = '';
+ $output .= $this->header();
+ $output .= $this->heading(get_string('pluginname', 'tool_assignmentupgrade'));
+ $output .= $this->box($detected);
+ $output .= html_writer::start_tag('ul');
+ foreach ($actions as $action) {
+ $output .= html_writer::tag('li',
+ html_writer::link($action->url, $action->name) . ' - ' .
+ $action->description);
+ }
+ $output .= html_writer::end_tag('ul');
+ $output .= $this->footer();
+ return $output;
+ }
+
+ /**
+ * Render a page that is just a simple message.
+ * @param string $message the message to display.
+ * @return string html to output.
+ */
+ public function simple_message_page($message) {
+ $output = '';
+ $output .= $this->header();
+ $output .= $this->heading($message);
+ $output .= $this->back_to_index();
+ $output .= $this->footer();
+ return $output;
+ }
+
+ /**
+ * Render the confirm batch operation page
+ * @param stdClass $data Submitted form data with list of assignments to upgrade
+ * @return string html to output.
+ */
+ public function confirm_batch_operation_page(stdClass $data) {
+ $output = '';
+ $output .= $this->header();
+
+ $output .= $this->heading(get_string('confirmbatchupgrade', 'tool_assignmentupgrade'));
+ $output .= $this->output->spacer(array(), true);
+
+ $output .= $this->container_start('tool_assignmentupgrade_confirmbatch');
+
+ $output .= $this->render(new tool_assignmentupgrade_batchoperationconfirm($data));
+ $output .= $this->container_end();
+
+ $output .= $this->back_to_index();
+ $output .= $this->footer();
+ return $output;
+ }
+
+ /**
+ * Render the confirm batch continue / cancel links
+ * @param tool_assignmentupgrade_batchoperationconfirm $confirm Wrapper class to determine the continue message and url
+ * @return string html to output.
+ */
+ public function render_tool_assignmentupgrade_batchoperationconfirm(tool_assignmentupgrade_batchoperationconfirm $confirm) {
+ $output = '';
+
+ if ($confirm->continueurl) {
+ $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'));
+ }
+ return $output;
+ }
+
+ /**
+ * Render the list of assignments that still need to be upgraded page.
+ * @param tool_assignmentupgrade_assignments_table $assignments of data about assignments.
+ * @param tool_assignmentupgrade_batchoperations_form $batchform Submitted form with list of assignments to upgrade
+ * @return string html to output.
+ */
+ public function assignment_list_page(tool_assignmentupgrade_assignments_table $assignments, tool_assignmentupgrade_batchoperations_form $batchform) {
+ $output = '';
+ $output .= $this->header();
+ $this->page->requires->js_init_call('M.tool_assignmentupgrade.init_upgrade_table', array());
+
+
+ $output .= $this->heading(get_string('notupgradedtitle', 'tool_assignmentupgrade'));
+ $output .= $this->box(get_string('notupgradedintro', 'tool_assignmentupgrade'));
+ $output .= $this->output->spacer(array(), true);
+
+ $output .= $this->container_start('tool_assignmentupgrade_upgradetable');
+
+ $output .= $this->flexible_table($assignments, $assignments->get_rows_per_page(), true);
+ $output .= $this->container_end();
+
+ if ($assignments->anyupgradableassignments) {
+ $output .= $this->container_start('tool_assignmentupgrade_batchform');
+ $output .= $this->moodleform($batchform);
+ $output .= $this->container_end();
+ }
+
+ $output .= $this->back_to_index();
+ $output .= $this->footer();
+ return $output;
+ }
+
+ /**
+ * Render the result of an assignment conversion
+ * @param array $assignments - An array of arrays with keys $entry['assignmentsummary', 'success', 'log']
+ * See convert_assignment_result for more description of these keys.
+ * @return string html to output.
+ */
+ public function convert_multiple_assignments_result($assignments) {
+ $output = '';
+ $output .= $this->header();
+ $output .= $this->heading(get_string('batchupgrade', 'tool_assignmentupgrade'));
+
+ foreach ($assignments as $assignment) {
+ $assignmentsummary = $assignment['assignmentsummary'];
+ $success = $assignment['success'];
+ $log = $assignment['log'];
+
+ $output .= $this->heading(get_string('upgradeassignmentsummary', 'tool_assignmentupgrade', $assignmentsummary), 5);
+ if ($success) {
+ $output .= $this->container(get_string('upgradeassignmentsuccess', 'tool_assignmentupgrade'));
+
+ } else {
+ $output .= $this->container(get_string('upgradeassignmentfailed', 'tool_assignmentupgrade', $assignment));
+ }
+ if (isset($assignmentsummary->courseid)) {
+ $output .= html_writer::link(new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid)) ,get_string('viewcourse', 'tool_assignmentupgrade'));
+ }
+
+
+ }
+
+ $output .= $this->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
+
+
+ $output .= $this->footer();
+ return $output;
+ }
+
+ /**
+ * Render the result of an assignment conversion
+ * @param stdClass $assignmentsummary data about the assignment to upgrade.
+ * @param bool $success Set to true if the outcome of the conversion was a success
+ * @param string $log The log from the conversion
+ * @return string html to output.
+ */
+ public function convert_assignment_result($assignmentsummary, $success, $log) {
+ $output = '';
+ $output .= $this->header();
+ $output .= $this->heading(get_string('conversioncomplete', 'tool_assignmentupgrade'));
+
+ if (!$success) {
+ $output .= get_string('conversionfailed', 'tool_assignmentupgrade', $log);
+ } else {
+ $output .= html_writer::link(new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid)) ,get_string('viewcourse', 'tool_assignmentupgrade'));
+ }
+
+ $output .= $this->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
+
+
+ $output .= $this->footer();
+ return $output;
+ }
+
+ /**
+ * Render the are-you-sure page to confirm a manual upgrade.
+ * @param stdClass $assignmentsummary data about the assignment to upgrade.
+ * @return string html to output.
+ */
+ public function convert_assignment_are_you_sure($assignmentsummary) {
+ $output = '';
+ $output .= $this->header();
+ $output .= $this->heading(get_string('areyousure', 'tool_assignmentupgrade'));
+
+ $params = array('id' => $assignmentsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
+ $output .= $this->confirm(get_string('areyousuremessage', 'tool_assignmentupgrade', $assignmentsummary),
+ new single_button(tool_assignmentupgrade_url('upgradesingle', $params), get_string('yes')),
+ tool_assignmentupgrade_url('listnotupgraded'));
+
+ $output .= $this->footer();
+ return $output;
+ }
+
+ /**
+ * Helper method dealing with the fact we can not just fetch the output of flexible_table
+ *
+ * @param flexible_table $table
+ * @param int $rowsperpage
+ * @param bool $displaylinks Show links in the table
+ * @return string HTML
+ */
+ protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
+
+ $o = '';
+ ob_start();
+ $table->out($rowsperpage, $displaylinks);
+ $o = ob_get_contents();
+ ob_end_clean();
+
+ return $o;
+ }
+
+ /**
+ * Helper method dealing with the fact we can not just fetch the output of moodleforms
+ *
+ * @param moodleform $mform
+ * @return string HTML
+ */
+ protected function moodleform(moodleform $mform) {
+
+ $o = '';
+ ob_start();
+ $mform->display();
+ $o = ob_get_contents();
+ ob_end_clean();
+
+ return $o;
+ }
+
+
+ /**
+ * Render a link in a div, such as the 'Back to plugin main page' link.
+ * @param string|moodle_url $url the link URL.
+ * @param string $text the link text.
+ * @return string html to output.
+ */
+ public function end_of_page_link($url, $text) {
+ return html_writer::tag('div', html_writer::link($url, $text), array('class' => 'mdl-align'));
+ }
+
+ /**
+ * Output a link back to the plugin index page.
+ * @return string html to output.
+ */
+ public function back_to_index() {
+ return $this->end_of_page_link(tool_assignmentupgrade_url('index'), get_string('backtoindex', 'tool_assignmentupgrade'));
+ }
+}
View
31 admin/tool/assignmentupgrade/settings.php
@@ -0,0 +1,31 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Adds this plugin to the admin menu.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+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')));
+}
View
11 admin/tool/assignmentupgrade/styles.css
@@ -0,0 +1,11 @@
+#page-admin-tool-assignmentupgrade-listnotupgraded .tool_assignmentupgrade_upgradetable .c0 { display: none; }
+#page-admin-tool-assignmentupgrade-listnotupgraded.jsenabled .tool_assignmentupgrade_upgradetable .c0 { display: table-cell; }
+/*
+.gradingbatchoperationsform { display: none; }
+.jsenabled .gradingbatchoperationsform { display: block; }
+*/
+
+#page-admin-tool-assignmentupgrade-listnotupgraded .tool_assignmentupgrade_upgradetable tr.selectedrow td { background-color: #ffeecc; }
+#page-admin-tool-assignmentupgrade-listnotupgraded .tool_assignmentupgrade_upgradetable tr.unselectedrow td { background-color: white; }
+
+
View
55 admin/tool/assignmentupgrade/upgradableassignmentsbatchform.php
@@ -0,0 +1,55 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains the forms to create and edit an instance of this module
+ *
+ * @package tool_assignmentupgrade
+ * @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('Direct access to this script is forbidden.');
+
+
+/** Include formslib.php */
+require_once ($CFG->libdir.'/formslib.php');
+
+/**
+ * Assignment upgrade batch operations form
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class tool_assignmentupgrade_batchoperations_form extends moodleform {
+ /**
+ * Define this form - is called from parent constructor
+ */
+ function definition() {
+ $mform = $this->_form;
+ $instance = $this->_customdata;
+
+ $mform->addElement('header', 'general', get_string('batchoperations', 'tool_assignmentupgrade'));
+ // visible elements
+ $mform->addElement('hidden', 'selectedassignments', '', array('class'=>'selectedassignments'));
+
+ $mform->addElement('submit', 'upgradeselected', get_string('upgradeselected', 'tool_assignmentupgrade'));
+ $mform->addElement('submit', 'upgradeall', get_string('upgradeall', 'tool_assignmentupgrade'));
+ }
+
+}
+
View
172 admin/tool/assignmentupgrade/upgradableassignmentstable.php
@@ -0,0 +1,172 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains the definition for the grading table which subclassses easy_table
+ *
+ * @package tool_assignmentupgrade
+ * @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();
+
+require_once($CFG->libdir.'/tablelib.php');
+require_once($CFG->libdir.'/gradelib.php');
+require_once($CFG->dirroot.'/mod/assign/locallib.php');
+
+/**
+ * Extends table_sql to provide a table of assignment submissions
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
+ * @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) */
+ private $rownum = -1;
+ /** @var renderer_base for getting output */
+ private $output = null;
+ /** @var boolean anyupgradableassignments - True if there is one or more assignments that can upgraded */
+ public $anyupgradableassignments = false;
+
+ /**
+ * 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) {
+ global $PAGE;
+ parent::__construct('tool_assignmentupgrade_assignments');
+ $this->perpage = $perpage;
+ $this->output = $PAGE->get_renderer('tool_assignmentupgrade');
+
+ $this->define_baseurl(new moodle_url('/admin/tool/assignmentupgrade/listnotupgraded.php'));
+
+ $this->anyupgradableassignments = tool_assignmentupgrade_any_upgradable_assignments();
+
+ // 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';
+ $from = '{assignment} a JOIN {course} c ON a.course = c.id ' .
+ ' LEFT JOIN {assignment_submissions} s ON a.id = s.assignment';
+
+
+ $where = '1 = 1';
+ $where .= ' GROUP BY a.id, a.name, a.assignmenttype, c.shortname, c.id ';
+
+ $this->set_sql($fields, $from, $where, array());
+ $this->set_count_sql('SELECT COUNT(*) FROM ' . $from, array());
+
+ $columns = array();
+ $headers = array();
+
+ $columns[] = 'select';
+ $headers[] = get_string('select', 'tool_assignmentupgrade') . '<div class="selectall"><input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/></div>';
+ $columns[] = 'upgradable';
+ $headers[] = get_string('upgradable', 'tool_assignmentupgrade');
+ $columns[] = 'id';
+ $headers[] = get_string('assignmentid', 'tool_assignmentupgrade');
+ $columns[] = 'courseshortname';
+ $headers[] = get_string('course');
+ $columns[] = 'name';
+ $headers[] = get_string('name');
+ $columns[] = 'type';
+ $headers[] = get_string('assignmenttype', 'tool_assignmentupgrade');
+ $columns[] = 'submissioncount';
+ $headers[] = get_string('submissions', 'tool_assignmentupgrade');
+
+ // set the columns
+ $this->define_columns($columns);
+ $this->define_headers($headers);
+ $this->no_sorting('upgradable');
+ $this->no_sorting('select');
+ }
+
+ /**
+ * Return the number of rows to display on a single page
+ *
+ * @return int The number of rows per page
+ */
+ function get_rows_per_page() {
+ return $this->perpage;
+ }
+
+ /**
+ * Format a link to the assignment instance
+ *
+ * @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);
+ }
+
+
+ /**
+ * Format a link to the upgrade single tool
+ *
+ * @param stdClass $row (contains cached result from previous upgradable check)
+ * @return string
+ */
+ function col_upgradable(stdClass $row) {
+ if ($row->upgradable) {
+ return html_writer::link(new moodle_url('/admin/tool/assignmentupgrade/upgradesingleconfirm.php',
+ array('id' => $row->id)), get_string('supported', 'tool_assignmentupgrade'));
+ } else {
+ return get_string('notsupported', 'tool_assignmentupgrade');
+ }
+ }
+
+ /**
+ * Insert a checkbox for selecting the current row for batch operations
+ *
+ * @param stdClass $row
+ * @return string
+ */
+ function col_select(stdClass $row) {
+ global $CFG;
+ $version = get_config('assignment_' . $row->type, 'version');
+ require_once($CFG->dirroot . '/mod/assign/locallib.php');
+ if (assign::can_upgrade_assignment($row->type, $version)) {
+ $row->upgradable = true;
+ return '<input type="checkbox" name="selectedassignment" value="' . $row->id . '"/>';
+ }
+ $row->upgradable = false;
+ return '';
+ }
+
+ /**
+ * 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.
+ * @return string HTML fragment.
+ */
+ protected function show_hide_link($column, $index) {
+ if ($index > 0) {
+ return parent::show_hide_link($column, $index);
+ }
+ return '';
+ }
+}
View
46 admin/tool/assignmentupgrade/upgradesingle.php
@@ -0,0 +1,46 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Script to show all the assignments that have not been upgraded after the main upgrade.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../../../config.php');
+require_once(dirname(__FILE__) . '/locallib.php');
+require_once($CFG->libdir . '/adminlib.php');
+
+$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)));
+
+$PAGE->navbar->add(get_string('upgradesingle', 'tool_assignmentupgrade'));
+$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
+
+$assignmentinfo = tool_assignmentupgrade_get_assignment($assignmentid);
+if (!$assignmentinfo) {
+ print_error('invalidrequest');
+ die();
+}
+
+$log = '';
+$result = tool_assignmentupgrade_upgrade_assignment($assignmentinfo, $log);
+
+echo $renderer->convert_assignment_result($assignmentinfo, $result, $log);
View
39 admin/tool/assignmentupgrade/upgradesingleconfirm.php
@@ -0,0 +1,39 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Script to show all the assignments that have not been upgraded after the main upgrade.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../../../config.php');
+require_once(dirname(__FILE__) . '/locallib.php');
+require_once($CFG->libdir . '/adminlib.php');
+
+$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)));
+
+$PAGE->navbar->add(get_string('upgradesingle', 'tool_assignmentupgrade'));
+$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
+
+$assignmentinfo = tool_assignmentupgrade_get_assignment($assignmentid);
+
+echo $renderer->convert_assignment_are_you_sure($assignmentinfo);
View
29 admin/tool/assignmentupgrade/version.php
@@ -0,0 +1,29 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Version details.
+ *
+ * @package tool_assignmentupgrade
+ * @copyright 2012 NetSpot
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version = 2012021700;
+$plugin->requires = 2011092100;
+$plugin->component = 'tool_assignmentupgrade';
View
480 mod/assign/adminlib.php
@@ -0,0 +1,480 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains the classes for the admin settings of the assign module.
+ *
+ * @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
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/** Include adminlib.php */
+require_once($CFG->libdir . '/adminlib.php');
+
+/**
+ * Admin external page that displays a list of the installed submission plugins.
+ *
+ * @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
+ */
+class assign_admin_page_manage_assign_plugins extends admin_externalpage {
+
+ /** @var string the name of plugin subtype */
+ private $subtype = '';
+
+ /**
+ * The constructor - calls parent constructor
+ *
+ * @param string $subtype
+ */
+ 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)));
+ }
+
+ /**
+ * Search plugins for the specified string
+ *
+ * @param string $query The string to search for
+ * @return array
+ */
+ public function search($query) {
+ if ($result = parent::search($query)) {
+ return $result;
+ }
+
+ $found = false;
+ $textlib = new textlib();
+
+ foreach (get_plugin_list($this->subtype) as $name => $notused) {
+ if (strpos($textlib::strtolower(get_string('pluginname', $this->subtype . '_' . $name)),
+ $query) !== false) {
+ $found = true;
+ break;
+ }
+ }
+ if ($found) {
+ $result = new stdClass();
+ $result->page = $this;
+ $result->settings = array();
+ return array($this->name => $result);
+ } else {
+ return array();
+ }
+ }
+}
+
+
+/**
+ * Class that handles the display and configuration of the list of submission plugins.
+ *
+ * @package mod_assign
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class assign_plugin_manager {
+
+ /** @var object the url of the manage submission plugin page */
+ private $pageurl;
+ /** @var string any error from the current action */
+ private $error = '';
+ /** @var string either submission or feedback */
+ private $subtype = '';
+
+ /**
+ * Constructor for this assignment plugin manager
+ * @param string $subtype - either assignsubmission or assignfeedback
+ */
+ public function __construct($subtype) {
+ $this->pageurl = new moodle_url('/mod/assign/adminmanageplugins.php', array('subtype'=>$subtype));
+ $this->subtype = $subtype;
+ }
+
+
+ /**
+ * Return a list of plugins sorted by the order defined in the admin interface
+ *
+ * @return array The list of plugins
+ */
+ public function get_sorted_plugins_list() {
+ $names = get_plugin_list($this->subtype);
+
+ $result = array();
+
+ foreach ($names as $name => $path) {
+ $idx = get_config($this->subtype . '_' . $name, 'sortorder');
+ if (!$idx) {
+ $idx = 0;
+ }
+ while (array_key_exists($idx, $result)) $idx +=1;
+ $result[$idx] = $name;
+ }
+ ksort($result);
+
+ return $result;
+ }
+
+
+ /**
+ * Util function for writing an action icon link
+ *
+ * @param string $action URL parameter to include in the link
+ * @param string $plugintype URL parameter to include in the link
+ * @param string $icon The key to the icon to use (e.g. 't/up')
+ * @param string $alt The string description of the link used as the title and alt text
+ * @return string The icon/link
+ */
+ private function format_icon_link($action, $plugintype, $icon, $alt) {
+ global $OUTPUT;
+
+ return $OUTPUT->action_icon(new moodle_url($this->pageurl,
+ array('action' => $action, 'plugin'=> $plugintype, 'sesskey' => sesskey())),
+ new pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
+ null, array('title' => $alt)) . ' ';
+ }
+
+ /**
+ * Write the HTML for the submission plugins table.
+ *
+ * @return None
+ */
+ private function view_plugins_table() {
+ global $OUTPUT, $CFG;
+ /** Include tablelib.php */
+ require_once($CFG->libdir . '/tablelib.php');
+
+ // Set up the table.
+ $this->view_header();
+ $table = new flexible_table($this->subtype . 'pluginsadminttable');
+ $table->define_baseurl($this->pageurl);
+ $table->define_columns(array('pluginname', 'version', 'hideshow', 'order',
+ 'delete', 'settings'));
+ $table->define_headers(array(get_string($this->subtype . 'pluginname', 'assign'),
+ get_string('version'), get_string('hideshow', 'assign'),
+ get_string('order'), get_string('delete'), get_string('settings')));
+ $table->set_attribute('id', $this->subtype . 'plugins');
+ $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
+ $table->setup();
+
+
+ $plugins = $this->get_sorted_plugins_list();
+ $shortsubtype = substr($this->subtype, strlen('assign'));
+
+ foreach ($plugins as $idx => $plugin) {
+ $row = array();
+
+ $row[] = get_string('pluginname', $this->subtype . '_' . $plugin);
+ $row[] = get_config($this->subtype . '_' . $plugin, 'version');
+
+ $visible = !get_config($this->subtype . '_' . $plugin, 'disabled');
+
+ if ($visible) {
+ $row[] = $this->format_icon_link('hide', $plugin, 'i/hide', get_string('disable'));
+ } else {
+ $row[] = $this->format_icon_link('show', $plugin, 'i/show', get_string('enable'));
+ }
+
+ $movelinks = '';
+ if (!$idx == 0) {
+ $movelinks .= $this->format_icon_link('moveup', $plugin, 't/up', get_string('up'));
+ } else {
+ $movelinks .= $OUTPUT->spacer(array('width'=>15));
+ }
+ if ($idx != count($plugins) - 1) {
+ $movelinks .= $this->format_icon_link('movedown', $plugin, 't/down', get_string('down'));
+ }
+ $row[] = $movelinks;
+
+ if ($row[1] != '') {
+ $row[] = $this->format_icon_link('delete', $plugin, 't/delete', get_string('delete'));
+ } else {
+ $row[] = '&nbsp;';
+ }
+ if ($row[1] != '' && file_exists($CFG->dirroot . '/mod/assign/' . $shortsubtype . '/' . $plugin . '/settings.php')) {
+ $row[] = html_writer::link(new moodle_url('/admin/settings.php',
+ array('section' => $this->subtype . '_' . $plugin)), get_string('settings'));
+ } else {
+ $row[] = '&nbsp;';
+ }
+ $table->add_data($row);
+ }
+
+
+ $table->finish_output();
+ $this->view_footer();
+ }
+
+ /**
+ * Write the page header
+ *
+ * @return None
+ */
+ private function view_header() {
+ global $OUTPUT;
+ admin_externalpage_setup('manage' . $this->subtype . 'plugins');
+ // Print the page heading.
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('manage' . $this->subtype . 'plugins', 'assign'));
+ }
+
+ /**
+ * Write the page footer
+ *
+ * @return None
+ */
+ private function view_footer() {
+ global $OUTPUT;
+ echo $OUTPUT->footer();
+ }
+
+ /**
+ * Check this user has permission to edit the list of installed plugins
+ *
+ * @return None
+ */
+ private function check_permissions() {
+ // Check permissions.
+ require_login();
+ $systemcontext = context_system::instance();
+ require_capability('moodle/site:config', $systemcontext);
+ }
+
+ /**
+ * Delete the database and files associated with this plugin.
+ *
+ * @param string $plugin - The type of the plugin to delete
+ * @return string the name of the next page to display
+ */
+ public function delete_plugin($plugin) {
+ global $CFG, $DB, $OUTPUT;
+ $confirm = optional_param('confirm', null, PARAM_BOOL);
+
+ if ($confirm) {
+ // Delete any configuration records.
+ if (!unset_all_config_for_plugin('assignsubmission_' . $plugin)) {
+ $this->error = $OUTPUT->notification(get_string('errordeletingconfig', 'admin', $this->subtype . '_' . $plugin));
+ }
+
+
+ // 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
+ $DB->delete_records('assign_plugin_config', array('plugin'=>$plugin, 'subtype'=>$this->subtype));
+
+ // Then the tables themselves
+ drop_plugin_tables($this->subtype . '_' . $plugin, $CFG->dirroot . '/mod/assign/' . $this->subtype . '/' .$plugin. '/db/install.xml', false);
+
+ // Remove event handlers and dequeue pending events
+ events_uninstall($this->subtype . '_' . $plugin);
+
+ // the page to display
+ return 'plugindeleted';
+ } else {
+ // the page to display
+ return 'confirmdelete';
+ }
+
+ }
+
+ /**
+ * 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
+ */
+ private function view_plugin_deleted($plugin) {
+ global $OUTPUT;
+ $this->view_header();
+ echo $OUTPUT->heading(get_string('deletingplugin', 'assign', get_string('pluginname', $this->subtype . '_' . $plugin)));
+ echo $this->error;
+ echo $OUTPUT->notification(get_string('plugindeletefiles', 'moodle', array('name'=>get_string('pluginname', $this->subtype . '_' . $plugin), 'directory'=>('/mod/assign/' . $this->subtype . '/'.$plugin))));
+ echo $OUTPUT->continue_button($this->pageurl);
+ $this->view_footer();
+ }
+
+ /**
+ * 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
+ */
+ 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)),
+ $this->pageurl);
+ $this->view_footer();
+ }
+
+
+
+ /**
+ * Hide this plugin
+ *
+ * @param string $plugin - The plugin to hide
+ * @return string The next page to display
+ */
+ public function hide_plugin($plugin) {
+ set_config('disabled', 1, $this->subtype . '_' . $plugin);
+ return 'view';
+ }
+
+ /**
+ * 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
+ $plugins = $this->get_sorted_plugins_list();
+
+ $currentindex = 0;
+
+ // throw away the keys
+
+ $plugins = array_values($plugins);
+
+ // find this plugin in the list
+ foreach ($plugins as $key => $plugin) {
+ if ($plugin == $plugintomove) {
+ $currentindex = $key;
+ break;
+ }
+ }
+
+ // make the switch
+ if ($dir == 'up') {
+ if ($currentindex > 0) {
+ $tempplugin = $plugins[$currentindex - 1];
+ $plugins[$currentindex - 1] = $plugins[$currentindex];
+ $plugins[$currentindex] = $tempplugin;
+ }
+ } else if ($dir == 'down') {
+ if ($currentindex < (count($plugins) - 1)) {
+ $tempplugin = $plugins[$currentindex + 1];
+ $plugins[$currentindex + 1] = $plugins[$currentindex];
+ $plugins[$currentindex] = $tempplugin;
+ }
+ }
+
+ // save the new normal order
+ foreach ($plugins as $key => $plugin) {
+ set_config('sortorder', $key, $this->subtype . '_' . $plugin);
+ }
+ return 'view';
+ }
+
+
+ /**
+ * Show this plugin
+ *
+ * @param string $plugin - The plugin to show
+ * @return string The next page to display
+ */
+ public function show_plugin($plugin) {
+ set_config('disabled', 0, $this->subtype . '_' . $plugin);
+ return 'view';
+ }
+
+
+ /**
+ * 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
+ * @return None
+ */
+ public function execute($action, $plugin) {
+ if ($action == null) {
+ $action = 'view';
+ }
+
+ $this->check_permissions();
+
+ // process
+ if ($action == 'delete' && $plugin != null) {
+ $action = $this->delete_plugin($plugin);
+ } else if ($action == 'hide' && $plugin != null) {
+ $action = $this->hide_plugin($plugin);
+ } else if ($action == 'show' && $plugin != null) {
+ $action = $this->show_plugin($plugin);
+ } else if ($action == 'moveup' && $plugin != null) {
+ $action = $this->move_plugin($plugin, 'up');
+ } else if ($action == 'movedown' && $plugin != null) {
+ $action = $this->move_plugin($plugin, 'down');
+ }
+
+
+ // view
+ if ($action == 'confirmdelete' && $plugin != null) {
+ $this->view_confirm_delete($plugin);
+ } else if ($action == 'plugindeleted' && $plugin != null) {
+ $this->view_plugin_deleted($plugin);
+ } else if ($action == 'view') {
+ $this->view_plugins_table();
+ }
+ }
+
+ /**
+ * This function adds plugin pages to the navigation menu
+ *
+ * @static
+ * @param string $subtype - The type of plugin (submission or feedback)
+ * @param part_of_admin_tree $admin - The handle to the admin menu
+ * @param admin_settingpage $settings - The handle to current node in the navigation tree
+ * @param stdClass $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, stdClass $module) {
+ global $CFG;
+
+ $plugins = get_plugin_list_with_file($subtype, 'settings.php', false);
+ $pluginsbyname = array();
+ foreach ($plugins as $plugin => $plugindir) {
+ $pluginname = get_string('pluginname', $subtype . '_'.$plugin);
+ $pluginsbyname[$pluginname] = $plugin;
+ }
+ ksort($pluginsbyname);
+
+ // We need to reset settings after the loop
+ $tempsettings = $settings;
+ foreach ($pluginsbyname as $pluginname => $plugin) {
+ $settings = new admin_settingpage($subtype . '_'.$plugin,
+ $pluginname, 'moodle/site:config', !$module->visible);
+ if ($admin->fulltree) {
+ $shortsubtype = substr($subtype, strlen('assign'));
+ include($CFG->dirroot . "/mod/assign/$shortsubtype/$plugin/settings.php");
+ }
+
+ $admin->add($subtype . 'plugins', $settings);
+ }
+
+ // Reset settings to the original point in the tree
+ $settings = $tempsettings;
+
+ }
+}
View
36 mod/assign/adminmanageplugins.php
@@ -0,0 +1,36 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * Allows the admin to manage assignment plugins
+ *
+ * @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
+ */
+
+/** 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
+$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));
View
525 mod/assign/assignmentplugin.php
@@ -0,0 +1,525 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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 <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains the functions for assign_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
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Abstract class for assign_plugin (submission/feedback).
+ *
+ * @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
+ */
+abstract class assign_plugin {
+
+ /** @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 = '';
+ /** @var string $error error message */
+ private $error = '';
+
+
+ /**
+ * Constructor for the abstract plugin type class
+ *
+ * @param assign $assignment
+ * @param string $type
+ */
+ public final function __construct(assign $assignment, $type) {
+ $this->assignment = $assignment;
+ $this->type = $type;
+ }
+
+ /**
+ * Is this the first plugin in the list?
+ *
+ * @return bool
+ */
+ public final function is_first() {
+ $order = get_config($this->get_subtype() . '_' . $this->get_type(), 'sortorder');
+
+ if ($order == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Is this the last plugin in the list?
+ *
+ * @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')) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * This function should be overridden to provide an array of elements that can be added to a moodle
+ * form for display in the settings page for the assignment.
+ * @param MoodleQuickForm $mform The form to add the elements to
+ * @return $array
+ */
+ public function get_settings(MoodleQuickForm $mform) {
+ return;
+ }
+
+ /**
+ * Allows the plugin 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 data_preprocessing(&$defaultvalues) {
+ return;
+ }
+
+ /**
+ * The assignment subtype is responsible for saving it's own settings as the database table for the
+ * standard type cannot be modified.
+ *
+ * @param stdClass $formdata - the data submitted from the form
+ * @return bool - on error the subtype should call set_error and return false.
+ */
+ public function save_settings(stdClass $formdata) {
+ return true;
+ }
+
+ /**
+ * Save the error message from the last error
+ *
+ * @param string $msg - the error description
+ */
+ protected final function set_error($msg) {
+ $this->error = $msg;
+ }
+
+ /**
+ * What was the last error?
+ *
+ *
+ * @return string
+ */
+ public final function get_error() {
+ return $this->error;
+ }
+
+ /**
+ * Should return the name of this plugin type.
+ *
+ * @return string - the name
+ */
+ public abstract function get_name();
+
+ /**
+ * Should return the subtype of this plugin.
+ *
+ * @return string - either 'assignsubmission' or 'feedback'
+ */
+ public abstract function get_subtype();
+
+ /**
+ * Should return the type of this plugin.
+ *
+ * @return string - the type
+ */
+ public final function get_type() {
+ return $this->type;
+ }
+
+ /**
+ * Get the installed version of this plugin
+ *
+ * @return string
+ */
+ public final function get_version() {
+ $version = get_config($this->get_subtype() . '_' . $this->get_type(), 'version');
+ if ($version) {
+ return $version;
+ } else {
+ return '';
+ }
+ }
+
+ /**
+ * Get the required moodle version for this plugin
+ *
+ * @return string
+ */
+ public final function get_requires() {
+ $requires = get_config($this->get_subtype() . '_' . $this->get_type(), 'requires');
+ if ($requires) {
+ return $requires;