.
defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_textfield extends feedback_item_base {
protected $type = "textfield";
private $commonparams;
private $item_form;
private $item;
public function init() {
}
public function build_editform($item, $feedback, $cm) {
global $DB, $CFG;
require_once('textfield_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) ? '' : $item->presentation;
$size_and_length = explode('|', $item->presentation);
if (isset($size_and_length[0]) AND $size_and_length[0] >= 5) {
$itemsize = $size_and_length[0];
} else {
$itemsize = 30;
}
$itemlength = isset($size_and_length[1]) ? $size_and_length[1] : 5;
$item->itemsize = $itemsize;
$item->itemmaxlength = $itemlength;
//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);
//build the form
$customdata = array('item' => $item,
'common' => $commonparams,
'positionlist' => $positionlist,
'position' => $position);
$this->item_form = new feedback_textfield_form('edit_item.php', $customdata);
}
//this function only can used after the call of build_editform()
public function show_editform() {
$this->item_form->display();
}
public function is_cancelled() {
return $this->item_form->is_cancelled();
}
public function get_data() {
if ($this->item = $this->item_form->get_data()) {
return true;
}
return false;
}
public function save_item() {
global $DB;
if (!$item = $this->item_form->get_data()) {
return false;
}
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));
}
//liefert eine Struktur ->name, ->data = array(mit Antworten)
public function get_analysed($item, $groupid = false, $courseid = false) {
global $DB;
$analysed_val = null;
$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) {
$data[] = str_replace("\n", '
', $value->value);
}
$analysed_val->data = $data;
}
return $analysed_val;
}
public function get_printval($item, $value) {
if (!isset($value->value)) {
return '';
}
return $value->value;
}
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
$values = feedback_get_group_values($item, $groupid, $courseid);
if ($values) {
echo '