5 include_once(
"./Services/Block/classes/class.ilBlockGUI.php");
6 include_once(
"./Modules/Poll/classes/class.ilObjPoll.php");
34 $lng->loadLanguageModule(
"poll");
65 return "ilobjpollgui";
82 $this->poll_block = $a_block;
92 $next_class = $ilCtrl->getNextClass();
93 $cmd = $ilCtrl->getCmd(
"getHTML");
109 $mess = $this->poll_block->getMessage($ilUser->getId());
112 $this->tpl->setVariable(
"TXT_QUESTION", $mess);
122 if($this->poll_block->mayVote($ilUser->getId()))
124 $this->tpl->setCurrentBlock(
"mode_info_bl");
125 if($this->poll_block->getPoll()->getNonAnonymous())
127 $mode_info = $lng->txt(
"poll_non_anonymous_warning");
131 $mode_info = $lng->txt(
"poll_anonymous_warning");
133 $this->tpl->setVariable(
"MODE_INFO", $mode_info);
134 $this->tpl->parseCurrentBlock();
136 $is_multi_answer = ($this->poll_block->getPoll()->getMaxNumberOfAnswers() > 1);
138 if(isset(
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()]))
140 $last_vote =
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()];
141 unset(
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()]);
145 $error = sprintf($lng->txt(
"poll_vote_error_multi"),
146 $this->poll_block->getPoll()->getMaxNumberOfAnswers());
150 $error = $lng->txt(
"poll_vote_error_single");
153 $this->tpl->setCurrentBlock(
"error_bl");
154 $this->tpl->setVariable(
"FORM_ERROR", $error);
155 $this->tpl->parseCurrentBlock();
158 $this->tpl->setCurrentBlock(
"answer");
159 foreach($a_poll->getAnswers() as $item)
161 if(!$is_multi_answer)
163 $this->tpl->setVariable(
"ANSWER_INPUT",
"radio");
164 $this->tpl->setVariable(
"ANSWER_NAME",
"aw");
168 $this->tpl->setVariable(
"ANSWER_INPUT",
"checkbox");
169 $this->tpl->setVariable(
"ANSWER_NAME",
"aw[]");
171 if(is_array($last_vote) && in_array($item[
"id"], $last_vote))
173 $this->tpl->setVariable(
"ANSWER_STATUS",
'checked="checked"');
176 $this->tpl->setVariable(
"VALUE_ANSWER", $item[
"id"]);
177 $this->tpl->setVariable(
"TXT_ANSWER_VOTE", nl2br($item[
"answer"]));
178 $this->tpl->parseCurrentBlock();
187 $url .=
"#poll".$a_poll->getID();
189 $this->tpl->setVariable(
"URL_FORM", $url);
190 $this->tpl->setVariable(
"CMD_FORM",
"vote");
191 $this->tpl->setVariable(
"TXT_SUBMIT", $lng->txt(
"poll_vote"));
193 if($this->poll_block->getPoll()->getVotingPeriod())
195 $this->tpl->setVariable(
"TXT_VOTING_PERIOD",
196 sprintf($lng->txt(
"poll_voting_period_info"),
203 if ($this->poll_block->maySeeResults($ilUser->getId()))
205 if (!$this->poll_block->mayNotResultsYet($ilUser->getId()))
208 foreach ($a_poll->getAnswers() as $item)
210 $answers[$item[
"id"]] = $item[
"answer"];
213 $perc = $this->poll_block->getPoll()->getVotePercentages();
215 $perc = $perc[
"perc"];
217 $this->tpl->setVariable(
"TOTAL_ANSWERS", sprintf($lng->txt(
"poll_population"),
$total));
222 if ($this->poll_block->getPoll()->getSortResultByVotes())
226 foreach (array_keys($answers) as $answer_id)
228 if (!in_array($answer_id, $order))
230 $order[] = $answer_id;
236 $order = array_keys($answers);
243 include_once(
"./Services/Chart/classes/class.ilChart.php");
246 $chart->setSize(
"100%", 200);
247 $chart->setAutoResize(
true);
249 $chart_data = $chart->getDataInstance();
251 foreach ($order as $answer_id)
253 $chart_data->addPoint(
254 round($perc[$answer_id][
"perc"]),
255 nl2br($answers[$answer_id])
262 $chart->addData($chart_data);
264 $pie_legend_id =
"poll_legend_".$this->getRefId();
266 $legend->setContainer($pie_legend_id);
267 $chart->setLegend($legend);
269 $this->tpl->setVariable(
"PIE_LEGEND_ID", $pie_legend_id);
270 $this->tpl->setVariable(
"PIE_CHART", $chart->getHTML());
275 include_once
"Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
277 $this->tpl->setCurrentBlock(
"answer_result");
278 foreach ($order as $answer_id)
281 $pbar->setCurrent(round($perc[$answer_id][
"perc"]));
282 $this->tpl->setVariable(
"PERC_ANSWER_RESULT", $pbar->render());
283 $this->tpl->setVariable(
"TXT_ANSWER_RESULT", nl2br($answers[$answer_id]));
284 $this->tpl->parseCurrentBlock();
293 $end = $this->poll_block->getPoll()->getVotingPeriodEnd();
299 if($this->poll_block->getPoll()->hasUserVoted($ilUser->getId()))
301 $info .= $lng->txt(
"poll_block_message_already_voted").
" ";
304 $this->tpl->setVariable(
"TOTAL_ANSWERS", $info.
305 sprintf($lng->txt(
"poll_block_results_available_on"), $end));
308 else if($this->poll_block->getPoll()->hasUserVoted($ilUser->getId()))
310 $this->tpl->setVariable(
"TOTAL_ANSWERS", $lng->txt(
"poll_block_message_already_voted"));
315 $this->tpl->setVariable(
"ANCHOR_ID", $a_poll->getID());
316 $this->tpl->setVariable(
"TXT_QUESTION", nl2br(trim($a_poll->getQuestion())));
318 $desc = trim($a_poll->getDescription());
321 $this->tpl->setVariable(
"TXT_DESC", nl2br($desc));
324 $img = $a_poll->getImageFullPath();
327 $this->tpl->setVariable(
"URL_IMAGE",
$img);
330 if ($this->poll_block->showComments()) {
331 $this->tpl->setCurrentBlock(
"comment_link");
332 $this->tpl->setVariable(
"LANG_COMMENTS", $lng->txt(
'poll_comments'));
333 $this->tpl->setVariable(
"COMMENT_JSCALL", $this->
commentJSCall());
334 $this->tpl->setVariable(
"COMMENTS_COUNT_ID", $this->
getRefId());
338 if($comments_count > 0)
340 $this->tpl->setVariable(
"COMMENTS_COUNT",
"(".$comments_count.
")");
345 $redraw_url = $ilCtrl->getLinkTarget($this,
"getNumberOfCommentsForRedraw",
347 $this->tpl->setVariable(
"COMMENTS_REDRAW_URL", $redraw_url);
349 $tpl->addJavaScript(
"Modules/Poll/js/ilPoll.js");
350 self::$js_init =
true;
363 $this->poll_block->setRefId($this->
getRefId());
364 $this->may_write = $ilAccess->checkAccess(
"write",
"", $this->
getRefId());
365 $this->has_content = $this->poll_block->hasAnyContent($ilUser->getId(), $this->
getRefId());
367 if(!$this->may_write && !$this->has_content)
372 $poll_obj = $this->poll_block->getPoll();
373 $this->
setTitle($poll_obj->getTitle());
374 $this->
setData(array($poll_obj));
379 if(!$this->poll_block->getMessage($ilUser->getId()))
382 include_once
"./Services/Notification/classes/class.ilNotification.php";
388 $lng->txt(
"poll_notification_unsubscribe"));
395 $lng->txt(
"poll_notification_subscribe"));
399 if ($this->may_write)
405 $lng->txt(
"edit_content"));
409 $lng->txt(
"settings"));
439 include_once(
"./Services/Notes/classes/class.ilNoteGUI.php");
440 include_once(
"./Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
450 $jsCall =
$comment->getListCommentsJSCall($ajaxHash,
"ilPoll.redrawComments(".$refId.
");");
464 echo
"(".$number.
")";
482 include_once(
"./Services/Notes/classes/class.ilNote.php");
487 if(count($number) == 0)