[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/submission/comments/ -> locallib.php (source)

   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          $comment->set_view_permission(true);
  73  
  74          $o = $this->assignment->get_renderer()->container($comment->output(true), 'commentscontainer');
  75          return $o;
  76      }
  77  
  78      /**
  79       * Always return true because the submission comments are not part of the submission form.
  80       *
  81       * @param stdClass $submission
  82       * @return bool
  83       */
  84      public function is_empty(stdClass $submission) {
  85          return true;
  86      }
  87  
  88      /**
  89       * Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type
  90       * and version.
  91       *
  92       * @param string $type old assignment subtype
  93       * @param int $version old assignment version
  94       * @return bool True if upgrade is possible
  95       */
  96      public function can_upgrade($type, $version) {
  97  
  98          if ($type == 'upload' && $version >= 2011112900) {
  99              return true;
 100          }
 101          return false;
 102      }
 103  
 104  
 105      /**
 106       * Upgrade the settings from the old assignment to the new plugin based one
 107       *
 108       * @param context $oldcontext - the context for the old assignment
 109       * @param stdClass $oldassignment - the data for the old assignment
 110       * @param string $log - can be appended to by the upgrade
 111       * @return bool was it a success? (false will trigger a rollback)
 112       */
 113      public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) {
 114          if ($oldassignment->assignmenttype == 'upload') {
 115              // Disable if allow notes was not enabled.
 116              if (!$oldassignment->var2) {
 117                  $this->disable();
 118              }
 119          }
 120          return true;
 121      }
 122  
 123      /**
 124       * Upgrade the submission from the old assignment to the new one
 125       *
 126       * @param context $oldcontext The context for the old assignment
 127       * @param stdClass $oldassignment The data record for the old assignment
 128       * @param stdClass $oldsubmission The data record for the old submission
 129       * @param stdClass $submission The new submission record
 130       * @param string $log Record upgrade messages in the log
 131       * @return bool true or false - false will trigger a rollback
 132       */
 133      public function upgrade(context $oldcontext,
 134                              stdClass $oldassignment,
 135                              stdClass $oldsubmission,
 136                              stdClass $submission,
 137                              & $log) {
 138  
 139          if ($oldsubmission->data1 != '') {
 140  
 141              // Need to used this init() otherwise it does not have the javascript includes.
 142              comment::init();
 143  
 144              $options = new stdClass();
 145              $options->area = 'submission_comments_upgrade';
 146              $options->course = $this->assignment->get_course();
 147              $options->context = $this->assignment->get_context();
 148              $options->itemid = $submission->id;
 149              $options->component = 'assignsubmission_comments';
 150              $options->showcount = true;
 151              $options->displaycancel = true;
 152  
 153              $comment = new comment($options);
 154              $comment->add($oldsubmission->data1);
 155              $comment->set_view_permission(true);
 156  
 157              return $comment->output(true);
 158          }
 159  
 160          return true;
 161      }
 162  
 163      /**
 164       * The submission comments plugin has no submission component so should not be counted
 165       * when determining whether to show the edit submission link.
 166       * @return boolean
 167       */
 168      public function allow_submissions() {
 169          return false;
 170      }
 171  
 172      /**
 173       * Automatically enable or disable this plugin based on "$CFG->commentsenabled"
 174       *
 175       * @return bool
 176       */
 177      public function is_enabled() {
 178          global $CFG;
 179  
 180          return (!empty($CFG->usecomments));
 181      }
 182  
 183      /**
 184       * Automatically hide the setting for the submission plugin.
 185       *
 186       * @return bool
 187       */
 188      public function is_configurable() {
 189          return false;
 190      }
 191  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1