PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/feedback/item/label/lib.php

https://github.com/cgtaylor/moodle
PHP | 234 lines | 148 code | 42 blank | 44 comment | 9 complexity | a15b77bbbfc041c5574f056f2d3b4131 MD5 | raw file
  1. <?php
  2. defined('MOODLE_INTERNAL') OR die('not allowed');
  3. require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
  4. require_once($CFG->libdir.'/formslib.php');
  5. class feedback_item_label extends feedback_item_base {
  6. var $type = "label";
  7. var $presentationoptions = null;
  8. var $commonparams;
  9. var $item_form;
  10. var $context;
  11. var $item;
  12. function init() {
  13. global $CFG;
  14. $this->presentationoptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext'=>true);
  15. }
  16. function build_editform($item, $feedback, $cm) {
  17. global $DB, $CFG;
  18. require_once('label_form.php');
  19. //get the lastposition number of the feedback_items
  20. $position = $item->position;
  21. $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
  22. if($position == -1){
  23. $i_formselect_last = $lastposition + 1;
  24. $i_formselect_value = $lastposition + 1;
  25. $item->position = $lastposition + 1;
  26. }else {
  27. $i_formselect_last = $lastposition;
  28. $i_formselect_value = $item->position;
  29. }
  30. //the elements for position dropdownlist
  31. $positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
  32. //all items for dependitem
  33. $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
  34. $commonparams = array('cmid'=>$cm->id,
  35. 'id'=>isset($item->id) ? $item->id : NULL,
  36. 'typ'=>$item->typ,
  37. 'items'=>$feedbackitems,
  38. 'feedback'=>$feedback->id);
  39. $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
  40. //preparing the editor for new file-api
  41. $item->presentationformat = FORMAT_HTML;
  42. $item->presentationtrust = 1;
  43. $item = file_prepare_standard_editor($item,
  44. 'presentation', //name of the form element
  45. $this->presentationoptions,
  46. $this->context,
  47. 'mod_feedback',
  48. 'item', //the filearea
  49. $item->id);
  50. //build the form
  51. $this->item_form = new feedback_label_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'presentationoptions'=>$this->presentationoptions));
  52. }
  53. //this function only can used after the call of build_editform()
  54. function show_editform() {
  55. $this->item_form->display();
  56. }
  57. function is_cancelled() {
  58. return $this->item_form->is_cancelled();
  59. }
  60. function get_data() {
  61. if($this->item = $this->item_form->get_data()) {
  62. return true;
  63. }
  64. return false;
  65. }
  66. function save_item() {
  67. global $DB;
  68. if(!$item = $this->item_form->get_data()) {
  69. return false;
  70. }
  71. if(isset($item->clone_item) AND $item->clone_item) {
  72. $item->id = ''; //to clone this item
  73. $item->position++;
  74. }
  75. $item->presentation = '';
  76. $item->hasvalue = $this->get_hasvalue();
  77. if(!$item->id) {
  78. $item->id = $DB->insert_record('feedback_item', $item);
  79. }else {
  80. $DB->update_record('feedback_item', $item);
  81. }
  82. $item = file_postupdate_standard_editor($item,
  83. 'presentation',
  84. $this->presentationoptions,
  85. $this->context,
  86. 'mod_feedback',
  87. 'item',
  88. $item->id);
  89. $DB->update_record('feedback_item', $item);
  90. return $DB->get_record('feedback_item', array('id'=>$item->id));
  91. }
  92. function print_item($item){
  93. <<<<<<< HEAD
  94. global $DB;
  95. =======
  96. global $DB, $CFG;
  97. require_once($CFG->libdir . '/filelib.php');
  98. >>>>>>> 54b7b5993fbd4386eb4eadb4f97da8d41dfa16bf
  99. //is the item a template?
  100. if(!$item->feedback AND $item->template) {
  101. $template = $DB->get_record('feedback_template', array('id'=>$item->template));
  102. $context = get_context_instance(CONTEXT_COURSE, $template->course);
  103. $filearea = 'template';
  104. }else {
  105. $cm = get_coursemodule_from_instance('feedback', $item->feedback);
  106. $context = get_context_instance(CONTEXT_MODULE, $cm->id);
  107. $filearea = 'item';
  108. }
  109. $item->presentationformat = FORMAT_HTML;
  110. $item->presentationtrust = 1;
  111. $output = file_rewrite_pluginfile_urls($item->presentation, 'pluginfile.php', $context->id, 'mod_feedback', $filearea, $item->id);
  112. echo format_text($output, FORMAT_HTML, array('overflowdiv'=>true));
  113. }
  114. /**
  115. * print the item at the edit-page of feedback
  116. *
  117. * @global object
  118. * @param object $item
  119. * @return void
  120. */
  121. function print_item_preview($item) {
  122. global $OUTPUT, $DB;
  123. if($item->dependitem) {
  124. if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
  125. echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>';
  126. }
  127. }
  128. $this->print_item($item);
  129. }
  130. /**
  131. * print the item at the complete-page of feedback
  132. *
  133. * @global object
  134. * @param object $item
  135. * @param string $value
  136. * @param bool $highlightrequire
  137. * @return void
  138. */
  139. function print_item_complete($item, $value = '', $highlightrequire = false) {
  140. $this->print_item($item);
  141. }
  142. /**
  143. * print the item at the complete-page of feedback
  144. *
  145. * @global object
  146. * @param object $item
  147. * @param string $value
  148. * @return void
  149. */
  150. function print_item_show_value($item, $value = '') {
  151. $this->print_item($item);
  152. }
  153. function create_value($data) {
  154. return false;
  155. }
  156. function compare_value($item, $dbvalue, $dependvalue) {
  157. return false;
  158. }
  159. //used by create_item and update_item functions,
  160. //when provided $data submitted from feedback_show_edit
  161. function get_presentation($data) {
  162. // $context = get_context_instance(CONTEXT_MODULE, $data->cmid);
  163. // $presentation = new stdClass();
  164. // $presentation->id = null;
  165. // $presentation->definition = '';
  166. // $presentation->format = FORMAT_HTML;
  167. // $draftid_editor = file_get_submitted_draft_itemid('presentation');
  168. // $currenttext = file_prepare_draft_area($draftid_editor, $context->id, 'mod_feedback', 'item_label', $presentation->id, array('subdirs'=>true), $presentation->definition);
  169. // $presentation->entry = array('text'=>$currenttext, 'format'=>$presentation->format, 'itemid'=>$draftid_editor);
  170. // return $data->presentation;
  171. }
  172. function postupdate($item) {
  173. global $DB;
  174. $context = get_context_instance(CONTEXT_MODULE, $item->cmid);
  175. $item = file_postupdate_standard_editor($item, 'presentation', $this->presentationoptions, $context, 'mod_feedback', 'item', $item->id);
  176. // $item = new stdClass();
  177. // $item->id = $data->id
  178. $DB->update_record('feedback_item', $item);
  179. return $item->id;
  180. }
  181. function get_hasvalue() {
  182. return 0;
  183. }
  184. function can_switch_require() {
  185. return false;
  186. }
  187. function check_value($value, $item) {}
  188. function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {}
  189. function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {}
  190. function get_printval($item, $value) {}
  191. function get_analysed($item, $groupid = false, $courseid = false) {}
  192. }