ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilPollAnswerTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
19  function __construct($a_parent_obj, $a_parent_cmd)
20  {
21  global $ilCtrl, $lng;
22 
23  $this->setId("ilobjpollaw");
24 
25  parent::__construct($a_parent_obj, $a_parent_cmd);
26 
27  $this->addColumn($lng->txt("poll_sortorder"), "pos");
28  $this->addColumn($lng->txt("poll_answer"), "answer");
29  $this->addColumn($lng->txt("poll_absolute"), "votes");
30  $this->addColumn($lng->txt("poll_percentage"), "percentage");
31 
32  $total = $this->getItems();
33 
34  $this->setTitle($this->lng->txt("poll_question").": \"".
35  $a_parent_obj->object->getQuestion()."\"");
36  $this->setDescription(sprintf($lng->txt("poll_population"), $total));
37 
38  if($total)
39  {
40  $this->addCommandButton("confirmDeleteAllVotes", $lng->txt("poll_delete_votes"));
41  }
42 
43  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
44  $this->setRowTemplate("tpl.answer_row.html", "Modules/Poll");
45  $this->setDefaultOrderField("pos");
46  $this->setDefaultOrderDirection("asc");
47 
48  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
49  }
50 
51  public function numericOrdering($a_field)
52  {
53  if($a_field != "answer")
54  {
55  return true;
56  }
57  return false;
58  }
59 
60  function getItems()
61  {
62  $data = $this->parent_obj->object->getAnswers();
63  $perc = $this->parent_obj->object->getVotePercentages();
64  $total = $perc["total"];
65  $perc = $perc["perc"];
66 
67  // add current percentages
68  foreach($data as $idx => $item)
69  {
70  if(!isset($perc[$item["id"]]))
71  {
72  $data[$idx]["percentage"] = 0;
73  $data[$idx]["votes"] = 0;
74  }
75  else
76  {
77  $data[$idx]["percentage"] = round($perc[$item["id"]]["perc"]);
78  $data[$idx]["votes"] = $perc[$item["id"]]["abs"];
79  }
80  }
81 
82  $this->setData($data);
83 
84  return $total;
85  }
86 
87  protected function fillRow($a_set)
88  {
89  $this->tpl->setVariable("VALUE_POS", $a_set["pos"]/10);
90  $this->tpl->setVariable("TXT_ANSWER", nl2br($a_set["answer"]));
91  $this->tpl->setVariable("VALUE_VOTES", $a_set["votes"]);
92  $this->tpl->setVariable("VALUE_PERCENTAGE", $a_set["percentage"]);
93  }
94 
95  protected function fillRowCSV($a_csv, $a_set)
96  {
97  $a_csv->addColumn($a_set["pos"]/10);
98  $a_csv->addColumn($a_set["answer"]);
99  $a_csv->addColumn($a_set["votes"]);
100  $a_csv->addColumn($a_set["percentage"]);
101  $a_csv->addRow();
102  }
103 
104  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
105  {
106  $a_excel->setCell($a_row, 0, $a_set["pos"]/10);
107  $a_excel->setCell($a_row, 1, $a_set["answer"]);
108  $a_excel->setCell($a_row, 2, $a_set["votes"]);
109  $a_excel->setCell($a_row, 3, $a_set["percentage"]."%");
110  }
111 }
112 
113 ?>
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
setDescription($a_val)
Set description.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setExportFormats(array $formats)
Set available export formats.
__construct($a_parent_obj, $a_parent_cmd)
Constructor.
setId($a_val)
Set id.
$total
Definition: Utf8Test.php:87
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
TableGUI class for poll answers.
Class ilTable2GUI.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
setCell($a_row, $a_col, $a_value)
Set cell value.
fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
global $lng
Definition: privfeed.php:17
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.