ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilPollResultsHandler Class Reference
+ 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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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

40  {
41  $this->sort_by_votes = $poll->getSortResultByVotes();
42  $this->answers = $answers;
43  $res = $poll->getVotePercentages();
44  $this->total_votes = (int) ($res['total'] ?? 0);
45  $res = (array) ($res['perc'] ?? []);
46  $this->answer_percentages = array_map(
47  fn(array $a) => (float) ($a['perc'] ?? 0),
48  $res
49  );
50  $this->answer_totals = array_map(
51  fn(array $a) => (int) ($a['abs'] ?? 0),
52  $res
53  );
54  }
$res
Definition: ltiservices.php:66
$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 92 of file class.ilPollResultsHandler.php.

References $id.

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

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

◆ getAnswerText()

ilPollResultsHandler::getAnswerText ( int  $id)

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

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

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

◆ getAnswerTotal()

ilPollResultsHandler::getAnswerTotal ( int  $id)

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

References $id.

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

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

◆ getOrderedAnswerIds()

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

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

References $answer_totals, and $id.

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

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

◆ getTotalVotes()

ilPollResultsHandler::getTotalVotes ( )

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

References $total_votes.

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

Field Documentation

◆ $answer_percentages

array ilPollResultsHandler::$answer_percentages
protected

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

◆ $answer_totals

array ilPollResultsHandler::$answer_totals
protected

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

Referenced by getOrderedAnswerIds().

◆ $answers

ilPollAnswersHandler ilPollResultsHandler::$answers
protected

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

Referenced by __construct().

◆ $sort_by_votes

bool ilPollResultsHandler::$sort_by_votes
protected

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

◆ $total_votes

int ilPollResultsHandler::$total_votes
protected

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

Referenced by getTotalVotes().


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