ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function __construct($a_parent_obj, $a_parent_cmd)
20  {
21  global $DIC;
22 
23  $this->ctrl = $DIC->ctrl();
24  $this->lng = $DIC->language();
25  $ilCtrl = $DIC->ctrl();
26  $lng = $DIC->language();
27 
28  $this->setId("ilobjpollaw");
29 
30  parent::__construct($a_parent_obj, $a_parent_cmd);
31 
32  $this->addColumn($lng->txt("poll_sortorder"), "pos");
33  $this->addColumn($lng->txt("poll_answer"), "answer");
34  $this->addColumn($lng->txt("poll_absolute"), "votes");
35  $this->addColumn($lng->txt("poll_percentage"), "percentage");
36 
37  $total = $this->getItems();
38 
39  $this->setTitle($this->lng->txt("poll_question") . ": \"" .
40  $a_parent_obj->object->getQuestion() . "\"");
41  $this->setDescription(sprintf($lng->txt("poll_population"), $total));
42 
43  if ($total) {
44  $this->addCommandButton("confirmDeleteAllVotes", $lng->txt("poll_delete_votes"));
45  }
46 
47  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
48  $this->setRowTemplate("tpl.answer_row.html", "Modules/Poll");
49  $this->setDefaultOrderField("pos");
50  $this->setDefaultOrderDirection("asc");
51 
52  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
53  }
54 
55  public function numericOrdering($a_field)
56  {
57  if ($a_field != "answer") {
58  return true;
59  }
60  return false;
61  }
62 
63  public function getItems()
64  {
65  $data = $this->parent_obj->object->getAnswers();
66  $perc = $this->parent_obj->object->getVotePercentages();
67  $total = $perc["total"];
68  $perc = $perc["perc"];
69 
70  // add current percentages
71  foreach ($data as $idx => $item) {
72  if (!isset($perc[$item["id"]])) {
73  $data[$idx]["percentage"] = 0;
74  $data[$idx]["votes"] = 0;
75  } else {
76  $data[$idx]["percentage"] = round($perc[$item["id"]]["perc"]);
77  $data[$idx]["votes"] = $perc[$item["id"]]["abs"];
78  }
79  }
80 
81  $this->setData($data);
82 
83  return $total;
84  }
85 
86  protected function fillRow($a_set)
87  {
88  $this->tpl->setVariable("VALUE_POS", $a_set["pos"] / 10);
89  $this->tpl->setVariable("TXT_ANSWER", nl2br($a_set["answer"]));
90  $this->tpl->setVariable("VALUE_VOTES", $a_set["votes"]);
91  $this->tpl->setVariable("VALUE_PERCENTAGE", $a_set["percentage"]);
92  }
93 
94  protected function fillRowCSV($a_csv, $a_set)
95  {
96  $a_csv->addColumn($a_set["pos"] / 10);
97  $a_csv->addColumn($a_set["answer"]);
98  $a_csv->addColumn($a_set["votes"]);
99  $a_csv->addColumn($a_set["percentage"]);
100  $a_csv->addRow();
101  }
102 
103  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
104  {
105  $a_excel->setCell($a_row, 0, $a_set["pos"] / 10);
106  $a_excel->setCell($a_row, 1, $a_set["answer"]);
107  $a_excel->setCell($a_row, 2, $a_set["votes"]);
108  $a_excel->setCell($a_row, 3, $a_set["percentage"] . "%");
109  }
110 }
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.
global $DIC
Definition: saml.php:7
__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.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
fillRowExcel(ilExcel $a_excel, &$a_row, $a_set)
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
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.