MDL-41131 assign module: remove setting for submission comments and edipdf plugins...
authorrwijaya <rwijaya@moodle.com>
Wed, 9 Oct 2013 12:14:26 +0000 (20:14 +0800)
committerrwijaya <rwijaya@moodle.com>
Mon, 14 Oct 2013 04:43:26 +0000 (12:43 +0800)
mod/assign/assignmentplugin.php
mod/assign/feedback/editpdf/locallib.php
mod/assign/locallib.php
mod/assign/submission/comments/locallib.php
mod/assign/submission/comments/settings.php [deleted file]
mod/assign/tests/locallib_test.php
mod/assign/tests/upgradelib_test.php

index ea6a36a..52ab2f9 100644 (file)
@@ -636,4 +636,14 @@ abstract class assign_plugin {
     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;
+    }
 }
index d1d3cf5..c7372bf 100644 (file)
@@ -253,4 +253,25 @@ class assign_feedback_editpdf extends assign_feedback_plugin {
         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;
+    }
 }
index aa51367..2ec6da6 100644 (file)
@@ -967,8 +967,12 @@ class assign {
      */
     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());
index 52fbfda..787f3f5 100644 (file)
@@ -168,4 +168,24 @@ class assign_submission_comments extends assign_submission_plugin {
     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;
+    }
 }
diff --git a/mod/assign/submission/comments/settings.php b/mod/assign/submission/comments/settings.php
deleted file mode 100644 (file)
index 53412bf..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?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 defines the admin settings for this plugin
- *
- * @package   assignsubmission_comments
- * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-$settings->add(new admin_setting_configcheckbox('assignsubmission_comments/default',
-                   new lang_string('default', 'assignsubmission_comments'),
-                   new lang_string('default_help', 'assignsubmission_comments'), 0));
-
index ed10b06..341dfca 100644 (file)
@@ -1378,5 +1378,62 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
         $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'));
+    }
 }
 
index 263cc1d..2df6e74 100644 (file)
@@ -46,7 +46,13 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
     }
 
     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 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
         $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 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
         $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 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
         $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 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
         $plugin = $assign->get_feedback_plugin_by_type('offline');
         $this->assertEmpty($plugin->is_enabled());
 
+        $CFG->usecomments = $commentconfig;
         course_delete_module($cm->id);
     }
 }