[ Index ]

PHP Cross Reference of moodle-2.8

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 $commonparams;
  25      private $item_form;
  26      private $context;
  27      private $item;
  28  
  29      public function init() {
  30          global $CFG;
  31          $this->presentationoptions = array('maxfiles' => EDITOR_UNLIMITED_FILES,
  32                                             'trusttext'=>true);
  33  
  34      }
  35  
  36      public function build_editform($item, $feedback, $cm) {
  37          global $DB, $CFG;
  38          require_once ('label_form.php');
  39  
  40          //get the lastposition number of the feedback_items
  41          $position = $item->position;
  42          $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
  43          if ($position == -1) {
  44              $i_formselect_last = $lastposition + 1;
  45              $i_formselect_value = $lastposition + 1;
  46              $item->position = $lastposition + 1;
  47          } else {
  48              $i_formselect_last = $lastposition;
  49              $i_formselect_value = $item->position;
  50          }
  51          //the elements for position dropdownlist
  52          $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
  53  
  54          //all items for dependitem
  55          $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
  56          $commonparams = array('cmid'=>$cm->id,
  57                               'id'=>isset($item->id) ? $item->id : null,
  58                               'typ'=>$item->typ,
  59                               'items'=>$feedbackitems,
  60                               'feedback'=>$feedback->id);
  61  
  62          $this->context = context_module::instance($cm->id);
  63  
  64          //preparing the editor for new file-api
  65          $item->presentationformat = FORMAT_HTML;
  66          $item->presentationtrust = 1;
  67  
  68          // Append editor context to presentation options, giving preference to existing context.
  69          $this->presentationoptions = array_merge(array('context' => $this->context),
  70                                                   $this->presentationoptions);
  71  
  72          $item = file_prepare_standard_editor($item,
  73                                              'presentation', //name of the form element
  74                                              $this->presentationoptions,
  75                                              $this->context,
  76                                              'mod_feedback',
  77                                              'item', //the filearea
  78                                              $item->id);
  79  
  80          //build the form
  81          $customdata = array('item' => $item,
  82                              'common' => $commonparams,
  83                              'positionlist' => $positionlist,
  84                              'position' => $position,
  85                              'presentationoptions' => $this->presentationoptions);
  86  
  87          $this->item_form = new feedback_label_form('edit_item.php', $customdata);
  88      }
  89  
  90      //this function only can used after the call of build_editform()
  91      public function show_editform() {
  92          $this->item_form->display();
  93      }
  94  
  95      public function is_cancelled() {
  96          return $this->item_form->is_cancelled();
  97      }
  98  
  99      public function get_data() {
 100          if ($this->item = $this->item_form->get_data()) {
 101              return true;
 102          }
 103          return false;
 104      }
 105  
 106      public function save_item() {
 107          global $DB;
 108  
 109          if (!$item = $this->item_form->get_data()) {
 110              return false;
 111          }
 112  
 113          if (isset($item->clone_item) AND $item->clone_item) {
 114              $item->id = ''; //to clone this item
 115              $item->position++;
 116          }
 117  
 118          $item->presentation = '';
 119  
 120          $item->hasvalue = $this->get_hasvalue();
 121          if (!$item->id) {
 122              $item->id = $DB->insert_record('feedback_item', $item);
 123          } else {
 124              $DB->update_record('feedback_item', $item);
 125          }
 126  
 127          $item = file_postupdate_standard_editor($item,
 128                                                  'presentation',
 129                                                  $this->presentationoptions,
 130                                                  $this->context,
 131                                                  'mod_feedback',
 132                                                  'item',
 133                                                  $item->id);
 134  
 135          $DB->update_record('feedback_item', $item);
 136  
 137          return $DB->get_record('feedback_item', array('id'=>$item->id));
 138      }
 139  
 140      public function print_item($item) {
 141          global $DB, $CFG;
 142  
 143          require_once($CFG->libdir . '/filelib.php');
 144  
 145          //is the item a template?
 146          if (!$item->feedback AND $item->template) {
 147              $template = $DB->get_record('feedback_template', array('id'=>$item->template));
 148              if ($template->ispublic) {
 149                  $context = context_system::instance();
 150              } else {
 151                  $context = context_course::instance($template->course);
 152              }
 153              $filearea = 'template';
 154          } else {
 155              $cm = get_coursemodule_from_instance('feedback', $item->feedback);
 156              $context = context_module::instance($cm->id);
 157              $filearea = 'item';
 158          }
 159  
 160          $item->presentationformat = FORMAT_HTML;
 161          $item->presentationtrust = 1;
 162  
 163          $output = file_rewrite_pluginfile_urls($item->presentation,
 164                                                 'pluginfile.php',
 165                                                 $context->id,
 166                                                 'mod_feedback',
 167                                                 $filearea,
 168                                                 $item->id);
 169  
 170          $formatoptions = array('overflowdiv'=>true, 'trusted'=>$CFG->enabletrusttext);
 171          echo format_text($output, FORMAT_HTML, $formatoptions);
 172      }
 173  
 174      /**
 175       * print the item at the edit-page of feedback
 176       *
 177       * @global object
 178       * @param object $item
 179       * @return void
 180       */
 181      public function print_item_preview($item) {
 182          global $OUTPUT, $DB;
 183  
 184          if ($item->dependitem) {
 185              if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
 186                  echo ' <span class="feedback_depend">';
 187                  echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
 188                  echo '</span>';
 189              }
 190          }
 191          $this->print_item($item);
 192      }
 193  
 194      /**
 195       * print the item at the complete-page of feedback
 196       *
 197       * @global object
 198       * @param object $item
 199       * @param string $value
 200       * @param bool $highlightrequire
 201       * @return void
 202       */
 203      public function print_item_complete($item, $value = '', $highlightrequire = false) {
 204          $this->print_item($item);
 205      }
 206  
 207      /**
 208       * print the item at the complete-page of feedback
 209       *
 210       * @global object
 211       * @param object $item
 212       * @param string $value
 213       * @return void
 214       */
 215      public function print_item_show_value($item, $value = '') {
 216          $this->print_item($item);
 217      }
 218  
 219      public function create_value($data) {
 220          return false;
 221      }
 222  
 223      public function compare_value($item, $dbvalue, $dependvalue) {
 224          return false;
 225      }
 226  
 227      //used by create_item and update_item functions,
 228      //when provided $data submitted from feedback_show_edit
 229      public function get_presentation($data) {
 230      }
 231  
 232      public function postupdate($item) {
 233          global $DB;
 234  
 235          $context = context_module::instance($item->cmid);
 236          $item = file_postupdate_standard_editor($item,
 237                                                  'presentation',
 238                                                  $this->presentationoptions,
 239                                                  $context,
 240                                                  'mod_feedback',
 241                                                  'item',
 242                                                  $item->id);
 243  
 244          $DB->update_record('feedback_item', $item);
 245          return $item->id;
 246      }
 247  
 248      public function get_hasvalue() {
 249          return 0;
 250      }
 251  
 252      public function can_switch_require() {
 253          return false;
 254      }
 255  
 256      public function check_value($value, $item) {
 257      }
 258  
 259      public function excelprint_item(&$worksheet,
 260                               $row_offset,
 261                               $xls_formats,
 262                               $item,
 263                               $groupid,
 264                               $courseid = false) {
 265      }
 266  
 267      public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
 268      }
 269      public function get_printval($item, $value) {
 270      }
 271      public function get_analysed($item, $groupid = false, $courseid = false) {
 272      }
 273      public function value_type() {
 274          return PARAM_BOOL;
 275      }
 276      public function clean_input_value($value) {
 277          return '';
 278      }
 279  }


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