From: agrabs Date: Mon, 28 Apr 2008 09:58:09 +0000 (+0000) Subject: merge the items dropdown, radio and check to multiplechoice item X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6ee09cfe8b99f16b1baae13370c3ad4becdb0766;p=moodle.git merge the items dropdown, radio and check to multiplechoice item merge the items dropdownrated, radiorated to multiplechoicerated item the creating or editing of an item now use the formslib --- diff --git a/mod/feedback/db/upgrade.php b/mod/feedback/db/upgrade.php index e8c2c8b0d5..83a12af9de 100644 --- a/mod/feedback/db/upgrade.php +++ b/mod/feedback/db/upgrade.php @@ -141,6 +141,32 @@ function xmldb_feedback_upgrade($oldversion=0) { } } + if ($result && $oldversion < 2008042400) { //New version in version.php + if($all_nonanonymous_feedbacks = get_records('feedback', 'anonymous', 2)) { + $update_sql = 'UPDATE '.$CFG->prefix.'feedback_completed SET anonymous_response = 2 WHERE feedback = '; + foreach ($all_nonanonymous_feedbacks as $fb) { + $result = $result && execute_sql($update_sql.$fb->id); + } + } + } + + if ($result && $oldversion < 2008042401) { //New version in version.php + if($result) { + $update_sql1 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = CONCAT('r>>>>>',presentation) WHERE typ IN('radio','radiorated')"; + $update_sql2 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = CONCAT('d>>>>>',presentation) WHERE typ IN('dropdown','dropdownrated')"; + $update_sql3 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = CONCAT('c>>>>>',presentation) WHERE typ = 'check'"; + $result = $result && execute_sql($update_sql1); + $result = $result && execute_sql($update_sql2); + $result = $result && execute_sql($update_sql3); + } + if($result) { + $update_sql1 = "UPDATE ".$CFG->prefix."feedback_item SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')"; + $update_sql2 = "UPDATE ".$CFG->prefix."feedback_item SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')"; + $result = $result && execute_sql($update_sql1); + $result = $result && execute_sql($update_sql2); + } + } + /// And upgrade begins here. For each one, you'll need one /// block of code similar to the next one. Please, delete diff --git a/mod/feedback/edit_item.php b/mod/feedback/edit_item.php index 70f3c4780a..2f584bd67f 100644 --- a/mod/feedback/edit_item.php +++ b/mod/feedback/edit_item.php @@ -20,10 +20,11 @@ // set up some general variables $usehtmleditor = can_use_html_editor(); + if(($formdata = data_submitted('nomatch')) AND !confirm_sesskey()) { error('no sesskey defined'); } - + if ($id) { if (! $cm = get_coursemodule_from_id('feedback', $id)) { error("Course Module ID was incorrect"); @@ -69,7 +70,7 @@ if(isset($formdata->cancel)){ redirect(htmlspecialchars('edit.php?id=' . $id)); } - + // if(isset($formdata->editcancel) AND $formdata->editcancel == 1){ // redirect(htmlspecialchars('edit.php?id=' . $id)); // } @@ -130,11 +131,55 @@ if(isset($error)){echo $error;} feedback_print_errors(); - + + //new formdefinition + require_once('blank_form.php'); + $itemclass = 'feedback_item_'.$typ; + $itemobj = new $itemclass(); + $item_form = &$itemobj->show_edit($item); + + // $item_form = new feedback_blank_form(); + + $i_form = &$item_form->_form; + // $i_form->addElement('header', 'general', 'Titel'); + $i_form->addElement('hidden', 'id', $id); + $i_form->addElement('hidden', 'itemid', isset($item->id)?$item->id:''); + $i_form->addElement('hidden', 'typ', $typ); + $i_form->addElement('hidden', 'feedbackid', $feedback->id); + + + $lastposition = count_records('feedback_item', 'feedback', $feedback->id); + if($position == -1){ + $i_formselect_last = $lastposition + 1; + $i_formselect_value = $lastposition + 1; + }else { + $i_formselect_last = $lastposition; + $i_formselect_value = $item->position; + } + $i_formselect = $i_form->addElement('select', + 'position', + get_string('position', 'feedback').' ', + array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true)); + $i_formselect->setValue($i_formselect_value); + if(!empty($item->id)){ + $i_form->addElement('hidden', 'updateitem', '1'); + $i_form->addElement('submit', 'update_item', get_string('update_item', 'feedback')); + // echo ''; + // echo ''; + }else{ + $i_form->addElement('hidden', 'saveitem', '1'); + $i_form->addElement('submit', 'save_item', get_string('save_item', 'feedback')); + // echo ''; + // echo ''; + } + $i_form->addElement('cancel'); + $item_form->display(); + +/* // print_simple_box_start('center'); print_box_start('generalbox boxwidthwide boxaligncenter'); - echo '
'; - echo ''; + echo ''; + echo ''; //this div makes the buttons stand side by side echo '
'; @@ -142,10 +187,10 @@ $itemobj = new $itemclass(); $itemobj->show_edit($item, $usehtmleditor); echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; //choose the position $lastposition = count_records('feedback_item', 'feedback', $feedback->id); @@ -172,7 +217,7 @@ echo '
'; ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// - +*/ // print_simple_box_end(); print_box_end(); diff --git a/mod/feedback/item/captcha/captcha_form.php b/mod/feedback/item/captcha/captcha_form.php new file mode 100644 index 0000000000..d212342913 --- /dev/null +++ b/mod/feedback/item/captcha/captcha_form.php @@ -0,0 +1,26 @@ +libdir.'/formslib.php'; + +class feedback_captcha_form extends moodleform { + var $type = "captcha"; + var $requiredcheck; + var $itemname; + var $select; + + function definition() { + $mform =& $this->_form; + + $mform->addElement('header', 'general', get_string($this->type, 'feedback')); + $this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback')); + + $this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"')); + + $this->select = $mform->addElement('select', + 'count_of_nums', + get_string('count_of_nums', 'feedback').' ', + array_slice(range(0,10),3,10,true)); + + } +} +?> diff --git a/mod/feedback/item/captcha/default.ttf b/mod/feedback/item/captcha/default.ttf deleted file mode 100644 index 754a9b7b39..0000000000 Binary files a/mod/feedback/item/captcha/default.ttf and /dev/null differ diff --git a/mod/feedback/item/captcha/lib.php b/mod/feedback/item/captcha/lib.php index 0aec717184..ab1ff6718d 100644 --- a/mod/feedback/item/captcha/lib.php +++ b/mod/feedback/item/captcha/lib.php @@ -8,36 +8,25 @@ class feedback_item_captcha extends feedback_item_base { } - function show_edit($item, $usehtmleditor = false) { + function show_edit($item) { + global $CFG; + + require_once('captcha_form.php'); + + $item_form = new feedback_captcha_form(); - $item->presentation=empty($item->presentation)? 3 : $item->presentation; + $item->presentation = empty($item->presentation) ? 3 : $item->presentation; + $item->name = empty($item->name) ? '' : $item->name; + + $item->required = isset($item->required) ? $item->required : 1; + if($item->required) { + $item_form->requiredcheck->setValue(true); + } - ?> - - - - - - - - - - - - -
-  (required = isset($item->required) ? $item->required : 1; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- -
- itemname->setValue($item->name); + + $item_form->select->setValue($item->presentation); + return $item_form; } //liefert eine Struktur ->name, ->data = array(mit Antworten) diff --git a/mod/feedback/item/captcha/print_captcha.php b/mod/feedback/item/captcha/print_captcha.php index 2723286b88..8a3111a528 100644 --- a/mod/feedback/item/captcha/print_captcha.php +++ b/mod/feedback/item/captcha/print_captcha.php @@ -23,7 +23,8 @@ $height = 40; $charcount = $SESSION->feedback->item->captcha->charcount; - $fontfile = $CFG->dirroot.'/mod/feedback/item/captcha/default.ttf'; + // $fontfile = $CFG->dirroot.'/mod/feedback/item/captcha/default.ttf'; + $fontfile = $CFG->libdir.'/default.ttf'; $ttfbox = imagettfbbox ( 30, 0, $fontfile, 'H' );//the text to measure $charwidth = $ttfbox[2]; diff --git a/mod/feedback/item/check/lib.php b/mod/feedback/item/check/lib.php deleted file mode 100644 index 65b7f789c3..0000000000 --- a/mod/feedback/item/check/lib.php +++ /dev/null @@ -1,314 +0,0 @@ -dirroot.'/mod/feedback/item/feedback_item_class.php'); - -define('FEEDBACK_CHECK_LINE_SEP', '|'); -define('FEEDBACK_CHECK_ADJUST_SEP', '<<<<<'); -class feedback_item_check extends feedback_item_base { - var $type = "check"; - function init() { - - } - - function show_edit($item, $usehtmleditor = false) { - - $item->presentation = empty($item->presentation) ? '' : $item->presentation; - - //check, whether the buttons are vertical or horizontal - $presentation = $horizontal = ''; - @list($presentation, $horizontal) = explode(FEEDBACK_CHECK_ADJUST_SEP, $item->presentation); - if(isset($horizontal) AND $horizontal == 1) { - $horizontal = true; - }else { - $horizontal = false; - } - - ?> - - - - - - - - - - - - - - -
- -  (required=isset($item->required) ? $item->required : 0; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- : -   /> -   /> -
- - - - - -
- typ; - $analysedItem[] = $item->name; - //die moeglichen Antworten extrahieren - $answers = null; - $presentation = ''; - @list($presentation) = explode(FEEDBACK_CHECK_ADJUST_SEP, $item->presentation); //remove the adjustment-info - - $answers = explode (FEEDBACK_CHECK_LINE_SEP, stripslashes_safe($presentation)); - if(!is_array($answers)) return null; - - //die Werte holen - $values = feedback_get_group_values($item, $groupid, $courseid); - if(!$values) return null; - //schleife ueber den Werten und ueber die Antwortmoeglichkeiten - - $analysedAnswer = array(); - - for($i = 1; $i <= sizeof($answers); $i++) { - $ans = null; - $ans->answertext = $answers[$i-1]; - $ans->answercount = 0; - foreach($values as $value) { - //ist die Antwort gleich dem index der Antworten + 1? - $vallist = explode(FEEDBACK_CHECK_LINE_SEP, $value->value); - foreach($vallist as $val) { - if ($val == $i) { - $ans->answercount++; - } - } - } - $ans->quotient = $ans->answercount / sizeof($values); - $analysedAnswer[] = $ans; - } - $analysedItem[] = $analysedAnswer; - return $analysedItem; - } - - function get_printval($item, $value) { - $printval = ''; - - if(!isset($value->value)) return $printval; - - @list($presentation) = explode(FEEDBACK_CHECK_ADJUST_SEP, $item->presentation); //remove the adjustment-info - - $presentation = array_values(explode (FEEDBACK_CHECK_LINE_SEP, stripslashes_safe($presentation))); - $vallist = array_values(explode (FEEDBACK_CHECK_LINE_SEP, $value->value)); - for($i = 0; $i < sizeof($vallist); $i++) { - for($k = 0; $k < sizeof($presentation); $k++) { - if($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0 - $printval .= trim($presentation[$k]) . chr(10); - break; - } - } - } - return $printval; - } - - function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) { - $sep_dec = get_string('separator_decimal', 'feedback'); - if(substr($sep_dec, 0, 2) == '[['){ - $sep_dec = FEEDBACK_DECIMAL; - } - - $sep_thous = get_string('separator_thousand', 'feedback'); - if(substr($sep_thous, 0, 2) == '[['){ - $sep_thous = FEEDBACK_THOUSAND; - } - - $analysedItem = $this->get_analysed($item, $groupid, $courseid); - if($analysedItem) { - $itemnr++; - $itemname = stripslashes($analysedItem[1]); - echo ''. $itemnr . '.) ' . $itemname .''; - $analysedVals = $analysedItem[2]; - $pixnr = 0; - foreach($analysedVals as $val) { - if( function_exists("bcmod")) { - $intvalue = bcmod($pixnr, 10); - }else { - $intvalue = 0; - } - $pix = "pics/$intvalue.gif"; - $pixnr++; - $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); - $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); - echo '-  ' . trim($val->answertext) . ':'.$intvalue.' ' . $val->answercount . (($val->quotient > 0)?' ('. $quotient . ' %)':'').''; - } - } - return $itemnr; - } - - function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { - $analysed_item = $this->get_analysed($item, $groupid, $courseid); - - - $data = $analysed_item[2]; - - $worksheet->setFormat(""); - //frage schreiben - $worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1])); - if(is_array($data)) { - for($i = 0; $i < sizeof($data); $i++) { - $aData = $data[$i]; - - $worksheet->setFormat(""); - $worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext)); - - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount); - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 2, $i + 1, $aData->quotient); - } - } - $rowOffset +=3 ; - return $rowOffset; - } - - function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ - - $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right'; - - //extract the adjustment-info - $presentation = $horizontal = ''; - @list($presentation, $horizontal) = explode(FEEDBACK_CHECK_ADJUST_SEP, $item->presentation); - if(isset($horizontal) AND $horizontal == 1) { - $horizontal = true; - }else { - $horizontal = false; - } - - $presentation = explode (FEEDBACK_CHECK_LINE_SEP, stripslashes_safe($presentation)); - if (is_array($value)) { - $values = $value; - }else { - $values = explode(FEEDBACK_CHECK_LINE_SEP, $value); - } - if($highlightrequire AND $item->required AND $values[0] == '') { - $highlight = 'bgcolor="#FFAAAA" class="missingrequire"'; - }else { - $highlight = ''; - } - $requiredmark = ($item->required == 1)?'':''; - - echo ''.format_text(stripslashes_safe($item->name).$requiredmark, true, false, false).''; - echo ''; - - $index = 1; - $checked = ''; - if($readonly){ - // print_simple_box_start($align); - print_box_start('generalbox boxalign'.$align); - foreach($presentation as $check){ - foreach($values as $val) { - if($val == $index){ - echo text_to_html($check . '
', true, false, false); - break; - } - } - $index++; - } - // print_simple_box_end(); - print_box_end(); - } else { - if($horizontal) { - echo ''; - } - foreach($presentation as $check){ - foreach($values as $val) { - if($val == $index){ - $checked = 'checked="checked"'; - break; - }else{ - $checked = ''; - } - } - $inputname = $item->typ. '_' . $item->id; - $inputid = $item->typ. '_' . $item->id.'_'.$index; - if($horizontal) { - ?> - - -
/> - -
-
/> - -
- '; - } - } - ?> - - - required != 1) return true; - if($value[0] == "")return false; - return true; - } - - function create_value($data) { - $vallist = $data; - return trim($this->item_arrayToString($vallist)); - } - - function get_presentation($data) { - $present = str_replace("\n", FEEDBACK_CHECK_LINE_SEP, trim($data->itemvalues)); - if($data->horizontal == 1) { - $present .= FEEDBACK_CHECK_ADJUST_SEP.'1'; - } - return $present; - } - - function get_hasvalue() { - return 1; - } - - function item_arrayToString($arr) { - if(!is_array($arr)) { - return ''; - } - $retval = ''; - $arrvals = array_values($arr); - $arrvals = clean_param($arrvals, PARAM_INT); //prevent sql-injection - $retval = $arrvals[0]; - for($i = 1; $i < sizeof($arrvals) - 1; $i++) { - $retval .= FEEDBACK_CHECK_LINE_SEP.$arrvals[$i]; - } - return $retval; - } -} -?> diff --git a/mod/feedback/item/dropdown/lib.php b/mod/feedback/item/dropdown/lib.php deleted file mode 100644 index c92b6ec849..0000000000 --- a/mod/feedback/item/dropdown/lib.php +++ /dev/null @@ -1,233 +0,0 @@ -dirroot.'/mod/feedback/item/feedback_item_class.php'); - -class feedback_item_dropdown extends feedback_item_base { - var $type = "dropdown"; - function init() { - - } - - function show_edit($item, $usehtmleditor = false) { - - $item->presentation=empty($item->presentation)?'':$item->presentation; - - ?> - - - - - - - - - - - - -
-  (required=isset($item->required)?$item->required:0; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- - - - presentation)); - ?> - -
- typ; - $analysedItem[] = $item->name; - //die moeglichen Antworten extrahieren - $answers = null; - $answers = explode ("|", stripslashes_safe($item->presentation)); - if(!is_array($answers)) return null; - - //die Werte holen - //$values = get_records('feedback_value', 'item', $item->id); - $values = feedback_get_group_values($item, $groupid, $courseid); - if(!$values) return null; - //schleife ueber den Werten und ueber die Antwortmoeglichkeiten - - $analysedAnswer = array(); - - for($i = 1; $i <= sizeof($answers); $i++) { - $ans = null; - $ans->answertext = $answers[$i-1]; - $ans->answercount = 0; - foreach($values as $value) { - //ist die Antwort gleich dem index der Antworten + 1? - if ($value->value == $i) { - $ans->answercount++; - } - } - $ans->quotient = $ans->answercount / sizeof($values); - $analysedAnswer[] = $ans; - } - $analysedItem[] = $analysedAnswer; - return $analysedItem; - } - - function get_printval($item, $value) { - $printval = ''; - - if(!isset($value->value)) return $printval; - - $presentation = explode ("|", stripslashes_safe($item->presentation)); - $index = 1; - foreach($presentation as $pres){ - if($value->value == $index){ - $printval = $pres; - break; - } - $index++; - } - return $printval; - } - - function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) { - $sep_dec = get_string('separator_decimal', 'feedback'); - if(substr($sep_dec, 0, 2) == '[['){ - $sep_dec = FEEDBACK_DECIMAL; - } - - $sep_thous = get_string('separator_thousand', 'feedback'); - if(substr($sep_thous, 0, 2) == '[['){ - $sep_thous = FEEDBACK_THOUSAND; - } - - $analysedItem = $this->get_analysed($item, $groupid, $courseid); - if($analysedItem) { - //echo ''; - $itemnr++; - echo ''; - $analysedVals = $analysedItem[2]; - $pixnr = 0; - foreach($analysedVals as $val) { - if( function_exists("bcmod")) { - $intvalue = bcmod($pixnr, 10); - }else { - $intvalue = 0; - } - $pix = "pics/$intvalue.gif"; - $pixnr++; - $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); - $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); - echo ''; - } - //echo '
'. $itemnr . '.) ' . stripslashes($analysedItem[1]) .'
-  ' . trim($val->answertext) . ':'.$intvalue.' ' . $val->answercount . (($val->quotient > 0)?' ('. $quotient . ' %)':'').'
'; - } - return $itemnr; - } - - function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { - $analysed_item = $this->get_analysed($item, $groupid, $courseid); - - - $data = $analysed_item[2]; - - $worksheet->setFormat(""); - //frage schreiben - $worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1])); - if(is_array($data)) { - for($i = 0; $i < sizeof($data); $i++) { - $aData = $data[$i]; - - $worksheet->setFormat(""); - $worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext)); - - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount); - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 2, $i + 1, $aData->quotient); - } - } - $rowOffset +=3 ; - return $rowOffset; - } - - function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ - $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right'; - - $presentation = explode ("|", stripslashes_safe($item->presentation)); - if($highlightrequire AND $item->required AND intval($value) <= 0) { - $highlight = 'bgcolor="#FFAAAA" class="missingrequire"'; - }else { - $highlight = ''; - } - $requiredmark = ($item->required == 1)?'':''; - ?> - valign="top" align="">name) . $requiredmark, true, false, false);?> - - - - - - required != 1) return true; - if($value == 0)return false; - return true; - } - - function create_value($data) { - $data = clean_param($data, PARAM_INT); - return $data; - } - - function get_presentation($data) { - $present = str_replace("\n", '|', trim($data->itemvalues)); - return $present; - } - - function get_hasvalue() { - return 1; - } -} -?> diff --git a/mod/feedback/item/dropdownrated/lib.php b/mod/feedback/item/dropdownrated/lib.php deleted file mode 100644 index 223a6d269a..0000000000 --- a/mod/feedback/item/dropdownrated/lib.php +++ /dev/null @@ -1,303 +0,0 @@ -dirroot.'/mod/feedback/item/feedback_item_class.php'); - -define('FEEDBACK_DROPDOWNRATED_MAXCOUNT', 10); //count of possible items -define('FEEDBACK_DROPDOWN_LINE_SEP', '|'); -define('FEEDBACK_DROPDOWN_VALUE_SEP', '####'); - - -class feedback_item_dropdownrated extends feedback_item_base { - var $type = "dropdownrated"; - function init() { - - } - - function show_edit($item, $usehtmleditor = false) { - - $item->presentation=empty($item->presentation)?'':$item->presentation; - - ?> - - - - - - - - - - - - -
-  (required=isset($item->required)?$item->required:0; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- - - presentation)); - if($itemvalues = explode(FEEDBACK_DROPDOWN_LINE_SEP, stripslashes_safe($item->presentation), FEEDBACK_DROPDOWNRATED_MAXCOUNT)){ - echo ''; - echo ''; - echo ''; - echo ''; - for ($i = 0; $i < FEEDBACK_DROPDOWNRATED_MAXCOUNT; $i++) { - if(count($itemvalues) > $i) { - $value = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $itemvalues[$i]); - if(count($value) <= 1) { - $value[0] = ''; $value[1] = ''; - } - }else { - $value[0] = ''; $value[1] = ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
'.get_string('line_values', 'feedback').''.get_string('line_labels', 'feedback').'
'; - } - - ?> -
- typ; - $analysedItem[] = $item->name; - //die moeglichen Antworten extrahieren - $lines = null; - $lines = explode (FEEDBACK_DROPDOWN_LINE_SEP, stripslashes_safe($item->presentation)); - if(!is_array($lines)) return null; - - //die Werte holen - //$values = get_records('feedback_value', 'item', $item->id); - $values = feedback_get_group_values($item, $groupid, $courseid); - if(!$values) return null; - //schleife ueber den Werten und ueber die Antwortmoeglichkeiten - - $analysedAnswer = array(); - - for($i = 1; $i <= sizeof($lines); $i++) { - $item_values = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $lines[$i-1]); - $ans = null; - $ans->answertext = $item_values[1]; - $avg = 0.0; - $anscount = 0; - foreach($values as $value) { - //ist die Antwort gleich dem index der Antworten + 1? - if ($value->value == $i) { - $avg += $item_values[0]; //erst alle Werte aufsummieren - $anscount++; - } - } - $ans->answercount = $anscount; - $ans->avg = doubleval($avg) / doubleval(sizeof($values)); - $ans->value = $item_values[0]; - $ans->quotient = $ans->answercount / sizeof($values); - $analysedAnswer[] = $ans; - } - $analysedItem[] = $analysedAnswer; - return $analysedItem; - } - - function get_printval($item, $value) { - $printval = ''; - - if(!isset($value->value)) return $printval; - - $presentation = explode (FEEDBACK_DROPDOWN_LINE_SEP, stripslashes_safe($item->presentation)); - $index = 1; - foreach($presentation as $pres){ - if($value->value == $index){ - $dropdown_label = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $pres); - $printval = $dropdown_label[1]; - break; - } - $index++; - } - return $printval; - } - - function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) { - $sep_dec = get_string('separator_decimal', 'feedback'); - if(substr($sep_dec, 0, 2) == '[['){ - $sep_dec = FEEDBACK_DECIMAL; - } - - $sep_thous = get_string('separator_thousand', 'feedback'); - if(substr($sep_thous, 0, 2) == '[['){ - $sep_thous = FEEDBACK_THOUSAND; - } - - $analysedItem = $this->get_analysed($item, $groupid, $courseid); - if($analysedItem) { - //echo ''; - $itemnr++; - echo ''; - $analysedVals = $analysedItem[2]; - $pixnr = 0; - $avg = 0.0; - foreach($analysedVals as $val) { - if( function_exists("bcmod")) { - $intvalue = bcmod($pixnr, 10); - }else { - $intvalue = 0; - } - $pix = "pics/$intvalue.gif"; - $pixnr++; - $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); - - $avg += $val->avg; - $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); - echo ''; - } - $avg = number_format(($avg), 2, $sep_dec, $sep_thous); - echo ''; - //echo '
'. $itemnr . '.) ' . stripslashes($analysedItem[1]) .'
-  ' . trim($val->answertext) . ' ('.$val->value.'):'.$intvalue.'' . $val->answercount. (($val->quotient > 0)?' ('. $quotient . ' %)':'') . '
'.get_string('average', 'feedback').': '.$avg.'
'; - } - return $itemnr; - } - - function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { - $analysed_item = $this->get_analysed($item, $groupid, $courseid); - - - $data = $analysed_item[2]; - - $worksheet->setFormat(""); - //frage schreiben - $worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1])); - if(is_array($data)) { - $avg = 0.0; - for($i = 0; $i < sizeof($data); $i++) { - $aData = $data[$i]; - - $worksheet->setFormat(""); - $worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext).' ('.$aData->value.')'); - - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount); - //$worksheet->setFormat(""); - //$worksheet->write_number($rowOffset + 2, $i + 1, $aData->avg); - $avg += $aData->avg; - } - //mittelwert anzeigen - $worksheet->setFormat(""); - $worksheet->write_string($rowOffset, sizeof($data) + 1, get_string('average', 'feedback')); - - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 1, sizeof($data) + 1, $avg); - } - $rowOffset +=2 ; - return $rowOffset; - } - - function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ - $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right'; - - $lines = explode (FEEDBACK_DROPDOWN_LINE_SEP, stripslashes_safe($item->presentation)); - $requiredmark = ($item->required == 1)?'':''; - if($highlightrequire AND $item->required AND intval($value) <= 0) { - $highlight = 'bgcolor="#FFAAAA" class="missingrequire"'; - }else { - $highlight = ''; - } - ?> - valign="top" align="">name) . $requiredmark, true, false, false);?> - - typ . '_' . $item->id . '">'; - echo ''; - foreach($lines as $line){ - if($value == $index){ - $selected = 'selected="selected"'; - }else{ - $selected = ''; - } - $dropdown_value = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $line); - if($edit) { - echo ''; - }else { - echo ''; - } - $index++; - } - echo ''; - /* - if($item->required == 1) { - echo ''; - } - */ - } - ?> - - required != 1) return true; - if(intval($value) > 0)return true; - return false; - } - - function create_value($data) { - $data = clean_param($data, PARAM_INT); - return $data; - } - - function get_presentation($data) { - $valuelines = $data->fr_val; - $labellines = $data->fr_label; - $present = ''; - if(!is_array($valuelines) AND !is_array($labellines)) { - return $present; - } - - //if( trim($valuelines[0]) != ''){ - $value = intval($valuelines[0]); - $label = $labellines[0]; - $present .= $value.FEEDBACK_DROPDOWN_VALUE_SEP.$label; - //} - - for($i = 1; $i < FEEDBACK_DROPDOWNRATED_MAXCOUNT; $i++) { - if( (trim($valuelines[$i]) == '') AND (trim($labellines[$i]) == ''))continue; - - $value = intval($valuelines[$i]); - $label = $labellines[$i]; - $present .= FEEDBACK_DROPDOWN_LINE_SEP.$value.FEEDBACK_DROPDOWN_VALUE_SEP.$label; - } - //$present = str_replace("\n", '|', trim($data->itemvalues)); - return $present; - } - - function get_hasvalue() { - return 1; - } -} -?> diff --git a/mod/feedback/item/label/label_form.php b/mod/feedback/item/label/label_form.php new file mode 100644 index 0000000000..3ebbc220b3 --- /dev/null +++ b/mod/feedback/item/label/label_form.php @@ -0,0 +1,18 @@ +libdir.'/formslib.php'; + +class feedback_label_form extends moodleform { + var $type = "label"; + var $area; + + function definition() { + $mform =& $this->_form; + + $mform->addElement('header', 'general', get_string($this->type, 'feedback')); + + $mform->addElement('hidden', 'itemname', $this->type); + $this->area = $mform->addElement('htmleditor', 'presentation', '', array('rows'=>20)); + } +} +?> diff --git a/mod/feedback/item/label/lib.php b/mod/feedback/item/label/lib.php index 7a9d76b8b8..e998e498cc 100644 --- a/mod/feedback/item/label/lib.php +++ b/mod/feedback/item/label/lib.php @@ -8,16 +8,17 @@ class feedback_item_label extends feedback_item_base { } - function show_edit($item, $usehtmleditor = false) { - $item->presentation=isset($item->presentation)?$item->presentation:''; - print_string('label', 'feedback'); - echo '
'; - print_textarea($usehtmleditor, 20, 0, 0, 0, "presentation", $item->presentation); - echo ''; - - if ($usehtmleditor) { - use_html_editor(); - } + function show_edit($item) { + global $CFG; + + require_once('label_form.php'); + + $item_form = new feedback_label_form(); + + $item->presentation = isset($item->presentation) ? $item->presentation : ''; + + $item_form->area->setValue($item->presentation); + return $item_form; } function print_item($item){ ?> diff --git a/mod/feedback/item/multichoice/lib.php b/mod/feedback/item/multichoice/lib.php new file mode 100644 index 0000000000..b342a0d24e --- /dev/null +++ b/mod/feedback/item/multichoice/lib.php @@ -0,0 +1,499 @@ +dirroot.'/mod/feedback/item/feedback_item_class.php'); + +define('FEEDBACK_MULTICHOICE_TYPE_SEP', '>>>>>'); +define('FEEDBACK_MULTICHOICE_LINE_SEP', '|'); +define('FEEDBACK_MULTICHOICE_ADJUST_SEP', '<<<<<'); + +class feedback_item_multichoice extends feedback_item_base { + var $type = "multichoice"; + function init() { + + } + + function show_edit($item) { + global $CFG; + + require_once('multichoice_form.php'); + + $item_form = new feedback_multichoice_form(); + + $item->presentation = empty($item->presentation) ? '' : $item->presentation; + $item->name = empty($item->name) ? '' : $item->name; + + $info = $this->get_info($item); + + $item->required = isset($item->required) ? $item->required : 0; + if($item->required) { + $item_form->requiredcheck->setValue(true); + } + + $item_form->itemname->setValue($item->name); + + $item_form->selectadjust->setValue($info->horizontal); + + $item_form->selecttype->setValue($info->subtype); + + $itemvalues = str_replace(FEEDBACK_MULTICHOICE_LINE_SEP, "\n", stripslashes_safe($info->presentation)); + $itemvalues = str_replace("\n\n", "\n", $itemvalues); + $item_form->values->setValue($itemvalues); + return $item_form; + } + + //liefert ein eindimensionales Array mit drei Werten(typ, name, XXX) + //XXX ist ein eindimensionales Array (anzahl der Antworten bei Typ Radio) Jedes Element ist eine Struktur (answertext, answercount) + function get_analysed($item, $groupid = false, $courseid = false) { + $info = $this->get_info($item); + + $analysedItem = array(); + $analysedItem[] = $item->typ; + $analysedItem[] = $item->name; + //die moeglichen Antworten extrahieren + $answers = null; + // $presentation = ''; + // @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info + + $answers = explode (FEEDBACK_MULTICHOICE_LINE_SEP, stripslashes_safe($info->presentation)); + if(!is_array($answers)) return null; + + //die Werte holen + $values = feedback_get_group_values($item, $groupid, $courseid); + if(!$values) return null; + //schleife ueber den Werten und ueber die Antwortmoeglichkeiten + + $analysedAnswer = array(); + if($info->subtype == 'c') { + for($i = 1; $i <= sizeof($answers); $i++) { + $ans = null; + $ans->answertext = $answers[$i-1]; + $ans->answercount = 0; + foreach($values as $value) { + //ist die Antwort gleich dem index der Antworten + 1? + $vallist = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value->value); + foreach($vallist as $val) { + if ($val == $i) { + $ans->answercount++; + } + } + } + $ans->quotient = $ans->answercount / sizeof($values); + $analysedAnswer[] = $ans; + } + }else { + for($i = 1; $i <= sizeof($answers); $i++) { + $ans = null; + $ans->answertext = $answers[$i-1]; + $ans->answercount = 0; + foreach($values as $value) { + //ist die Antwort gleich dem index der Antworten + 1? + if ($value->value == $i) { + $ans->answercount++; + } + } + $ans->quotient = $ans->answercount / sizeof($values); + $analysedAnswer[] = $ans; + } + } + $analysedItem[] = $analysedAnswer; + return $analysedItem; + } + + function get_printval($item, $value) { + $info = $this->get_info($item); + + $printval = ''; + + if(!isset($value->value)) return $printval; + + // @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info + + $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, stripslashes_safe($info->presentation)); + + if($info->subtype == 'c') { + $vallist = array_values(explode (FEEDBACK_MULTICHOICE_LINE_SEP, $value->value)); + for($i = 0; $i < sizeof($vallist); $i++) { + for($k = 0; $k < sizeof($presentation); $k++) { + if($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0 + $printval .= trim($presentation[$k]) . chr(10); + break; + } + } + } + }else { + $index = 1; + foreach($presentation as $pres){ + if($value->value == $index){ + $printval = $pres; + break; + } + $index++; + } + } + return $printval; + } + + function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) { + $sep_dec = get_string('separator_decimal', 'feedback'); + if(substr($sep_dec, 0, 2) == '[['){ + $sep_dec = FEEDBACK_DECIMAL; + } + + $sep_thous = get_string('separator_thousand', 'feedback'); + if(substr($sep_thous, 0, 2) == '[['){ + $sep_thous = FEEDBACK_THOUSAND; + } + + $analysedItem = $this->get_analysed($item, $groupid, $courseid); + if($analysedItem) { + $itemnr++; + $itemname = stripslashes($analysedItem[1]); + echo ''. $itemnr . '.) ' . $itemname .''; + $analysedVals = $analysedItem[2]; + $pixnr = 0; + foreach($analysedVals as $val) { + if( function_exists("bcmod")) { + $intvalue = bcmod($pixnr, 10); + }else { + $intvalue = 0; + } + $pix = "pics/$intvalue.gif"; + $pixnr++; + $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); + $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); + echo '-  ' . trim($val->answertext) . ':'.$intvalue.' ' . $val->answercount . (($val->quotient > 0)?' ('. $quotient . ' %)':'').''; + } + } + return $itemnr; + } + + function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { + $analysed_item = $this->get_analysed($item, $groupid, $courseid); + + + $data = $analysed_item[2]; + + $worksheet->setFormat(""); + //frage schreiben + $worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1])); + if(is_array($data)) { + for($i = 0; $i < sizeof($data); $i++) { + $aData = $data[$i]; + + $worksheet->setFormat(""); + $worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext)); + + $worksheet->setFormat(""); + $worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount); + $worksheet->setFormat(""); + $worksheet->write_number($rowOffset + 2, $i + 1, $aData->quotient); + } + } + $rowOffset +=3 ; + return $rowOffset; + } + + function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ + $info = $this->get_info($item); + $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right'; + + $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, stripslashes_safe($info->presentation)); + + + //test if required and no value is set so we have to mark this item + //we have to differ check and the other subtypes + if($info->subtype == 'c') { + if (is_array($value)) { + $values = $value; + }else { + $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); + } + if($highlightrequire AND $item->required AND $values[0] == '') { + $highlight = 'bgcolor="#FFAAAA" class="missingrequire"'; + }else { + $highlight = ''; + } + $requiredmark = ($item->required == 1)?'':''; + + echo ''.format_text(stripslashes_safe($item->name).$requiredmark, true, false, false).''; + echo ''; + }else { + if($highlightrequire AND $item->required AND intval($value) <= 0) { + $highlight = 'bgcolor="#FFAAAA" class="missingrequire"'; + }else { + $highlight = ''; + } + $requiredmark = ($item->required == 1)?'':''; + ?> + valign="top" align="">name) . $requiredmark, true, false, false);?> + + subtype == 'c') { + print_box_start('generalbox boxalign'.$align); + foreach($presentation as $pres){ + foreach($values as $val) { + if($val == $index){ + echo text_to_html($pres . '
', true, false, false); + break; + } + } + $index++; + } + // print_simple_box_end(); + print_box_end(); + }else { + foreach($presentation as $pres){ + if($value == $index){ + // print_simple_box_start($align); + print_box_start('generalbox boxalign'.$align); + echo text_to_html($pres, true, false, false); + // print_simple_box_end(); + print_box_end(); + break; + } + $index++; + } + } + } else { + //print the "not_selected" item on radiobuttons + if($info->subtype == 'r') { + ?> + + + +
/> + + +
+ subtype != 'd') { + if($info->horizontal) { + echo ''; + } + } + + switch($info->subtype) { + case 'r': + $this->print_item_radio($presentation, $item, $value, $info, $align); + break; + case 'c': + $this->print_item_check($presentation, $item, $value, $info, $align); + break; + case 'd': + $this->print_item_dropdown($presentation, $item, $value, $info, $align); + break; + } + + if($info->subtype != 'd') { + if($info->horizontal) { + echo '
'; + } + } + /* + if($item->required == 1) { + echo ''; + } + */ + } + ?> + + get_info($item); + + if($info->subtype == 'c') { + if((!isset($value) OR !is_array($value) OR $value[0] == '' OR $value[0] == 0) AND $item->required != 1){ + return true; + } + if($value[0] == ""){ + return false; + } + return true; + }else { + //if the item is not required, so the check is true if no value is given + if((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) return true; + if(intval($value) > 0)return true; + } + return false; + } + + function create_value($data) { + $vallist = $data; + return trim($this->item_arrayToString($vallist)); + } + + function get_presentation($data) { + $present = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($data->itemvalues)); + if(!isset($data->subtype)) { + $subtype = 'r'; + }else { + $subtype = substr($data->subtype, 0, 1); + } + if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') { + $present .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1'; + } + return $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$present; + } + + function get_hasvalue() { + return 1; + } + + function get_info($item) { + $presentation = empty($item->presentation) ? '' : $item->presentation; + + $info = new object(); + //check the subtype of the multichoice + //it can be check(c), radio(r) or dropdown(d) + $info->subtype = ''; + $info->presentation = ''; + $info->horizontal = false; + + @list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation); + if(!isset($info->subtype)) { + $info->subtype = 'r'; + } + + if($info->subtype != 'd') { + @list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation); + if(isset($info->horizontal) AND $info->horizontal == 1) { + $info->horizontal = true; + }else { + $info->horizontal = false; + } + } + return $info; + } + + function item_arrayToString($value) { + if(!is_array($value)) { + return $value; + } + $retval = ''; + $arrvals = array_values($value); + $arrvals = clean_param($arrvals, PARAM_INT); //prevent sql-injection + $retval = $arrvals[0]; + for($i = 1; $i < sizeof($arrvals) - 1; $i++) { + $retval .= FEEDBACK_MULTICHOICE_LINE_SEP.$arrvals[$i]; + } + return $retval; + } + + function print_item_radio($presentation, $item, $value, $info, $align) { + $index = 1; + $checked = ''; + foreach($presentation as $radio){ + if($value == $index){ + $checked = 'checked="checked"'; + }else{ + $checked = ''; + } + $inputname = $item->typ . '_' . $item->id; + $inputid = $inputname.'_'.$index; + if($info->horizontal) { + ?> + /> + + + + + + +
/> + +
+ typ. '_' . $item->id; + $inputid = $item->typ. '_' . $item->id.'_'.$index; + if($info->horizontal) { + ?> + /> + + + + +
/> + +
+ + + diff --git a/mod/feedback/item/multichoice/multichoice_form.php b/mod/feedback/item/multichoice/multichoice_form.php new file mode 100644 index 0000000000..d0f54ae56d --- /dev/null +++ b/mod/feedback/item/multichoice/multichoice_form.php @@ -0,0 +1,40 @@ +libdir.'/formslib.php'; + +class feedback_multichoice_form extends moodleform { + var $type = "multichoice"; + var $requiredcheck; + var $itemname; + var $selectadjust; + var $selecttype; + var $values; + + function definition() { + $mform =& $this->_form; + + $mform->addElement('header', 'general', get_string($this->type, 'feedback')); + + $this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback')); + + $this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"')); + + $this->selectadjust = $mform->addElement('select', + 'horizontal', + get_string('adjustment', 'feedback').' ', + array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback'))); + + $this->selecttype = $mform->addElement('select', + 'subtype', + get_string('multichoicetype', 'feedback').' ', + array('r'=>get_string('radio', 'feedback'), + 'c'=>get_string('check', 'feedback'), + 'd'=>get_string('dropdown', 'feedback'))); + + $mform->addElement('static', 'hint', get_string('multichoice_values', 'feedback'), get_string('use_one_line_for_each_value', 'feedback')); + + $this->values = $mform->addElement('textarea', 'itemvalues', '', 'wrap="virtual" rows="10" cols="30"'); + + } +} +?> diff --git a/mod/feedback/item/multichoicerated/lib.php b/mod/feedback/item/multichoicerated/lib.php new file mode 100644 index 0000000000..f896956d2d --- /dev/null +++ b/mod/feedback/item/multichoicerated/lib.php @@ -0,0 +1,419 @@ +dirroot.'/mod/feedback/item/feedback_item_class.php'); + +define('FEEDBACK_RADIORATED_ADJUST_SEP', '<<<<<'); + +define('FEEDBACK_MULTICHOICERATED_MAXCOUNT', 10); //count of possible items +define('FEEDBACK_MULTICHOICERATED_VALUE_SEP', '####'); +define('FEEDBACK_MULTICHOICERATED_VALUE_SEP2', '/'); +define('FEEDBACK_MULTICHOICERATED_TYPE_SEP', '>>>>>'); +define('FEEDBACK_MULTICHOICERATED_LINE_SEP', '|'); +define('FEEDBACK_MULTICHOICERATED_ADJUST_SEP', '<<<<<'); + +class feedback_item_multichoicerated extends feedback_item_base { + var $type = "multichoicerated"; + function init() { + + } + + function show_edit($item) { + global $CFG; + + require_once('multichoicerated_form.php'); + + $item_form = new feedback_multichoicerated_form(); + + $item->presentation = empty($item->presentation) ? '' : $item->presentation; + $item->name = empty($item->name) ? '' : $item->name; + + $info = $this->get_info($item); + + $item->required = isset($item->required) ? $item->required : 0; + if($item->required) { + $item_form->requiredcheck->setValue(true); + } + + $item_form->itemname->setValue($item->name); + + $item_form->selectadjust->setValue($info->horizontal); + + $item_form->selecttype->setValue($info->subtype); + + $itemvalues = $this->prepare_presentation_values_print($info->presentation, FEEDBACK_MULTICHOICERATED_VALUE_SEP, FEEDBACK_MULTICHOICERATED_VALUE_SEP2); + $item_form->values->setValue($itemvalues); + + return $item_form; + } + + //liefert ein eindimensionales Array mit drei Werten(typ, name, XXX) + //XXX ist ein eindimensionales Array (Mittelwert der Werte der Antworten bei Typ Radio_rated) Jedes Element ist eine Struktur (answertext, avg) + function get_analysed($item, $groupid = false, $courseid = false) { + $analysedItem = array(); + $analysedItem[] = $item->typ; + $analysedItem[] = $item->name; + + //die moeglichen Antworten extrahieren + $info = $this->get_info($item); + $lines = null; + $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, stripslashes_safe($info->presentation)); + if(!is_array($lines)) return null; + + //die Werte holen + $values = feedback_get_group_values($item, $groupid, $courseid); + if(!$values) return null; + //schleife ueber den Werten und ueber die Antwortmoeglichkeiten + + $analysedAnswer = array(); + + for($i = 1; $i <= sizeof($lines); $i++) { + $item_values = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $lines[$i-1]); + $ans = null; + $ans->answertext = $item_values[1]; + $avg = 0.0; + $anscount = 0; + foreach($values as $value) { + //ist die Antwort gleich dem index der Antworten + 1? + if ($value->value == $i) { + $avg += $item_values[0]; //erst alle Werte aufsummieren + $anscount++; + } + } + $ans->answercount = $anscount; + $ans->avg = doubleval($avg) / doubleval(sizeof($values)); + $ans->value = $item_values[0]; + $ans->quotient = $ans->answercount / sizeof($values); + $analysedAnswer[] = $ans; + } + $analysedItem[] = $analysedAnswer; + return $analysedItem; + } + + function get_printval($item, $value) { + $printval = ''; + + if(!isset($value->value)) return $printval; + + $info = $this->get_info($item); + + $presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, stripslashes_safe($info->presentation)); + $index = 1; + foreach($presentation as $pres){ + if($value->value == $index){ + $item_label = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres); + $printval = $item_label[1]; + break; + } + $index++; + } + return $printval; + } + + function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) { + $sep_dec = get_string('separator_decimal', 'feedback'); + if(substr($sep_dec, 0, 2) == '[['){ + $sep_dec = FEEDBACK_DECIMAL; + } + + $sep_thous = get_string('separator_thousand', 'feedback'); + if(substr($sep_thous, 0, 2) == '[['){ + $sep_thous = FEEDBACK_THOUSAND; + } + + $analysedItem = $this->get_analysed($item, $groupid, $courseid); + if($analysedItem) { + //echo ''; + $itemnr++; + echo ''; + $analysedVals = $analysedItem[2]; + $pixnr = 0; + $avg = 0.0; + foreach($analysedVals as $val) { + if( function_exists("bcmod")) { + $intvalue = bcmod($pixnr, 10); + }else { + $intvalue = 0; + } + $pix = "pics/$intvalue.gif"; + $pixnr++; + $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); + + $avg += $val->avg; + $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); + echo ''; + } + $avg = number_format(($avg), 2, $sep_dec, $sep_thous); + echo ''; + //echo '
'. $itemnr . '.) ' . stripslashes($analysedItem[1]) .'
-  ' . trim($val->answertext) . ' ('.$val->value.'):'.$intvalue.'' . $val->answercount. (($val->quotient > 0)?' ('. $quotient . ' %)':'') . '
'.get_string('average', 'feedback').': '.$avg.'
'; + } + return $itemnr; + } + + function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { + $analysed_item = $this->get_analysed($item, $groupid, $courseid); + + + $data = $analysed_item[2]; + + $worksheet->setFormat(""); + //frage schreiben + $worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1])); + if(is_array($data)) { + $avg = 0.0; + for($i = 0; $i < sizeof($data); $i++) { + $aData = $data[$i]; + + $worksheet->setFormat(""); + $worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext).' ('.$aData->value.')'); + + $worksheet->setFormat(""); + $worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount); + //$worksheet->setFormat(""); + //$worksheet->write_number($rowOffset + 2, $i + 1, $aData->avg); + $avg += $aData->avg; + } + //mittelwert anzeigen + $worksheet->setFormat(""); + $worksheet->write_string($rowOffset, sizeof($data) + 1, get_string('average', 'feedback')); + + $worksheet->setFormat(""); + $worksheet->write_number($rowOffset + 1, sizeof($data) + 1, $avg); + } + $rowOffset +=2 ; + return $rowOffset; + } + + function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ + $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right'; + $info = $this->get_info($item); + + $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, stripslashes_safe($info->presentation)); + $requiredmark = ($item->required == 1)?'':''; + if($highlightrequire AND $item->required AND intval($value) <= 0) { + $highlight = 'bgcolor="#FFAAAA" class="missingrequire"'; + }else { + $highlight = ''; + } + ?> + valign="top" align="">name) . $requiredmark, true, false, false);?> + + subtype) { + case 'r': + $this->print_item_radio($item, $value, $info, $align, $edit, $lines); + break; + case 'd': + $this->print_item_dropdown($item, $value, $info, $align, $edit, $lines); + break; + } + } + ?> + + required != 1) return true; + if(intval($value) > 0)return true; + return false; + } + + function create_value($data) { + $data = clean_param($data, PARAM_INT); + return $data; + } + + function get_presentation($data) { + // $present = str_replace("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, trim($data->itemvalues)); + $present = $this->prepare_presentation_values_save(trim($data->itemvalues), FEEDBACK_MULTICHOICERATED_VALUE_SEP2, FEEDBACK_MULTICHOICERATED_VALUE_SEP); + // $present = str_replace("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, trim($data->itemvalues)); + if(!isset($data->subtype)) { + $subtype = 'r'; + }else { + $subtype = substr($data->subtype, 0, 1); + } + if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') { + $present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1'; + } + return $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$present; + } + + function get_hasvalue() { + return 1; + } + + function get_info($item) { + $presentation = empty($item->presentation) ? '' : $item->presentation; + + $info = new object(); + //check the subtype of the multichoice + //it can be check(c), radio(r) or dropdown(d) + $info->subtype = ''; + $info->presentation = ''; + $info->horizontal = false; + + @list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation); + if(!isset($info->subtype)) { + $info->subtype = 'r'; + } + + + if($info->subtype != 'd') { + @list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation); + if(isset($info->horizontal) AND $info->horizontal == 1) { + $info->horizontal = true; + }else { + $info->horizontal = false; + } + } + + return $info; + } + + function print_item_radio($item, $value, $info, $align, $edit, $lines) { + $index = 1; + $checked = ''; + ?> + + + +
/> + + +
+ horizontal) { + echo ''; + } + foreach($lines as $line){ + if($value == $index){ + $checked = 'checked="checked"'; + }else{ + $checked = ''; + } + $radio_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line); + $inputname = $item->typ . '_' . $item->id; + $inputid = $inputname.'_'.$index; + if($info->horizontal) { + ?> + + +
/> + +
+
/> + +
+ horizontal) { + echo ''; + } + } + + function print_item_dropdown($item, $value, $info, $align, $edit, $lines) { + echo ''; + + } + + function prepare_presentation_values_print($valuestring, $valuesep1, $valuesep2) { + $lines = explode(FEEDBACK_MULTICHOICERATED_LINE_SEP, $valuestring); + $newlines = array(); + foreach($lines as $line) { + $value = ''; + $text = ''; + if(strpos($line, $valuesep1) === false) { + $value = 0; + $text = $line; + }else { + @list($value, $text) = explode($valuesep1, $line, 2); + } + + $value = intval($value); + $newlines[] = $value.$valuesep2.$text; + } + $newlines = implode("\n", $newlines); + return $newlines; + } + + function prepare_presentation_values_save($valuestring, $valuesep1, $valuesep2) { + $lines = explode("\n", $valuestring); + $newlines = array(); + foreach($lines as $line) { + $value = ''; + $text = ''; + + if(strpos($line, $valuesep1) === false) { + $value = 0; + $text = $line; + }else { + @list($value, $text) = explode($valuesep1, $line, 2); + } + + $value = intval($value); + $newlines[] = $value.$valuesep2.$text; + } + $newlines = implode(FEEDBACK_MULTICHOICERATED_LINE_SEP, $newlines); + return $newlines; + } +} +?> diff --git a/mod/feedback/item/multichoicerated/multichoicerated_form.php b/mod/feedback/item/multichoicerated/multichoicerated_form.php new file mode 100644 index 0000000000..12cc1b3dff --- /dev/null +++ b/mod/feedback/item/multichoicerated/multichoicerated_form.php @@ -0,0 +1,39 @@ +libdir.'/formslib.php'; + +class feedback_multichoicerated_form extends moodleform { + var $type = "multichoicerated"; + var $requiredcheck; + var $itemname; + var $selectadjust; + var $selecttype; + var $values; + + function definition() { + $mform =& $this->_form; + + $mform->addElement('header', 'general', get_string($this->type, 'feedback')); + + $this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback')); + + $this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"')); + + $this->selectadjust = $mform->addElement('select', + 'horizontal', + get_string('adjustment', 'feedback').' ', + array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback'))); + + $this->selecttype = $mform->addElement('select', + 'subtype', + get_string('multichoicetype', 'feedback').' ', + array('r'=>get_string('radio', 'feedback'), + 'd'=>get_string('dropdown', 'feedback'))); + + $mform->addElement('static', 'hint', get_string('multichoice_values', 'feedback'), get_string('use_one_line_for_each_value', 'feedback')); + + $this->values = $mform->addElement('textarea', 'itemvalues', '', 'wrap="virtual" rows="10" cols="30"'); + + } +} +?> diff --git a/mod/feedback/item/numeric/lib.php b/mod/feedback/item/numeric/lib.php index 6e65f6d91f..28a9731949 100644 --- a/mod/feedback/item/numeric/lib.php +++ b/mod/feedback/item/numeric/lib.php @@ -8,44 +8,32 @@ class feedback_item_numeric extends feedback_item_base { } - function show_edit($item, $usehtmleditor = false) { + function show_edit($item) { + global $CFG; + + require_once('numeric_form.php'); + + $item_form = new feedback_numeric_form(); - $item->presentation=empty($item->presentation)?'':$item->presentation; + $item->presentation = empty($item->presentation) ? '' : $item->presentation; + $item->name = empty($item->name) ? '' : $item->name; + + $item->required = isset($item->required) ? $item->required : 0; + if($item->required) { + $item_form->requiredcheck->setValue(true); + } - ?> - - - - - - - - - - presentation); - $range_from = isset($range_from_to[0]) ? intval($range_from_to[0]) : 0; - $range_to = isset($range_from_to[1]) ? intval($range_from_to[1]) : 0; - ?> - - - - - - - -
-  (required=isset($item->required)?$item->required:0; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- -
- -
- itemname->setValue($item->name); + + $range_from_to = explode('|',$item->presentation); + $range_from = isset($range_from_to[0]) ? intval($range_from_to[0]) : 0; + $range_to = isset($range_from_to[1]) ? intval($range_from_to[1]) : 0; + + $item_form->selectfrom->setValue($range_from); + + $item_form->selectto->setValue($range_to); + + return $item_form; } //liefert eine Struktur ->name, ->data = array(mit Antworten) diff --git a/mod/feedback/item/numeric/numeric_form.php b/mod/feedback/item/numeric/numeric_form.php new file mode 100644 index 0000000000..1b99b84d2d --- /dev/null +++ b/mod/feedback/item/numeric/numeric_form.php @@ -0,0 +1,26 @@ +libdir.'/formslib.php'; + +class feedback_numeric_form extends moodleform { + var $type = "numeric"; + var $requiredcheck; + var $itemname; + var $selectfrom; + var $selectto; + + function definition() { + $mform =& $this->_form; + + $mform->addElement('header', 'general', get_string($this->type, 'feedback')); + $this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback')); + + $this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"')); + + $this->selectfrom = $mform->addElement('text', 'numericrangefrom', get_string('numeric_range_from', 'feedback'), array('size="10"','maxlength="10"')); + + $this->selectto = $mform->addElement('text', 'numericrangeto', get_string('numeric_range_to', 'feedback'), array('size="10"','maxlength="10"')); + + } +} +?> diff --git a/mod/feedback/item/radio/lib.php b/mod/feedback/item/radio/lib.php deleted file mode 100644 index 0cb2fc95a3..0000000000 --- a/mod/feedback/item/radio/lib.php +++ /dev/null @@ -1,307 +0,0 @@ -dirroot.'/mod/feedback/item/feedback_item_class.php'); - -define('FEEDBACK_RADIO_LINE_SEP', '|'); -define('FEEDBACK_RADIO_ADJUST_SEP', '<<<<<'); - -class feedback_item_radio extends feedback_item_base { - var $type = "radio"; - function init() { - - } - - function show_edit($item, $usehtmleditor = false) { - - $item->presentation = empty($item->presentation) ? '' : $item->presentation; - - //check, whether the buttons are vertical or horizontal - $presentation = $horizontal = ''; - @list($presentation, $horizontal) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); - if(isset($horizontal) AND $horizontal == 1) { - $horizontal = true; - }else { - $horizontal = false; - } - - ?> - - - - - - - - - - - - - - - -
-  (required=isset($item->required)?$item->required:0; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- : -   /> -   /> -
- - - - - -
- typ; - $analysedItem[] = $item->name; - //die moeglichen Antworten extrahieren - $answers = null; - $presentation = ''; - @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info - - $answers = explode (FEEDBACK_RADIO_LINE_SEP, stripslashes_safe($presentation)); - if(!is_array($answers)) return null; - - //die Werte holen - //$values = get_records('feedback_value', 'item', $item->id); - $values = feedback_get_group_values($item, $groupid, $courseid); - if(!$values) return null; - //schleife ueber den Werten und ueber die Antwortmoeglichkeiten - - $analysedAnswer = array(); - - for($i = 1; $i <= sizeof($answers); $i++) { - $ans = null; - $ans->answertext = $answers[$i-1]; - $ans->answercount = 0; - foreach($values as $value) { - //ist die Antwort gleich dem index der Antworten + 1? - if ($value->value == $i) { - $ans->answercount++; - } - } - $ans->quotient = $ans->answercount / sizeof($values); - $analysedAnswer[] = $ans; - } - $analysedItem[] = $analysedAnswer; - return $analysedItem; - } - - function get_printval($item, $value) { - $printval = ''; - - if(!isset($value->value)) return $printval; - - @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info - - $presentation = explode (FEEDBACK_RADIO_LINE_SEP, stripslashes_safe($presentation)); - $index = 1; - foreach($presentation as $pres){ - if($value->value == $index){ - $printval = $pres; - break; - } - $index++; - } - return $printval; - } - - function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) { - $sep_dec = get_string('separator_decimal', 'feedback'); - if(substr($sep_dec, 0, 2) == '[['){ - $sep_dec = FEEDBACK_DECIMAL; - } - - $sep_thous = get_string('separator_thousand', 'feedback'); - if(substr($sep_thous, 0, 2) == '[['){ - $sep_thous = FEEDBACK_THOUSAND; - } - - $analysedItem = $this->get_analysed($item, $groupid, $courseid); - if($analysedItem) { - //echo ''; - $itemnr++; - echo ''; - $analysedVals = $analysedItem[2]; - $pixnr = 0; - foreach($analysedVals as $val) { - if( function_exists("bcmod")) { - $intvalue = bcmod($pixnr, 10); - }else { - $intvalue = 0; - } - $pix = "pics/$intvalue.gif"; - $pixnr++; - $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); - $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); - echo ''; - } - //echo '
'. $itemnr . '.) ' . $analysedItem[1] .'
-  ' . trim($val->answertext) . ':'.$intvalue.' ' . $val->answercount . (($val->quotient > 0)?' ('. $quotient . ' %)':'').'
'; - } - return $itemnr; - } - - function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { - $analysed_item = $this->get_analysed($item, $groupid, $courseid); - - - $data = $analysed_item[2]; - - $worksheet->setFormat(""); - //frage schreiben - $worksheet->write_string($rowOffset, 0, $analysed_item[1]); - if(is_array($data)) { - for($i = 0; $i < sizeof($data); $i++) { - $aData = $data[$i]; - - $worksheet->setFormat(""); - $worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext)); - - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount); - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 2, $i + 1, $aData->quotient); - } - } - $rowOffset +=3 ; - return $rowOffset; - } - - function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ - $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right'; - - //extract the adjustment-info - $presentation = $horizontal = ''; - @list($presentation, $horizontal) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); - if(isset($horizontal) AND $horizontal == 1) { - $horizontal = true; - }else { - $horizontal = false; - } - - $presentation = explode (FEEDBACK_RADIO_LINE_SEP, stripslashes_safe($presentation)); - if($highlightrequire AND $item->required AND intval($value) <= 0) { - $highlight = 'bgcolor="#FFAAAA" class="missingrequire"'; - }else { - $highlight = ''; - } - $requiredmark = ($item->required == 1)?'':''; - ?> - valign="top" align="">name) . $requiredmark, true, false, false);?> - - - - - -
/> - - -
- '; - } - foreach($presentation as $radio){ - if($value == $index){ - $checked = 'checked="checked"'; - }else{ - $checked = ''; - } - $inputname = $item->typ . '_' . $item->id; - $inputid = $inputname.'_'.$index; - if($horizontal) { - ?> - /> - - - - - - -
/> - -
- '; - } - /* - if($item->required == 1) { - echo ''; - } - */ - } - ?> - - required != 1) return true; - if(intval($value) > 0)return true; - return false; - } - - function create_value($data) { - $data = clean_param($data, PARAM_INT); - return $data; - } - - function get_presentation($data) { - $present = str_replace("\n", FEEDBACK_RADIO_LINE_SEP, trim($data->itemvalues)); - if($data->horizontal == 1) { - $present .= FEEDBACK_RADIO_ADJUST_SEP.'1'; - } - return $present; - } - - function get_hasvalue() { - return 1; - } -} -?> diff --git a/mod/feedback/item/radiorated/lib.php b/mod/feedback/item/radiorated/lib.php deleted file mode 100644 index 18b4a9699b..0000000000 --- a/mod/feedback/item/radiorated/lib.php +++ /dev/null @@ -1,378 +0,0 @@ -dirroot.'/mod/feedback/item/feedback_item_class.php'); - -define('FEEDBACK_RADIORATED_MAXCOUNT', 10); //count of possible items -define('FEEDBACK_RADIORATED_LINE_SEP', '|'); -define('FEEDBACK_RADIORATED_VALUE_SEP', '####'); -define('FEEDBACK_RADIORATED_ADJUST_SEP', '<<<<<'); - -class feedback_item_radiorated extends feedback_item_base { - var $type = "radiorated"; - function init() { - - } - - function show_edit($item, $usehtmleditor = false) { - - $item->presentation = empty($item->presentation) ? '' : $item->presentation; - - //check, whether the buttons are vertical or horizontal - $presentation = $horizontal = ''; - @list($presentation, $horizontal) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); - if(isset($horizontal) AND $horizontal == 1) { - $horizontal = true; - }else { - $horizontal = false; - } - ?> - - - - - - - - - - - - - - - -
-  (required=isset($item->required)?$item->required:0; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- : -   /> -   /> -
- - - presentation)); - if($itemvalues = explode(FEEDBACK_RADIORATED_LINE_SEP, stripslashes_safe($presentation), FEEDBACK_RADIORATED_MAXCOUNT)){ - echo ''; - echo ''; - echo ''; - echo ''; - for ($i = 0; $i < FEEDBACK_RADIORATED_MAXCOUNT; $i++) { - if(count($itemvalues) > $i) { - $value = explode(FEEDBACK_RADIORATED_VALUE_SEP, $itemvalues[$i]); - if(count($value) <= 1) { - $value[0] = ''; $value[1] = ''; - } - }else { - $value[0] = ''; $value[1] = ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
'.get_string('line_values', 'feedback').''.get_string('line_labels', 'feedback').'
'; - } - - ?> -
- typ; - $analysedItem[] = $item->name; - //die moeglichen Antworten extrahieren - $lines = null; - $presentation = ''; - @list($presentation) = explode(FEEDBACK_RADIORATED_ADJUST_SEP, $item->presentation); //remove the adjustment-info - $lines = explode (FEEDBACK_RADIORATED_LINE_SEP, stripslashes_safe($presentation)); - if(!is_array($lines)) return null; - - //die Werte holen - //$values = get_records('feedback_value', 'item', $item->id); - $values = feedback_get_group_values($item, $groupid, $courseid); - if(!$values) return null; - //schleife ueber den Werten und ueber die Antwortmoeglichkeiten - - $analysedAnswer = array(); - - for($i = 1; $i <= sizeof($lines); $i++) { - $item_values = explode(FEEDBACK_RADIORATED_VALUE_SEP, $lines[$i-1]); - $ans = null; - $ans->answertext = $item_values[1]; - $avg = 0.0; - $anscount = 0; - foreach($values as $value) { - //ist die Antwort gleich dem index der Antworten + 1? - if ($value->value == $i) { - $avg += $item_values[0]; //erst alle Werte aufsummieren - $anscount++; - } - } - $ans->answercount = $anscount; - $ans->avg = doubleval($avg) / doubleval(sizeof($values)); - $ans->value = $item_values[0]; - $ans->quotient = $ans->answercount / sizeof($values); - $analysedAnswer[] = $ans; - } - $analysedItem[] = $analysedAnswer; - return $analysedItem; - } - - function get_printval($item, $value) { - $printval = ''; - - if(!isset($value->value)) return $printval; - - @list($presentation) = explode(FEEDBACK_RADIORATED_ADJUST_SEP, $item->presentation); //remove the adjustment-info - - $presentation = explode (FEEDBACK_RADIORATED_LINE_SEP, stripslashes_safe($presentation)); - $index = 1; - foreach($presentation as $pres){ - if($value->value == $index){ - $radio_label = explode(FEEDBACK_RADIORATED_VALUE_SEP, $pres); - $printval = $radio_label[1]; - break; - } - $index++; - } - return $printval; - } - - function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) { - $sep_dec = get_string('separator_decimal', 'feedback'); - if(substr($sep_dec, 0, 2) == '[['){ - $sep_dec = FEEDBACK_DECIMAL; - } - - $sep_thous = get_string('separator_thousand', 'feedback'); - if(substr($sep_thous, 0, 2) == '[['){ - $sep_thous = FEEDBACK_THOUSAND; - } - - $analysedItem = $this->get_analysed($item, $groupid, $courseid); - if($analysedItem) { - //echo ''; - $itemnr++; - echo ''; - $analysedVals = $analysedItem[2]; - $pixnr = 0; - $avg = 0.0; - foreach($analysedVals as $val) { - - if( function_exists("bcmod")) { - $intvalue = bcmod($pixnr, 10); - }else { - $intvalue = 0; - } - $pix = "pics/$intvalue.gif"; - $pixnr++; - $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); - - $avg += $val->avg; - $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); - echo ''; - } - $avg = number_format(($avg), 2, $sep_dec, $sep_thous); - echo ''; - //echo '
'. $itemnr . '.) ' . $analysedItem[1] .'
-  ' . trim($val->answertext) . ' ('.$val->value.'):'.$intvalue.'' . $val->answercount. (($val->quotient > 0)?' ('. $quotient . ' %)':'') . '
'.get_string('average', 'feedback').': '.$avg.'
'; - } - return $itemnr; - } - - function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { - $analysed_item = $this->get_analysed($item, $groupid, $courseid); - - - $data = $analysed_item[2]; - - $worksheet->setFormat(""); - //frage schreiben - $worksheet->write_string($rowOffset, 0, $analysed_item[1]); - if(is_array($data)) { - $avg = 0.0; - for($i = 0; $i < sizeof($data); $i++) { - $aData = $data[$i]; - - $worksheet->setFormat(""); - $worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext).' ('.$aData->value.')'); - - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount); - //$worksheet->setFormat(""); - //$worksheet->write_number($rowOffset + 2, $i + 1, $aData->avg); - $avg += $aData->avg; - } - //mittelwert anzeigen - $worksheet->setFormat(""); - $worksheet->write_string($rowOffset, sizeof($data) + 1, get_string('average', 'feedback')); - - $worksheet->setFormat(""); - $worksheet->write_number($rowOffset + 1, sizeof($data) + 1, $avg); - } - $rowOffset +=2 ; - return $rowOffset; - } - - function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ - $align = get_string('thisdirection') == 'ltr' ? 'left' : 'right'; - - //extract the adjustment-info - $presentation = $horizontal = ''; - @list($presentation, $horizontal) = explode(FEEDBACK_RADIORATED_ADJUST_SEP, $item->presentation); - if(isset($horizontal) AND $horizontal == 1) { - $horizontal = true; - }else { - $horizontal = false; - } - - $lines = explode (FEEDBACK_RADIORATED_LINE_SEP, stripslashes_safe($presentation)); - if($highlightrequire AND $item->required AND intval($value) <= 0) { - $highlight = 'bgcolor="#FFAAAA" class="missingrequire"'; - }else { - $highlight = ''; - } - $requiredmark = ($item->required == 1)?'':''; - ?> - valign="top" align="">name) . $requiredmark, true, false, false);?> - - - - - -
/> - - -
- '; - } - foreach($lines as $line){ - if($value == $index){ - $checked = 'checked="checked"'; - }else{ - $checked = ''; - } - $radio_value = explode(FEEDBACK_RADIORATED_VALUE_SEP, $line); - $inputname = $item->typ . '_' . $item->id; - $inputid = $inputname.'_'.$index; - if($horizontal) { - ?> - /> - - - - -
/> - -
- '; - } - /* - if($item->required == 1) { - echo ''; - } - */ - } - ?> - - required != 1) return true; - if(intval($value) > 0)return true; - return false; - } - - function create_value($data) { - $data = clean_param($data, PARAM_INT); - return $data; - } - - function get_presentation($data) { - $valuelines = $data->fr_val; - $labellines = $data->fr_label; - $present = ''; - if(!is_array($valuelines) AND !is_array($labellines)) { - return $present; - } - - //if( trim($valuelines[0]) != ''){ - $value = intval($valuelines[0]); - $label = $labellines[0]; - $present .= $value.FEEDBACK_RADIORATED_VALUE_SEP.$label; - //} - - for($i = 1; $i < FEEDBACK_RADIORATED_MAXCOUNT; $i++) { - if( (trim($valuelines[$i]) == '') AND (trim($labellines[$i]) == ''))continue; - - $value = intval($valuelines[$i]); - $label = $labellines[$i]; - $present .= FEEDBACK_RADIORATED_LINE_SEP.$value.FEEDBACK_RADIORATED_VALUE_SEP.$label; - } - //$present = str_replace("\n", '|', trim($data->itemvalues)); - if($data->horizontal == 1) { - $present .= FEEDBACK_RADIORATED_ADJUST_SEP.'1'; - } - return $present; - } - - function get_hasvalue() { - return 1; - } -} -?> diff --git a/mod/feedback/item/textarea/lib.php b/mod/feedback/item/textarea/lib.php index 8bbd1be22a..e70995eadc 100644 --- a/mod/feedback/item/textarea/lib.php +++ b/mod/feedback/item/textarea/lib.php @@ -8,49 +8,30 @@ class feedback_item_textarea extends feedback_item_base { } - function show_edit($item, $usehtmleditor = false) { + function show_edit($item) { + global $CFG; - $item->presentation=empty($item->presentation)?'':$item->presentation; + require_once('textarea_form.php'); + + $item_form = new feedback_textarea_form(); - ?> - - - - - - - - - - - - - - - - -
-  (required=isset($item->required)?$item->required:0; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- -
- -
- presentation = empty($item->presentation) ? '' : $item->presentation; + $item->name = empty($item->name) ? '' : $item->name; + + $item->required = isset($item->required) ? $item->required : 0; + if($item->required) { + $item_form->requiredcheck->setValue(true); + } + + $item_form->itemname->setValue($item->name); + + $widthAndHeight = explode('|',$item->presentation); + $itemwidth = isset($widthAndHeight[0]) ? $widthAndHeight[0] : 30; + $itemheight = isset($widthAndHeight[1]) ? $widthAndHeight[1] : 5; + $item_form->selectwith->setValue($itemwidth); + $item_form->selectheight->setValue($itemheight); + + return $item_form; } //liefert eine Struktur ->name, ->data = array(mit Antworten) diff --git a/mod/feedback/item/textarea/textarea_form.php b/mod/feedback/item/textarea/textarea_form.php new file mode 100644 index 0000000000..0a9eb50569 --- /dev/null +++ b/mod/feedback/item/textarea/textarea_form.php @@ -0,0 +1,32 @@ +libdir.'/formslib.php'; + +class feedback_textarea_form extends moodleform { + var $type = "textarea"; + var $requiredcheck; + var $itemname; + var $selectwith; + var $selectheight; + + function definition() { + $mform =& $this->_form; + + $mform->addElement('header', 'general', get_string($this->type, 'feedback')); + $this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback')); + + $this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"')); + + $this->selectwith = $mform->addElement('select', + 'itemwidth', + get_string('textarea_width', 'feedback').' ', + array_slice(range(0,80),5,80,true)); + + $this->selectheight = $mform->addElement('select', + 'itemheight', + get_string('textarea_height', 'feedback').' ', + array_slice(range(0,40),5,40,true)); + + } +} +?> diff --git a/mod/feedback/item/textfield/lib.php b/mod/feedback/item/textfield/lib.php index a45758a38b..0e3ce60147 100644 --- a/mod/feedback/item/textfield/lib.php +++ b/mod/feedback/item/textfield/lib.php @@ -8,50 +8,30 @@ class feedback_item_textfield extends feedback_item_base { } - function show_edit($item, $usehtmleditor = false) { + function show_edit($item) { + global $CFG; + + require_once('textfield_form.php'); + + $item_form = new feedback_textfield_form(); + + $item->presentation = empty($item->presentation) ? '' : $item->presentation; + $item->name = empty($item->name) ? '' : $item->name; + + $item->required = isset($item->required) ? $item->required : 0; + if($item->required) { + $item_form->requiredcheck->setValue(true); + } - $item->presentation=empty($item->presentation)?'':$item->presentation; + $item_form->itemname->setValue($item->name); - ?> - - - - - - - - - - - - - - - - -
-  (required=isset($item->required)?$item->required:0; - echo ($item->required == 1?'checked="checked"':''); - ?> /> ) -
- -
- -
- presentation); + $itemsize = isset($sizeAndLength[0]) ? $sizeAndLength[0] : 30; + $itemlength = isset($sizeAndLength[1]) ? $sizeAndLength[1] : 5; + $item_form->selectwith->setValue($itemsize); + $item_form->selectheight->setValue($itemlength); + + return $item_form; } //liefert eine Struktur ->name, ->data = array(mit Antworten) diff --git a/mod/feedback/item/textfield/textfield_form.php b/mod/feedback/item/textfield/textfield_form.php new file mode 100644 index 0000000000..454f6ac508 --- /dev/null +++ b/mod/feedback/item/textfield/textfield_form.php @@ -0,0 +1,32 @@ +libdir.'/formslib.php'; + +class feedback_textfield_form extends moodleform { + var $type = "textfield"; + var $requiredcheck; + var $itemname; + var $selectwith; + var $selectheight; + + function definition() { + $mform =& $this->_form; + + $mform->addElement('header', 'general', get_string($this->type, 'feedback')); + $this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback')); + + $this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"')); + + $this->selectwith = $mform->addElement('select', + 'itemsize', + get_string('textfield_size', 'feedback').' ', + array_slice(range(0,80),5,80,true)); + + $this->selectheight = $mform->addElement('select', + 'itemmaxlength', + get_string('textfield_maxlength', 'feedback').' ', + array_slice(range(0,40),5,40,true)); + + } +} +?> diff --git a/mod/feedback/restorelib.php b/mod/feedback/restorelib.php index 93f4c9047e..abe1d06380 100644 --- a/mod/feedback/restorelib.php +++ b/mod/feedback/restorelib.php @@ -26,12 +26,14 @@ // //----------------------------------------------------------- + define('FEEDBACK_MULTICHOICERESTORE_TYPE_SEP', '>>>>>'); + function feedback_restore_mods($mod,$restore) { global $CFG; - $allValues = array(); - $allTrackings = array(); + // $allValues = array(); + // $allTrackings = array(); $status = true; $restore_userdata = restore_userdata_selected($restore,'feedback',$mod->id); @@ -119,6 +121,28 @@ if($version >= 1) { $item->typ = backup_todb($item_info['#']['TYP']['0']['#']); $item->hasvalue = backup_todb($item_info['#']['HASVALUE']['0']['#']); + switch($item->typ) { + case 'radio': + $item->typ = 'multichoice'; + $item->presentation = 'r'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation; + break; + case 'check': + $item->typ = 'multichoice'; + $item->presentation = 'c'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation; + break; + case 'dropdown': + $item->typ = 'multichoice'; + $item->presentation = 'd'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation; + break; + case 'radiorated': + $item->typ = 'multichoicerated'; + $item->presentation = 'r'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation; + break; + case 'dropdownrated': + $item->typ = 'multichoicerated'; + $item->presentation = 'd'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation; + break; + } } else { $oldtyp = intval(backup_todb($item_info['#']['TYP']['0']['#'])); switch($oldtyp) { @@ -158,6 +182,7 @@ $values = $item_info['#']['FBVALUES']['0']['#']['FBVALUE']; for($ii = 0; $ii < sizeof($values); $ii++) { $value_info = $values[$ii]; + $value = new object(); $value->id = ''; $value->item = $newitemid; $value->completed = 0; @@ -168,7 +193,7 @@ //put this new value into the database $newvalueid = insert_record('feedback_value', $value); $value->id = $newvalueid; - $allValues[] = $value; + // $allValues[] = $value; } } } @@ -178,6 +203,7 @@ $trackings = $info['MOD']['#']['TRACKINGS']['0']['#']['TRACKING']; for($i = 0; $i < sizeof($trackings); $i++) { $tracking_info = $trackings[$i]; + $tracking = new object(); $tracking->id = ''; $tracking->userid = backup_todb($tracking_info['#']['USERID']['0']['#']); //have to change later $tracking->feedback = $newid; @@ -194,13 +220,14 @@ //save the tracking $newtrackingid = insert_record('feedback_tracking', $tracking); $tracking->id = $newtrackingid; - $allTrackings[] = $tracking; + // $allTrackings[] = $tracking; } //restore completeds $completeds = $info['MOD']['#']['COMPLETEDS']['0']['#']['COMPLETED']; for($i = 0; $i < sizeof($completeds); $i++) { $completed_info = $completeds[$i]; + $completed = new object(); $completed->feedback = $newid; $completed->userid = backup_todb($completed_info['#']['USERID']['0']['#']); $completed->timemodified = backup_todb($completed_info['#']['TIMEMODIFIED']['0']['#']); diff --git a/mod/feedback/version.php b/mod/feedback/version.php index 7592d5e5ff..c4788a76af 100644 --- a/mod/feedback/version.php +++ b/mod/feedback/version.php @@ -10,7 +10,7 @@ */ - $module->version = 2008042300; // The current module version (Date: YYYYMMDDXX) + $module->version = 2008042401; // The current module version (Date: YYYYMMDDXX) $module->requires = 2007101503; // Requires this Moodle version $feedback_version_intern = 1; //this version is used for restore older backups $module->cron = 0; // Period for cron to check this module (secs)