ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPollBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Block/classes/class.ilBlockGUI.php");
6 include_once("./Modules/Poll/classes/class.ilObjPoll.php");
7 
18 {
19  static $block_type = "poll";
20 
21  protected $poll_block; // [ilPollBlock]
22 
26  function __construct()
27  {
28  global $lng;
29 
31 
32  $lng->loadLanguageModule("poll");
33  $this->setRowTemplate("tpl.block.html", "Modules/Poll");
34  }
35 
41  static function getBlockType()
42  {
43  return self::$block_type;
44  }
45 
51  static function isRepositoryObject()
52  {
53  return true;
54  }
55 
59  static function getScreenMode()
60  {
61  return IL_SCREEN_SIDE;
62  }
63 
67  function setBlock($a_block)
68  {
69  $this->setBlockId($a_block->getId());
70  $this->poll_block = $a_block;
71  }
72 
76  function &executeCommand()
77  {
78  global $ilCtrl;
79 
80  $next_class = $ilCtrl->getNextClass();
81  $cmd = $ilCtrl->getCmd("getHTML");
82 
83  switch ($next_class)
84  {
85  default:
86  return $this->$cmd();
87  }
88  }
89 
90  function fillRow($a_poll)
91  {
92  global $ilCtrl, $lng, $ilUser;
93 
94 
95  // handle messages
96 
97  $mess = $this->poll_block->getMessage($ilUser->getId());
98  if($mess)
99  {
100  $this->tpl->setVariable("TXT_QUESTION", $mess);
101  return;
102  }
103 
104 
105  // nested form problem
106  if(!$_SESSION["il_cont_admin_panel"])
107  {
108  // vote
109 
110  if($this->poll_block->mayVote($ilUser->getId()))
111  {
112  $this->tpl->setCurrentBlock("answer");
113  foreach($a_poll->getAnswers() as $item)
114  {
115  $this->tpl->setVariable("VALUE_ANSWER", $item["id"]);
116  $this->tpl->setVariable("TXT_ANSWER_VOTE", nl2br($item["answer"]));
117  $this->tpl->parseCurrentBlock();
118  }
119 
120  $ilCtrl->setParameterByClass("ilobjpollgui",
121  "ref_id", $this->getRefId());
122  $url = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjpollgui"),
123  "vote");
124  $ilCtrl->clearParametersByClass("ilobjpollgui");
125 
126  $url .= "#poll".$a_poll->getID();
127 
128  $this->tpl->setVariable("URL_FORM", $url);
129  $this->tpl->setVariable("CMD_FORM", "vote");
130  $this->tpl->setVariable("TXT_SUBMIT", $lng->txt("poll_vote"));
131 
132  if($this->poll_block->getPoll()->getVotingPeriod())
133  {
134  $this->tpl->setVariable("TXT_VOTING_PERIOD",
135  sprintf($lng->txt("poll_voting_period_info"),
136  ilDatePresentation::formatDate(new ilDateTime($this->poll_block->getPoll()->getVotingPeriodEnd(), IL_CAL_UNIX))));
137  }
138  }
139 
140 
141  // result
142  if($this->poll_block->maySeeResults($ilUser->getId()))
143  {
144  if(!$this->poll_block->mayNotResultsYet($ilUser->getId()))
145  {
146  $perc = $this->poll_block->getPoll()->getVotePercentages();
147  $total = $perc["total"];
148  $perc = $perc["perc"];
149 
150  $this->tpl->setVariable("TOTAL_ANSWERS", sprintf($lng->txt("poll_population"), $total));
151 
152  $this->tpl->setCurrentBlock("answer_result");
153  foreach($a_poll->getAnswers() as $item)
154  {
155  $this->tpl->setVariable("TXT_ANSWER_RESULT", nl2br($item["answer"]));
156  $this->tpl->setVariable("PERC_ANSWER_RESULT", round($perc[$item["id"]]["perc"]));
157  $this->tpl->parseCurrentBlock();
158  }
159  }
160  else
161  {
164  $end = $this->poll_block->getPoll()->getVotingPeriodEnd();
167 
168  // #14607
169  $info = "";
170  if($this->poll_block->getPoll()->hasUserVoted($ilUser->getId()))
171  {
172  $info .= $lng->txt("poll_block_message_already_voted")." ";
173  }
174 
175  $this->tpl->setVariable("TOTAL_ANSWERS", $info.
176  sprintf($lng->txt("poll_block_results_available_on"), $end));
177  }
178  }
179  else if($this->poll_block->getPoll()->hasUserVoted($ilUser->getId()))
180  {
181  $this->tpl->setVariable("TOTAL_ANSWERS", $lng->txt("poll_block_message_already_voted"));
182  }
183  }
184 
185 
186  $this->tpl->setVariable("ANCHOR_ID", $a_poll->getID());
187  $this->tpl->setVariable("TXT_QUESTION", nl2br(trim($a_poll->getQuestion())));
188 
189  $desc = trim($a_poll->getDescription());
190  if($desc)
191  {
192  $this->tpl->setVariable("TXT_DESC", nl2br($desc));
193  }
194 
195  $img = $a_poll->getImageFullPath();
196  if($img)
197  {
198  $this->tpl->setVariable("URL_IMAGE", $img);
199  }
200  }
201 
205  function getHTML()
206  {
207  global $ilCtrl, $lng, $ilAccess, $ilUser, $tree, $objDefinition;
208 
209  $this->poll_block->setRefId($this->getRefId());
210  $this->may_write = $ilAccess->checkAccess("write", "", $this->getRefId());
211  $this->has_content = $this->poll_block->hasAnyContent($ilUser->getId(), $this->getRefId());
212 
213  if(!$this->may_write && !$this->has_content)
214  {
215  return "";
216  }
217 
218  $poll_obj = $this->poll_block->getPoll();
219  $this->setTitle($poll_obj->getTitle());
220  $this->setData(array($poll_obj));
221 
222  if ($this->may_write)
223  {
224  // edit
225  $ilCtrl->setParameterByClass("ilobjpollgui",
226  "ref_id", $this->getRefId());
227  $this->addBlockCommand(
228  $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjpollgui"),
229  "render"),
230  $lng->txt("edit_content"));
231  $this->addBlockCommand(
232  $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjpollgui"),
233  "edit"),
234  $lng->txt("settings"));
235 
236  /* delete (#10993 - see ilBlockGUI)
237  $parent_id = $tree->getParentId($this->getRefId());
238  $type = ilObject::_lookupType($parent_id, true);
239  $class = $objDefinition->getClassName($type);
240  if($class)
241  {
242  $class = "ilobj".strtolower($class)."gui";
243  $ilCtrl->setParameterByClass($class, "ref_id", $parent_id);
244  $ilCtrl->setParameterByClass($class, "item_ref_id", $this->getRefId());
245  $this->addBlockCommand(
246  $ilCtrl->getLinkTargetByClass($class, "delete"),
247  $lng->txt("delete"));
248  }
249  */
250 
251  $ilCtrl->clearParametersByClass("ilobjpollgui");
252  }
253 
254  return parent::getHTML();
255  }
256 }
257 
258 ?>