ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_once 'Modules/Forum/classes/class.ilForumModerators.php';
5 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
6 include_once 'Services/Table/classes/class.ilTable2GUI.php';
7 include_once 'Services/Search/classes/class.ilQueryParser.php';
8 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
9 
17 {
18  private $ctrl;
19  private $tpl;
20  private $lng;
21  private $tabs;
22  private $error;
23  private $user;
24  private $toolbar;
25 
30 
31  private $ref_id = 0;
32 
33  public function __construct()
34  {
35  global $DIC;
36  $this->ctrl = $DIC->ctrl();
37  $this->tpl = $DIC->ui()->mainTemplate();
38  $this->lng = $DIC->language();
39  $this->access = $DIC->access();
40  $this->tabs = $DIC->tabs();
41  $this->error = $DIC['ilErr'];
42  $this->user = $DIC->user();
43  $this->toolbar = $DIC->toolbar();
44 
45  $this->tabs->activateTab('frm_moderators');
46  $this->lng->loadLanguageModule('search');
47 
48  if (!$this->access->checkAccess('write', '', (int) $_GET['ref_id'])) {
49  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
50  }
51 
52  $this->oForumModerators = new ilForumModerators((int) $_GET['ref_id']);
53  $this->ref_id = (int) $_GET['ref_id'];
54  }
55 
59  public function executeCommand()
60  {
61  $next_class = $this->ctrl->getNextClass($this);
62  $cmd = $this->ctrl->getCmd();
63 
64  switch ($next_class) {
65  case 'ilrepositorysearchgui':
66  include_once 'Services/Search/classes/class.ilRepositorySearchGUI.php';
67  $rep_search = new ilRepositorySearchGUI();
68  $rep_search->setCallback($this, 'addModerator');
69  $this->ctrl->setReturn($this, 'showModerators');
70  $this->ctrl->forwardCommand($rep_search);
71  break;
72 
73  default:
74  if (!$cmd) {
75  $cmd = 'showModerators';
76  }
77  $this->$cmd();
78  break;
79  }
80  }
81 
85  public function addModerator($users = array())
86  {
87  if (!$users) {
88  ilUtil::sendFailure($this->lng->txt('frm_moderators_select_one'));
89  return;
90  }
91 
92  include_once "Modules/Forum/classes/class.ilForumNotification.php";
93  $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
94  include_once "Modules/Forum/classes/class.ilForumProperties.php";
95  $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
96  $frm_noti_type = $objFrmProps->getNotificationType();
97 
98  foreach ($users as $user_id) {
99  $this->oForumModerators->addModeratorRole((int) $user_id);
100  if ($isCrsGrp && $frm_noti_type != 'default') {
101  $tmp_frm_noti = new ilForumNotification($this->ref_id);
102  $tmp_frm_noti->setUserId((int) $user_id);
103  $tmp_frm_noti->setUserIdNoti($this->user->getId());
104  $tmp_frm_noti->setUserToggle((int) $objFrmProps->getUserToggleNoti());
105  $tmp_frm_noti->setAdminForce((int) $objFrmProps->getAdminForceNoti());
106 
107  $tmp_frm_noti->insertAdminForce();
108  }
109  }
110 
111  ilUtil::sendSuccess($this->lng->txt('frm_moderator_role_added_successfully'), true);
112  $this->ctrl->redirect($this, 'showModerators');
113  }
114 
118  public function detachModeratorRole()
119  {
120  if (!isset($_POST['usr_id']) || !is_array($_POST['usr_id'])) {
121  ilUtil::sendFailure($this->lng->txt('frm_moderators_select_at_least_one'));
122  return $this->showModerators();
123  }
124 
125  $entries = $this->oForumModerators->getCurrentModerators();
126  if (count($_POST['usr_id']) == count($entries)) {
127  ilUtil::sendFailure($this->lng->txt('frm_at_least_one_moderator'));
128  return $this->showModerators();
129  }
130 
131  include_once "Modules/Forum/classes/class.ilForumNotification.php";
132  $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
133 
134  if ($isCrsGrp) {
135  include_once "Services/Membership/classes/class.ilParticipants.php";
136  }
137 
138  include_once "Modules/Forum/classes/class.ilForumProperties.php";
139  $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
140  $frm_noti_type = $objFrmProps->getNotificationType();
141 
142  foreach ($_POST['usr_id'] as $usr_id) {
143  $this->oForumModerators->detachModeratorRole((int) $usr_id);
144 
145  if ($isCrsGrp && $frm_noti_type != 'default') {
146  if (!ilParticipants::_isParticipant($this->ref_id, $usr_id)) {
147  $tmp_frm_noti = new ilForumNotification($this->ref_id);
148  $tmp_frm_noti->setUserId((int) $usr_id);
149  $tmp_frm_noti->setForumId(ilObject::_lookupObjId($this->ref_id));
150 
151  $tmp_frm_noti->deleteAdminForce();
152  }
153  }
154  }
155 
156  ilUtil::sendSuccess($this->lng->txt('frm_moderators_detached_role_successfully'), true);
157  $this->ctrl->redirect($this, 'showModerators');
158  }
159 
163  public function showModerators()
164  {
165  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
167  $this,
168  $this->toolbar,
169  array(
170  'auto_complete_name' => $this->lng->txt('user'),
171  'submit_name' => $this->lng->txt('add'),
172  'add_search' => true,
173  'add_from_container' => $this->oForumModerators->getRefId()
174  )
175  );
176 
177  require_once 'Modules/Forum/classes/class.ilForumModeratorsTableGUI.php';
178  $tbl = new ilForumModeratorsTableGUI($this, 'showModerators', '', (int) $_GET['ref_id']);
179 
180  $entries = $this->oForumModerators->getCurrentModerators();
181  $num = count($entries);
182  $result = array();
183  $i = 0;
184  foreach ($entries as $usr_id) {
188  $user = ilObjectFactory::getInstanceByObjId($usr_id, false);
189  // Bugfix/Fallback for #25640
190  if (!$user) {
191  $this->oForumModerators->detachModeratorRole((int) $usr_id);
192  continue;
193  }
194 
195  if ($num > 1) {
196  $result[$i]['check'] = ilUtil::formCheckbox(false, 'usr_id[]', $user->getId());
197  } else {
198  $result[$i]['check'] = '';
199  }
200  $result[$i]['login'] = $user->getLogin();
201  $result[$i]['firstname'] = $user->getFirstname();
202  $result[$i]['lastname'] = $user->getLastname();
203  ++$i;
204  }
205 
206  $tbl->setData($result);
207  $this->tpl->setContent($tbl->getHTML());
208  }
209 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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
Create styles array
The data for the language used.
$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