ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPollBlock.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Block/classes/class.ilCustomBlock.php");
5
13{
17 protected $lng;
18
19
23 public function __construct($a_id = 0)
24 {
25 global $DIC;
26
28 $this->lng = $DIC->language();
29 }
30
31 protected $poll; // [ilObjPoll]
32 protected $answers; // [array]
33 protected $visible; // [bool]
34 protected $active; // [bool]
35
41 public function setRefId($a_id)
42 {
43 include_once "Modules/Poll/classes/class.ilObjPoll.php";
44 $this->poll = new ilObjPoll($a_id, true);
45 $this->answers = $this->poll->getAnswers();
46 }
47
53 public function getPoll()
54 {
55 return $this->poll;
56 }
57
64 public function hasAnyContent($a_user_id, $a_ref_id)
65 {
66 if (!sizeof($this->answers)) {
67 return false;
68 }
69
70 include_once "Modules/Poll/classes/class.ilObjPollAccess.php";
71 $this->active = ilObjPollAccess::_isActivated($a_ref_id);
72 if (!$this->active) {
73 return false;
74 }
75
76 if (!$this->maySeeQuestion($a_user_id) &&
77 !$this->maySeeResults($a_user_id)) {
78 return false;
79 }
80
81 return true;
82 }
83
84 public function maySeeQuestion($a_user_id)
85 {
86 if (!$this->active) {
87 return false;
88 }
89
90 if ($this->poll->hasUserVoted($a_user_id)) {
91 return false;
92 }
93
94 if ($this->poll->getVotingPeriod() &&
95 ($this->poll->getVotingPeriodBegin() > time() ||
96 $this->poll->getVotingPeriodEnd() < time())) {
97 return false;
98 }
99
100 return true;
101 }
102
103 public function mayVote($a_user_id)
104 {
105 return $this->maySeeQuestion($a_user_id) && $a_user_id != ANONYMOUS_USER_ID;
106 }
107
108 public function mayNotResultsYet()
109 {
110 if ($this->poll->getViewResults() == ilObjPoll::VIEW_RESULTS_AFTER_PERIOD &&
111 $this->poll->getVotingPeriod() &&
112 $this->poll->getVotingPeriodEnd() > time()) {
113 return true;
114 }
115 return false;
116 }
117
118 public function maySeeResults($a_user_id)
119 {
120 if (!$this->active) {
121 return false;
122 }
123
124 switch ($this->poll->getViewResults()) {
126 return false;
127
129 // fallthrough
130
131 // #12023 - see mayNotResultsYet()
133 return true;
134
136 if ($this->poll->hasUserVoted($a_user_id)) {
137 return true;
138 }
139 return false;
140 }
141 }
142
143 public function getMessage($a_user_id)
144 {
146
147 if (!sizeof($this->answers)) {
148 return $lng->txt("poll_block_message_no_answers");
149 }
150
151 if (!$this->active) {
152 if (!$this->poll->isOnline()) {
153 return $lng->txt("poll_block_message_offline");
154 }
155 if ($this->poll->getAccessBegin() > time()) {
156 $date = ilDatePresentation::formatDate(new ilDateTime($this->poll->getAccessBegin(), IL_CAL_UNIX));
157 return sprintf($lng->txt("poll_block_message_inactive"), $date);
158 }
159 }
160 }
161
167 public function showResultsAs()
168 {
169 return $this->poll->getShowResultsAs();
170 }
171
176 public function showComments()
177 {
178 return $this->poll->getShowComments();
179 }
180}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
This is the super class of all custom blocks.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static _isActivated($a_ref_id)
Is activated?
Class ilObjPoll.
const VIEW_RESULTS_ALWAYS
const VIEW_RESULTS_AFTER_VOTE
const VIEW_RESULTS_AFTER_PERIOD
const VIEW_RESULTS_NEVER
Custom block for polls.
mayVote($a_user_id)
maySeeResults($a_user_id)
setRefId($a_id)
Set ref id (needed for poll access)
showResultsAs()
Show Results as (Barchart or Piechart)
hasAnyContent($a_user_id, $a_ref_id)
Check if user will see any content (vote/result)
__construct($a_id=0)
Constructor.
showComments()
Are Comments enabled or disabled.
maySeeQuestion($a_user_id)
getPoll()
Get poll object.
getMessage($a_user_id)
const ANONYMOUS_USER_ID
Definition: constants.php:25
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc