ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
10 
20 {
21  private $ctrl = null;
22  private $tpl = null;
23  private $lng = null;
24  private $ref_id = 0;
25  private $oForumModerators = null;
26 
27  public function __construct()
28  {
37  global $ilCtrl, $tpl, $lng, $ilTabs, $ilAccess, $ilias;
38 
39  $this->ctrl = $ilCtrl;
40  $this->tpl = $tpl;
41  $this->lng = $lng;
42 
43  $ilTabs->setTabActive('frm_moderators');
44  $this->lng->loadLanguageModule('search');
45 
46  if(!$ilAccess->checkAccess('write', '', (int)$_GET['ref_id']))
47  {
48  $ilias->raiseError($this->lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
49  }
50 
51  $this->oForumModerators = new ilForumModerators((int)$_GET['ref_id']);
52  $this->ref_id = (int)$_GET['ref_id'];
53  }
54 
55  public function executeCommand()
56  {
57  $next_class = $this->ctrl->getNextClass($this);
58  $cmd = $this->ctrl->getCmd();
59 
60 
61  switch ($next_class)
62  {
63  case 'ilrepositorysearchgui':
64 
65  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
66  $rep_search = new ilRepositorySearchGUI();
67  $rep_search->setCallback($this,
68  'addModerator');
69  // Set tabs
70  $this->ctrl->setReturn($this,'showModerators');
71  $this->ctrl->forwardCommand($rep_search);
72 
73  break;
74 
75  default:
76  if(!$cmd)
77  {
78  $cmd = 'showModerators';
79  }
80  $this->$cmd();
81  break;
82  }
83  return true;
84  }
85 
86  public function addModerator()
87  {
88  global $ilUser;
89 
90  if(!$_POST['user'])
91  {
92  ilUtil::sendInfo($this->lng->txt('frm_moderators_select_one'));
93  return $this->showModeratorsSearchResult($_SESSION['frm']['moderators']['search_result']);
94  }
95 
96  include_once "Modules/Forum/classes/class.ilForumNotification.php";
97  $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
98  include_once "Modules/Forum/classes/class.ilForumProperties.php";
99  $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
100  $frm_noti_type = $objFrmProps->getNotificationType();
101 
102  unset($_SESSION['frm']['moderators']['search_result']);
103  foreach($_POST['user'] as $user_id)
104  {
105  $this->oForumModerators->addModeratorRole((int)$user_id);
106 
107  if($isCrsGrp && $frm_noti_type != 'default')
108  {
109  $tmp_frm_noti = new ilForumNotification($this->ref_id);
110  $tmp_frm_noti->setUserId((int)$user_id);
111  $tmp_frm_noti->setUserIdNoti($ilUser->getId());
112  $tmp_frm_noti->setUserToggle((int)$objFrmProps->getUserToggleNoti());
113  $tmp_frm_noti->setAdminForce((int)$objFrmProps->getAdminForceNoti());
114 
115  $tmp_frm_noti->insertAdminForce();
116  }
117  }
118 
119  ilUtil::sendInfo($this->lng->txt('frm_moderator_role_added_successfully'));
120  return $this->showModerators();
121  }
122 
123  public function showModeratorsSearchResult($users = array())
124  {
125  }
126 
127  public function searchModerators()
128  {
129  if(!is_object($oQueryParser = $this->parseQueryString(ilUtil::stripSlashes($_POST['search_query']))))
130  {
131  ilUtil::sendInfo($oQueryParser);
132  return $this->searchModeratorsForm();
133  }
134 
135  $oUserSearchFirstname = ilObjectSearchFactory::_getUserSearchInstance($oQueryParser);
136  $oUserSearchFirstname->setFields(array('firstname'));
138  $oSearchResult = $oUserSearchFirstname->performSearch();
139 
140  $oUserSearchLastname = ilObjectSearchFactory::_getUserSearchInstance($oQueryParser);
141  $oUserSearchLastname->setFields(array('lastname'));
142  $oSearchResultLastname = $oUserSearchLastname->performSearch();
143  $oSearchResult->mergeEntries($oSearchResultLastname);
144 
145 
146  $oUserSearchLogin = ilObjectSearchFactory::_getUserSearchInstance($oQueryParser);
147  $oUserSearchLogin->setFields(array('login'));
148  $oSearchResultLogin = $oUserSearchLogin->performSearch();
149  $oSearchResult->mergeEntries($oSearchResultLogin);
150 
151  $oSearchResult->filter(ROOT_FOLDER_ID, $oQueryParser->getCombination() == 'and');
152  $search_results = $oSearchResult->getUniqueResults();
153 
154  if(is_array($search_results) && count($search_results))
155  {
156  $_SESSION['frm']['moderators']['search_result'] = $search_results;
157  return $this->showModeratorsSearchResult($search_results);
158  }
159  else
160  {
161  ilUtil::sendInfo($this->lng->txt('frm_moderators_matches_in_no_results'));
162  return $this->searchModeratorsForm();
163  }
164  }
165 
166  private function parseQueryString($query_string)
167  {
168  $oQueryParser = new ilQueryParser($query_string);
169  $oQueryParser->setCombination('or');
170  $oQueryParser->parse();
171 
172  if(!$oQueryParser->validate())
173  {
174  return $oQueryParser->getMessage();
175  }
176  return $oQueryParser;
177  }
178 
179  public function detachModeratorRole()
180  {
181 
182  $entries = $this->oForumModerators->getCurrentModerators();
183 
184  if(count($_POST['usr_id']) == count($entries))
185  {
186  ilUtil::sendInfo($this->lng->txt('frm_at_least_one_moderator'));
187  return $this->showModerators();
188  }
189  if(!is_array($_POST['usr_id']))
190  {
191  ilUtil::sendInfo($this->lng->txt('frm_moderators_select_at_least_one'));
192  return $this->showModerators();
193  }
194  include_once "Modules/Forum/classes/class.ilForumNotification.php";
195  $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
196 
197  if($isCrsGrp)
198  {
199  global $tree;
200  $parent_ref_id = $tree->getParentId($this->ref_id);
201 
202  include_once "Services/Membership/classes/class.ilParticipants.php";
203  }
204 
205  include_once "Modules/Forum/classes/class.ilForumProperties.php";
206  $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
207  $frm_noti_type = $objFrmProps->getNotificationType();
208 
209  foreach($_POST['usr_id'] as $usr_id)
210  {
211  $this->oForumModerators->detachModeratorRole((int)$usr_id);
212 
213  if($isCrsGrp && $frm_noti_type != 'default')
214  {
215  //IMPORTANT!! delete this forced notification ONLY if the user is NOT a crs/grp member!!
216  if(!ilParticipants::_isParticipant($this->ref_id, $usr_id))
217  {
218  $tmp_frm_noti = new ilForumNotification($this->ref_id);
219  $tmp_frm_noti->setUserId((int)$usr_id);
220  $tmp_frm_noti->setForumId(ilObject::_lookupObjId($this->ref_id));
221 
222  $tmp_frm_noti->deleteAdminForce();
223  }
224  }
225  }
226 
227  ilUtil::sendInfo($this->lng->txt('frm_moderators_detached_role_successfully'));
228  return $this->showModerators();
229  }
230 
231  public function showModerators()
232  {
235  global $ilToolbar;
236 
237  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forum_moderators.html', 'Modules/Forum');
238  // search button
239  $ilToolbar->addButton($this->lng->txt("search_users"),
240  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','start'));
241 
242  $tbl = new ilTable2GUI($this);
243  $tbl->setId('frm_show_mods_tbl_'.$_GET['ref_id']);
244  $tbl->setFormAction($this->ctrl->getFormAction($this, 'detachModeratorRole'));
245  $tbl->setTitle($this->lng->txt('frm_moderators'));
246  $tbl->setRowTemplate('tpl.forum_moderators_table_row.html', 'Modules/Forum');
247 
248  $tbl->addColumn('', 'check', '1%');
249  $tbl->addColumn($this->lng->txt('login'),'login', '30%');
250  $tbl->addColumn($this->lng->txt('firstname'),'firstname', '30%');
251  $tbl->addColumn($this->lng->txt('lastname'),'lastname', '30%');
252 
253  $tbl->setDefaultOrderField('login');
254 
255  $entries = $this->oForumModerators->getCurrentModerators();
256  $result = array();
257  if(count($entries))
258  {
259  $counter = 0;
260  foreach($entries as $usr_id)
261  {
262  $oUser = ilObjectFactory::getInstanceByObjId($usr_id, false);
263  if(is_object($oUser))
264  {
265  if(count($entries) > 1)
266  {
267  $result[$counter]['check'] = ilUtil::formCheckbox(0, 'usr_id[]', $oUser->getId());
268  }
269  $result[$counter]['login'] = $oUser->getLogin();
270  $result[$counter]['firstname'] = $oUser->getFirstname();
271  $result[$counter]['lastname'] = $oUser->getLastname();
272 
273  ++$counter;
274  }
275  }
276 
277  if(count($entries) > 1)
278  {
279  $tbl->enable('select_all');
280  $tbl->setSelectAllCheckbox('usr_id');
281  $tbl->addMultiCommand('detachModeratorRole', $this->lng->txt('frm_detach_moderator_role'));
282  }
283  }
284  else
285  {
286  $tbl->disable('header');
287  $tbl->disable('footer');
288 
289  $tbl->setNoEntriesText($this->lng->txt('frm_moderators_not_exist_yet'));
290  }
291 
292  $tbl->setData($result);
293  $this->tpl->setVariable('TXT_FORUM_MODERATORS', $tbl->getHTML());
294  }
295 }