5 include_once(
"./Services/Block/classes/class.ilBlockGUI.php");
6 include_once(
"./Modules/Poll/classes/class.ilObjPoll.php");
32 $this->lng = $DIC->language();
33 $this->ctrl = $DIC->ctrl();
34 $this->
user = $DIC->user();
35 $this->access = $DIC->access();
36 $lng = $DIC->language();
38 parent::__construct();
40 $lng->loadLanguageModule(
"poll");
51 return self::$block_type;
71 return "ilobjpollgui";
88 $this->poll_block = $a_block;
98 $next_class =
$ilCtrl->getNextClass();
99 $cmd =
$ilCtrl->getCmd(
"getHTML");
101 switch ($next_class) {
103 return $this->$cmd();
117 $mess = $this->poll_block->getMessage(
$ilUser->getId());
119 $this->tpl->setVariable(
"TXT_QUESTION", $mess);
128 if ($this->poll_block->mayVote(
$ilUser->getId())) {
129 $this->tpl->setCurrentBlock(
"mode_info_bl");
130 if ($this->poll_block->getPoll()->getNonAnonymous()) {
131 $mode_info =
$lng->txt(
"poll_non_anonymous_warning");
133 $mode_info =
$lng->txt(
"poll_anonymous_warning");
135 $this->tpl->setVariable(
"MODE_INFO", $mode_info);
136 $this->tpl->parseCurrentBlock();
138 $is_multi_answer = ($this->poll_block->getPoll()->getMaxNumberOfAnswers() > 1);
140 if (isset(
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()])) {
141 $last_vote =
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()];
142 unset(
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()]);
144 if ($is_multi_answer) {
146 $lng->txt(
"poll_vote_error_multi"),
147 $this->poll_block->getPoll()->getMaxNumberOfAnswers()
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) {
160 if (!$is_multi_answer) {
161 $this->tpl->setVariable(
"ANSWER_INPUT",
"radio");
162 $this->tpl->setVariable(
"ANSWER_NAME",
"aw");
164 $this->tpl->setVariable(
"ANSWER_INPUT",
"checkbox");
165 $this->tpl->setVariable(
"ANSWER_NAME",
"aw[]");
167 if (is_array($last_vote) && in_array($item[
"id"], $last_vote)) {
168 $this->tpl->setVariable(
"ANSWER_STATUS",
'checked="checked"');
171 $this->tpl->setVariable(
"VALUE_ANSWER", $item[
"id"]);
172 $this->tpl->setVariable(
"TXT_ANSWER_VOTE", nl2br($item[
"answer"]));
173 $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()) {
194 $this->tpl->setVariable(
195 "TXT_VOTING_END_PERIOD",
197 $lng->txt(
"poll_voting_period_info"),
206 if ($this->poll_block->maySeeResults(
$ilUser->getId())) {
207 if (!$this->poll_block->mayNotResultsYet(
$ilUser->getId())) {
209 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));
221 if ($this->poll_block->getPoll()->getSortResultByVotes()) {
224 foreach (array_keys($answers) as $answer_id) {
225 if (!in_array($answer_id, $order)) {
226 $order[] = $answer_id;
230 $order = array_keys($answers);
235 include_once(
"./Services/Chart/classes/class.ilChart.php");
238 $chart->setSize(
"100%", 200);
239 $chart->setAutoResize(
true);
241 $chart_data =
$chart->getDataInstance();
243 foreach ($order as $answer_id) {
244 $chart_data->addPoint(
245 round($perc[$answer_id][
"perc"]),
246 nl2br($answers[$answer_id])
253 $chart->addData($chart_data);
255 $pie_legend_id =
"poll_legend_" . $this->
getRefId();
257 $legend->setContainer($pie_legend_id);
260 $this->tpl->setVariable(
"PIE_LEGEND_ID", $pie_legend_id);
261 $this->tpl->setVariable(
"PIE_CHART",
$chart->getHTML());
265 include_once
"Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
267 $this->tpl->setCurrentBlock(
"answer_result");
268 foreach ($order as $answer_id) {
270 $pbar->setCurrent(round($perc[$answer_id][
"perc"]));
271 $this->tpl->setVariable(
"PERC_ANSWER_RESULT", $pbar->render());
272 $this->tpl->setVariable(
"TXT_ANSWER_RESULT", nl2br($answers[$answer_id]));
273 $this->tpl->parseCurrentBlock();
280 $end = $this->poll_block->getPoll()->getVotingPeriodEnd();
286 if ($this->poll_block->getPoll()->hasUserVoted(
$ilUser->getId())) {
287 $info .=
$lng->txt(
"poll_block_message_already_voted") .
" ";
290 $this->tpl->setVariable(
"TOTAL_ANSWERS",
$info .
291 sprintf(
$lng->txt(
"poll_block_results_available_on"),
$end));
293 } elseif ($this->poll_block->getPoll()->hasUserVoted(
$ilUser->getId())) {
294 $this->tpl->setVariable(
"TOTAL_ANSWERS",
$lng->txt(
"poll_block_message_already_voted"));
298 if (!$this->poll_block->mayVote(
$ilUser->getId()) && !$this->poll_block->getPoll()->hasUserVoted(
$ilUser->getId())) {
299 if ($this->poll_block->getPoll()->getVotingPeriod()) {
300 $this->tpl->setVariable(
303 $lng->txt(
"poll_voting_period_full_info"),
310 $this->tpl->setVariable(
"TXT_QUESTION", nl2br(trim($a_poll->getQuestion())));
312 $img = $a_poll->getImageFullPath();
314 require_once(
'./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
320 $this->tpl->setVariable(
"ANCHOR_ID", $a_poll->getID());
323 $desc = trim($a_poll->getDescription());
325 $this->tpl->setVariable(
"TXT_DESC", nl2br($desc));
329 if ($this->poll_block->showComments()) {
330 $this->tpl->setCurrentBlock(
"comment_link");
331 $this->tpl->setVariable(
"LANG_COMMENTS",
$lng->txt(
'poll_comments'));
332 $this->tpl->setVariable(
"COMMENT_JSCALL", $this->
commentJSCall());
333 $this->tpl->setVariable(
"COMMENTS_COUNT_ID", $this->
getRefId());
337 if ($comments_count > 0) {
338 $this->tpl->setVariable(
"COMMENTS_COUNT",
"(" . $comments_count .
")");
341 if (!self::$js_init) {
342 $redraw_url =
$ilCtrl->getLinkTarget(
344 "getNumberOfCommentsForRedraw",
349 $this->tpl->setVariable(
"COMMENTS_REDRAW_URL", $redraw_url);
351 $tpl->addJavaScript(
"Modules/Poll/js/ilPoll.js");
352 self::$js_init =
true;
367 $this->poll_block->setRefId($this->
getRefId());
368 $this->may_write = $ilAccess->checkAccess(
"write",
"", $this->
getRefId());
369 $this->has_content = $this->poll_block->hasAnyContent(
$ilUser->getId(), $this->
getRefId());
371 #22078 and 22079 it always contains something. 377 $poll_obj = $this->poll_block->getPoll();
378 $this->
setTitle($poll_obj->getTitle());
387 if (!$this->poll_block->getMessage(
$ilUser->getId())) {
389 include_once
"./Services/Notification/classes/class.ilNotification.php";
396 $lng->txt(
"poll_notification_unsubscribe")
404 $lng->txt(
"poll_notification_subscribe")
409 if ($this->may_write) {
416 $lng->txt(
"edit_content")
423 $lng->txt(
"settings")
444 return parent::getHTML();
454 include_once(
"./Services/Notes/classes/class.ilNoteGUI.php");
455 include_once(
"./Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
469 $jsCall =
$comment->getListCommentsJSCall($ajaxHash,
"ilPoll.redrawComments(" . $refId .
");");
482 echo
"(" . $number .
")";
498 include_once(
"./Services/Notes/classes/class.ilNote.php");
503 if (count($number) == 0) {
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
executeCommand()
execute command
static hasNotification($type, $user_id, $id)
Check notification status for object and user.
commentJSCall()
Builds JavaScript Call to open CommentLayer via html link.
static _countNotesAndComments($a_rep_obj_id, $a_sub_obj_id=null)
Get all notes related to a specific object.
getNumberOfComments($ref_id)
Get comment count.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
const SHOW_RESULTS_AS_PIECHART
getRepositoryObjectGUIName()
Get repository object GUI name.
static _lookupObjectId($a_ref_id)
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
getHTML()
Get block HTML code.
static getBlockType()
Get block type.
static getInstance()
Factory.
setTitle($a_title)
Set Title.
static buildAjaxHash($a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type=null, $a_sub_id=null)
Build ajax hash.
setBlockId($a_block_id=0)
Set Block Id.
setData($a_data)
Set Data.
static signFile($path_to_file)
Create styles array
The data for the language used.
addBlockCommand( $a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
static isRepositoryObject()
Is block of repository object?
getRefId()
Get Ref Id (only used if isRepositoryObject() is true).
BlockGUI class for polls.
getNumberOfCommentsForRedraw()
Returns comment count for JS Redraw.
This class represents a block method of a block.
__construct()
Constructor.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
static getScreenMode()
Get Screen Mode for current command.
static getInstanceByType($a_type, $a_id)
Get type instance.
setBlock($a_block)
Do most of the initialisation.