ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRegistrationGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 abstract class ilRegistrationGUI
34 {
35  protected $container = null;
36  protected $ref_id;
37  protected $obj_id;
38 
39  protected $participants;
40  protected $waiting_list = null;
41  protected $form;
42 
43  protected $registration_possible = true;
44  protected $join_error = '';
45 
46 
47  protected $tpl;
48  protected $lng;
49  protected $ctrl;
50 
58  public function __construct($a_container)
59  {
60  global $lng,$ilCtrl,$tpl;
61 
62  $this->lng = $lng;
63  $this->lng->loadLanguageModule('crs');
64  $this->lng->loadLanguageModule('grp');
65 
66  $this->ctrl = $ilCtrl;
67  $this->tpl = $tpl;
68 
69  $this->container = $a_container;
70  $this->ref_id = $this->container->getRefId();
71  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
72  $this->type = ilObject::_lookupType($this->obj_id);
73 
74  // Init participants
75  $this->initParticipants();
76 
77  // Init waiting list
78  $this->initWaitingList();
79  }
80 
87  protected function isRegistrationPossible()
88  {
89  return (bool) $this->registration_possible;
90  }
91 
99  protected function enableRegistration($a_status)
100  {
101  $this->registration_possible = $a_status;
102  }
103 
104 
111  abstract protected function initParticipants();
112 
120  abstract protected function initWaitingList();
121 
128  abstract protected function isWaitingListActive();
129 
135  protected function getWaitingList()
136  {
137  return $this->waiting_list;
138  }
139 
140  protected function leaveWaitingList()
141  {
142  global $ilUser,$tree,$ilCtrl;
143 
144  $this->getWaitingList()->removeFromList($ilUser->getId());
145  $parent = $tree->getParentId($this->container->getRefId());
146 
147  $message = sprintf($this->lng->txt($this->container->getType().'_removed_from_waiting_list'),
148  $this->container->getTitle());
149  ilUtil::sendSuccess($message,true);
150  ilUtil::redirect('repository.php?ref_id='.$parent);
151  }
152 
159  abstract protected function getFormTitle();
160 
167  abstract protected function fillInformations();
168 
174  abstract protected function fillRegistrationPeriod();
175 
183  abstract protected function fillMaxMembers();
184 
185 
192  abstract protected function fillRegistrationType();
193 
200  protected function fillMembershipLimitation()
201  {
202  global $ilAccess;
203 
204  include_once('Modules/Course/classes/class.ilObjCourseGrouping.php');
205  if(!$items = ilObjCourseGrouping::_getGroupingItems($this->container))
206  {
207  return true;
208  }
209 
210  $mem = new ilCustomInputGUI($this->lng->txt('groupings'));
211 
212  $tpl = new ilTemplate('tpl.membership_limitation_form.html',true,true,'Services/Membership');
213  $tpl->setVariable('LIMIT_INTRO',$this->lng->txt($this->type.'_grp_info_reg'));
214 
215  foreach($items as $ref_id)
216  {
217  $obj_id = ilObject::_lookupObjId($ref_id);
220 
221  if($ilAccess->checkAccess('visible','',$ref_id,$type))
222  {
223  include_once('./classes/class.ilLink.php');
224  $tpl->setVariable('LINK_ITEM','repository.php?ref_id='.$ref_id);
225  $tpl->setVariable('ITEM_LINKED_TITLE',$title);
226  }
227  else
228  {
229  $tpl->setVariable('ITEM_TITLE');
230  }
231  $tpl->setCurrentBlock('items');
232  $tpl->setVariable('TYPE_ICON',ilUtil::getTypeIconPath($type,$obj_id,'tiny'));
233  $tpl->setVariable('ALT_ICON',$this->lng->txt('obj_'.$type));
234  $tpl->parseCurrentBlock();
235  }
236 
237  $mem->setHtml($tpl->get());
238 
239 
241  {
242  $mem->setAlert($this->container->getMessage());
243  $this->enableRegistration(false);
244  }
245  $this->form->addItem($mem);
246  }
247 
254  protected function fillAgreement()
255  {
256  return true;
257  }
258 
259 
265  public function cancel()
266  {
267  global $tree;
268 
269  ilUtil::redirect('repository.php?ref_id='.
270  $tree->getParentId($this->container->getRefId()));
271  }
272 
280  public function show()
281  {
282  $this->initForm();
283 
284  $this->tpl->setContent($this->form->getHTML());
285  }
286 
294  public function join()
295  {
296  $this->initForm();
297 
298  if(!$this->validate())
299  {
300  ilUtil::sendFailure($this->join_error);
301  $this->show();
302  return false;
303  }
304 
305  $this->add();
306  }
307 
308 
315  protected function validate()
316  {
317  return true;
318  }
319 
326  protected function initForm()
327  {
328  global $ilUser;
329 
330  if(is_object($this->form))
331  {
332  return true;
333  }
334 
335  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
336  $this->form = new ilPropertyFormGUI();
337  $this->form->setFormAction($this->ctrl->getFormAction($this,'join'));
338  $this->form->setTitle($this->getFormTitle());
339 
340  $this->fillInformations();
341  $this->fillMembershipLimitation();
342  if($this->isRegistrationPossible())
343  {
344  $this->fillRegistrationPeriod();
345  }
346  if($this->isRegistrationPossible())
347  {
348  $this->fillRegistrationType();
349  }
350  if($this->isRegistrationPossible())
351  {
352  $this->fillMaxMembers();
353  }
354  if($this->isRegistrationPossible())
355  {
356  $this->fillAgreement();
357  }
358  $this->addCommandButtons();
359  }
360 
365  protected function addCommandButtons()
366  {
367  global $ilUser;
368 
369  if($this->isRegistrationPossible() and $this->isWaitingListActive() and !$this->getWaitingList()->isOnList($ilUser->getId()))
370  {
371  $this->form->addCommandButton('join',$this->lng->txt('mem_add_to_wl'));
372  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
373  }
374  elseif($this->isRegistrationPossible() and !$this->getWaitingList()->isOnList($ilUser->getId()))
375  {
376  $this->form->addCommandButton('join',$this->lng->txt('join'));
377  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
378  }
379  if($this->getWaitingList()->isOnList($ilUser->getId()))
380  {
382  sprintf($this->lng->txt($this->container->getType().'_cancel_waiting_list'),
383  $this->container->getTitle())
384  );
385  $this->form->addCommandButton('leaveWaitingList', $this->lng->txt('leave_waiting_list'));
386  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
387  }
388  }
389 
394  protected function updateSubscriptionRequest()
395  {
396  global $ilUser,$tree;
397 
398  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
399  ilUtil::sendSuccess($this->lng->txt('sub_request_saved'),true);
400  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
401  }
402 
403  protected function cancelSubscriptionRequest()
404  {
405  global $ilUser,$tree;
406 
407  $this->participants->deleteSubscriber($ilUser->getId());
408  ilUtil::sendSuccess($this->lng->txt('sub_request_deleted'),true);
409  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
410 
411  }
412 }
413 ?>