Skip to content

Commit

Permalink
Merge branch 'MDL-30816_m23' of git://github.com/rwijaya/moodle into …
Browse files Browse the repository at this point in the history
…MOODLE_23_STABLE
  • Loading branch information
Sam Hemelryk committed Jul 8, 2012
2 parents aacf322 + a2af7fd commit 9bf1621
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 84 deletions.
7 changes: 5 additions & 2 deletions mod/choice/lang/en/choice.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@
* To facilitate student decision-making, for example allowing students to vote on a direction for the course'; * To facilitate student decision-making, for example allowing students to vote on a direction for the course';
$string['modulename_link'] = 'mod/choice/view'; $string['modulename_link'] = 'mod/choice/view';
$string['modulenameplural'] = 'Choices'; $string['modulenameplural'] = 'Choices';
$string['moveselectedusersto'] = 'Move selected users to...';
$string['mustchooseone'] = 'You must choose an answer before saving. Nothing was saved.'; $string['mustchooseone'] = 'You must choose an answer before saving. Nothing was saved.';
$string['noguestchoose'] = 'Sorry, guests are not allowed to make choices.'; $string['noguestchoose'] = 'Sorry, guests are not allowed to make choices.';
$string['noresultsviewable'] = 'The results are not currently viewable.'; $string['noresultsviewable'] = 'The results are not currently viewable.';
$string['notanswered'] = 'Not answered yet'; $string['notanswered'] = 'Not answered yet';
$string['notenrolledchoose'] = 'Sorry, only enrolled users are allowed to make choices.'; $string['notenrolledchoose'] = 'Sorry, only enrolled users are allowed to make choices.';
$string['notopenyet'] = 'Sorry, this activity is not available until {$a}'; $string['notopenyet'] = 'Sorry, this activity is not available until {$a}';
$string['numberofuser'] = 'The number of user';
$string['numberofuserinpercentage'] = 'The number of user in percentage';
$string['option'] = 'Option'; $string['option'] = 'Option';
$string['page-mod-choice-x'] = 'Any choice module page'; $string['page-mod-choice-x'] = 'Any choice module page';
$string['pluginadministration'] = 'Choice administration'; $string['pluginadministration'] = 'Choice administration';
Expand All @@ -89,6 +92,7 @@
$string['removemychoice'] = 'Remove my choice'; $string['removemychoice'] = 'Remove my choice';
$string['removeresponses'] = 'Remove all responses'; $string['removeresponses'] = 'Remove all responses';
$string['responses'] = 'Responses'; $string['responses'] = 'Responses';
$string['responsesresultgraphheader'] = 'Graph display';
$string['responsesto'] = 'Responses to {$a}'; $string['responsesto'] = 'Responses to {$a}';
$string['savemychoice'] = 'Save my choice'; $string['savemychoice'] = 'Save my choice';
$string['showunanswered'] = 'Show column for unanswered'; $string['showunanswered'] = 'Show column for unanswered';
Expand All @@ -98,7 +102,6 @@
$string['timerestrict'] = 'Restrict answering to this time period'; $string['timerestrict'] = 'Restrict answering to this time period';
$string['viewallresponses'] = 'View {$a} responses'; $string['viewallresponses'] = 'View {$a} responses';
$string['withselected'] = 'With selected'; $string['withselected'] = 'With selected';
$string['userchoosethisoption'] = 'User choose this option';
$string['yourselection'] = 'Your selection'; $string['yourselection'] = 'Your selection';
$string['skipresultgraph'] = 'Skip result graph'; $string['skipresultgraph'] = 'Skip result graph';
$string['moveselectedusersto'] = 'Move selected users to...';
$string['numberofuser'] = 'The number of user';
239 changes: 157 additions & 82 deletions mod/choice/renderer.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -141,36 +141,72 @@ public function display_publish_name_vertical($choices) {
$table->cellspacing = 0; $table->cellspacing = 0;
$table->attributes['class'] = 'results names '; $table->attributes['class'] = 'results names ';
$table->tablealign = 'center'; $table->tablealign = 'center';
$table->summary = get_string('responsesto', 'choice', format_string($choices->name));
$table->data = array(); $table->data = array();


$count = 0; $count = 0;
ksort($choices->options); ksort($choices->options);


$columns = array(); $columns = array();
$celldefault = new html_table_cell();
$celldefault->attributes['class'] = 'data';

// This extra cell is needed in order to support accessibility for screenreader. MDL-30816
$accessiblecell = new html_table_cell();
$accessiblecell->scope = 'row';
$accessiblecell->text = get_string('choiceoptions', 'choice');
$columns['options'][] = $accessiblecell;

$usernumberheader = clone($celldefault);
$usernumberheader->header = true;
$usernumberheader->attributes['class'] = 'header data';
$usernumberheader->text = get_string('numberofuser', 'choice');
$columns['usernumber'][] = $usernumberheader;


foreach ($choices->options as $optionid => $options) { foreach ($choices->options as $optionid => $options) {
$coldata = ''; $celloption = clone($celldefault);
$cellusernumber = clone($celldefault);
$cellusernumber->style = 'text-align: center;';

$celltext = '';
if ($choices->showunanswered && $optionid == 0) { if ($choices->showunanswered && $optionid == 0) {
$coldata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option')); $celltext = format_string(get_string('notanswered', 'choice'));
} else if ($optionid > 0) { } else if ($optionid > 0) {
$coldata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class'=>'option')); $celltext = format_string($choices->options[$optionid]->text);
} }
$numberofuser = 0; $numberofuser = 0;
if (!empty($options->user) && count($options->user) > 0) { if (!empty($options->user) && count($options->user) > 0) {
$numberofuser = count($options->user); $numberofuser = count($options->user);
} }


$coldata .= html_writer::tag('div', ' ('.$numberofuser. ')', array('class'=>'numberofuser', 'title' => get_string('numberofuser', 'choice'))); $celloption->text = $celltext;
$columns[] = $coldata; $cellusernumber->text = $numberofuser;

$columns['options'][] = $celloption;
$columns['usernumber'][] = $cellusernumber;
} }


$table->head = $columns; $table->head = $columns['options'];
$table->data[] = new html_table_row($columns['usernumber']);


$coldata = '';
$columns = array(); $columns = array();

// This extra cell is needed in order to support accessibility for screenreader. MDL-30816
$accessiblecell = new html_table_cell();
$accessiblecell->text = get_string('userchoosethisoption', 'choice');
$accessiblecell->header = true;
$accessiblecell->scope = 'row';
$accessiblecell->attributes['class'] = 'header data';
$columns[] = $accessiblecell;

foreach ($choices->options as $optionid => $options) { foreach ($choices->options as $optionid => $options) {
$coldata = ''; $cell = new html_table_cell();
$cell->attributes['class'] = 'data';

if ($choices->showunanswered || $optionid > 0) { if ($choices->showunanswered || $optionid > 0) {
if (!empty($options->user)) { if (!empty($options->user)) {
$optionusers = '';
foreach ($options->user as $user) { foreach ($options->user as $user) {
$data = ''; $data = '';
if (empty($user->imagealt)){ if (empty($user->imagealt)){
Expand All @@ -188,19 +224,17 @@ public function display_publish_name_vertical($choices) {
$name = html_writer::tag('a', fullname($user, $choices->fullnamecapability), array('href'=>$userlink, 'class'=>'username')); $name = html_writer::tag('a', fullname($user, $choices->fullnamecapability), array('href'=>$userlink, 'class'=>'username'));
$data .= html_writer::tag('div', $name, array('class'=>'fullname')); $data .= html_writer::tag('div', $name, array('class'=>'fullname'));
$data .= html_writer::tag('div','', array('class'=>'clearfloat')); $data .= html_writer::tag('div','', array('class'=>'clearfloat'));
$coldata .= html_writer::tag('div', $data, array('class'=>'user')); $optionusers .= html_writer::tag('div', $data, array('class'=>'user'));
} }
$cell->text = $optionusers;
} }
} }

$columns[] = $cell;
$columns[] = $coldata;
$count++; $count++;
} }
$row = new html_table_row($columns);
$table->data[] = $row;


$table->data[] = $columns;
foreach ($columns as $d) {
$table->colclasses[] = 'data';
}
$html .= html_writer::tag('div', html_writer::table($table), array('class'=>'response')); $html .= html_writer::tag('div', html_writer::table($table), array('class'=>'response'));


$actiondata = ''; $actiondata = '';
Expand Down Expand Up @@ -245,71 +279,88 @@ public function display_publish_anonymous_vertical($choices) {
$table->cellpadding = 5; $table->cellpadding = 5;
$table->cellspacing = 0; $table->cellspacing = 0;
$table->attributes['class'] = 'results anonymous '; $table->attributes['class'] = 'results anonymous ';
$table->summary = get_string('responsesto', 'choice', format_string($choices->name));
$table->data = array(); $table->data = array();

$count = 0; $count = 0;
ksort($choices->options); ksort($choices->options);
$columns = array(); $columns = array();
$rows = array(); $rows = array();


foreach ($choices->options as $optionid => $options) { $headercelldefault = new html_table_cell();
$numberofuser = 0; $headercelldefault->scope = 'row';
if (!empty($options->user)) { $headercelldefault->header = true;
$numberofuser = count($options->user); $headercelldefault->attributes = array('class'=>'header data');

// column header
$tableheader = clone($headercelldefault);
$tableheader->text = html_writer::tag('div', get_string('choiceoptions', 'choice'), array('class' => 'accesshide'));
$rows['header'][] = $tableheader;

// graph row header
$graphheader = clone($headercelldefault);
$graphheader->text = html_writer::tag('div', get_string('responsesresultgraphheader', 'choice'), array('class' => 'accesshide'));
$rows['graph'][] = $graphheader;

// user number row header
$usernumberheader = clone($headercelldefault);
$usernumberheader->text = get_string('numberofuser', 'choice');
$rows['usernumber'][] = $usernumberheader;

// user percentage row header
$userpercentageheader = clone($headercelldefault);
$userpercentageheader->text = get_string('numberofuserinpercentage', 'choice');
$rows['userpercentage'][] = $userpercentageheader;

$contentcelldefault = new html_table_cell();
$contentcelldefault->attributes = array('class'=>'data');

foreach ($choices->options as $optionid => $option) {
// calculate display length
$height = $percentageamount = $numberofuser = 0;
$usernumber = $userpercentage = '';

if (!empty($option->user)) {
$numberofuser = count($option->user);
} }
$height = 0;
$percentageamount = 0;
if($choices->numberofuser > 0) { if($choices->numberofuser > 0) {
$height = ($CHOICE_COLUMN_HEIGHT * ((float)$numberofuser / (float)$choices->numberofuser)); $height = ($CHOICE_COLUMN_HEIGHT * ((float)$numberofuser / (float)$choices->numberofuser));
$percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0; $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
} }


$displaydiagram = html_writer::tag('img','', array('style'=>'height:'.$height.'px;width:49px;', 'alt'=>'', 'src'=>$this->output->pix_url('column', 'choice'))); $displaygraph = html_writer::tag('img','', array('style'=>'height:'.$height.'px;width:49px;', 'alt'=>'', 'src'=>$this->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(); // header
$printskiplink = true; $headercell = clone($contentcelldefault);
foreach ($choices->options as $optionid => $options) { $headercell->text = $option->text;
$columndata = ''; $rows['header'][] = $headercell;
$numberofuser = 0;
if (!empty($options->user)) {
$numberofuser = count($options->user);
}


if ($printskiplink) { // Graph
$columndata .= html_writer::tag('div', '', array('class'=>'skip-block-to', 'id'=>'skipresultgraph')); $graphcell = clone($contentcelldefault);
$printskiplink = false; $graphcell->attributes = array('class'=>'graph vertical data');
} $graphcell->text = $displaygraph;
$rows['graph'][] = $graphcell;


if ($choices->showunanswered && $optionid == 0) { $usernumber .= html_writer::tag('div', ' '.$numberofuser.'', array('class'=>'numberofuser', 'title'=> get_string('numberofuser', 'choice')));
$columndata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option')); $userpercentage .= html_writer::tag('div', format_float($percentageamount,1). '%', array('class'=>'percentage'));
} 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) { // number of user
$percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0; $usernumbercell = clone($contentcelldefault);
} $usernumbercell->text = $usernumber;
$columndata .= html_writer::tag('div', format_float($percentageamount,1). '%', array('class'=>'percentage')); $rows['usernumber'][] = $usernumbercell;


$cell = new html_table_cell(); // percentage of user
$cell->text = $columndata; $numbercell = clone($contentcelldefault);
$cell->attributes = array('class'=>'data header'); $numbercell->text = $userpercentage;
$columns[] = $cell; $rows['userpercentage'][] = $numbercell;
} }
$rowdata = new html_table_row();
$rowdata->cells = $columns;
$rows[] = $rowdata;


$table->data = $rows; $table->head = $rows['header'];
$trgraph = new html_table_row($rows['graph']);
$trusernumber = new html_table_row($rows['usernumber']);
$truserpercentage = new html_table_row($rows['userpercentage']);
$table->data = array($trgraph, $trusernumber, $truserpercentage);


$header = html_writer::tag('h2',format_string(get_string("responses", "choice"))); $header = html_writer::tag('h2',format_string(get_string("responses", "choice")));
$html .= html_writer::tag('div', $header, array('class'=>'responseheader')); $html .= html_writer::tag('div', $header, array('class'=>'responseheader'));
Expand All @@ -331,52 +382,76 @@ public function display_publish_anonymous_horizontal($choices) {
$table->cellpadding = 5; $table->cellpadding = 5;
$table->cellspacing = 0; $table->cellspacing = 0;
$table->attributes['class'] = 'results anonymous '; $table->attributes['class'] = 'results anonymous ';
$table->summary = get_string('responsesto', 'choice', format_string($choices->name));
$table->data = array(); $table->data = array();


$columnheaderdefault = new html_table_cell();
$columnheaderdefault->scope = 'col';

$tableheadertext = clone($columnheaderdefault);
$tableheadertext->text = get_string('choiceoptions', 'choice');

$tableheadernumber = clone($columnheaderdefault);
$tableheadernumber->text = get_string('numberofuser', 'choice');

$tableheaderpercentage = clone($columnheaderdefault);
$tableheaderpercentage->text = get_string('numberofuserinpercentage', 'choice');

$tableheadergraph = clone($columnheaderdefault);
$tableheadergraph->text = get_string('responsesresultgraphheader', 'choice');

$table->head = array($tableheadertext, $tableheadernumber, $tableheaderpercentage, $tableheadergraph);

$count = 0; $count = 0;
ksort($choices->options); ksort($choices->options);


$columndefault = new html_table_cell();
$columndefault->attributes['class'] = 'data';

$colheaderdefault = new html_table_cell();
$colheaderdefault->scope = 'row';
$colheaderdefault->header = true;
$colheaderdefault->attributes['class'] = 'header data';

$rows = array(); $rows = array();
foreach ($choices->options as $optionid => $options) { foreach ($choices->options as $optionid => $options) {
$numberofuser = 0; $colheader = clone($colheaderdefault);
$graphcell = new html_table_cell(); $colheader->text = $options->text;

$graphcell = clone($columndefault);
$datacellnumber = clone($columndefault);
$datacellpercentage = clone($columndefault);

$numberofuser = $width = $percentageamount = 0;

if (!empty($options->user)) { if (!empty($options->user)) {
$numberofuser = count($options->user); $numberofuser = count($options->user);
} }


$width = 0;
$percentageamount = 0;
$columndata = '';
if($choices->numberofuser > 0) { if($choices->numberofuser > 0) {
$width = ($CHOICE_COLUMN_WIDTH * ((float)$numberofuser / (float)$choices->numberofuser)); $width = ($CHOICE_COLUMN_WIDTH * ((float)$numberofuser / (float)$choices->numberofuser));
$percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0; $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
} }
$displaydiagram = html_writer::tag('img','', array('style'=>'height:50px; width:'.$width.'px', 'alt'=>'', 'src'=>$this->output->pix_url('row', 'choice')));


$skiplink = html_writer::tag('a', get_string('skipresultgraph', 'choice'), array('href'=>'#skipresultgraph'. $optionid, 'class'=>'skip-block')); $attributes = array();
$skiphandler = html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipresultgraph'.$optionid)); $attributes['style'] = 'height:50px; width:'.$width.'px';
$attributes['alt'] = '';
$attributes['src'] = $this->output->pix_url('row', 'choice');
$displaydiagram = html_writer::tag('img','', $attributes);


$graphcell->text = $skiplink . $displaydiagram . $skiphandler; $graphcell->text = $displaydiagram;
$graphcell->attributes = array('class'=>'graph horizontal'); $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) { if($choices->numberofuser > 0) {
$percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0; $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
} }
$columndata .= html_writer::tag('div', format_float($percentageamount,1). '%', array('class'=>'percentage'));


$datacell->text = $columndata; $datacellnumber->text = $numberofuser;
$datacell->attributes = array('class'=>'header'); $datacellpercentage->text = format_float($percentageamount,1). '%';



$row = new html_table_row(); $row = new html_table_row();
$row->cells = array($datacell, $graphcell); $row->cells = array($colheader, $datacellnumber, $datacellpercentage, $graphcell);
$rows[] = $row; $rows[] = $row;
} }


Expand Down
2 changes: 2 additions & 0 deletions mod/choice/styles.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@


.path-mod-choice .results.anonymous .graph.vertical, .path-mod-choice .results.anonymous .graph.vertical,
.path-mod-choice .cell {vertical-align: bottom; text-align: center; } .path-mod-choice .cell {vertical-align: bottom; text-align: center; }
.path-mod-choice .results.anonymous th.header {border: 1px solid inherit;}

.path-mod-choice .results.names .header{width:10%; white-space: normal;} .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 .cell{vertical-align: top; text-align: left;}
.path-mod-choice .results.names .user, .path-mod-choice .results.names .user,
Expand Down

0 comments on commit 9bf1621

Please sign in to comment.