ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilForumModeratorsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  private $ctrl;
13  private $tpl;
14  private $lng;
15  private $tabs;
16  private $error;
17  private $user;
18  private $toolbar;
19 
24 
25  private $ref_id = 0;
26 
27  public function __construct()
28  {
29  global $DIC;
30  $this->ctrl = $DIC->ctrl();
31  $this->tpl = $DIC->ui()->mainTemplate();
32  $this->lng = $DIC->language();
33  $this->access = $DIC->access();
34  $this->tabs = $DIC->tabs();
35  $this->error = $DIC['ilErr'];
36  $this->user = $DIC->user();
37  $this->toolbar = $DIC->toolbar();
38 
39  $this->tabs->activateTab('frm_moderators');
40  $this->lng->loadLanguageModule('search');
41 
42  if (!$this->access->checkAccess('write', '', (int) $_GET['ref_id'])) {
43  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
44  }
45 
46  $this->oForumModerators = new ilForumModerators((int) $_GET['ref_id']);
47  $this->ref_id = (int) $_GET['ref_id'];
48  }
49 
53  public function executeCommand()
54  {
55  $next_class = $this->ctrl->getNextClass($this);
56  $cmd = $this->ctrl->getCmd();
57 
58  switch ($next_class) {
59  case 'ilrepositorysearchgui':
60  $rep_search = new ilRepositorySearchGUI();
61  $rep_search->setCallback($this, 'addModerator');
62  $this->ctrl->setReturn($this, 'showModerators');
63  $this->ctrl->forwardCommand($rep_search);
64  break;
65 
66  default:
67  if (!$cmd) {
68  $cmd = 'showModerators';
69  }
70  $this->$cmd();
71  break;
72  }
73  }
74 
78  public function addModerator($users = array())
79  {
80  if (!$users) {
81  ilUtil::sendFailure($this->lng->txt('frm_moderators_select_one'));
82  return;
83  }
84 
85  $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
86  $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
87  $frm_noti_type = $objFrmProps->getNotificationType();
88 
89  foreach ($users as $user_id) {
90  $this->oForumModerators->addModeratorRole((int) $user_id);
91  if ($isCrsGrp && $frm_noti_type != 'default') {
92  $tmp_frm_noti = new ilForumNotification($this->ref_id);
93  $tmp_frm_noti->setUserId((int) $user_id);
94  $tmp_frm_noti->setUserIdNoti($this->user->getId());
95  $tmp_frm_noti->setUserToggle((int) $objFrmProps->getUserToggleNoti());
96  $tmp_frm_noti->setAdminForce((int) $objFrmProps->getAdminForceNoti());
97 
98  $tmp_frm_noti->insertAdminForce();
99  }
100  }
101 
102  ilUtil::sendSuccess($this->lng->txt('frm_moderator_role_added_successfully'), true);
103  $this->ctrl->redirect($this, 'showModerators');
104  }
105 
109  public function detachModeratorRole()
110  {
111  if (!isset($_POST['usr_id']) || !is_array($_POST['usr_id'])) {
112  ilUtil::sendFailure($this->lng->txt('frm_moderators_select_at_least_one'));
113  return $this->showModerators();
114  }
115 
116  $entries = $this->oForumModerators->getCurrentModerators();
117  if (count($_POST['usr_id']) == count($entries)) {
118  ilUtil::sendFailure($this->lng->txt('frm_at_least_one_moderator'));
119  return $this->showModerators();
120  }
121 
122  $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
123 
124  $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
125  $frm_noti_type = $objFrmProps->getNotificationType();
126 
127  foreach ($_POST['usr_id'] as $usr_id) {
128  $this->oForumModerators->detachModeratorRole((int) $usr_id);
129 
130  if ($isCrsGrp && $frm_noti_type != 'default') {
131  if (!ilParticipants::_isParticipant($this->ref_id, $usr_id)) {
132  $tmp_frm_noti = new ilForumNotification($this->ref_id);
133  $tmp_frm_noti->setUserId((int) $usr_id);
134  $tmp_frm_noti->setForumId(ilObject::_lookupObjId($this->ref_id));
135 
136  $tmp_frm_noti->deleteAdminForce();
137  }
138  }
139  }
140 
141  ilUtil::sendSuccess($this->lng->txt('frm_moderators_detached_role_successfully'), true);
142  $this->ctrl->redirect($this, 'showModerators');
143  }
144 
148  public function showModerators()
149  {
151  $this,
152  $this->toolbar,
153  array(
154  'auto_complete_name' => $this->lng->txt('user'),
155  'submit_name' => $this->lng->txt('add'),
156  'add_search' => true,
157  'add_from_container' => $this->oForumModerators->getRefId()
158  )
159  );
160 
161  $tbl = new ilForumModeratorsTableGUI($this, 'showModerators', '', (int) $_GET['ref_id']);
162 
163  $entries = $this->oForumModerators->getCurrentModerators();
164  $num = count($entries);
165  $result = array();
166  $i = 0;
167  foreach ($entries as $usr_id) {
171  $user = ilObjectFactory::getInstanceByObjId($usr_id, false);
172  // Bugfix/Fallback for #25640
173  if (!$user) {
174  $this->oForumModerators->detachModeratorRole((int) $usr_id);
175  continue;
176  }
177 
178  if ($num > 1) {
179  $result[$i]['check'] = ilUtil::formCheckbox(false, 'usr_id[]', $user->getId());
180  } else {
181  $result[$i]['check'] = '';
182  }
183  $result[$i]['login'] = $user->getLogin();
184  $result[$i]['firstname'] = $user->getFirstname();
185  $result[$i]['lastname'] = $user->getLastname();
186  ++$i;
187  }
188 
189  $tbl->setData($result);
190  $this->tpl->setContent($tbl->getHTML());
191  }
192 }
static _isParentNodeGrpCrs($a_ref_id)
static _isParticipant($a_ref_id, $a_usr_id)
Static function to check if a user is a participant of the container object.
$result
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$tbl
Definition: example_048.php:81
Class ilForumNotification.
user()
Definition: user.php:4
Class ilForumModeratorsTableGUI.
static getInstance($a_obj_id=0)
Class ilForumModeratorsGUI.
static _lookupObjId($a_id)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$users
Definition: authpage.php:44
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$i
Definition: disco.tpl.php:19
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
Class ilForumModerators.
$_POST["username"]
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public