ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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 {
14  protected $poll; // [ilObjPoll]
15  protected $answers; // [array]
16  protected $visible; // [bool]
17  protected $active; // [bool]
18 
24  public function setRefId($a_id)
25  {
26  include_once "Modules/Poll/classes/class.ilObjPoll.php";
27  $this->poll = new ilObjPoll($a_id, true);
28  $this->answers = $this->poll->getAnswers();
29  }
30 
36  public function getPoll()
37  {
38  return $this->poll;
39  }
40 
47  public function hasAnyContent($a_user_id, $a_ref_id)
48  {
49  if(!sizeof($this->answers))
50  {
51  return false;
52  }
53 
54  include_once "Modules/Poll/classes/class.ilObjPollAccess.php";
55  $this->active = ilObjPollAccess::_isActivated($a_ref_id);
56  if(!$this->active)
57  {
58  return false;
59  }
60 
61  if(!$this->mayVote($a_user_id) &&
62  !$this->maySeeResults($a_user_id))
63  {
64  return false;
65  }
66 
67  return true;
68  }
69 
70  public function mayVote($a_user_id)
71  {
72  if(!$this->active)
73  {
74  return false;
75  }
76 
77  if($a_user_id == ANONYMOUS_USER_ID)
78  {
79  return false;
80  }
81 
82  if($this->poll->hasUserVoted($a_user_id))
83  {
84  return false;
85  }
86 
87  if($this->poll->getVotingPeriod() &&
88  ($this->poll->getVotingPeriodBegin() > time() ||
89  $this->poll->getVotingPeriodEnd() < time()))
90  {
91  return false;
92  }
93 
94  return true;
95  }
96 
97  public function mayNotResultsYet()
98  {
99  if($this->poll->getViewResults() == ilObjPoll::VIEW_RESULTS_AFTER_PERIOD &&
100  $this->poll->getVotingPeriod() &&
101  $this->poll->getVotingPeriodEnd() > time())
102  {
103  return true;
104  }
105  return false;
106  }
107 
108  public function maySeeResults($a_user_id)
109  {
110  if(!$this->active)
111  {
112  return false;
113  }
114 
115  switch($this->poll->getViewResults())
116  {
118  return false;
119 
121  // fallthrough
122 
123  // #12023 - see mayNotResultsYet()
125  return true;
126 
128  if($this->poll->hasUserVoted($a_user_id))
129  {
130  return true;
131  }
132  return false;
133  }
134  }
135 
136  public function getMessage($a_user_id)
137  {
138  global $lng;
139 
140  if(!sizeof($this->answers))
141  {
142  return $lng->txt("poll_block_message_no_answers");
143  }
144 
145  if(!$this->active)
146  {
147  if(!$this->poll->isOnline())
148  {
149  return $lng->txt("poll_block_message_offline");
150  }
151  if($this->poll->getAccessBegin() > time())
152  {
153  $date = ilDatePresentation::formatDate(new ilDateTime($this->poll->getAccessBegin(), IL_CAL_UNIX));
154  return sprintf($lng->txt("poll_block_message_inactive"), $date);
155  }
156  }
157  }
158 }
159 
160 ?>