ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilPollAnswersHandler 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 ilPollAnswersHandler:

Public Member Functions

 __construct (ilObjPoll $poll, string $vote_url, string $vote_cmd)
 
 popLastVoteFromSession ()
 TODO session handling should get its own class. More...
 
 getAnswers ()
 
 getAnswer (int $id)
 
 getNumberOfAnswers ()
 
 getAnswerLimitForInfo ()
 
 getAnswerLimit ()
 
 getVoteURL ()
 
 getVoteCommand ()
 

Protected Attributes

string $vote_url
 
string $vote_cmd
 
int $poll_id
 
array $answers
 
int $answer_limit
 

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.ilPollAnswersHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilPollAnswersHandler::__construct ( ilObjPoll  $poll,
string  $vote_url,
string  $vote_cmd 
)

Definition at line 34 of file class.ilPollAnswersHandler.php.

References $answers, $id, $vote_cmd, $vote_url, ilObjPoll\getAnswers(), ilObject\getId(), ilObjPoll\getMaxNumberOfAnswers(), and ILIAS\Repository\int().

38  {
39  $this->vote_url = $vote_url;
40  $this->vote_cmd = $vote_cmd;
41  $this->answer_limit = $poll->getMaxNumberOfAnswers();
42  $this->poll_id = $poll->getId();
43 
44  $answers = [];
45  foreach ($poll->getAnswers() as $answer) {
46  $id = (int) ($answer['id'] ?? 0);
47  $text = (string) ($answer['answer'] ?? '');
48  $answers[$id] = $text;
49  }
50  $this->answers = $answers;
51  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

Member Function Documentation

◆ getAnswer()

ilPollAnswersHandler::getAnswer ( int  $id)

Definition at line 78 of file class.ilPollAnswersHandler.php.

References $id.

78  : string
79  {
80  return (string) ($this->answers[$id] ?? '');
81  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ getAnswerLimit()

ilPollAnswersHandler::getAnswerLimit ( )

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

References $answer_limit.

Referenced by getAnswerLimitForInfo(), and ilPollAnswersRenderer\render().

98  : int
99  {
100  return $this->answer_limit;
101  }
+ Here is the caller graph for this function:

◆ getAnswerLimitForInfo()

ilPollAnswersHandler::getAnswerLimitForInfo ( )

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

References getAnswerLimit(), and getNumberOfAnswers().

88  : ?int
89  {
90  $single_answer = $this->getAnswerLimit() === 1;
91  $below_max = $this->getNumberOfAnswers() > $this->getAnswerLimit();
92  if ($below_max && !$single_answer) {
93  return $this->getAnswerLimit();
94  }
95  return null;
96  }
+ Here is the call graph for this function:

◆ getAnswers()

ilPollAnswersHandler::getAnswers ( )
Returns
Generator|string[]

Definition at line 71 of file class.ilPollAnswersHandler.php.

References $id.

Referenced by ilPollAnswersRenderer\render().

71  : Generator
72  {
73  foreach ($this->answers as $id => $answer) {
74  yield $id => $answer;
75  }
76  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ getNumberOfAnswers()

ilPollAnswersHandler::getNumberOfAnswers ( )

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

Referenced by getAnswerLimitForInfo().

83  : int
84  {
85  return count($this->answers);
86  }
+ Here is the caller graph for this function:

◆ getVoteCommand()

ilPollAnswersHandler::getVoteCommand ( )

Definition at line 108 of file class.ilPollAnswersHandler.php.

References $vote_cmd.

Referenced by ilPollAnswersRenderer\render().

108  : string
109  {
110  return $this->vote_cmd;
111  }
+ Here is the caller graph for this function:

◆ getVoteURL()

ilPollAnswersHandler::getVoteURL ( )

Definition at line 103 of file class.ilPollAnswersHandler.php.

References $vote_url.

Referenced by ilPollAnswersRenderer\render().

103  : string
104  {
105  return $this->vote_url;
106  }
+ Here is the caller graph for this function:

◆ popLastVoteFromSession()

ilPollAnswersHandler::popLastVoteFromSession ( )

TODO session handling should get its own class.

Definition at line 56 of file class.ilPollAnswersHandler.php.

References $poll_id, ilSession\get(), and ilSession\set().

Referenced by ilPollAnswersRenderer\render().

56  : ?array
57  {
58  $session_last_poll_vote = ilSession::get('last_poll_vote');
59  if (isset($session_last_poll_vote[$this->poll_id])) {
60  $last_vote = $session_last_poll_vote[$this->poll_id];
61  unset($session_last_poll_vote[$this->poll_id]);
62  ilSession::set('last_poll_vote', $session_last_poll_vote);
63  return $last_vote;
64  }
65  return null;
66  }
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $answer_limit

int ilPollAnswersHandler::$answer_limit
protected

Definition at line 32 of file class.ilPollAnswersHandler.php.

Referenced by getAnswerLimit().

◆ $answers

array ilPollAnswersHandler::$answers
protected

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

Referenced by __construct().

◆ $poll_id

int ilPollAnswersHandler::$poll_id
protected

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

Referenced by popLastVoteFromSession().

◆ $vote_cmd

string ilPollAnswersHandler::$vote_cmd
protected

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

Referenced by __construct(), and getVoteCommand().

◆ $vote_url

string ilPollAnswersHandler::$vote_url
protected

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

Referenced by __construct(), and getVoteURL().


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