ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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.

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

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

+ 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.

77 : string
78 {
79 return (string) ($this->answers[$id] ?? '');
80 }

References $id.

◆ getAnswerLimit()

ilPollAnswersHandler::getAnswerLimit ( )

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

97 : int
98 {
100 }

References $answer_limit.

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

+ Here is the caller graph for this function:

◆ getAnswerLimitForInfo()

ilPollAnswersHandler::getAnswerLimitForInfo ( )

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

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 }

References getAnswerLimit(), and getNumberOfAnswers().

+ Here is the call graph for this function:

◆ getAnswers()

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

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

70 : Generator
71 {
72 foreach ($this->answers as $id => $answer) {
73 yield $id => $answer;
74 }
75 }

References $id.

◆ getNumberOfAnswers()

ilPollAnswersHandler::getNumberOfAnswers ( )

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

82 : int
83 {
84 return count($this->answers);
85 }

Referenced by getAnswerLimitForInfo().

+ Here is the caller graph for this function:

◆ getVoteCommand()

ilPollAnswersHandler::getVoteCommand ( )

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

107 : string
108 {
109 return $this->vote_cmd;
110 }

References $vote_cmd.

◆ getVoteURL()

ilPollAnswersHandler::getVoteURL ( )

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

102 : string
103 {
104 return $this->vote_url;
105 }

References $vote_url.

◆ popLastVoteFromSession()

ilPollAnswersHandler::popLastVoteFromSession ( )

TODO session handling should get its own class.

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

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)
static set(string $a_var, $a_val)
Set a value.

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

+ Here is the call 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: