ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilPollResultsHandler Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilPollResultsHandler:

Public Member Functions

 __construct (ilObjPoll $poll, ilPollAnswersHandler $answers)
 
 getOrderedAnswerIds ()
 
 getTotalVotes ()
 
 getAnswerText (int $id)
 
 getAnswerPercentage (int $id)
 
 getAnswerTotal (int $id)
 

Protected Attributes

ilPollAnswersHandler $answers
 
bool $sort_by_votes
 
int $total_votes
 
array $answer_percentages
 
array $answer_totals
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 22 of file class.ilPollResultsHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilPollResultsHandler::__construct ( ilObjPoll  $poll,
ilPollAnswersHandler  $answers 
)

Definition at line 38 of file class.ilPollResultsHandler.php.

References Vendor\Package\$a, $answers, $res, ilObjPoll\getSortResultByVotes(), ilObjPoll\getVotePercentages(), and ILIAS\Repository\int().

41  {
42  $this->sort_by_votes = $poll->getSortResultByVotes();
43  $this->answers = $answers;
44  $res = $poll->getVotePercentages();
45  $this->total_votes = (int) ($res['total'] ?? 0);
46  $res = (array) ($res['perc'] ?? []);
47  $this->answer_percentages = array_map(
48  fn (array $a) => (float) ($a['perc'] ?? 0),
49  $res
50  );
51  $this->answer_totals = array_map(
52  fn (array $a) => (int) ($a['abs'] ?? 0),
53  $res
54  );
55  }
$res
Definition: ltiservices.php:69
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

Member Function Documentation

◆ getAnswerPercentage()

ilPollResultsHandler::getAnswerPercentage ( int  $id)

Definition at line 93 of file class.ilPollResultsHandler.php.

References $id.

Referenced by ilPollResultsRenderer\renderBarChart(), and ilPollResultsRenderer\renderStackedChart().

93  : float
94  {
95  return $this->answer_percentages[$id] ?? 0;
96  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the caller graph for this function:

◆ getAnswerText()

ilPollResultsHandler::getAnswerText ( int  $id)

Definition at line 88 of file class.ilPollResultsHandler.php.

Referenced by ilPollResultsRenderer\renderBarChart(), and ilPollResultsRenderer\renderStackedChart().

88  : string
89  {
90  return $this->answers->getAnswer($id);
91  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the caller graph for this function:

◆ getAnswerTotal()

ilPollResultsHandler::getAnswerTotal ( int  $id)

Definition at line 98 of file class.ilPollResultsHandler.php.

References $id.

Referenced by ilPollResultsRenderer\renderBarChart(), and ilPollResultsRenderer\renderStackedChart().

98  : int
99  {
100  return $this->answer_totals[$id] ?? 0;
101  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the caller graph for this function:

◆ getOrderedAnswerIds()

ilPollResultsHandler::getOrderedAnswerIds ( )
Returns
Generator|int[]

Definition at line 60 of file class.ilPollResultsHandler.php.

References $answer_totals, and $id.

Referenced by ilPollResultsRenderer\renderBarChart(), and ilPollResultsRenderer\renderStackedChart().

60  : Generator
61  {
62  if ($this->sort_by_votes) {
63  $order = $this->answer_totals;
64  arsort($order);
65  $order = array_keys($order);
66 
67  foreach ($this->answers->getAnswers() as $id => $answer) {
68  if (!in_array($id, $order)) {
69  $order[] = $id;
70  }
71  }
72 
73  foreach ($order as $id) {
74  yield $id;
75  }
76  } else {
77  foreach ($this->answers->getAnswers() as $id => $answer) {
78  yield $id;
79  }
80  }
81  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the caller graph for this function:

◆ getTotalVotes()

ilPollResultsHandler::getTotalVotes ( )

Definition at line 83 of file class.ilPollResultsHandler.php.

References $total_votes.

83  : int
84  {
85  return $this->total_votes;
86  }

Field Documentation

◆ $answer_percentages

array ilPollResultsHandler::$answer_percentages
protected

Definition at line 31 of file class.ilPollResultsHandler.php.

◆ $answer_totals

array ilPollResultsHandler::$answer_totals
protected

Definition at line 36 of file class.ilPollResultsHandler.php.

Referenced by getOrderedAnswerIds().

◆ $answers

ilPollAnswersHandler ilPollResultsHandler::$answers
protected

Definition at line 24 of file class.ilPollResultsHandler.php.

Referenced by __construct().

◆ $sort_by_votes

bool ilPollResultsHandler::$sort_by_votes
protected

Definition at line 25 of file class.ilPollResultsHandler.php.

◆ $total_votes

int ilPollResultsHandler::$total_votes
protected

Definition at line 26 of file class.ilPollResultsHandler.php.

Referenced by getTotalVotes().


The documentation for this class was generated from the following file: