. defined('MOODLE_INTERNAL') OR die('not allowed'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); class feedback_item_info extends feedback_item_base { protected $type = "info"; /** Mode recording response time (for non-anonymous feedbacks only) */ const MODE_RESPONSETIME = 1; /** Mode recording current course */ const MODE_COURSE = 2; /** Mode recording current course category */ const MODE_CATEGORY = 3; /** Special constant to keep the current timestamp as value for the form element */ const CURRENTTIMESTAMP = '__CURRENT__TIMESTAMP__'; public function build_editform($item, $feedback, $cm) { global $DB, $CFG; require_once('info_form.php'); //get the lastposition number of the feedback_items $position = $item->position; $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); if ($position == -1) { $i_formselect_last = $lastposition + 1; $i_formselect_value = $lastposition + 1; $item->position = $lastposition + 1; } else { $i_formselect_last = $lastposition; $i_formselect_value = $item->position; } //the elements for position dropdownlist $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true); $item->presentation = empty($item->presentation) ? self::MODE_COURSE : $item->presentation; $item->required = 0; //all items for dependitem $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $commonparams = array('cmid'=>$cm->id, 'id'=>isset($item->id) ? $item->id : null, 'typ'=>$item->typ, 'items'=>$feedbackitems, 'feedback'=>$feedback->id); // Options for the 'presentation' select element. $presentationoptions = array(); if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO || $item->presentation == self::MODE_RESPONSETIME) { // "Response time" is hidden anyway in case of anonymous feedback, no reason to offer this option. // However if it was already selected leave it in the dropdown. $presentationoptions[self::MODE_RESPONSETIME] = get_string('responsetime', 'feedback'); } $presentationoptions[self::MODE_COURSE] = get_string('course'); $presentationoptions[self::MODE_CATEGORY] = get_string('coursecategory'); //build the form $this->item_form = new feedback_info_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position' => $position, 'presentationoptions' => $presentationoptions)); } public function save_item() { global $DB; if (!$this->get_data()) { return false; } $item = $this->item; if (isset($item->clone_item) AND $item->clone_item) { $item->id = ''; //to clone this item $item->position++; } $item->hasvalue = $this->get_hasvalue(); if (!$item->id) { $item->id = $DB->insert_record('feedback_item', $item); } else { $DB->update_record('feedback_item', $item); } return $DB->get_record('feedback_item', array('id'=>$item->id)); } /** * Helper function for collected data, both for analysis page and export to excel * * @param stdClass $item the db-object from feedback_item * @param int|false $groupid * @param int $courseid * @return stdClass */ protected function get_analysed($item, $groupid = false, $courseid = false) { $presentation = $item->presentation; $analysed_val = new stdClass(); $analysed_val->data = null; $analysed_val->name = $item->name; $values = feedback_get_group_values($item, $groupid, $courseid); if ($values) { $data = array(); foreach ($values as $value) { $datavalue = new stdClass(); switch($presentation) { case self::MODE_RESPONSETIME: $datavalue->value = $value->value; $datavalue->show = $value->value ? userdate($datavalue->value) : ''; break; case self::MODE_COURSE: $datavalue->value = $value->value; $datavalue->show = $datavalue->value; break; case self::MODE_CATEGORY: $datavalue->value = $value->value; $datavalue->show = $datavalue->value; break; } $data[] = $datavalue; } $analysed_val->data = $data; } return $analysed_val; } public function get_printval($item, $value) { if (strval($value->value) === '') { return ''; } return $item->presentation == self::MODE_RESPONSETIME ? userdate($value->value) : $value->value; } public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { echo "
'; echo $itemnr . ' '; if (strval($item->label) !== '') { echo '('. format_string($item->label).') '; } echo format_text($item->name, FORMAT_HTML, array('noclean' => true, 'para' => false)); echo ' | |
---|---|
';
echo str_replace("\n", ' ', $data[$i]->show); echo ' |