ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjiLincClassroom.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2005 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 
33 require_once ('./classes/class.ilObject.php');
34 require_once ('./Modules/ILinc/classes/class.ilnetucateXMLAPI.php');
35 
37 {
44  function ilObjiLincClassroom($a_icla_id,$a_icrs_id)
45  {
46  global $ilErr,$ilias,$lng;
47 
48  $this->type = "icla";
49  $this->id = $a_icla_id;
50  $this->parent = $a_icrs_id;
51  $this->ilincAPI = new ilnetucateXMLAPI();
52 
53  $this->ilErr =& $ilErr;
54  $this->ilias =& $ilias;
55  $this->lng =& $lng;
56 
57  $this->max_title = MAXLENGTH_OBJ_TITLE;
58  $this->max_desc = MAXLENGTH_OBJ_DESC;
59  $this->add_dots = true;
60 
61  $this->referenced = false;
62  $this->call_by_reference = false;
63 
64  if (!empty($this->id))
65  {
66  $this->read();
67  }
68 
69  return $this;
70  }
71 
72  function _lookupiCourseId($a_ref_id)
73  {
74  global $ilDB;
75 
76  $q = "SELECT course_id FROM ilinc_data ".
77  "LEFT JOIN object_reference ON object_reference.obj_id=ilinc_data.obj_id ".
78  "WHERE object_reference.ref_id = ".$ilDB->quote($a_ref_id);
79  $obj_set = $ilDB->query($q);
80  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
81 
82  return $obj_rec["course_id"];
83  }
84 
89  function read()
90  {
91  $this->ilincAPI->findClass($this->id);
92  $response = $this->ilincAPI->sendRequest();
93 
94  if ($response->isError())
95  {
96  if (!$response->getErrorMsg())
97  {
98  $this->error_msg = "err_read_class";
99  }
100  else
101  {
102  $this->error_msg = $response->getErrorMsg();
103  }
104 
105  return false;
106  }
107 
108  //var_dump($response->data['classes']);
109 
110  $this->setTitle($response->data['classes'][$this->id]['name']);
111  $this->setDescription($response->data['classes'][$this->id]['description']);
112  $this->setDocentId($response->data['classes'][$this->id]['instructoruserid']);
113  $this->setStatus($response->data['classes'][$this->id]['alwaysopen']);
114  }
115 
116  function joinClass(&$a_user_obj,$a_ilinc_class_id)
117  {
118 
119  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
120  $ilinc_user = new ilObjiLincUser($a_user_obj);
121 
122  $this->ilincAPI->joinClass($ilinc_user,$a_ilinc_class_id);
123  $response = $this->ilincAPI->sendRequest("joinClass");
124 
125  if ($response->isError())
126  {
127  if (!$response->getErrorMsg())
128  {
129  $this->error_msg = "err_join_classroom";
130  }
131  else
132  {
133  $this->error_msg = $response->getErrorMsg();
134  }
135 
136  return false;
137  }
138 
139  // return URL to join class room
140  return trim($response->data['url']['cdata']);
141  }
142 
143  // not used yet
144  function findUser(&$a_user_obj)
145  {
146  $this->ilincAPI->findUser($a_user_obj);
147  $response = $this->ilincAPI->sendRequest();
148 
149  var_dump($response->data);
150  exit;
151  }
152 
159  function update($a_data = "")
160  {
161  $data = array(
162  "name" => $this->getTitle(),
163  "description" => $this->getDescription(),
164  "instructoruserid" => $this->getDocentId(),
165  "alwaysopen" => $this->getStatus()
166  );
167 
168  if (!is_array($a_data))
169  {
170  $a_data = array();
171  }
172 
173  $result = array_merge($data,$a_data);
174 
175  $this->ilincAPI->editClass($this->id,$result);
176 
177  $response = $this->ilincAPI->sendRequest("editClass");
178 
179  if ($response->isError())
180  {
181  if (!$response->getErrorMsg())
182  {
183  $this->error_msg = "err_edit_classroom";
184  }
185  else
186  {
187  $this->error_msg = $response->getErrorMsg();
188  }
189 
190  return false;
191  }
192 
193  $this->result_msg = $response->getResultMsg();
194 
195  return true;
196  }
197 
204  function delete()
205  {
206  $this->ilincAPI->removeClass($this->id);
207  $response = $this->ilincAPI->sendRequest();
208 
209  if ($response->isError())
210  {
211  if (!$response->getErrorMsg())
212  {
213  $this->error_msg = "err_delete_classroom";
214  }
215  else
216  {
217  $this->error_msg = $response->getErrorMsg();
218  }
219 
220  return false;
221  }
222 
223  return true;
224  }
225 
226  // returns array of docents of course
227  function getDocentList()
228  {
229  $ilinc_crs_id = ilObjiLincClassroom::_lookupiCourseId($this->parent);
230 
231  $this->ilincAPI->findRegisteredUsersByRole($ilinc_crs_id,true);
232  $response = $this->ilincAPI->sendRequest();
233 
234  if (is_array($response->data['users']))
235  {
236  return $response->data['users'];
237  }
238 
239  return array();
240  }
241 
242  function _getDocent($a_ilinc_user_id)
243  {
244  global $ilDB, $lng;
245 
246  $fullname = false;
247 
248  $q = "SELECT title,firstname,lastname FROM usr_data WHERE ilinc_id = ".$ilDB->quote($a_ilinc_user_id)." LIMIT 1";
249  $r = $ilDB->query($q);
250 
251  while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
252  {
253  $fullname = ilObjiLincClassroom::_setFullname($row->title,$row->firstname,$row->lastname);
254  }
255 
256  return $fullname;
257  }
258 
259  function _setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
260  {
261  $fullname = "";
262 
263  if ($a_title)
264  {
265  $fullname = $a_title." ";
266  }
267 
268  if ($a_firstname)
269  {
270  $fullname .= $a_firstname." ";
271  }
272 
273  if ($a_lastname)
274  {
275  return $fullname.$a_lastname;
276  }
277  }
278 
279  function setDocentId($a_ilinc_user_id)
280  {
281  $this->docent_id = $a_ilinc_user_id;
282  }
283 
284  function getDocentName()
285  {
286  if (!$this->docent_name)
287  {
288  $this->docent_name = $this->_getDocent($this->docent_id);
289  }
290 
291  return $this->docent_name;
292  }
293 
294  function getDocentId()
295  {
296  return $this->docent_id;
297  }
298 
299  function setStatus($a_status)
300  {
301  if ($a_status == "Wahr" or $a_status == "1" or $a_status == true)
302  {
303  $this->status = "1";
304  }
305  else
306  {
307  $this->status = "0";
308  }
309  }
310 
311  function getStatus()
312  {
313  return $this->status;
314  }
315 
316  function getErrorMsg()
317  {
318  $err_msg = $this->error_msg;
319  $this->error_msg = "";
320 
321  return $err_msg;
322  }
323 } // END class.ilObjiLincClassroom
324 ?>