### Eclipse Workspace Patch 1.0 #P moodle21fork Index: mod/questionnaire/styles.css =================================================================== RCS file: /cvsroot/moodle/contrib/plugins/mod/questionnaire/styles.css,v retrieving revision 1.5 diff -u -r1.5 styles.css --- mod/questionnaire/styles.css 2 Aug 2011 12:43:35 -0000 1.5 +++ mod/questionnaire/styles.css 15 Sep 2011 21:36:50 -0000 @@ -195,7 +195,9 @@ text-align:right; } body#page-mod-questionnaire-view .c0, -body#page-mod-questionnaire-preview .c0 { +body#page-mod-questionnaire-preview .c0, +body#page-mod-questionnaire-report .likertresp .c0, +body#page-mod-questionnaire-myreport .likertresp .c0 { background-color: #fafafa; border: #CCCCCC 1px solid; padding-left:5px; @@ -204,7 +206,9 @@ } body#page-mod-questionnaire-view .c1, -body#page-mod-questionnaire-preview .c1 { +body#page-mod-questionnaire-preview .c1, +body#page-mod-questionnaire-report .likertresp .c1, +body#page-mod-questionnaire-myreport .likertresp .c1 { background-color: #eee; border: #FFFFFF 1px solid; padding-left:5px; Index: mod/questionnaire/questiontypes/questiontypes.class.php =================================================================== RCS file: /cvsroot/moodle/contrib/plugins/mod/questionnaire/questiontypes/questiontypes.class.php,v retrieving revision 1.100 diff -u -r1.100 questiontypes.class.php --- mod/questionnaire/questiontypes/questiontypes.class.php 2 Aug 2011 12:43:35 -0000 1.100 +++ mod/questionnaire/questiontypes/questiontypes.class.php 15 Sep 2011 21:36:51 -0000 @@ -756,6 +756,7 @@ if ($rows = $this->get_response_rank_results($rids, $sort)) { if($this->type_id == 8) { //Rank foreach ($this->counts as $key => $value) { + $ccontent = $key; if (array_key_exists($ccontent, $rows)) { $avg = $rows[$ccontent]->average; @@ -766,6 +767,8 @@ $this->counts[$ccontent]->avg = $avg; } $this->mkresavg(count($rids), $this->precise, $prtotal, $this->length, $sort); + // see discussion http://moodle.org/mod/forum/discuss.php?d=185106 + $this->mkrescount($rids, $rows, $this->precise, $this->length, $sort); } else { foreach ($rows as $row) { $rank = $row->rank; @@ -2028,6 +2031,202 @@ echo html_writer::table($table); } + function mkrescount($rids, $rows, $precision, $length, $sort) { + // display number of responses - see http://moodle.org/mod/forum/discuss.php?d=185106 + global $CFG, $DB; + + // prepare data to be displayed + $ridstr = ''; + if (is_array($rids)) { + foreach ($rids as $rid) { + $ridstr .= (empty($ridstr) ? ' AND response_id IN ('.$rid : ', '.$rid); + } + $ridstr .= ') '; + } else if (is_int($rids)) { + $ridstr = ' AND response_id = '.$rids.' '; + } + $questionid = $this->id; + $sql = 'SELECT r.id, c.content, r.rank, c.id AS choiceid '. + 'FROM '.$CFG->prefix.'questionnaire_quest_choice c ,'. + $CFG->prefix.'questionnaire_response_rank r '. + 'WHERE c.question_id = '.$questionid. + ' AND r.question_id = c.question_id'. + ' AND r.choice_id = c.id '. + $ridstr. + ' ORDER BY choiceid, rank ASC'; + $choices = $DB->get_records_sql($sql); + + //sort rows (results) by average value + if ($sort != 'default') { + $sortArray = array(); + foreach($rows as $row){ + foreach($row as $key=>$value){ + if(!isset($sortArray[$key])){ + $sortArray[$key] = array(); + } + $sortArray[$key][] = $value; + } + } + $orderby = "average"; + switch ($sort) { + case 'ascending': + array_multisort($sortArray[$orderby],SORT_ASC,$rows); + break; + case 'descending': + array_multisort($sortArray[$orderby],SORT_DESC,$rows); + break; + } + } + $nbranks = $this->length; + $ranks = array(); + foreach($rows as $row) { + $choiceid = $row->id; + foreach($choices as $choice) { + if ($choice->choiceid == $choiceid) { + $n = 0; + for ($i=0;$i<$nbranks;$i++){ + if ($choice->rank == $i) { + $n++; + if (!isset($ranks[$choice->content][$i])) { + $ranks[$choice->content][$i] = 0; + } + $ranks[$choice->content][$i] += $n; + } + } + } + } + } + + // prepare settings for display + $strresp = '
'.get_string('responses', 'questionnaire').'
'; + $strtotal = ''.get_string('total', 'questionnaire').''; + $isna = $this->precise == 1; + $isnahead = ''; + $osgood = false; + $nbchoices = count ($this->counts); + if ($precision == 3) { // Osgood's semantic differential + $osgood = true; + } + if ($isna) { + $isnahead = get_string('notapplicable', 'questionnaire').'
(#)'; + } + // background color for even-number cell + $bg = 'c0'; + if ($precision == 1) { + $na = get_string('notapplicable', 'questionnaire'); + } else { + $na = ''; + } + $colspan = $length + 1 + ($na !='') + $osgood; + $nameddegrees = 0; + $n = array(); + $mods = array(); + foreach ($this->choices as $cid => $choice) { + $content = $choice->content; + // check for number from 1 to 3 digits, followed by the equal sign = (to accomodate named degrees) + if (ereg("^([0-9]{1,3})=(.*)$", $content,$ndd)) { + $n[$nameddegrees] = format_text($ndd[2], FORMAT_HTML); + $nameddegrees++; + } + else { + $contents = choice_values($content); + if ($contents->modname) { + $choice->content = $contents->text; + } + } + } + // if we have named degrees, provide for wider degree columns (than for numbers) + // do not provide wider degree columns if we have an Osgood's semantic differential + if ($nameddegrees || $osgood) { + $colwidth = 'auto'; + $leftcolwidth = 'auto'; + } else { + $colwidth = '40px'; + $leftcolwidth = '55%'; + } + + // display begins here (old HTML style) + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + // display the column titles + for ($j = 0; $j < $this->length; $j++) { + if (isset($n[$j])) { + $str = $n[$j]; + } else { + $str = $j+1; + } + echo ''; + $bg = ($bg == 'c0' ? 'c1' : 'c0'); + } + if (!$osgood) { + echo ''; + } else { + echo ''; + } + if ($na) { + echo ''; + } + echo ''; + + // now display the responses + foreach($ranks as $content => $rank) { + // first display the list of degrees (named or un-named) + echo ''; + // number of NOT AVAILABLE responses for this possible answer + $nbna = $this->counts[$content]->nbna; + // TOTAL number of responses for this possible answer + $nbresp = ''.$this->counts[$content]->num.''; + // background color for odd-number cell + $bg = 'c1'; + if ($osgood) { + list($content, $contentright) = split('[|]', $content); + echo ''; + } else { + $contents = choice_values($content); + if ($contents->modname) { + $content = $contents->text; + } + echo ''; + } + + // display ranks/rates numbers + $maxrank = max($rank); + for ($i = 0; $i <= $length - 1; $i++) { + $bg = ($bg == 'c0' ? 'c1' : 'c0'); + if (isset($rank[$i])) { + $str = $rank[$i]; + // emphasize responses with max rank value + if ($str == $maxrank) { + $str = ''.$str.''; + } + } else { + $str = 0; + } + echo ''; + } + + $bg = ($bg == 'c0' ? 'c1' : 'c0'); + if (!$osgood) { + echo''; + if ($na) { + $bg = ($bg == 'c0' ? 'c1' : 'c0'); + echo ''; + } + } else { + $bg = ($bg == 'c0' ? 'c1' : 'c0'); + echo ''. + ''; + } + echo ''; + } + echo '
'.$strresp.'
'.$str.''.$strtotal.''.$strtotal.''.$na.'
'.format_text($content, FORMAT_HTML).' '.format_text($content, FORMAT_HTML).' '.$str.''.$nbresp.''; + echo $nbna.' '.format_text($contentright, FORMAT_HTML).''.$nbresp.'
'; + } + /* {{{ proto void mkresrank(array weights, int total, int precision, bool show_totals) Builds HTML showing RANK results. */ function mkresrank($total, $precision, $showTotals) {