Skip to content

Commit

Permalink
MDL-41131 assign module: remove setting for submission comments and e…
Browse files Browse the repository at this point in the history
…dipdf plugins' setting.
  • Loading branch information
rwijaya committed Oct 14, 2013
1 parent f8eff10 commit f159ad7
Showing 7 changed files with 146 additions and 34 deletions.
10 changes: 10 additions & 0 deletions mod/assign/assignmentplugin.php
Original file line number Diff line number Diff line change
@@ -636,4 +636,14 @@ public function has_user_summary() {
public function get_external_parameters() {
return null;
}

/**
* If true, the plugin will appear on the module settings page and can be
* enabled/disabled per assignment instance.
*
* @return bool
*/
public function is_configurable() {
return true;
}
}
21 changes: 21 additions & 0 deletions mod/assign/feedback/editpdf/locallib.php
Original file line number Diff line number Diff line change
@@ -253,4 +253,25 @@ public function delete_instance() {
return true;
}

/**
* Automatically enable or disable editpdf feedback plugin based on
* whether the ghostscript path is set correctly.
*
* @return bool
*/
public function is_enabled() {
$testpath = assignfeedback_editpdf\pdf::test_gs_path();
if ($testpath->status == assignfeedback_editpdf\pdf::GSPATH_OK) {
return true;
}
return false;
}
/**
* Automatically hide the setting for the editpdf feedback plugin.
*
* @return bool false
*/
public function is_configurable() {
return false;
}
}
8 changes: 6 additions & 2 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
@@ -967,8 +967,12 @@ protected function add_plugin_grade_elements($grade, MoodleQuickForm $mform, std
*/
protected function add_plugin_settings(assign_plugin $plugin, MoodleQuickForm $mform, & $pluginsenabled) {
global $CFG;
if ($plugin->is_visible()) {

if ($plugin->is_visible() && !$plugin->is_configurable() && $plugin->is_enabled()) {
$name = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
$pluginsenabled[] = $mform->createElement('hidden', $name, 1);
$mform->setType($name, PARAM_BOOL);
$plugin->get_settings($mform);
} else if ($plugin->is_visible() && $plugin->is_configurable()) {
$name = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
$label = $plugin->get_name();
$label .= ' ' . $this->get_renderer()->help_icon('enabled', $plugin->get_subtype() . '_' . $plugin->get_type());
20 changes: 20 additions & 0 deletions mod/assign/submission/comments/locallib.php
Original file line number Diff line number Diff line change
@@ -168,4 +168,24 @@ public function upgrade(context $oldcontext,
public function allow_submissions() {
return false;
}

/**
* Automatically enable or disable this plugin based on "$CFG->commentsenabled"
*
* @return bool
*/
public function is_enabled() {
global $CFG;

return (!empty($CFG->usecomments));
}

/**
* Automatically hide the setting for the submission plugin.
*
* @return bool
*/
public function is_configurable() {
return false;
}
}
28 changes: 0 additions & 28 deletions mod/assign/submission/comments/settings.php

This file was deleted.

57 changes: 57 additions & 0 deletions mod/assign/tests/locallib_test.php
Original file line number Diff line number Diff line change
@@ -1378,5 +1378,62 @@ public function test_disable_submit_after_cutoff_date() {
$this->assertNotContains($output, get_string('submitassignment', 'assign'),
'Should not be able to submit after cutoff date.');
}
/**
* Testing for submission comment plugin settings
*/
public function test_submission_comment_plugin_settings() {
global $CFG;

$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
}

$CFG->usecomments = true;
$assign = $this->create_instance();
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEquals(1, $plugin->is_enabled('enabled'));

$assign = $this->create_instance(array('assignsubmission_comments_enabled' => 0));
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEquals(1, $plugin->is_enabled('enabled'));

$assign = $this->create_instance(array('assignsubmission_comments_enabled' => 1));
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEquals(1, $plugin->is_enabled('enabled'));

$CFG->usecomments = false;
$assign = $this->create_instance();
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEquals(0, $plugin->is_enabled('enabled'));

$assign = $this->create_instance(array('assignsubmission_comments_enabled' => 0));
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEquals(0, $plugin->is_enabled('enabled'));

$assign = $this->create_instance(array('assignsubmission_comments_enabled' => 1));
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEquals(0, $plugin->is_enabled('enabled'));

$CFG->usecomments = $commentconfig;
}

/**
* Testing for feedback comment plugin settings
*/
public function test_feedback_plugin_settings() {

$assign = $this->create_instance();
$plugin = $assign->get_feedback_plugin_by_type('comments');
$this->assertEquals(0, $plugin->is_enabled('enabled'));

$assign = $this->create_instance(array('assignfeedback_comments_enabled' => 0));
$plugin = $assign->get_feedback_plugin_by_type('comments');
$this->assertEquals(0, $plugin->is_enabled('enabled'));

$assign = $this->create_instance(array('assignfeedback_comments_enabled' => 1));
$plugin = $assign->get_feedback_plugin_by_type('comments');
$this->assertEquals(1, $plugin->is_enabled('enabled'));
}
}

36 changes: 32 additions & 4 deletions mod/assign/tests/upgradelib_test.php
Original file line number Diff line number Diff line change
@@ -46,7 +46,13 @@ protected function tearDown() {
}

public function test_upgrade_upload_assignment() {
global $DB;
global $DB, $CFG;

$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
}
$CFG->usecomments = false;

$this->setUser($this->editingteachers[0]);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
@@ -81,11 +87,18 @@ public function test_upgrade_upload_assignment() {
$plugin = $assign->get_feedback_plugin_by_type('offline');
$this->assertEmpty($plugin->is_enabled());

$CFG->usecomments = $commentconfig;
course_delete_module($cm->id);
}

public function test_upgrade_uploadsingle_assignment() {
global $DB;
global $DB, $CFG;

$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
}
$CFG->usecomments = false;

$this->setUser($this->editingteachers[0]);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
@@ -120,11 +133,18 @@ public function test_upgrade_uploadsingle_assignment() {
$plugin = $assign->get_feedback_plugin_by_type('offline');
$this->assertEmpty($plugin->is_enabled());

$CFG->usecomments = $commentconfig;
course_delete_module($cm->id);
}

public function test_upgrade_onlinetext_assignment() {
global $DB;
global $DB, $CFG;

$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
}
$CFG->usecomments = false;

$this->setUser($this->editingteachers[0]);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
@@ -159,11 +179,18 @@ public function test_upgrade_onlinetext_assignment() {
$plugin = $assign->get_feedback_plugin_by_type('offline');
$this->assertEmpty($plugin->is_enabled());

$CFG->usecomments = $commentconfig;
course_delete_module($cm->id);
}

public function test_upgrade_offline_assignment() {
global $DB;
global $DB, $CFG;

$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
}
$CFG->usecomments = false;

$this->setUser($this->editingteachers[0]);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
@@ -198,6 +225,7 @@ public function test_upgrade_offline_assignment() {
$plugin = $assign->get_feedback_plugin_by_type('offline');
$this->assertEmpty($plugin->is_enabled());

$CFG->usecomments = $commentconfig;
course_delete_module($cm->id);
}
}

0 comments on commit f159ad7

Please sign in to comment.