Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file contains the definition for the library class for online comment submission plugin
  19   *
  20   * @package assignsubmission_comments
  21   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25   defined('MOODLE_INTERNAL') || die();
  26  
  27   require_once($CFG->dirroot . '/comment/lib.php');
  28   require_once($CFG->dirroot . '/mod/assign/submissionplugin.php');
  29  
  30  /**
  31   * Library class for comment submission plugin extending submission plugin base class
  32   *
  33   * @package assignsubmission_comments
  34   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class assign_submission_comments extends assign_submission_plugin {
  38  
  39      /**
  40       * Get the name of the online comment submission plugin
  41       * @return string
  42       */
  43      public function get_name() {
  44          return get_string('pluginname', 'assignsubmission_comments');
  45      }
  46  
  47      /**
  48       * Display AJAX based comment in the submission status table
  49       *
  50       * @param stdClass $submission
  51       * @param bool $showviewlink - If the comments are long this is
  52       *                             set to true so they can be shown in a separate page
  53       * @return string
  54       */
  55      public function view_summary(stdClass $submission, & $showviewlink) {
  56  
  57          // Never show a link to view full submission.
  58          $showviewlink = false;
  59          // Need to used this init() otherwise it does not have the javascript includes.
  60          comment::init();
  61  
  62          $options = new stdClass();
  63          $options->area    = 'submission_comments';
  64          $options->course    = $this->assignment->get_course();
  65          $options->context = $this->assignment->get_context();
  66          $options->itemid  = $submission->id;
  67          $options->component = 'assignsubmission_comments';
  68          $options->showcount = true;
  69          $options->displaycancel = true;
  70  
  71          $comment = new comment($options);
  72  
  73          $o = $this->assignment->get_renderer()->container($comment->output(true), 'commentscontainer');
  74          return $o;
  75      }
  76  
  77      /**
  78       * Always return true because the submission comments are not part of the submission form.
  79       *
  80       * @param stdClass $submission
  81       * @return bool
  82       */
  83      public function is_empty(stdClass $submission) {
  84          return true;
  85      }
  86  
  87      /**
  88       * Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type
  89       * and version.
  90       *
  91       * @param string $type old assignment subtype
  92       * @param int $version old assignment version
  93       * @return bool True if upgrade is possible
  94       */
  95      public function can_upgrade($type, $version) {
  96  
  97          if ($type == 'upload' && $version >= 2011112900) {
  98              return true;
  99          }
 100          return false;
 101      }
 102  
 103  
 104      /**
 105       * Upgrade the settings from the old assignment to the new plugin based one
 106       *
 107       * @param context $oldcontext - the context for the old assignment
 108       * @param stdClass $oldassignment - the data for the old assignment
 109       * @param string $log - can be appended to by the upgrade
 110       * @return bool was it a success? (false will trigger a rollback)
 111       */
 112      public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) {
 113          if ($oldassignment->assignmenttype == 'upload') {
 114              // Disable if allow notes was not enabled.
 115              if (!$oldassignment->var2) {
 116                  $this->disable();
 117              }
 118          }
 119          return true;
 120      }
 121  
 122      /**
 123       * Upgrade the submission from the old assignment to the new one
 124       *
 125       * @param context $oldcontext The context for the old assignment
 126       * @param stdClass $oldassignment The data record for the old assignment
 127       * @param stdClass $oldsubmission The data record for the old submission
 128       * @param stdClass $submission The new submission record
 129       * @param string $log Record upgrade messages in the log
 130       * @return bool true or false - false will trigger a rollback
 131       */
 132      public function upgrade(context $oldcontext,
 133                              stdClass $oldassignment,
 134                              stdClass $oldsubmission,
 135                              stdClass $submission,
 136                              & $log) {
 137  
 138          if ($oldsubmission->data1 != '') {
 139  
 140              // Need to used this init() otherwise it does not have the javascript includes.
 141              comment::init();
 142  
 143              $options = new stdClass();
 144              $options->area = 'submission_comments_upgrade';
 145              $options->course = $this->assignment->get_course();
 146              $options->context = $this->assignment->get_context();
 147              $options->itemid = $submission->id;
 148              $options->component = 'assignsubmission_comments';
 149              $options->showcount = true;
 150              $options->displaycancel = true;
 151  
 152              $comment = new comment($options);
 153              $comment->add($oldsubmission->data1);
 154              $comment->set_view_permission(true);
 155  
 156              return $comment->output(true);
 157          }
 158  
 159          return true;
 160      }
 161  
 162      /**
 163       * The submission comments plugin has no submission component so should not be counted
 164       * when determining whether to show the edit submission link.
 165       * @return boolean
 166       */
 167      public function allow_submissions() {
 168          return false;
 169      }
 170  
 171      /**
 172       * Automatically enable or disable this plugin based on "$CFG->commentsenabled"
 173       *
 174       * @return bool
 175       */
 176      public function is_enabled() {
 177          global $CFG;
 178  
 179          return (!empty($CFG->usecomments));
 180      }
 181  
 182      /**
 183       * Automatically hide the setting for the submission plugin.
 184       *
 185       * @return bool
 186       */
 187      public function is_configurable() {
 188          return false;
 189      }
 190  
 191      /**
 192       * Return the plugin configs for external functions.
 193       *
 194       * @return array the list of settings
 195       * @since Moodle 3.2
 196       */
 197      public function get_config_for_external() {
 198          return (array) $this->get_config();
 199      }
 200  }