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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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

37  {
38  $this->vote_url = $vote_url;
39  $this->vote_cmd = $vote_cmd;
40  $this->answer_limit = $poll->getMaxNumberOfAnswers();
41  $this->poll_id = $poll->getId();
42 
43  $answers = [];
44  foreach ($poll->getAnswers() as $answer) {
45  $id = (int) ($answer['id'] ?? 0);
46  $text = (string) ($answer['answer'] ?? '');
47  $answers[$id] = $text;
48  }
49  $this->answers = $answers;
50  }
$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 77 of file class.ilPollAnswersHandler.php.

References $id.

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

◆ getAnswerLimit()

ilPollAnswersHandler::getAnswerLimit ( )

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

References $answer_limit.

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

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

◆ getAnswerLimitForInfo()

ilPollAnswersHandler::getAnswerLimitForInfo ( )

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

References getAnswerLimit(), getNumberOfAnswers(), and null.

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

◆ getAnswers()

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

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

References $id.

Referenced by ilPollAnswersRenderer\render().

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

◆ getNumberOfAnswers()

ilPollAnswersHandler::getNumberOfAnswers ( )

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

Referenced by getAnswerLimitForInfo().

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

◆ getVoteCommand()

ilPollAnswersHandler::getVoteCommand ( )

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

References $vote_cmd.

Referenced by ilPollAnswersRenderer\render().

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

◆ getVoteURL()

ilPollAnswersHandler::getVoteURL ( )

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

References $vote_url.

Referenced by ilPollAnswersRenderer\render().

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

◆ popLastVoteFromSession()

ilPollAnswersHandler::popLastVoteFromSession ( )

TODO session handling should get its own class.

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

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

Referenced by ilPollAnswersRenderer\render().

55  : ?array
56  {
57  $session_last_poll_vote = ilSession::get('last_poll_vote');
58  if (isset($session_last_poll_vote[$this->poll_id])) {
59  $last_vote = $session_last_poll_vote[$this->poll_id];
60  unset($session_last_poll_vote[$this->poll_id]);
61  ilSession::set('last_poll_vote', $session_last_poll_vote);
62  return $last_vote;
63  }
64  return null;
65  }
static get(string $a_var)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 31 of file class.ilPollAnswersHandler.php.

Referenced by getAnswerLimit().

◆ $answers

array ilPollAnswersHandler::$answers
protected

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

Referenced by __construct().

◆ $poll_id

int ilPollAnswersHandler::$poll_id
protected

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

Referenced by popLastVoteFromSession().

◆ $vote_cmd

string ilPollAnswersHandler::$vote_cmd
protected

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

Referenced by __construct(), and getVoteCommand().

◆ $vote_url

string ilPollAnswersHandler::$vote_url
protected

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

Referenced by __construct(), and getVoteURL().


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