ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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->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  {
145  $lng = $this->lng;
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 }
maySeeQuestion($a_user_id)
const VIEW_RESULTS_AFTER_PERIOD
showComments()
Are Comments enabled or disabled.
const VIEW_RESULTS_AFTER_VOTE
const VIEW_RESULTS_NEVER
const ANONYMOUS_USER_ID
Definition: constants.php:25
getMessage($a_user_id)
const VIEW_RESULTS_ALWAYS
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
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
showResultsAs()
Show Results as (Barchart or Piechart)
global $DIC
Definition: goto.php:24
This is the super class of all custom blocks.
Class ilObjPoll.
Custom block for polls.
__construct(Container $dic, ilPlugin $plugin)
maySeeResults($a_user_id)
hasAnyContent($a_user_id, $a_ref_id)
Check if user will see any content (vote/result)
__construct($a_id=0)
Constructor.