ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilPollAnswersRenderer Class Reference
+ Collaboration diagram for ilPollAnswersRenderer:

Public Member Functions

 __construct (ilLanguage $lng, Refinery $refinery)
 
 render (ilTemplate $tpl, ilPollAnswersHandler $answers, bool $disable_input)
 

Protected Member Functions

 renderAnswer (ilTemplate $tpl, int $id, string $answer, ?array $last_vote, bool $single_answer, bool $disable_input)
 

Protected Attributes

ilLanguage $lng
 
Refinery $refinery
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilPollAnswersRenderer::__construct ( ilLanguage  $lng,
Refinery  $refinery 
)

Definition at line 28 of file class.ilPollAnswersRenderer.php.

References $lng, $refinery, ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

Member Function Documentation

◆ render()

ilPollAnswersRenderer::render ( ilTemplate  $tpl,
ilPollAnswersHandler  $answers,
bool  $disable_input 
)

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

References $id, ilPollAnswersHandler\getAnswerLimit(), ilPollAnswersHandler\getAnswers(), ilPollAnswersHandler\getVoteCommand(), ilPollAnswersHandler\getVoteURL(), ILIAS\Repository\lng(), ilTemplate\parseCurrentBlock(), ilPollAnswersHandler\popLastVoteFromSession(), renderAnswer(), ilTemplate\setCurrentBlock(), and HTML_Template_IT\setVariable().

40  : void {
41  $single_answer = ($answers->getAnswerLimit() === 1);
42 
43  if (!is_null($last_vote = $answers->popLastVoteFromSession())) {
44  if (!$single_answer && empty($last_vote)) {
45  $error = $this->lng->txt("poll_vote_error_multi_no_answer");
46  } elseif (!$single_answer) {
47  $error = sprintf(
48  $this->lng->txt("poll_vote_error_multi"),
49  $answers->getAnswerLimit()
50  );
51  } else {
52  $error = $this->lng->txt("poll_vote_error_single");
53  }
54 
55  $tpl->setCurrentBlock("error_bl");
56  $tpl->setVariable("FORM_ERROR", $error);
57  $tpl->parseCurrentBlock();
58  }
59 
60  $tpl->setCurrentBlock('answer');
61  foreach ($answers->getAnswers() as $id => $answer) {
62  $this->renderAnswer(
63  $tpl,
64  $id,
65  $answer,
66  $last_vote,
67  $single_answer,
68  $disable_input
69  );
70  }
71 
72  if (!$disable_input) {
73  $tpl->setVariable("URL_FORM", $answers->getVoteURL());
74  $tpl->setVariable("CMD_FORM", $answers->getVoteCommand());
75  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("poll_vote"));
76  }
77  }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
renderAnswer(ilTemplate $tpl, int $id, string $answer, ?array $last_vote, bool $single_answer, bool $disable_input)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
popLastVoteFromSession()
TODO session handling should get its own class.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ renderAnswer()

ilPollAnswersRenderer::renderAnswer ( ilTemplate  $tpl,
int  $id,
string  $answer,
?array  $last_vote,
bool  $single_answer,
bool  $disable_input 
)
protected

Definition at line 79 of file class.ilPollAnswersRenderer.php.

References ilTemplate\parseCurrentBlock(), ILIAS\Repository\refinery(), and HTML_Template_IT\setVariable().

Referenced by render().

86  : void {
87  if ($single_answer) {
88  $tpl->setVariable("ANSWER_INPUT", "radio");
89  $tpl->setVariable("ANSWER_NAME", "aw");
90  } else {
91  $tpl->setVariable("ANSWER_INPUT", "checkbox");
92  $tpl->setVariable("ANSWER_NAME", "aw[]");
93 
94  $status = [];
95  if (!empty($last_vote) && is_array($last_vote) && in_array($id, $last_vote)) {
96  $status[] = 'checked="checked"';
97  }
98  if ($disable_input) {
99  $status[] = 'disabled';
100  }
101  if ($status) {
102  $tpl->setVariable("ANSWER_STATUS", implode(' ', $status));
103  }
104  }
105  $tpl->setVariable("VALUE_ANSWER", $id);
106  $tpl->setVariable(
107  "TXT_ANSWER_VOTE",
108  $this->refinery->encode()->htmlSpecialCharsAsEntities()->transform(nl2br($answer))
109  );
110  $tpl->parseCurrentBlock();
111  }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $lng

ilLanguage ilPollAnswersRenderer::$lng
protected

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

Referenced by __construct().

◆ $refinery

Refinery ilPollAnswersRenderer::$refinery
protected

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

Referenced by __construct().


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