ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_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 
27  parent::__construct($a_id);
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->mayVote($a_user_id) &&
77  !$this->maySeeResults($a_user_id)) {
78  return false;
79  }
80 
81  return true;
82  }
83 
84  public function mayVote($a_user_id)
85  {
86  if (!$this->active) {
87  return false;
88  }
89 
90  if ($a_user_id == ANONYMOUS_USER_ID) {
91  return false;
92  }
93 
94  if ($this->poll->hasUserVoted($a_user_id)) {
95  return false;
96  }
97 
98  if ($this->poll->getVotingPeriod() &&
99  ($this->poll->getVotingPeriodBegin() > time() ||
100  $this->poll->getVotingPeriodEnd() < time())) {
101  return false;
102  }
103 
104  return true;
105  }
106 
107  public function mayNotResultsYet()
108  {
109  if ($this->poll->getViewResults() == ilObjPoll::VIEW_RESULTS_AFTER_PERIOD &&
110  $this->poll->getVotingPeriod() &&
111  $this->poll->getVotingPeriodEnd() > time()) {
112  return true;
113  }
114  return false;
115  }
116 
117  public function maySeeResults($a_user_id)
118  {
119  if (!$this->active) {
120  return false;
121  }
122 
123  switch ($this->poll->getViewResults()) {
125  return false;
126 
128  // fallthrough
129 
130  // #12023 - see mayNotResultsYet()
132  return true;
133 
135  if ($this->poll->hasUserVoted($a_user_id)) {
136  return true;
137  }
138  return false;
139  }
140  }
141 
142  public function getMessage($a_user_id)
143  {
144  $lng = $this->lng;
145 
146  if (!sizeof($this->answers)) {
147  return $lng->txt("poll_block_message_no_answers");
148  }
149 
150  if (!$this->active) {
151  if (!$this->poll->isOnline()) {
152  return $lng->txt("poll_block_message_offline");
153  }
154  if ($this->poll->getAccessBegin() > time()) {
155  $date = ilDatePresentation::formatDate(new ilDateTime($this->poll->getAccessBegin(), IL_CAL_UNIX));
156  return sprintf($lng->txt("poll_block_message_inactive"), $date);
157  }
158  }
159  }
160 
166  public function showResultsAs()
167  {
168  return $this->poll->getShowResultsAs();
169  }
170 
175  public function showComments()
176  {
177  return $this->poll->getShowComments();
178  }
179 }
const VIEW_RESULTS_AFTER_PERIOD
showComments()
Are Comments enabled or disabled.
const VIEW_RESULTS_AFTER_VOTE
const VIEW_RESULTS_NEVER
global $DIC
Definition: saml.php:7
getMessage($a_user_id)
const VIEW_RESULTS_ALWAYS
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
static _isActivated($a_ref_id)
Is activated?
getPoll()
Get poll object.
mayVote($a_user_id)
setRefId($a_id)
Set ref id (needed for poll access)
const IL_CAL_UNIX
showResultsAs()
Show Results as (Barchart or Piechart)
Date and time handling
This is the super class of all custom blocks.
Class ilObjPoll.
Custom block for polls.
maySeeResults($a_user_id)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
hasAnyContent($a_user_id, $a_ref_id)
Check if user will see any content (vote/result)
__construct($a_id=0)
Constructor.