diff --git a/mod/choice/index.php b/mod/choice/index.php
index b0a3dd65ae8..0ae6484271d 100644
--- a/mod/choice/index.php
+++ b/mod/choice/index.php
@@ -20,6 +20,7 @@
$strchoices = get_string("modulenameplural", "choice");
$strsectionname = get_string('sectionname', 'format_'.$course->format);
$PAGE->set_title($strchoices);
+ $PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strchoices);
echo $OUTPUT->header();
diff --git a/mod/choice/lang/en/choice.php b/mod/choice/lang/en/choice.php
index 5be54ea79dc..57ece3482b4 100644
--- a/mod/choice/lang/en/choice.php
+++ b/mod/choice/lang/en/choice.php
@@ -86,3 +86,6 @@ $string['timerestrict'] = 'Restrict answering to this time period';
$string['viewallresponses'] = 'View {$a} responses';
$string['withselected'] = 'With selected';
$string['yourselection'] = 'Your selection';
+$string['skipresultgraph'] = 'Skip result graph';
+$string['moveselectedusersto'] = 'Move selected users to...';
+$string['numberofuser'] = 'The number of user';
diff --git a/mod/choice/lib.php b/mod/choice/lib.php
index 12e74a15c83..54de30cc123 100644
--- a/mod/choice/lib.php
+++ b/mod/choice/lib.php
@@ -25,6 +25,10 @@
global $CHOICE_COLUMN_HEIGHT;
$CHOICE_COLUMN_HEIGHT = 300;
+/** @global int $CHOICE_COLUMN_WIDTH */
+global $CHOICE_COLUMN_WIDTH;
+$CHOICE_COLUMN_WIDTH = 300;
+
define('CHOICE_PUBLISH_ANONYMOUS', '0');
define('CHOICE_PUBLISH_NAMES', '1');
@@ -184,126 +188,50 @@ function choice_update_instance($choice) {
* @global object
* @param object $choice
* @param object $user
- * @param object $cm
+ * @param object $coursemodule
* @param array $allresponses
- * @return void output is echo'd
+ * @return array
*/
-function choice_show_form($choice, $user, $cm, $allresponses) {
+function choice_prepare_options($choice, $user, $coursemodule, $allresponses) {
global $DB;
-//$cdisplay is an array of the display info for a choice $cdisplay[$optionid]->text - text name of option.
-// ->maxanswers -maxanswers for this option
-// ->full - whether this option is full or not. 0=not full, 1=full
- $cdisplay = array();
- $aid = 0;
- $choicefull = false;
- $cdisplay = array();
+ $cdisplay = array('options'=>array());
- if ($choice->limitanswers) { //set choicefull to true by default if limitanswers.
- $choicefull = true;
- }
-
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $cdisplay['limitanswers'] = true;
+ $context = get_context_instance(CONTEXT_MODULE, $coursemodule->id);
foreach ($choice->option as $optionid => $text) {
if (isset($text)) { //make sure there are no dud entries in the db with blank text values.
- $cdisplay[$aid]->optionid = $optionid;
- $cdisplay[$aid]->text = $text;
- $cdisplay[$aid]->maxanswers = $choice->maxanswers[$optionid];
+ $option = new stdClass;
+ $option->attributes = new stdClass;
+ $option->attributes->value = $optionid;
+ $option->text = $text;
+ $option->maxanswers = $choice->maxanswers[$optionid];
+ $option->displaylayout = $choice->display;
+
if (isset($allresponses[$optionid])) {
- $cdisplay[$aid]->countanswers = count($allresponses[$optionid]);
+ $option->countanswers = count($allresponses[$optionid]);
} else {
- $cdisplay[$aid]->countanswers = 0;
+ $option->countanswers = 0;
}
- if ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $user->id, 'optionid' => $optionid))) {
- $cdisplay[$aid]->checked = ' checked="checked" ';
- } else {
- $cdisplay[$aid]->checked = '';
+ if ($DB->record_exists('choice_answers', array('choiceid' => $choice->id, 'userid' => $user->id, 'optionid' => $optionid))) {
+ $option->attributes->checked = true;
}
- if ( $choice->limitanswers &&
- ($cdisplay[$aid]->countanswers >= $cdisplay[$aid]->maxanswers) &&
- (empty($cdisplay[$aid]->checked)) ) {
- $cdisplay[$aid]->disabled = ' disabled="disabled" ';
- } else {
- $cdisplay[$aid]->disabled = '';
- if ($choice->limitanswers && ($cdisplay[$aid]->countanswers < $cdisplay[$aid]->maxanswers)) {
- $choicefull = false; //set $choicefull to false - as the above condition hasn't been set.
+ if ( $choice->limitanswers && ($option->countanswers >= $option->maxanswers) && empty($option->attributes->checked)) {
+ $option->attributes->disabled = true;
}
+ $cdisplay['options'][] = $option;
}
- $aid++;
}
- }
- switch ($choice->display) {
- case CHOICE_DISPLAY_HORIZONTAL:
- echo "
";
- break;
- case CHOICE_DISPLAY_VERTICAL:
- $displayoptions->para = false;
- echo "";
- break;
- }
- //show save choice button
- echo '";
-}
/**
* @global object
@@ -398,32 +326,49 @@ function choice_show_reportlink($user, $cm) {
/**
* @global object
- * @global int
- * @global string
- * @global object
- * @uses CONTEXT_MODULE
- * @uses CHOICE_PUBLISH_NAMES
- * @uses CHOICE_PUBLISH_ANONYMOUS
* @param object $choice
* @param object $course
- * @param object $cm
+ * @param object $coursemodule
* @param array $allresponses
- * @param int $forcepublish
- * @return void Output is echo'd
+
+ * * @param bool $allresponses
+ * @return object
*/
-function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish='') {
+function prepare_choice_show_results($choice, $course, $cm, $allresponses, $forcepublish=false) {
global $CFG, $CHOICE_COLUMN_HEIGHT, $FULLSCRIPT, $PAGE, $OUTPUT, $DB;
- echo $OUTPUT->heading(get_string("responses", "choice"));
- if (empty($forcepublish)) { //alow the publish setting to be overridden
- $forcepublish = $choice->publish;
+ $display = clone($choice);
+ $display->coursemoduleid = $cm->id;
+ $display->courseid = $course->id;
+
+ //overwrite options value;
+ $display->options = array();
+ $totaluser = 0;
+ foreach ($choice->option as $optionid => $optiontext) {
+ $display->options[$optionid] = new stdClass;
+ $display->options[$optionid]->text = $optiontext;
+ $display->options[$optionid]->maxanswer = $choice->maxanswers[$optionid];
+
+ if (array_key_exists($optionid, $allresponses)) {
+ $display->options[$optionid]->user = $allresponses[$optionid]; //->user;
+ $totaluser += count($allresponses[$optionid]);
}
+ }
+ unset($display->option);
+ unset($display->maxanswers);
+
+ $display->numberofuser = $totaluser;
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $display->viewresponsecapability = has_capability('mod/choice:readresponses', $context);
+ $display->deleterepsonsecapability = has_capability('mod/choice:deleteresponses',$context);
+ $display->fullnamecapability = has_capability('moodle/site:viewfullnames', $context);
if (empty($allresponses)) {
echo $OUTPUT->heading(get_string("nousersyet"));
return false;
}
+
$totalresponsecount = 0;
foreach ($allresponses as $optionid => $userlist) {
if ($choice->showunanswered || $optionid) {
@@ -559,93 +504,9 @@ function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish
echo "";
}
break;
-
-
- case CHOICE_PUBLISH_ANONYMOUS:
-
- echo "";
- echo "";
- $maxcolumn = 0;
- if ($choice->showunanswered) {
- echo "| ";
- print_string('notanswered', 'choice');
- echo " | ";
- $column[0] = 0;
- foreach ($allresponses[0] as $user) {
- $column[0]++;
}
- $maxcolumn = $column[0];
+ return $display;
}
- $count = 1;
-
- foreach ($choice->option as $optionid => $optiontext) {
- echo "";
- echo format_string($optiontext);
- echo " | ";
-
- $column[$optionid] = 0;
- if (isset($allresponses[$optionid])) {
- $column[$optionid] = count($allresponses[$optionid]);
- if ($column[$optionid] > $maxcolumn) {
- $maxcolumn = $column[$optionid];
- }
- } else {
- $column[$optionid] = 0;
- }
- }
- echo "
";
-
- $height = 0;
-
- if ($choice->showunanswered) {
- if ($maxcolumn) {
- $height = $CHOICE_COLUMN_HEIGHT * ((float)$column[0] / (float)$maxcolumn);
- }
- echo "";
- echo " ";
- echo " | ";
- }
- $count = 1;
- foreach ($choice->option as $optionid => $optiontext) {
- if ($maxcolumn) {
- $height = $CHOICE_COLUMN_HEIGHT * ((float)$column[$optionid] / (float)$maxcolumn);
- }
- echo "";
- echo " ";
- echo " | ";
- $count++;
- }
- echo "
";
-
-
- if ($choice->showunanswered) {
- echo '';
- if (!$choice->limitanswers) {
- echo $column[0];
- echo ' ('.format_float(((float)$column[0]/(float)$totalresponsecount)*100.0,1).'%)';
- }
- echo ' | ';
- }
- $count = 1;
- foreach ($choice->option as $optionid => $optiontext) {
- echo "";
- if ($choice->limitanswers) {
- echo get_string("taken", "choice").":";
- echo $column[$optionid].' ';
- echo get_string("limit", "choice").":";
- echo $choice->maxanswers[$optionid];
- } else {
- echo $column[$optionid];
- echo ' ('.format_float(((float)$column[$optionid]/(float)$totalresponsecount)*100.0,1).'%)';
- }
- echo " | ";
- $count++;
- }
- echo "
";
-
- break;
- }
-}
/**
* @global object
diff --git a/mod/choice/pix/column.png b/mod/choice/pix/column.png
new file mode 100644
index 00000000000..88fbae915b9
Binary files /dev/null and b/mod/choice/pix/column.png differ
diff --git a/mod/choice/pix/row.png b/mod/choice/pix/row.png
new file mode 100644
index 00000000000..d082724c452
Binary files /dev/null and b/mod/choice/pix/row.png differ
diff --git a/mod/choice/renderer.php b/mod/choice/renderer.php
new file mode 100644
index 00000000000..613ecf1390a
--- /dev/null
+++ b/mod/choice/renderer.php
@@ -0,0 +1,395 @@
+.
+
+/**
+ * Moodle renderer used to display special elements of the lesson module
+ *
+ * @package Choice
+ * @copyright 2010 Rossiani Wijaya
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ **/
+define ('DISPLAY_HORIZONTAL_LAYOUT', 0);
+define ('DISPLAY_VERTICAL_LAYOUT', 1);
+
+class mod_choice_renderer extends plugin_renderer_base {
+
+ /**
+ * Returns HTML to display choices of option
+ * @param object $options
+ * @param int $coursemoduleid
+ * @param bool $vertical
+ * @return string
+ */
+ public function display_options($options, $coursemoduleid, $vertical = false) {
+ global $CFG;
+
+ $layoutclass = 'horizontal';
+ if ($vertical) {
+ $layoutclass = 'vertical';
+ }
+
+ $attributes = array('method'=>'POST', 'target'=>$CFG->wwwroot.'/mod/choice/view.php', 'class'=> $layoutclass);
+
+ $html = html_writer::start_tag('form', $attributes);
+ $html .= html_writer::start_tag('ul', array('class'=>'choices' ));
+
+ $availableoption = count($options['options']);
+ foreach ($options['options'] as $option) {
+ $html .= html_writer::start_tag('li', array('class'=>'option'));
+ $option->attributes->name = 'answer';
+ $option->attributes->type = 'radio';
+
+ $labeltext = $option->text;
+ if (!empty($option->attributes->disabled)) {
+ $labeltext .= ' ' . get_string('full', 'choice');
+ $availableoption--;
+ }
+
+ $html .= html_writer::empty_tag('input', (array)$option->attributes);
+ $html .= html_writer::tag('label', $labeltext, array('for'=>$option->attributes->name));
+ $html .= html_writer::end_tag('li');
+ }
+ $html .= html_writer::tag('li','', array('class'=>'clearfloat'));
+ $html .= html_writer::end_tag('ul');
+ $html .= html_writer::tag('div', '', array('class'=>'clearfloat'));
+ $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
+ $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$coursemoduleid));
+
+ if (!empty($options['hascapability']) && ($options['hascapability'])) {
+ if ($availableoption < 1) {
+ $html .= html_writer::tag('label', get_string('choicefull', 'choice'));
+ } else {
+ $html .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('savemychoice','choice'), 'class'=>'button'));
+ }
+
+ if (!empty($options['allowupdate']) && ($options['allowupdate'])) {
+ $url = new moodle_url('view.php', array('id'=>$coursemoduleid, 'action'=>'delchoice', 'sesskey'=>sesskey()));
+ $html .= html_writer::link($url, get_string('removemychoice','choice'));
+ }
+ } else {
+ $html .= html_writer::tag('label', get_string('havetologin', 'choice'));
+ }
+
+ $html .= html_writer::end_tag('ul');
+ $html .= html_writer::end_tag('form');
+
+ return $html;
+ }
+
+ /**
+ * Returns HTML to display choices result
+ * @param object $choices
+ * @param bool $forcepublish
+ * @return string
+ */
+ public function display_result($choices, $forcepublish = false) {
+ global $CFG, $OUTPUT;
+
+ if (empty($forcepublish)) { //alow the publish setting to be overridden
+ $forcepublish = $choices->publish;
+ }
+
+ $displaylayout = $choices->display;
+
+ if ($forcepublish) { //CHOICE_PUBLISH_NAMES
+ return $this->display_publish_name_vertical($choices);
+ } else { //CHOICE_PUBLISH_ANONYMOUS';
+ if ($displaylayout == DISPLAY_HORIZONTAL_LAYOUT) {
+ return $this->display_publish_anonymous_horizontal($choices);
+ }
+ return $this->display_publish_anonymous_vertical($choices);
+ }
+ }
+
+ /**
+ * Returns HTML to display choices result
+ * @param object $choices
+ * @param bool $forcepublish
+ * @return string
+ */
+ public function display_publish_name_vertical($choices) {
+ global $CFG, $OUTPUT, $PAGE;
+
+ $html ='';
+ $html .= html_writer::tag('h2',format_string(get_string("responses", "choice")), array('class'=>'main'));
+
+ $attributes = array('method'=>'POST');
+ $attributes['action'] = $CFG->wwwroot.'/mod/choice/view.php';
+ $attributes['id'] = 'attemptsform';
+
+ if ($choices->viewresponsecapability) {
+ $html .= html_writer::start_tag('form', $attributes);
+ $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $choices->coursemoduleid));
+ $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
+ $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=>'overview'));
+ }
+
+ $table = new html_table();
+ $table->cellpadding = 0;
+ $table->cellspacing = 0;
+ $table->attributes['class'] = 'results names ';
+ $table->tablealign = 'center';
+ $table->data = array();
+
+ $count = 0;
+ ksort($choices->options);
+
+ $columns = array();
+ foreach ($choices->options as $optionid => $options) {
+ $coldata = '';
+ if ($choices->showunanswered && $optionid == 0) {
+ $coldata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option'));
+ } else if ($optionid > 0) {
+ $coldata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class'=>'option'));
+ }
+ $numberofuser = 0;
+ if (!empty($options->user) && count($options->user) > 0) {
+ $numberofuser = count($options->user);
+ }
+
+ $coldata .= html_writer::tag('div', ' ('.$numberofuser. ')', array('class'=>'numberofuser', 'title' => get_string('numberofuser', 'choice')));
+ $columns[] = $coldata;
+ }
+
+ $table->head = $columns;
+
+ $coldata = '';
+ $columns = array();
+ foreach ($choices->options as $optionid => $options) {
+ $coldata = '';
+ if ($choices->showunanswered || $optionid > 0) {
+ if (!empty($options->user)) {
+ foreach ($options->user as $user) {
+ $data = '';
+ if (empty($user->imagealt)){
+ $user->imagealt = '';
+ }
+
+ if ($choices->viewresponsecapability && $choices->deleterepsonsecapability && $optionid > 0) {
+ $attemptaction = html_writer::checkbox('attemptid[]', $user->id,'');
+ $data .= html_writer::tag('div', $attemptaction, array('class'=>'attemptaction'));
+ }
+ $userimage = $OUTPUT->user_picture($user, array('courseid'=>$choices->courseid));
+ $data .= html_writer::tag('div', $userimage, array('class'=>'image'));
+
+ $name = html_writer::tag('a', fullname($user, $choices->fullnamecapability), array('href'=>$CFG->wwwroot . '/user/view.php?id='.$user->id.'&course='.$choices->courseid, 'class'=>'username'));
+ $data .= html_writer::tag('div', $name, array('class'=>'fullname'));
+ $data .= html_writer::tag('div','', array('class'=>'clearfloat'));
+ $coldata .= html_writer::tag('div', $data, array('class'=>'user'));
+ }
+ }
+ }
+
+ $columns[] = $coldata;
+ $count++;
+ }
+
+ $table->data[] = $columns;
+ foreach ($columns as $d) {
+ $table->colclasses[] = 'data';
+ }
+
+ $html .= html_writer::table($table);
+
+ $actiondata = '';
+ if ($choices->viewresponsecapability && $choices->deleterepsonsecapability) {
+ $selecturl = new moodle_url('#');
+
+ $selectallactions = new component_action('click',"select_all_in", array('div',null,'tablecontainer'));
+ $selectall = new action_link($selecturl, get_string('selectall', 'quiz'), $selectallactions);
+ $actiondata .= $OUTPUT->render($selectall) . ' / ';
+
+ $deselectallactions = new component_action('click',"deselect_all_in", array('div',null,'tablecontainer'));
+ $deselectall = new action_link($selecturl, get_string('selectnone', 'quiz'), $deselectallactions);
+ $actiondata .= $OUTPUT->render($deselectall);
+
+ $actiondata .= html_writer::tag('label', ' ' . get_string('withselected', 'quiz') . ' ', array('for'=>'menuaction'));
+
+ $actionurl = new moodle_url($CFG->wwwroot.'/mod/choice/view.php', array('sesskey'=>sesskey(), 'action'=>'delete_confirmation()'));
+ $select = new single_select($actionurl, 'action', array('delete'=>get_string('delete')), null, array(''=>get_string('moveselectedusersto', 'choice')), 'attemptsform');
+
+ $actiondata .= $OUTPUT->render($select);
+ }
+ $html .= html_writer::tag('div', $actiondata, array('class'=>'responseaction'));
+
+ if ($choices->viewresponsecapability) {
+ $html .= html_writer::end_tag('form');
+ }
+
+ return $html;
+ }
+
+
+ /**
+ * Returns HTML to display choices result
+ * @param object $choices
+ * @return string
+ */
+ public function display_publish_anonymous_vertical($choices) {
+ global $CHOICE_COLUMN_HEIGHT, $OUTPUT;
+
+ $html = '';
+ $table = new html_table();
+ $table->cellpadding = 5;
+ $table->cellspacing = 0;
+ $table->attributes['class'] = 'results anonymous ';
+ $table->data = array();
+ $count = 0;
+ ksort($choices->options);
+ $columns = array();
+ $rows = array();
+
+ foreach ($choices->options as $optionid => $options) {
+ $numberofuser = 0;
+ if (!empty($options->user)) {
+ $numberofuser = count($options->user);
+ }
+ $height = 0;
+ $percentageamount = 0;
+ if($choices->numberofuser > 0) {
+ $height = ($CHOICE_COLUMN_HEIGHT * ((float)$numberofuser / (float)$choices->numberofuser));
+ $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
+ }
+
+ $displaydiagram = html_writer::tag('img','', array('style'=>'height:'.$height.'px;width:49px;', 'alt'=>'', 'src'=>$OUTPUT->pix_url('column', 'choice')));
+
+ $cell = new html_table_cell();
+ $cell->text = $displaydiagram;
+ $cell->attributes = array('class'=>'graph vertical data');
+ $columns[] = $cell;
+ }
+ $rowgraph = new html_table_row();
+ $rowgraph->cells = $columns;
+ $rows[] = $rowgraph;
+
+ $columns = array();
+ $printskiplink = true;
+ foreach ($choices->options as $optionid => $options) {
+ $columndata = '';
+ $numberofuser = 0;
+ if (!empty($options->user)) {
+ $numberofuser = count($options->user);
+ }
+
+ if ($printskiplink) {
+ $columndata .= html_writer::tag('div', '', array('class'=>'skip-block-to', 'id'=>'skipresultgraph'));
+ $printskiplink = false;
+ }
+
+ if ($choices->showunanswered && $optionid == 0) {
+ $columndata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option'));
+ } else if ($optionid > 0) {
+ $columndata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class'=>'option'));
+ }
+ $columndata .= html_writer::tag('div', ' ('.$numberofuser.')', array('class'=>'numberofuser', 'title'=> get_string('numberofuser', 'choice')));
+
+ if($choices->numberofuser > 0) {
+ $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
+ }
+ $columndata .= html_writer::tag('div', format_float($percentageamount,1). '%', array('class'=>'percentage'));
+
+ $cell = new html_table_cell();
+ $cell->text = $columndata;
+ $cell->attributes = array('class'=>'data header');
+ $columns[] = $cell;
+ }
+ $rowdata = new html_table_row();
+ $rowdata->cells = $columns;
+ $rows[] = $rowdata;
+
+ $table->data = $rows;
+
+ $header = html_writer::tag('h2',format_string(get_string("responses", "choice")));
+ $html .= html_writer::tag('div', $header, array('class'=>'responseheader'));
+ $html .= html_writer::tag('a', get_string('skipresultgraph', 'choice'), array('href'=>'#skipresultgraph', 'class'=>'skip-block'));
+ $html .= html_writer::table($table);
+
+ return $html;
+ }
+
+ /**
+ * Returns HTML to display choices result
+ * @param object $choices
+ * @return string
+ */
+ public function display_publish_anonymous_horizontal($choices) {
+ global $CHOICE_COLUMN_WIDTH, $OUTPUT;
+
+ $table = new html_table();
+ $table->cellpadding = 5;
+ $table->cellspacing = 0;
+ $table->attributes['class'] = 'results anonymous ';
+ $table->data = array();
+
+ $count = 0;
+ ksort($choices->options);
+
+ $rows = array();
+ foreach ($choices->options as $optionid => $options) {
+ $numberofuser = 0;
+ $graphcell = new html_table_cell();
+ if (!empty($options->user)) {
+ $numberofuser = count($options->user);
+ }
+
+ $width = 0;
+ $percentageamount = 0;
+ $columndata = '';
+ if($choices->numberofuser > 0) {
+ $width = ($CHOICE_COLUMN_WIDTH * ((float)$numberofuser / (float)$choices->numberofuser));
+ $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
+ }
+ $displaydiagram = html_writer::tag('img','', array('style'=>'height:50px; width:'.$width.'px', 'alt'=>'', 'src'=>$OUTPUT->pix_url('row', 'choice')));
+
+ $skiplink = html_writer::tag('a', get_string('skipresultgraph', 'choice'), array('href'=>'#skipresultgraph'. $optionid, 'class'=>'skip-block'));
+ $skiphandler = html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipresultgraph'.$optionid));
+
+ $graphcell->text = $skiplink . $displaydiagram . $skiphandler;
+ $graphcell->attributes = array('class'=>'graph horizontal');
+
+ $datacell = new html_table_cell();
+ if ($choices->showunanswered && $optionid == 0) {
+ $columndata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option'));
+ } else if ($optionid > 0) {
+ $columndata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class'=>'option'));
+ }
+ $columndata .= html_writer::tag('div', ' ('.$numberofuser.')', array('title'=> get_string('numberofuser', 'choice'), 'class'=>'numberofuser'));
+
+ if($choices->numberofuser > 0) {
+ $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
+ }
+ $columndata .= html_writer::tag('div', format_float($percentageamount,1). '%', array('class'=>'percentage'));
+
+ $datacell->text = $columndata;
+ $datacell->attributes = array('class'=>'header');
+
+ $row = new html_table_row();
+ $row->cells = array($datacell, $graphcell);
+ $rows[] = $row;
+ }
+
+ $table->data = $rows;
+
+ $html = '';
+ $header = html_writer::tag('h2',format_string(get_string("responses", "choice")));
+ $html .= html_writer::tag('div', $header, array('class'=>'responseheader'));
+ $html .= html_writer::table($table);
+
+ return $html;
+ }
+}
+
diff --git a/mod/choice/report.php b/mod/choice/report.php
index 48872af657a..fd28a6b7144 100644
--- a/mod/choice/report.php
+++ b/mod/choice/report.php
@@ -215,25 +215,31 @@
}
exit;
}
- choice_show_results($choice, $course, $cm, $users, $format); //show table with students responses.
+ $results = prepare_choice_show_results($choice, $course, $cm, $users);
+ $renderer = $PAGE->get_renderer('mod_choice');
+ echo $renderer->display_result($results, has_capability('mod/choice:readresponses', $context));
+
//now give links for downloading spreadsheets.
if (!empty($users) && has_capability('mod/choice:downloadresponses',$context)) {
- echo "
\n";
- echo "\n";
- echo "| ";
+ $downloadoptions = array();
$options = array();
$options["id"] = "$cm->id";
$options["download"] = "ods";
- echo $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadods"));
- echo " | ";
- $options["download"] = "xls";
- echo $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadexcel"));
- echo " | ";
- $options["download"] = "txt";
- echo $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadtext"));
+ $button = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadods"));
+ $downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
- echo " |
";
+ $options["download"] = "xls";
+ $buttons = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadexcel"));
+ $downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
+
+ $options["download"] = "txt";
+ $button = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadtext"));
+ $downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
+
+ $downloadlist = html_writer::tag('ul', implode('', $downloadoptions));
+ $downloadlist .= html_writer::tag('div', '', array('class'=>'clearfloat'));
+ echo html_writer::tag('div',$downloadlist, array('class'=>'downloadreport'));
}
echo $OUTPUT->footer();
diff --git a/mod/choice/styles.css b/mod/choice/styles.css
index 5cf1ef789d7..425e2ae3c49 100644
--- a/mod/choice/styles.css
+++ b/mod/choice/styles.css
@@ -3,8 +3,52 @@
.path-mod-choice .button {text-align:center;}
.path-mod-choice .attemptcell {width:5px;white-space: nowrap;}
.path-mod-choice .anonymous,
-.path-mod-choice .names {margin-left:auto;margin-right:auto;}
-.path-mod-choice .downloadreport {border-width:0;margin-left:auto;margin-right:auto;}
+.path-mod-choice .names {margin-left:auto;margin-right:auto; width:80%;}
+.path-mod-choice .downloadreport {border-width:0;margin-left:10%;}
.path-mod-choice .choiceresponse {width:100%;}
.path-mod-choice .choiceresponse .picture {width:10px;white-space: nowrap;}
-.path-mod-choice .choiceresponse .fullname {width:100%;white-space: nowrap;}
\ No newline at end of file
+.path-mod-choice .choiceresponse .fullname {width:100%;white-space: nowrap;}
+
+.path-mod-choice .responseheader {width: 100%; text-align: center; margin-top: 10px;}
+.path-mod-choice .choices .option label {vertical-align: top;}
+.path-mod-choice .choices .option input {vertical-align: middle;}
+
+.path-mod-choice .horizontal,
+.path-mod-choice .vertical {margin-left: 10%;margin-right: 10%;}
+.path-mod-choice .horizontal .choices .option {padding-right:20px;display:inline; white-space: normal;}
+.path-mod-choice .horizontal .choices .button {margin-top: 10px;}
+.path-mod-choice ul.choices li {list-style:none;}
+.path-mod-choice .results { text-align: center;}
+.path-mod-choice .results.anonymous .graph.horizontal {vertical-align: middle;text-align: left;}
+
+.path-mod-choice .results.anonymous .graph.vertical,
+.path-mod-choice .cell {vertical-align: bottom; text-align: center; }
+.path-mod-choice .results.names .header{width:10%; white-space: normal;}
+.path-mod-choice .results.names .cell{vertical-align: top; text-align: left;}
+.path-mod-choice .results.names .user,
+.path-mod-choice #yourselection {padding: 5px;}
+.path-mod-choice .results.names .user .attemptaction,
+.path-mod-choice .results.names .user .image,
+.path-mod-choice .results.names .user .fullname{float:left;}
+.path-mod-choice .results.names .user .fullname{padding-left: 5px;}
+.path-mod-choice .results .data.header {width: 20%;}
+.path-mod-choice .responseaction {text-align: center;}
+
+#page-mod-choice-report .downloadreport ul li {list-style:none;padding: 0 20px; display: inline;float: left; }
+.path-mod-choice .clearfloat {float:none; clear:both;}
+
+/**
+ * Overide for RTL layout
+ */
+.path-mod-choice.dir-rtl .horizontal .choices .option {padding-right:0px; padding-left: 20px; float:right;}
+.path-mod-choice.dir-rtl .results.anonymous .graph.horizontal {text-align: right;}
+.path-mod-choice.dir-rtl .results.anonymous { text-align: center; }
+.path-mod-choice.dir-rtl .results.names .cell{text-align: right;}
+.path-mod-choice.dir-rtl .results.names .user .attemptaction,
+.path-mod-choice.dir-rtl .results.names .user .image,
+.path-mod-choice.dir-rtl .results.names .user .fullname,
+.path-mod-choice.dir-rtl .results.names .user .fullname{padding-left: 0px; padding-right: 5px;}
+.path-mod-choice.dir-rtl .downloadreport {margin-left:0;margin-right: 25%;}
+
+#page-mod-choice-report.dir-rtl .downloadreport ul li{float:right;}
+#page-mod-choice-view.dir-rtl .reportlink {text-align: left;}
diff --git a/mod/choice/view.php b/mod/choice/view.php
index 80a78d17a46..9fdc63c89a3 100644
--- a/mod/choice/view.php
+++ b/mod/choice/view.php
@@ -37,7 +37,6 @@
if ($action == 'delchoice' and confirm_sesskey() and is_enrolled($context, NULL, 'mod/choice:choose') and $choice->allowupdate) {
if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) {
- //print_object($answer);
$DB->delete_records('choice_answers', array('id' => $answer->id));
}
}
@@ -95,7 +94,7 @@
//if user has already made a selection, and they are not allowed to update it, show their selected answer.
if (isloggedin() && ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) &&
empty($choice->allowupdate) ) {
- echo $OUTPUT->box(get_string("yourselection", "choice", userdate($choice->timeopen)).": ".format_string(choice_get_option_text($choice, $current->optionid)));
+ echo $OUTPUT->box(get_string("yourselection", "choice", userdate($choice->timeopen)).": ".format_string(choice_get_option_text($choice, $current->optionid)), 'generalbox', 'yourselection');
}
/// Print the form
@@ -115,21 +114,15 @@
if ( (!$current or $choice->allowupdate) and $choiceopen and is_enrolled($context, NULL, 'mod/choice:choose')) {
// They haven't made their choice yet or updates allowed and choice is open
- echo '';
-
+ $options = choice_prepare_options($choice, $USER, $cm, $allresponses);
+ $renderer = $PAGE->get_renderer('mod_choice');
+ echo $renderer->display_options($options, $cm->id, $choice->display);
$choiceformshown = true;
} else {
$choiceformshown = false;
}
-
-
if (!$choiceformshown) {
-
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
if (isguestuser()) {
@@ -153,14 +146,20 @@
}
// print the results at the bottom of the screen
-
if ( $choice->showresults == CHOICE_SHOWRESULTS_ALWAYS or
($choice->showresults == CHOICE_SHOWRESULTS_AFTER_ANSWER and $current ) or
- ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and !$choiceopen ) ) {
+ ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and !$choiceopen )) {
- choice_show_results($choice, $course, $cm, $allresponses); //show table with students responses.
+ if (!empty($choice->showunanswered)) {
+ $choice->option[0] = get_string('notanswered', 'choice');
+ $choice->maxanswers[0] = 0;
+ }
- } else if (!$choiceformshown) {
+ $results = prepare_choice_show_results($choice, $course, $cm, $allresponses);
+ $renderer = $PAGE->get_renderer('mod_choice');
+
+ echo $renderer->display_result($results);
+ } else if (!$choiceformshown) {
echo $OUTPUT->box(get_string('noresultsviewable', 'choice'));
}
diff --git a/theme/base/style/core.css b/theme/base/style/core.css
index 3129fbbe4eb..88b66347be7 100644
--- a/theme/base/style/core.css
+++ b/theme/base/style/core.css
@@ -93,6 +93,7 @@ img.emoticon {vertical-align: middle;width: 15px;height: 15px;}
form.popupform,
form.popupform div {display: inline;}
.arrow_button input {overflow:hidden;}
+
/** IE6 float + background bug solution **/
.ie6 li.section {line-height:1.2em;width:100%;}
@@ -624,7 +625,9 @@ body.tag .managelink {padding: 5px;}
.userenrolment .col_enrol .enrolment {float:left;padding:3px;margin:3px;}
.userenrolment .col_enrol .enrolment a {float:right;margin-left:3px;}
-/** Overide for RTL layout **/
+/**
+* Overide for RTL layout
+**/
.dir-rtl .headermain {float:right;}
.dir-rtl .headermenu {float:left;}
.dir-rtl .breadcrumb {float:right;}
@@ -634,6 +637,9 @@ body.tag .managelink {padding: 5px;}
.dir-rtl .loginbox .loginform .form-label {float:right;text-align:left;}
.dir-rtl .loginbox .loginform .form-input {text-align: right;}
+/**
+ * Backup
+ */
.backup-restore .backup-section {clear:both;border:1px solid #ddd;background-color:#f6f6f6;margin-bottom:1em;}
.backup-restore .backup-section > h2.header {padding:5px 6px;margin:0;border-bottom:1px solid #ddd;}
.backup-restore .backup-section .backup-sub-section {margin:0 25px;background-color:#f9f9f9;border:1px solid #f3f3f3;margin-bottom:1em;}
@@ -652,3 +658,16 @@ body.tag .managelink {padding: 5px;}
.corelightbox {background-color:#CCC;position:absolute;top:0;left:0;width:100%;height:100%;text-align:center;}
.corelightbox img {position:fixed;top:50%;}
+
+/**
+ * IE - Overide for RTL layout
+ */
+.ie.dir-rtl .mform .fitem .felement {margin-right:0;text-align:right;float:right;}
+
+/**
+ * Choice
+ */
+.path-mod-choice .results .option,
+.path-mod-choice .results .numberofuser,
+.path-mod-choice .results .percentage {font-weight: bold; font-size: 108%;}
+
diff --git a/theme/canvas/style/mods.css b/theme/canvas/style/mods.css
index 772de35982a..f59fd8815ba 100644
--- a/theme/canvas/style/mods.css
+++ b/theme/canvas/style/mods.css
@@ -335,21 +335,28 @@
padding: 5px;
}
-.path-mod-choice .header {
+.path-mod-choice .header, .path-mod-choice td {
border-top: 1px solid;
border-color: #ddd;
}
.path-mod-choice .count,
.path-mod-choice .header,
-.path-mod-choice .data {
+.path-mod-choice .data,
+.path-mod-choice .lastcol {
border-right: 1px solid #ddd;
}
-.path-mod-choice .col1 {
+.path-mod-choice .col1, .path-mod-choice .c0,
+.path-mod-choice .lastcol {
border-left: 1px solid #ddd;
}
+.path-mod-choice .lastrow td {
+ border-bottom: 1px solid #ddd;
+ border-top: 1px solid #ddd;
+}
+
.path-mod-choice .count {
border-top: 2px solid #ddd;
background: #f5f5f5;