2009-11-01 14:55:15 +00:00
|
|
|
<?php
|
2011-10-28 00:30:42 +02:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2010-03-28 10:00:24 +00:00
|
|
|
defined('MOODLE_INTERNAL') OR die('not allowed');
|
2008-04-23 09:33:54 +00:00
|
|
|
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
|
|
|
|
|
|
|
|
class feedback_item_textarea extends feedback_item_base {
|
2011-10-28 00:30:42 +02:00
|
|
|
protected $type = "textarea";
|
|
|
|
private $commonparams;
|
|
|
|
private $item_form;
|
|
|
|
private $item;
|
2010-04-23 22:58:44 +00:00
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function init() {
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function build_editform($item, $feedback, $cm) {
|
2010-04-23 22:58:44 +00:00
|
|
|
global $DB, $CFG;
|
2008-04-28 09:58:09 +00:00
|
|
|
require_once('textarea_form.php');
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2010-04-23 22:58:44 +00:00
|
|
|
//get the lastposition number of the feedback_items
|
|
|
|
$position = $item->position;
|
|
|
|
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
|
2011-10-28 00:30:42 +02:00
|
|
|
if ($position == -1) {
|
2010-04-23 22:58:44 +00:00
|
|
|
$i_formselect_last = $lastposition + 1;
|
|
|
|
$i_formselect_value = $lastposition + 1;
|
|
|
|
$item->position = $lastposition + 1;
|
2011-10-28 00:30:42 +02:00
|
|
|
} else {
|
2010-04-23 22:58:44 +00:00
|
|
|
$i_formselect_last = $lastposition;
|
|
|
|
$i_formselect_value = $item->position;
|
2008-04-28 09:58:09 +00:00
|
|
|
}
|
2010-04-23 22:58:44 +00:00
|
|
|
//the elements for position dropdownlist
|
2011-10-28 00:30:42 +02:00
|
|
|
$positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
|
|
|
|
|
2010-04-23 22:58:44 +00:00
|
|
|
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
|
2011-10-28 00:30:42 +02:00
|
|
|
|
|
|
|
$width_and_height = explode('|', $item->presentation);
|
|
|
|
|
|
|
|
if (isset($width_and_height[0]) AND $width_and_height[0] >= 5) {
|
|
|
|
$itemwidth = $width_and_height[0];
|
|
|
|
} else {
|
|
|
|
$itemwidth = 30;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($width_and_height[1])) {
|
|
|
|
$itemheight = $width_and_height[1];
|
|
|
|
} else {
|
|
|
|
$itemheight = 5;
|
|
|
|
}
|
2010-04-23 22:58:44 +00:00
|
|
|
$item->itemwidth = $itemwidth;
|
|
|
|
$item->itemheight = $itemheight;
|
|
|
|
|
2010-05-16 20:05:51 +00:00
|
|
|
//all items for dependitem
|
|
|
|
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
|
2010-04-23 22:58:44 +00:00
|
|
|
$commonparams = array('cmid'=>$cm->id,
|
2011-10-28 00:30:42 +02:00
|
|
|
'id'=>isset($item->id) ? $item->id : null,
|
2010-04-23 22:58:44 +00:00
|
|
|
'typ'=>$item->typ,
|
2010-05-16 20:05:51 +00:00
|
|
|
'items'=>$feedbackitems,
|
2010-04-23 22:58:44 +00:00
|
|
|
'feedback'=>$feedback->id);
|
|
|
|
|
|
|
|
//build the form
|
2011-10-28 00:30:42 +02:00
|
|
|
$customdata = array('item' => $item,
|
|
|
|
'common' => $commonparams,
|
|
|
|
'positionlist' => $positionlist,
|
|
|
|
'position' => $position);
|
|
|
|
|
|
|
|
$this->item_form = new feedback_textarea_form('edit_item.php', $customdata);
|
2010-04-23 22:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//this function only can used after the call of build_editform()
|
2011-10-28 00:30:42 +02:00
|
|
|
public function show_editform() {
|
2010-04-23 22:58:44 +00:00
|
|
|
$this->item_form->display();
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
|
|
|
|
public function is_cancelled() {
|
2010-04-23 22:58:44 +00:00
|
|
|
return $this->item_form->is_cancelled();
|
|
|
|
}
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function get_data() {
|
|
|
|
if ($this->item = $this->item_form->get_data()) {
|
2010-04-23 22:58:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function save_item() {
|
2010-04-23 22:58:44 +00:00
|
|
|
global $DB;
|
2011-10-28 00:30:42 +02:00
|
|
|
|
|
|
|
if (!$item = $this->item_form->get_data()) {
|
2010-04-23 22:58:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
|
|
|
|
if (isset($item->clone_item) AND $item->clone_item) {
|
2010-06-04 21:12:27 +00:00
|
|
|
$item->id = ''; //to clone this item
|
|
|
|
$item->position++;
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
|
2010-04-23 23:18:56 +00:00
|
|
|
$item->hasvalue = $this->get_hasvalue();
|
2011-10-28 00:30:42 +02:00
|
|
|
if (!$item->id) {
|
2010-04-23 22:58:44 +00:00
|
|
|
$item->id = $DB->insert_record('feedback_item', $item);
|
2011-10-28 00:30:42 +02:00
|
|
|
} else {
|
2010-04-23 22:58:44 +00:00
|
|
|
$DB->update_record('feedback_item', $item);
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
|
2010-04-23 22:58:44 +00:00
|
|
|
return $DB->get_record('feedback_item', array('id'=>$item->id));
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
|
|
|
|
2010-04-23 22:58:44 +00:00
|
|
|
|
2008-04-23 09:33:54 +00:00
|
|
|
//liefert eine Struktur ->name, ->data = array(mit Antworten)
|
2011-10-28 00:30:42 +02:00
|
|
|
public function get_analysed($item, $groupid = false, $courseid = false) {
|
2008-06-07 22:22:06 +00:00
|
|
|
global $DB;
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
$analysed_val = null;
|
|
|
|
$analysed_val->data = array();
|
|
|
|
$analysed_val->name = $item->name;
|
|
|
|
|
2008-04-23 09:33:54 +00:00
|
|
|
$values = feedback_get_group_values($item, $groupid, $courseid);
|
2011-10-28 00:30:42 +02:00
|
|
|
if ($values) {
|
2008-04-23 09:33:54 +00:00
|
|
|
$data = array();
|
2011-10-28 00:30:42 +02:00
|
|
|
foreach ($values as $value) {
|
2008-04-23 09:33:54 +00:00
|
|
|
$data[] = str_replace("\n", '<br />', $value->value);
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
$analysed_val->data = $data;
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
return $analysed_val;
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function get_printval($item, $value) {
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
if (!isset($value->value)) {
|
|
|
|
return '';
|
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
|
|
|
|
return $value->value;
|
|
|
|
}
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
|
2008-04-23 09:33:54 +00:00
|
|
|
$values = feedback_get_group_values($item, $groupid, $courseid);
|
2011-10-28 00:30:42 +02:00
|
|
|
if ($values) {
|
|
|
|
echo '<tr><th colspan="2" align="left">';
|
|
|
|
echo $itemnr.' ('.$item->label.') '.$item->name;
|
|
|
|
echo '</th></tr>';
|
|
|
|
foreach ($values as $value) {
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<td valign="top" align="left">';
|
|
|
|
echo '- ';
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td align="left" valign="top">';
|
|
|
|
echo str_replace("\n", '<br />', $value->value);
|
|
|
|
echo '</td>';
|
|
|
|
echo '</tr>';
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function excelprint_item(&$worksheet, $row_offset,
|
|
|
|
$xls_formats, $item,
|
|
|
|
$groupid, $courseid = false) {
|
|
|
|
|
2008-04-23 09:33:54 +00:00
|
|
|
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
$worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2);
|
|
|
|
$worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2);
|
2008-04-23 09:33:54 +00:00
|
|
|
$data = $analysed_item->data;
|
2011-10-28 00:30:42 +02:00
|
|
|
if (is_array($data)) {
|
|
|
|
if (isset($data[0])) {
|
|
|
|
$worksheet->write_string($row_offset, 2, $data[0], $xls_formats->value_bold);
|
2008-06-10 13:04:34 +00:00
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
$row_offset++;
|
|
|
|
$sizeofdata = count($data);
|
|
|
|
for ($i = 1; $i < $sizeofdata; $i++) {
|
|
|
|
$worksheet->write_string($row_offset, 2, $data[$i], $xls_formats->default);
|
|
|
|
$row_offset++;
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
$row_offset++;
|
|
|
|
return $row_offset;
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
|
2010-04-21 11:48:49 +00:00
|
|
|
/**
|
|
|
|
* print the item at the edit-page of feedback
|
|
|
|
*
|
|
|
|
* @global object
|
|
|
|
* @param object $item
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-10-28 00:30:42 +02:00
|
|
|
public function print_item_preview($item) {
|
2010-05-16 20:05:51 +00:00
|
|
|
global $OUTPUT, $DB;
|
2011-10-28 00:30:42 +02:00
|
|
|
|
2010-04-21 11:48:49 +00:00
|
|
|
$align = right_to_left() ? 'right' : 'left';
|
2011-10-28 00:30:42 +02:00
|
|
|
$str_required_mark = '<span class="feedback_required_mark">*</span>';
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2010-04-21 11:48:49 +00:00
|
|
|
$presentation = explode ("|", $item->presentation);
|
2011-10-28 00:30:42 +02:00
|
|
|
$requiredmark = ($item->required == 1) ? $str_required_mark : '';
|
2010-04-30 23:02:30 +00:00
|
|
|
//print the question and label
|
|
|
|
echo '<div class="feedback_item_label_'.$align.'">';
|
|
|
|
echo '('.$item->label.') ';
|
|
|
|
echo format_text($item->name.$requiredmark, true, false, false);
|
2011-10-28 00:30:42 +02:00
|
|
|
if ($item->dependitem) {
|
|
|
|
if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
|
|
|
|
echo ' <span class="feedback_depend">';
|
|
|
|
echo '('.$dependitem->label.'->'.$item->dependvalue.')';
|
|
|
|
echo '</span>';
|
2010-05-16 20:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-30 23:02:30 +00:00
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
//print the presentation
|
|
|
|
echo '<div class="feedback_item_presentation_'.$align.'">';
|
|
|
|
echo '<span class="feedback_item_textarea">';
|
2011-10-28 00:30:42 +02:00
|
|
|
echo '<textarea name="'.$item->typ.'_'.$item->id.'" '.
|
|
|
|
'cols="'.$presentation[0].'" '.
|
|
|
|
'rows="'.$presentation[1].'">';
|
|
|
|
echo '</textarea>';
|
2010-04-30 23:02:30 +00:00
|
|
|
echo '</span>';
|
|
|
|
echo '</div>';
|
2010-04-21 11:48:49 +00:00
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
|
2010-04-21 11:48:49 +00:00
|
|
|
/**
|
|
|
|
* print the item at the complete-page of feedback
|
|
|
|
*
|
|
|
|
* @global object
|
|
|
|
* @param object $item
|
|
|
|
* @param string $value
|
|
|
|
* @param bool $highlightrequire
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-10-28 00:30:42 +02:00
|
|
|
public function print_item_complete($item, $value = '', $highlightrequire = false) {
|
2009-08-10 04:59:26 +00:00
|
|
|
global $OUTPUT;
|
2010-04-10 18:26:20 +00:00
|
|
|
$align = right_to_left() ? 'right' : 'left';
|
2011-10-28 00:30:42 +02:00
|
|
|
$str_required_mark = '<span class="feedback_required_mark">*</span>';
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2008-04-23 09:33:54 +00:00
|
|
|
$presentation = explode ("|", $item->presentation);
|
2011-10-28 00:30:42 +02:00
|
|
|
if ($highlightrequire AND $item->required AND strval($value) == '') {
|
2010-04-30 23:02:30 +00:00
|
|
|
$highlight = ' missingrequire';
|
2011-10-28 00:30:42 +02:00
|
|
|
} else {
|
2008-04-23 09:33:54 +00:00
|
|
|
$highlight = '';
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
$requiredmark = ($item->required == 1) ? $str_required_mark :'';
|
2010-04-30 23:02:30 +00:00
|
|
|
|
|
|
|
//print the question and label
|
|
|
|
echo '<div class="feedback_item_label_'.$align.$highlight.'">';
|
2009-03-13 14:35:25 +00:00
|
|
|
echo format_text($item->name . $requiredmark, true, false, false);
|
2010-04-30 23:02:30 +00:00
|
|
|
echo '</div>';
|
2011-10-28 00:30:42 +02:00
|
|
|
|
2010-04-30 23:02:30 +00:00
|
|
|
//print the presentation
|
|
|
|
echo '<div class="feedback_item_presentation_'.$align.$highlight.'">';
|
|
|
|
echo '<span class="feedback_item_textarea">';
|
2011-10-28 00:30:42 +02:00
|
|
|
echo '<textarea name="'.$item->typ.'_'.$item->id.'" '.
|
|
|
|
'cols="'.$presentation[0].'" '.
|
|
|
|
'rows="'.$presentation[1].'">';
|
|
|
|
echo ($value ? htmlspecialchars($value) : '');
|
|
|
|
echo '</textarea>';
|
2010-04-30 23:02:30 +00:00
|
|
|
echo '</span>';
|
|
|
|
echo '</div>';
|
2010-04-21 11:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* print the item at the complete-page of feedback
|
|
|
|
*
|
|
|
|
* @global object
|
|
|
|
* @param object $item
|
|
|
|
* @param string $value
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-10-28 00:30:42 +02:00
|
|
|
public function print_item_show_value($item, $value = '') {
|
2010-04-21 11:48:49 +00:00
|
|
|
global $OUTPUT;
|
|
|
|
$align = right_to_left() ? 'right' : 'left';
|
2011-10-28 00:30:42 +02:00
|
|
|
$str_required_mark = '<span class="feedback_required_mark">*</span>';
|
2010-04-21 11:48:49 +00:00
|
|
|
|
|
|
|
$presentation = explode ("|", $item->presentation);
|
2011-10-28 00:30:42 +02:00
|
|
|
$requiredmark = ($item->required == 1) ? $str_required_mark : '';
|
2010-04-30 23:02:30 +00:00
|
|
|
|
|
|
|
//print the question and label
|
|
|
|
echo '<div class="feedback_item_label_'.$align.'">';
|
2010-04-21 11:48:49 +00:00
|
|
|
echo '('.$item->label.') ';
|
|
|
|
echo format_text($item->name . $requiredmark, true, false, false);
|
2010-04-30 23:02:30 +00:00
|
|
|
echo '</div>';
|
2011-10-28 00:30:42 +02:00
|
|
|
|
2010-04-30 23:02:30 +00:00
|
|
|
//print the presentation
|
2010-04-21 11:48:49 +00:00
|
|
|
echo $OUTPUT->box_start('generalbox boxalign'.$align);
|
2011-10-28 00:30:42 +02:00
|
|
|
echo $value ? str_replace("\n", '<br />', $value) : ' ';
|
2010-04-21 11:48:49 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function check_value($value, $item) {
|
2008-04-23 09:33:54 +00:00
|
|
|
//if the item is not required, so the check is true if no value is given
|
2011-10-28 00:30:42 +02:00
|
|
|
if ((!isset($value) OR $value == '') AND $item->required != 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ($value == "") {
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function create_value($data) {
|
2008-06-09 16:53:30 +00:00
|
|
|
$data = clean_text($data);
|
2008-04-23 09:33:54 +00:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2010-05-16 20:05:51 +00:00
|
|
|
//compares the dbvalue with the dependvalue
|
|
|
|
//dbvalue is the value put in by the user
|
|
|
|
//dependvalue is the value that is compared
|
2011-10-28 00:30:42 +02:00
|
|
|
public function compare_value($item, $dbvalue, $dependvalue) {
|
|
|
|
if ($dbvalue == $dependvalue) {
|
2010-05-16 20:05:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
|
|
|
|
public function get_presentation($data) {
|
|
|
|
return $data->itemwidth.'|'.$data->itemheight;
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
public function get_hasvalue() {
|
2008-04-23 09:33:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
|
|
|
|
public function can_switch_require() {
|
2010-06-04 20:21:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
}
|