mirror of
https://github.com/moodle/moodle.git
synced 2025-03-07 01:10:02 +01:00
261 lines
8.7 KiB
PHP
261 lines
8.7 KiB
PHP
<?php
|
|
defined('MOODLE_INTERNAL') OR die('not allowed');
|
|
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
|
|
|
|
class feedback_item_textarea extends feedback_item_base {
|
|
var $type = "textarea";
|
|
var $commonparams;
|
|
var $item_form;
|
|
var $item;
|
|
|
|
function init() {
|
|
|
|
}
|
|
|
|
function build_editform($item, $feedback, $cm) {
|
|
global $DB, $CFG;
|
|
require_once('textarea_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;
|
|
|
|
$widthAndHeight = explode('|',$item->presentation);
|
|
$itemwidth = isset($widthAndHeight[0]) ? $widthAndHeight[0] : 30;
|
|
$itemheight = isset($widthAndHeight[1]) ? $widthAndHeight[1] : 5;
|
|
$item->itemwidth = $itemwidth;
|
|
$item->itemheight = $itemheight;
|
|
|
|
$commonparams = array('cmid'=>$cm->id,
|
|
'id'=>isset($item->id) ? $item->id : NULL,
|
|
'typ'=>$item->typ,
|
|
'feedback'=>$feedback->id);
|
|
|
|
//build the form
|
|
$this->item_form = new feedback_textarea_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position));
|
|
}
|
|
|
|
//this function only can used after the call of build_editform()
|
|
function show_editform() {
|
|
$this->item_form->display();
|
|
}
|
|
|
|
function is_cancelled() {
|
|
return $this->item_form->is_cancelled();
|
|
}
|
|
|
|
function get_data() {
|
|
if($this->item = $this->item_form->get_data()) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function save_item() {
|
|
global $DB;
|
|
|
|
if(!$item = $this->item_form->get_data()) {
|
|
return false;
|
|
}
|
|
|
|
$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)
|
|
function get_analysed($item, $groupid, $courseid = false) {
|
|
global $DB;
|
|
|
|
$aVal = null;
|
|
$aVal->data = array();
|
|
$aVal->name = $item->name;
|
|
//$values = $DB->get_records('feedback_value', array('item'=>$item->id));
|
|
$values = feedback_get_group_values($item, $groupid, $courseid);
|
|
if($values) {
|
|
$data = array();
|
|
foreach($values as $value) {
|
|
$data[] = str_replace("\n", '<br />', $value->value);
|
|
}
|
|
$aVal->data = $data;
|
|
}
|
|
return $aVal;
|
|
}
|
|
|
|
function get_printval($item, $value) {
|
|
|
|
if(!isset($value->value)) return '';
|
|
|
|
return $value->value;
|
|
}
|
|
|
|
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
|
|
$values = feedback_get_group_values($item, $groupid, $courseid);
|
|
if($values) {
|
|
//echo '<table>';2
|
|
// $itemnr++;
|
|
echo '<tr><th colspan="2" align="left">'. $itemnr . ' ('. $item->label .') ' . $item->name .'</th></tr>';
|
|
foreach($values as $value) {
|
|
echo '<tr><td valign="top" align="left">- </td><td align="left" valign="top">' . str_replace("\n", '<br />', $value->value) . '</td></tr>';
|
|
}
|
|
//echo '</table>';
|
|
}
|
|
// return $itemnr;
|
|
}
|
|
|
|
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {
|
|
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
|
|
|
|
// $worksheet->setFormat("<l><f><ro2><vo><c:green>");
|
|
$worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2);
|
|
$worksheet->write_string($rowOffset, 1, $item->name, $xlsFormats->head2);
|
|
$data = $analysed_item->data;
|
|
if(is_array($data)) {
|
|
// $worksheet->setFormat("<l><ro2><vo>");
|
|
if(isset($data[0])) {
|
|
$worksheet->write_string($rowOffset, 2, $data[0], $xlsFormats->value_bold);
|
|
}
|
|
$rowOffset++;
|
|
for($i = 1; $i < sizeof($data); $i++) {
|
|
// $worksheet->setFormat("<l><vo>");
|
|
$worksheet->write_string($rowOffset, 2, $data[$i], $xlsFormats->default);
|
|
$rowOffset++;
|
|
}
|
|
}
|
|
$rowOffset++;
|
|
return $rowOffset;
|
|
}
|
|
|
|
/**
|
|
* print the item at the edit-page of feedback
|
|
*
|
|
* @global object
|
|
* @param object $item
|
|
* @return void
|
|
*/
|
|
function print_item_preview($item) {
|
|
global $OUTPUT;
|
|
$align = right_to_left() ? 'right' : 'left';
|
|
|
|
$presentation = explode ("|", $item->presentation);
|
|
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
|
|
?>
|
|
<td valign="top" align="<?php echo $align;?>">
|
|
<?php
|
|
echo '('.$item->label.') ';
|
|
echo format_text($item->name . $requiredmark, true, false, false);
|
|
?>
|
|
</td>
|
|
<td valign="top" align="<?php echo $align;?>">
|
|
<textarea name="<?php echo $item->typ . '_' . $item->id;?>"
|
|
cols="<?php echo $presentation[0];?>"
|
|
rows="<?php echo $presentation[1];?>"></textarea>
|
|
</td>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* print the item at the complete-page of feedback
|
|
*
|
|
* @global object
|
|
* @param object $item
|
|
* @param string $value
|
|
* @param bool $highlightrequire
|
|
* @return void
|
|
*/
|
|
function print_item_complete($item, $value = '', $highlightrequire = false) {
|
|
global $OUTPUT;
|
|
$align = right_to_left() ? 'right' : 'left';
|
|
|
|
$presentation = explode ("|", $item->presentation);
|
|
if($highlightrequire AND $item->required AND strval($value) == '') {
|
|
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
|
|
}else {
|
|
$highlight = '';
|
|
}
|
|
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
|
|
?>
|
|
<td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>">
|
|
<?php
|
|
echo format_text($item->name . $requiredmark, true, false, false);
|
|
?>
|
|
</td>
|
|
<td valign="top" align="<?php echo $align;?>">
|
|
<textarea name="<?php echo $item->typ . '_' . $item->id;?>"
|
|
cols="<?php echo $presentation[0];?>"
|
|
rows="<?php echo $presentation[1];?>"><?php echo $value?htmlspecialchars($value):'';?></textarea>
|
|
</td>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* print the item at the complete-page of feedback
|
|
*
|
|
* @global object
|
|
* @param object $item
|
|
* @param string $value
|
|
* @return void
|
|
*/
|
|
function print_item_show_value($item, $value = '') {
|
|
global $OUTPUT;
|
|
$align = right_to_left() ? 'right' : 'left';
|
|
|
|
$presentation = explode ("|", $item->presentation);
|
|
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
|
|
?>
|
|
<td valign="top" align="<?php echo $align;?>">
|
|
<?php
|
|
echo '('.$item->label.') ';
|
|
echo format_text($item->name . $requiredmark, true, false, false);
|
|
?>
|
|
</td>
|
|
<td valign="top" align="<?php echo $align;?>">
|
|
<?php
|
|
echo $OUTPUT->box_start('generalbox boxalign'.$align);
|
|
echo $value?str_replace("\n",'<br />',$value):' ';
|
|
echo $OUTPUT->box_end();
|
|
?>
|
|
</td>
|
|
<?php
|
|
}
|
|
|
|
function check_value($value, $item) {
|
|
//if the item is not required, so the check is true if no value is given
|
|
if((!isset($value) OR $value == '') AND $item->required != 1) return true;
|
|
if($value == "")return false;
|
|
return true;
|
|
}
|
|
|
|
function create_value($data) {
|
|
$data = clean_text($data);
|
|
return $data;
|
|
}
|
|
|
|
function get_presentation($data) {
|
|
return $data->itemwidth . '|'. $data->itemheight;
|
|
}
|
|
|
|
function get_hasvalue() {
|
|
return 1;
|
|
}
|
|
}
|
|
?>
|