Commit e5403f8c authored by Damyon Wiese's avatar Damyon Wiese
Browse files

MDL-36904 Assignment: Fix all errors and warnings from codechecker

parent 9da506c2
......@@ -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);
}
......
......@@ -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');
......
......@@ -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);
}
......@@ -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();
......
M.tool_assignmentupgrade = {
init_upgrade_table: function(Y) {
......
......@@ -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'));
}
}
......
......@@ -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();
......
......@@ -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
}
......@@ -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'));
......
......@@ -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') . '<div class="selectall"><input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/></div>';
$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';
......@@ -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');
......
......@@ -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');
......
......@@ -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');
......
......@@ -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[] = '&nbsp;';
}
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();