[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/feedback/item/label/ -> lib.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  defined('MOODLE_INTERNAL') OR die('not allowed');
  18  require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
  19  require_once($CFG->libdir.'/formslib.php');
  20  
  21  class feedback_item_label extends feedback_item_base {
  22      protected $type = "label";
  23      private $presentationoptions = null;
  24      private $context;
  25  
  26      /**
  27       * Constructor
  28       */
  29      public function __construct() {
  30          $this->presentationoptions = array('maxfiles' => EDITOR_UNLIMITED_FILES,
  31                                             'trusttext'=>true);
  32  
  33      }
  34  
  35      public function build_editform($item, $feedback, $cm) {
  36          global $DB, $CFG;
  37          require_once ('label_form.php');
  38  
  39          //get the lastposition number of the feedback_items
  40          $position = $item->position;
  41          $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
  42          if ($position == -1) {
  43              $i_formselect_last = $lastposition + 1;
  44              $i_formselect_value = $lastposition + 1;
  45              $item->position = $lastposition + 1;
  46          } else {
  47              $i_formselect_last = $lastposition;
  48              $i_formselect_value = $item->position;
  49          }
  50          //the elements for position dropdownlist
  51          $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
  52  
  53          //all items for dependitem
  54          $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
  55          $commonparams = array('cmid'=>$cm->id,
  56                               'id'=>isset($item->id) ? $item->id : null,
  57                               'typ'=>$item->typ,
  58                               'items'=>$feedbackitems,
  59                               'feedback'=>$feedback->id);
  60  
  61          $this->context = context_module::instance($cm->id);
  62  
  63          //preparing the editor for new file-api
  64          $item->presentationformat = FORMAT_HTML;
  65          $item->presentationtrust = 1;
  66  
  67          // Append editor context to presentation options, giving preference to existing context.
  68          $this->presentationoptions = array_merge(array('context' => $this->context),
  69                                                   $this->presentationoptions);
  70  
  71          $item = file_prepare_standard_editor($item,
  72                                              'presentation', //name of the form element
  73                                              $this->presentationoptions,
  74                                              $this->context,
  75                                              'mod_feedback',
  76                                              'item', //the filearea
  77                                              $item->id);
  78  
  79          //build the form
  80          $customdata = array('item' => $item,
  81                              'common' => $commonparams,
  82                              'positionlist' => $positionlist,
  83                              'position' => $position,
  84                              'presentationoptions' => $this->presentationoptions);
  85  
  86          $this->item_form = new feedback_label_form('edit_item.php', $customdata);
  87      }
  88  
  89      public function save_item() {
  90          global $DB;
  91  
  92          if (!$item = $this->item_form->get_data()) {
  93              return false;
  94          }
  95  
  96          if (isset($item->clone_item) AND $item->clone_item) {
  97              $item->id = ''; //to clone this item
  98              $item->position++;
  99          }
 100  
 101          $item->presentation = '';
 102  
 103          $item->hasvalue = $this->get_hasvalue();
 104          if (!$item->id) {
 105              $item->id = $DB->insert_record('feedback_item', $item);
 106          } else {
 107              $DB->update_record('feedback_item', $item);
 108          }
 109  
 110          $item = file_postupdate_standard_editor($item,
 111                                                  'presentation',
 112                                                  $this->presentationoptions,
 113                                                  $this->context,
 114                                                  'mod_feedback',
 115                                                  'item',
 116                                                  $item->id);
 117  
 118          $DB->update_record('feedback_item', $item);
 119  
 120          return $DB->get_record('feedback_item', array('id'=>$item->id));
 121      }
 122  
 123      /**
 124       * prepares the item for output or export to file
 125       * @param stdClass $item
 126       * @return string
 127       */
 128      private function print_item($item) {
 129          global $DB, $CFG;
 130  
 131          require_once($CFG->libdir . '/filelib.php');
 132  
 133          //is the item a template?
 134          if (!$item->feedback AND $item->template) {
 135              $template = $DB->get_record('feedback_template', array('id'=>$item->template));
 136              if ($template->ispublic) {
 137                  $context = context_system::instance();
 138              } else {
 139                  $context = context_course::instance($template->course);
 140              }
 141              $filearea = 'template';
 142          } else {
 143              $cm = get_coursemodule_from_instance('feedback', $item->feedback);
 144              $context = context_module::instance($cm->id);
 145              $filearea = 'item';
 146          }
 147  
 148          $item->presentationformat = FORMAT_HTML;
 149          $item->presentationtrust = 1;
 150  
 151          $output = file_rewrite_pluginfile_urls($item->presentation,
 152                                                 'pluginfile.php',
 153                                                 $context->id,
 154                                                 'mod_feedback',
 155                                                 $filearea,
 156                                                 $item->id);
 157  
 158          $formatoptions = array('overflowdiv'=>true, 'trusted'=>$CFG->enabletrusttext);
 159          echo format_text($output, FORMAT_HTML, $formatoptions);
 160      }
 161  
 162      /**
 163       * @param stdClass $item
 164       * @param bool|true $withpostfix
 165       * @return string
 166       */
 167      public function get_display_name($item, $withpostfix = true) {
 168          return '';
 169      }
 170  
 171      /**
 172       * Adds an input element to the complete form
 173       *
 174       * @param stdClass $item
 175       * @param mod_feedback_complete_form $form
 176       */
 177      public function complete_form_element($item, $form) {
 178          global $DB;
 179          if (!$item->feedback AND $item->template) {
 180              // This is a template.
 181              $template = $DB->get_record('feedback_template', array('id' => $item->template));
 182              if ($template->ispublic) {
 183                  $context = context_system::instance();
 184              } else {
 185                  $context = context_course::instance($template->course);
 186              }
 187              $filearea = 'template';
 188          } else {
 189              // This is a question in the current feedback.
 190              $context = $form->get_cm()->context;
 191              $filearea = 'item';
 192          }
 193          $output = file_rewrite_pluginfile_urls($item->presentation, 'pluginfile.php',
 194                  $context->id, 'mod_feedback', $filearea, $item->id);
 195          $formatoptions = array('overflowdiv' => true, 'noclean' => true);
 196          $output = format_text($output, FORMAT_HTML, $formatoptions);
 197  
 198          $inputname = $item->typ . '_' . $item->id;
 199  
 200          $name = $this->get_display_name($item);
 201          $form->add_form_element($item, ['static', $inputname, $name, $output], false, false);
 202      }
 203  
 204      public function compare_value($item, $dbvalue, $dependvalue) {
 205          return false;
 206      }
 207  
 208      public function postupdate($item) {
 209          global $DB;
 210  
 211          $context = context_module::instance($item->cmid);
 212          $item = file_postupdate_standard_editor($item,
 213                                                  'presentation',
 214                                                  $this->presentationoptions,
 215                                                  $context,
 216                                                  'mod_feedback',
 217                                                  'item',
 218                                                  $item->id);
 219  
 220          $DB->update_record('feedback_item', $item);
 221          return $item->id;
 222      }
 223  
 224      public function get_hasvalue() {
 225          return 0;
 226      }
 227  
 228      public function can_switch_require() {
 229          return false;
 230      }
 231  
 232      public function excelprint_item(&$worksheet,
 233                               $row_offset,
 234                               $xls_formats,
 235                               $item,
 236                               $groupid,
 237                               $courseid = false) {
 238      }
 239  
 240      public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
 241      }
 242      public function get_printval($item, $value) {
 243      }
 244  }


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