[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/feedback/classes/event/ -> response_deleted.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   * The mod_feedback response deleted event.
  19   *
  20   * @package    mod_feedback
  21   * @copyright  2013 Ankit Agarwal
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
  23   */
  24  
  25  namespace mod_feedback\event;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * The mod_feedback response deleted event class.
  30   *
  31   * This event is triggered when a feedback response is deleted.
  32   *
  33   * @property-read array $other {
  34   *      Extra information about event.
  35   *
  36   *      - int anonymous: if feedback is anonymous.
  37   *      - int cmid: course module id.
  38   *      - int instanceid: id of instance.
  39   * }
  40   *
  41   * @package    mod_feedback
  42   * @since      Moodle 2.6
  43   * @copyright  2013 Ankit Agarwal
  44   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
  45   */
  46  class response_deleted extends \core\event\base {
  47  
  48      /**
  49       * Set basic properties for the event.
  50       */
  51      protected function init() {
  52          $this->data['objecttable'] = 'feedback_completed';
  53          $this->data['crud'] = 'd';
  54          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  55      }
  56  
  57      /**
  58       * Returns localised general event name.
  59       *
  60       * @return string
  61       */
  62      public static function get_name() {
  63          return get_string('eventresponsedeleted', 'mod_feedback');
  64      }
  65  
  66      /**
  67       * Returns non-localised event description with id's for admin use only.
  68       *
  69       * @return string
  70       */
  71      public function get_description() {
  72          return "The user with id '$this->userid' deleted the feedback for the user with id '$this->relateduserid' " .
  73              "for the feedback activity with course module id '$this->contextinstanceid'.";
  74      }
  75  
  76      /**
  77       * Replace add_to_log() statement.
  78       *
  79       * @return array of parameters to be passed to legacy add_to_log() function.
  80       */
  81      protected function get_legacy_logdata() {
  82          return array($this->courseid, 'feedback', 'delete', 'view.php?id=' . $this->other['cmid'], $this->other['instanceid'],
  83                  $this->other['instanceid']);
  84      }
  85  
  86      /**
  87       * Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response.
  88       *
  89       * @deprecated since 2.7
  90       *
  91       * @param int|\stdClass $userorid ID of the user.
  92       * @return bool True if the user can view the event, false otherwise.
  93       */
  94      public function can_view($userorid = null) {
  95          global $USER;
  96          debugging('can_view() method is deprecated, use anonymous flag instead if necessary.', DEBUG_DEVELOPER);
  97  
  98          if (empty($userorid)) {
  99              $userorid = $USER;
 100          }
 101          if ($this->anonymous) {
 102              return is_siteadmin($userorid);
 103          } else {
 104              return has_capability('mod/feedback:viewreports', $this->context, $userorid);
 105          }
 106      }
 107  
 108      /**
 109       * Custom validations
 110       *
 111       * @throws \coding_exception in case of any problems.
 112       */
 113      protected function validate_data() {
 114          parent::validate_data();
 115  
 116          if (!isset($this->relateduserid)) {
 117              throw new \coding_exception('The \'relateduserid\' must be set.');
 118          }
 119          if (!isset($this->other['anonymous'])) {
 120              throw new \coding_exception('The \'anonymous\' value must be set in other.');
 121          }
 122          if (!isset($this->other['cmid'])) {
 123              throw new \coding_exception('The \'cmid\' value must be set in other.');
 124          }
 125          if (!isset($this->other['instanceid'])) {
 126              throw new \coding_exception('The \'instanceid\' value must be set in other.');
 127          }
 128      }
 129  }
 130  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1