ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSubscriberTableGUI.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 
24 include_once('./Services/Table/classes/class.ilTable2GUI.php');
25 
26 
36 {
37  protected $subscribers = array();
38 
39  protected static $all_columns = null;
40 
41 
49  public function __construct($a_parent_obj,$show_content = true)
50  {
51  global $lng,$ilCtrl;
52 
53  $this->lng = $lng;
54  $this->lng->loadLanguageModule('grp');
55  $this->lng->loadLanguageModule('crs');
56  $this->ctrl = $ilCtrl;
57 
58  $this->setId('crs_sub_'. $a_parent_obj->object->getId());
59  parent::__construct($a_parent_obj,'members');
60 
61  $this->setFormName('subscribers');
62  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj,'members'));
63 
64  $this->addColumn('','f',"1");
65  $this->addColumn($this->lng->txt('name'),'lastname','20%');
66 
67  $all_cols = $this->getSelectableColumns();
68  foreach($this->getSelectedColumns() as $col)
69  {
70  $this->addColumn($all_cols[$col]['txt'], $col);
71  }
72 
73  $this->addColumn($this->lng->txt('application_date'),'sub_time',"10%");
74  $this->addColumn($this->lng->txt('subject'),'subject','15%');
75  $this->addColumn('','mail','10%');
76 
77  $this->addMultiCommand('assignSubscribers',$this->lng->txt('assign'));
78  $this->addMultiCommand('refuseSubscribers',$this->lng->txt('refuse'));
79  $this->addMultiCommand('sendMailToSelectedUsers',$this->lng->txt('crs_mem_send_mail'));
80 
81 
82  $this->setPrefix('subscribers');
83  $this->setSelectAllCheckbox('subscribers');
84  $this->setRowTemplate("tpl.show_subscribers_row.html","Services/Membership");
85 
86  if($show_content)
87  {
88  $this->enable('sort');
89  $this->enable('header');
90  $this->enable('numinfo');
91  $this->enable('select_all');
92  }
93  else
94  {
95  $this->disable('content');
96  $this->disable('header');
97  $this->disable('footer');
98  $this->disable('numinfo');
99  $this->disable('select_all');
100  }
101 
102  $this->setExternalSegmentation(true);
103  }
104 
109  public function getSelectableColumns()
110  {
111  if(self::$all_columns)
112  {
113  return self::$all_columns;
114  }
115 
116  include_once './Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php';
117  $ef = ilExportFieldsInfo::_getInstanceByType($this->getParentObject()->object->getType());
118  self::$all_columns = $ef->getSelectableFieldsInfo($this->getParentObject()->object->getId());
119  return self::$all_columns;
120  }
121 
122 
130  public function fillRow($a_set)
131  {
132  global $ilUser;
133 
134 
135  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
136  if(!ilObjCourseGrouping::_checkGroupingDependencies($this->getParentObject()->object,$a_set['id']) and
138  {
139  $prefix = $this->getParentObject()->object->getType();
140  $this->tpl->setVariable('ALERT_MSG',
141  sprintf($this->lng->txt($prefix.'_lim_assigned'),
142  ilObject::_lookupTitle(current($ids))
143  ));
144 
145  }
146 
147  $this->tpl->setVariable('VAL_ID',$a_set['usr_id']);
148  $this->tpl->setVariable('VAL_NAME',$a_set['lastname'].', '.$a_set['firstname']);
149 
150  foreach($this->getSelectedColumns() as $field)
151  {
152  switch($field)
153  {
154  case 'gender':
155  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
156  $this->tpl->setCurrentBlock('custom_fields');
157  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
158  $this->tpl->parseCurrentBlock();
159  break;
160 
161  case 'birthday':
162  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
163  $this->tpl->setCurrentBlock('custom_fields');
164  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
165  $this->tpl->parseCurrentBlock();
166  break;
167 
168  default:
169  $this->tpl->setCurrentBlock('custom_fields');
170  $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
171  $this->tpl->parseCurrentBlock();
172  break;
173  }
174  }
175 
176 
177  $this->tpl->setVariable('VAL_SUBTIME',ilDatePresentation::formatDate(new ilDateTime($a_set['sub_time'],IL_CAL_UNIX)));
178 
179  $this->ctrl->setParameterByClass(get_class($this->getParentObject()),'member_id',$a_set['usr_id']);
180  $link = $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()),'sendMailToSelectedUsers');
181  $this->tpl->setVariable('MAIL_LINK',$link);
182  $this->tpl->setVariable('MAIL_TITLE',$this->lng->txt('crs_mem_send_mail'));
183 
184 
185  if(strlen($a_set['subject']))
186  {
187  $this->tpl->setVariable('VAL_SUBJECT','"'.$a_set['subject'].'"');
188 
189  }
190  }
191 
199  public function readSubscriberData()
200  {
201  include_once './Services/Membership/classes/class.ilParticipants.php';
202 
203  $sub_data = ilParticipants::lookupSubscribersData($this->getParentObject()->object->getId());
204 
205  $sub_ids = array();
206  foreach($sub_data as $usr_id => $usr_data)
207  {
208  $sub_ids[] = $usr_id;
209  }
210 
211  $this->determineOffsetAndOrder();
212 
213  include_once './Services/User/classes/class.ilUserQuery.php';
214 
215  $additional_fields = $this->getSelectedColumns();
216  unset($additional_fields["firstname"]);
217  unset($additional_fields["lastname"]);
218  unset($additional_fields["last_login"]);
219  unset($additional_fields["access_until"]);
220 
221  $udf_ids = $usr_data_fields = $odf_ids = array();
222  foreach($additional_fields as $field)
223  {
224  if(substr($field, 0, 3) == 'udf')
225  {
226  $udf_ids[] = substr($field, 4);
227  continue;
228  }
229  if(substr($field, 0, 3) == 'odf')
230  {
231  $odf_ids[] = substr($field, 4);
232  continue;
233  }
234 
235  $usr_data_fields[] = $field;
236  }
237 
238  $usr_data = ilUserQuery::getUserListData(
239  $this->getOrderField(),
240  $this->getOrderDirection(),
241  $this->getOffset(),
242  $this->getLimit(),
243  '',
244  '',
245  null,
246  false,
247  false,
248  0,
249  0,
250  null,
251  $usr_data_fields,
252  $sub_ids
253  );
254 
255  foreach((array) $usr_data['set'] as $user)
256  {
257  $usr_ids[] = $user['usr_id'];
258  }
259 
260  // merge course data
261  $course_user_data = $this->getParentObject()->readMemberData($usr_ids,$this->type == 'admin');
262  $a_user_data = array();
263  foreach((array) $usr_data['set'] as $ud)
264  {
265  $a_user_data[$ud['usr_id']] = array_merge($ud,(array) $course_user_data[$ud['usr_id']]);
266  }
267 
268  // Custom user data fields
269  if($udf_ids)
270  {
271  include_once './Services/User/classes/class.ilUserDefinedData.php';
272  $data = ilUserDefinedData::lookupData($usr_ids, $udf_ids);
273  foreach($data as $usr_id => $fields)
274  {
275  if(!$this->checkAcceptance($usr_id))
276  {
277  continue;
278  }
279 
280  foreach($fields as $field_id => $value)
281  {
282  $a_user_data[$usr_id]['udf_' . $field_id] = $value;
283  }
284  }
285  }
286  // Object specific user data fields
287  if($odf_ids)
288  {
289  include_once './Modules/Course/classes/Export/class.ilCourseUserData.php';
290  $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId());
291  foreach($data as $usr_id => $fields)
292  {
293  // #7264: as we get data for all course members filter against user data
294  if(!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids))
295  {
296  continue;
297  }
298 
299  foreach($fields as $field_id => $value)
300  {
301  $a_user_data[$usr_id]['odf_' . $field_id] = $value;
302  }
303  }
304  }
305 
306  foreach($usr_data['set'] as $user)
307  {
308  // Check acceptance
309  if(!$this->checkAcceptance($user['usr_id']))
310  {
311  continue;
312  }
313  // DONE: accepted
314  foreach($usr_data_fields as $field)
315  {
316  $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : '';
317  }
318  }
319 
320  // Waiting list subscription
321  foreach($sub_data as $usr_id => $usr_data)
322  {
323  if(!in_array($usr_id, $usr_ids))
324  {
325  continue;
326  }
327  $a_user_data[$usr_id]['sub_time'] = $usr_data['time'];
328  $a_user_data[$usr_id]['subject'] = $usr_data['subject'];
329  }
330 
331  $this->setMaxCount(count($sub_ids));
332  return $this->setData($a_user_data);
333  }
334 
335  protected function checkAcceptance()
336  {
337  return true;
338  }
339 
340 }
341 ?>