ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 {
21  private $ctrl;
22 
26  private $tpl;
27 
31  private $lng;
32 
37 
38  private $ref_id = 0;
39 
40  public function __construct()
41  {
50  global $ilCtrl, $tpl, $lng, $ilTabs, $ilAccess, $ilias;
51 
52  $this->ctrl = $ilCtrl;
53  $this->tpl = $tpl;
54  $this->lng = $lng;
55 
56  $ilTabs->setTabActive('frm_moderators');
57  $this->lng->loadLanguageModule('search');
58 
59  if(!$ilAccess->checkAccess('write', '', (int)$_GET['ref_id']))
60  {
61  $ilias->raiseError($this->lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
62  }
63 
64  $this->oForumModerators = new ilForumModerators((int)$_GET['ref_id']);
65  $this->ref_id = (int)$_GET['ref_id'];
66  }
67 
71  public function executeCommand()
72  {
73  $next_class = $this->ctrl->getNextClass($this);
74  $cmd = $this->ctrl->getCmd();
75 
76  switch($next_class)
77  {
78  case 'ilrepositorysearchgui':
79  include_once 'Services/Search/classes/class.ilRepositorySearchGUI.php';
80  $rep_search = new ilRepositorySearchGUI();
81  $rep_search->setCallback($this, 'addModerator');
82  $this->ctrl->setReturn($this, 'showModerators');
83  $this->ctrl->forwardCommand($rep_search);
84  break;
85 
86  default:
87  if(!$cmd)
88  {
89  $cmd = 'showModerators';
90  }
91  $this->$cmd();
92  break;
93  }
94  }
95 
99  public function addModerator($users = array())
100  {
101  global $ilUser;
102 
103  if(!$users)
104  {
105  ilUtil::sendFailure($this->lng->txt('frm_moderators_select_one'));
106  return;
107  }
108 
109  include_once "Modules/Forum/classes/class.ilForumNotification.php";
110  $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
111  include_once "Modules/Forum/classes/class.ilForumProperties.php";
112  $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
113  $frm_noti_type = $objFrmProps->getNotificationType();
114 
115  foreach($users as $user_id)
116  {
117  $this->oForumModerators->addModeratorRole((int)$user_id);
118  if($isCrsGrp && $frm_noti_type != 'default')
119  {
120  $tmp_frm_noti = new ilForumNotification($this->ref_id);
121  $tmp_frm_noti->setUserId((int)$user_id);
122  $tmp_frm_noti->setUserIdNoti($ilUser->getId());
123  $tmp_frm_noti->setUserToggle((int)$objFrmProps->getUserToggleNoti());
124  $tmp_frm_noti->setAdminForce((int)$objFrmProps->getAdminForceNoti());
125 
126  $tmp_frm_noti->insertAdminForce();
127  }
128  }
129 
130  ilUtil::sendSuccess($this->lng->txt('frm_moderator_role_added_successfully'), true);
131  $this->ctrl->redirect($this, 'showModerators');
132  }
133 
137  public function detachModeratorRole()
138  {
139  if(!isset($_POST['usr_id']) || !is_array($_POST['usr_id']))
140  {
141  ilUtil::sendFailure($this->lng->txt('frm_moderators_select_at_least_one'));
142  return $this->showModerators();
143  }
144 
145  $entries = $this->oForumModerators->getCurrentModerators();
146  if(count($_POST['usr_id']) == count($entries))
147  {
148  ilUtil::sendFailure($this->lng->txt('frm_at_least_one_moderator'));
149  return $this->showModerators();
150  }
151 
152  include_once "Modules/Forum/classes/class.ilForumNotification.php";
153  $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
154 
155  if($isCrsGrp)
156  {
157  global $tree;
158  $parent_ref_id = $tree->getParentId($this->ref_id);
159 
160  include_once "Services/Membership/classes/class.ilParticipants.php";
161  }
162 
163  include_once "Modules/Forum/classes/class.ilForumProperties.php";
164  $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
165  $frm_noti_type = $objFrmProps->getNotificationType();
166 
167  foreach($_POST['usr_id'] as $usr_id)
168  {
169  $this->oForumModerators->detachModeratorRole((int)$usr_id);
170 
171  if($isCrsGrp && $frm_noti_type != 'default')
172  {
173  if(!ilParticipants::_isParticipant($this->ref_id, $usr_id))
174  {
175  $tmp_frm_noti = new ilForumNotification($this->ref_id);
176  $tmp_frm_noti->setUserId((int)$usr_id);
177  $tmp_frm_noti->setForumId(ilObject::_lookupObjId($this->ref_id));
178 
179  $tmp_frm_noti->deleteAdminForce();
180  }
181  }
182  }
183 
184  ilUtil::sendSuccess($this->lng->txt('frm_moderators_detached_role_successfully'),true);
185  $this->ctrl->redirect($this, 'showModerators');
186  }
187 
191  public function showModerators()
192  {
197  global $ilToolbar, $lng;
198 
199  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
201  $this,
202  $ilToolbar,
203  array(
204  'auto_complete_name' => $lng->txt('user'),
205  'submit_name' => $lng->txt('add'),
206  'add_search' => true,
207  'add_from_container' => $this->oForumModerators->getRefId()
208  )
209  );
210 
211  $tbl = new ilTable2GUI($this);
212  $tbl->setId('frm_show_mods_tbl_' . (int)$_GET['ref_id']);
213  $tbl->setFormAction($this->ctrl->getFormAction($this, 'detachModeratorRole'));
214  $tbl->setTitle($this->lng->txt('frm_moderators'));
215  $tbl->setRowTemplate('tpl.forum_moderators_table_row.html', 'Modules/Forum');
216  $tbl->setDefaultOrderField('login');
217 
218  $entries = $this->oForumModerators->getCurrentModerators();
219  $num = count($entries);
220  if($num > 1)
221  {
222  $tbl->addColumn('', 'check', '1%', true);
223  $tbl->setSelectAllCheckbox('usr_id');
224  $tbl->addMultiCommand('detachModeratorRole', $this->lng->txt('frm_detach_moderator_role'));
225  }
226  else if(!$entries)
227  {
228  $tbl->setNoEntriesText($this->lng->txt('frm_moderators_not_exist_yet'));
229  }
230  $tbl->addColumn($this->lng->txt('login'), 'login', '30%');
231  $tbl->addColumn($this->lng->txt('firstname'), 'firstname', '30%');
232  $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '30%');
233 
234  $result = array();
235  $i = 0;
236  foreach($entries as $usr_id)
237  {
241  $user = ilObjectFactory::getInstanceByObjId($usr_id);
242  if($num > 1)
243  {
244  $result[$i]['check'] = ilUtil::formCheckbox(false, 'usr_id[]', $user->getId());
245  }
246  else
247  {
248  $result[$i]['check'] = '';
249  }
250  $result[$i]['login'] = $user->getLogin();
251  $result[$i]['firstname'] = $user->getFirstname();
252  $result[$i]['lastname'] = $user->getLastname();
253  ++$i;
254  }
255 
256  $tbl->setData($result);
257  $this->tpl->setContent($tbl->getHTML());
258  }
259 }
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.
$_POST['username']
Definition: cron.php:12
$result
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
Class ilForumNotification.
global $ilCtrl
Definition: ilias.php:18
static getInstance($a_obj_id=0)
Class ilTable2GUI.
Class ilForumModeratorsGUI.
static _lookupObjId($a_id)
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array())
fill toolbar with
global $ilUser
Definition: imgupload.php:15
Class ilForumModerators.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public