ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjiLincCourse.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 
34 require_once 'Services/Container/classes/class.ilContainer.php';
35 require_once 'Modules/ILinc/classes/class.ilnetucateXMLAPI.php';
36 
38 {
45  public function ilObjiLincCourse($a_id = 0,$a_call_by_reference = true)
46  {
47  $this->type = 'icrs';
48  $this->ilObject($a_id,$a_call_by_reference);
49  $this->setRegisterMode(false);
50  $this->ilincAPI = new ilnetucateXMLAPI();
51 
52  $this->docent_ids = array();
53  $this->student_ids = array();
54  }
55 
56  public function getViewMode()
57  {
59  }
60 
65  function read()
66  {
67  global $ilDB, $ilErr;
68 
69  parent::read();
70 
71  // TODO: fetching default role should be done in rbacadmin
72  $q = "SELECT * FROM ilinc_data ".
73  "WHERE obj_id = ".$ilDB->quote($this->id);
74  $r = $ilDB->query($q);
75 
76  if($r->numRows() > 0)
77  {
78  $data = $r->fetchRow(DB_FETCHMODE_OBJECT);
79 
80  $this->ilinc_id = $data->course_id;
81  $this->activated = ilUtil::yn2tf($data->activation_offline);
82  $this->akclassvalue1 = $data->akclassvalue1;
83  $this->akclassvalue2 = $data->akclassvalue2;
84  }
85  else
86  {
87  $ilErr->raiseError("<b>Error: There is no dataset with id ".$this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
88  }
89  }
90 
91  function getiLincId()
92  {
93  return $this->ilinc_id;
94  }
95 
96  function getErrorMsg()
97  {
98  $err_msg = $this->error_msg;
99  $this->error_msg = "";
100 
101  return $err_msg;
102  }
103 
104  function getAKClassValue1()
105  {
106  return $this->akclassvalue1;
107  }
108 
109  function getAKClassValue2()
110  {
111  return $this->akclassvalue2;
112  }
113 
114  function setAKClassValue1($a_str)
115  {
116  $this->akclassvalue1 = $a_str;
117  }
118 
119  function setAKClassValue2($a_str)
120  {
121  $this->akclassvalue2 = $a_str;
122  }
123 
130  function update()
131  {
132  global $ilDB;
133 
134  $this->ilincAPI->editCourse($this->getiLincId(),$_POST["Fobject"]);
135  $response = $this->ilincAPI->sendRequest();
136 
137  if ($response->isError())
138  {
139  $this->error_msg = $response->getErrorMsg();
140  return false;
141  }
142 
143  // TODO: alter akclassvalues of classes here
144 
145  if (!parent::update())
146  {
147  $this->error_msg = "database_error";
148  return false;
149  }
150 
151  $q = "UPDATE ilinc_data SET ".
152  "activation_offline = ".$ilDB->quote($this->activated).", ".
153  "akclassvalue1 = ".$ilDB->quote($this->akclassvalue1).", ".
154  "akclassvalue2 = ".$ilDB->quote($this->akclassvalue2)." ".
155  "WHERE obj_id = ".$ilDB->quote($this->getId());
156  $r = $ilDB->query($q);
157 
158  return true;
159  }
160 
167  function addCourse()
168  {
169  $this->ilincAPI->addCourse($_POST["Fobject"]);
170  $response = $this->ilincAPI->sendRequest();
171 
172  if ($response->isError())
173  {
174  $this->error_msg = $response->getErrorMsg();
175  return false;
176  }
177 
178  $this->ilinc_id = $response->getFirstID();
179 
180  return true;
181  }
182 
183 
190  function delete()
191  {
192  global $ilDB;
193 
194  // always call parent delete function first!!
195  if (!parent::delete())
196  {
197  return false;
198  }
199 
200  //put here your module specific stuff
201  $q = "DELETE FROM ilinc_data WHERE course_id = ".$ilDB->quote($this->getiLincId());
202  $ilDB->query($q);
203 
204  // TODO: delete data in ilinc_registration table
205 
206  // remove course from ilinc server
207  $this->ilincAPI->removeCourse($this->getiLincId());
208  $response = $this->ilincAPI->sendRequest();
209 
210  return true;
211  }
212 
213  // store iLinc Id in ILIAS and set variable
214  function storeiLincId($a_icrs_id)
215  {
216  global $ilDB;
217 
218  $q = "INSERT INTO ilinc_data (obj_id,type,course_id,activation_offline) VALUES (".$ilDB->quote($this->id).",'icrs',".$ilDB->quote($a_icrs_id).",".$ilDB->quote($this->activated).")";
219  $ilDB->query($q);
220 
221  $this->ilinc_id = $a_icrs_id;
222  }
223 
224  // saveActivationStatus()
225  function saveActivationStatus($a_activated)
226  {
227  global $ilDB;
228 
229  $q = "UPDATE ilinc_data SET activation_offline = ".$ilDB->quote($a_activated)." WHERE obj_id = ".$ilDB->quote($this->getId());
230  $r = $ilDB->query($q);
231  }
232 
233  // saveAKClassValues
234  function saveAKClassValues($a_akclassvalue1,$a_akclassvalue2)
235  {
236  global $ilDB;
237 
238  $q = "UPDATE ilinc_data SET ".
239  "akclassvalue1= ".$ilDB->quote($a_akclassvalue1).", ".
240  "akclassvalue2= ".$ilDB->quote($a_akclassvalue2)." ".
241  "WHERE obj_id= ".$ilDB->quote($this->getId());
242  $r = $ilDB->query($q);
243  }
244 
251  function initDefaultRoles()
252  {
253  global $rbacadmin, $rbacreview;
254 
255  // create a local role folder
256  $rfoldObj =& $this->createRoleFolder();
257 
258  // ADMIN ROLE
259  // create role and assign role to rolefolder...
260  $roleObj = $rfoldObj->createRole("il_icrs_admin_".$this->getRefId(),"LearnLinc admin of seminar obj_no.".$this->getId());
261  $this->m_roleAdminId = $roleObj->getId();
262 
263  //set permission template of new local role
264  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_icrs_admin'";
265  $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
266  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
267 
268  // set object permissions of icrs object
269  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"icrs",$rfoldObj->getRefId());
270  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
271 
272  // set object permissions of role folder object
273  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
274  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
275 
276  // MEMBER ROLE
277  // create role and assign role to rolefolder...
278  $roleObj = $rfoldObj->createRole("il_icrs_member_".$this->getRefId(),"LearnLinc admin of seminar obj_no.".$this->getId());
279  $this->m_roleMemberId = $roleObj->getId();
280 
281  //set permission template of new local role
282  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_icrs_member'";
283  $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
284  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
285 
286  // set object permissions of icrs object
287  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"icrs",$rfoldObj->getRefId());
288  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
289 
290  // set object permissions of role folder object
291  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
292  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
293 
294  unset($rfoldObj);
295  unset($roleObj);
296 
297  $roles[] = $this->m_roleAdminId;
298  $roles[] = $this->m_roleMemberId;
299 
300  // Break inheritance and initialize permission settings using intersection method with a non_member_template
301  // not implemented for ilinc. maybe never will...
302  $this->__setCourseStatus();
303 
304  return $roles ? $roles : array();
305  }
306 
320  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
321  {
322  return true;
323  }
324 
332  function addMember(&$a_user_obj, $a_mem_role, $a_instructor = false)
333  {
334  global $rbacadmin;
335 //echo "0";
336  if (!isset($a_user_obj) && !isset($a_mem_role))
337  {
338  $this->error_msg = get_class($this)."::addMember(): Missing parameters !";
339  return false;
340  }
341 //echo "1";
342  // check if user is registered at iLinc server
343  if (!$this->userExists($a_user_obj))
344  {
345  // if not, add user on iLinc server
346  if ($this->addUser($a_user_obj) == false)
347  {
348  // error_msg already set
349  return false;
350  }
351  }
352 //echo "2";
353  // assign membership to icourse on iLinc server
354  if (!$this->registerUser($a_user_obj,$a_instructor))
355  {
356  // error_msg already set
357  return false;
358  }
359 //echo "3";
360  // finally assign user to member role in ILIAS
361  $this->join($a_user_obj->getId(),$a_mem_role);
362 //echo "4";
363  return true;
364  }
365 
371  function join($a_user_id, $a_mem_role="")
372  {
373  global $rbacadmin;
374 
375  if (is_array($a_mem_role))
376  {
377  foreach ($a_mem_role as $role)
378  {
379  $rbacadmin->assignUser($role,$a_user_id, false);
380  }
381  }
382  else
383  {
384  $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
385  }
386 
387  return true;
388  }
389 
394  function leave($a_user_id)
395  {
396  global $rbacadmin;
397 
398  $arr_groupRoles = $this->getMemberRoles($a_user_id);
399 
400  if (is_array($arr_groupRoles))
401  {
402  foreach ($arr_groupRoles as $groupRole)
403  {
404  $rbacadmin->deassignUser($groupRole, $a_user_id);
405  }
406  }
407  else
408  {
409  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
410  }
411 
412  return true;
413  }
414 
421  function getMemberRoles($a_user_id)
422  {
423  global $rbacadmin, $rbacreview;
424 
425  $arr_assignedRoles = array();
426 
427  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalRoles());
428 
429  return $arr_assignedRoles;
430  }
431 
438  function getMemberIds()
439  {
440  global $rbacadmin, $rbacreview;
441 
442  $usr_arr= array();
443 
444  $rol = $this->getLocalRoles();
445 
446  foreach ($rol as $value)
447  {
448  foreach ($rbacreview->assignedUsers($value) as $member_id)
449  {
450  array_push($usr_arr,$member_id);
451  }
452  }
453 
454  $mem_arr = array_unique($usr_arr);
455 
456  return $mem_arr ? $mem_arr : array();
457  }
458 
466  function getMemberData($a_mem_ids, $active = 1)
467  {
468  global $rbacadmin, $rbacreview, $ilBench, $ilDB;
469 
470  $usr_arr= array();
471 
472  $q = "SELECT login,firstname,lastname,title,usr_id,ilinc_id ".
473  "FROM usr_data ".
474  "WHERE usr_id IN (".implode(',',$a_mem_ids).")";
475 
476  if (is_numeric($active) && $active > -1)
477  $q .= "AND active = ".$ilDB->quote($active);
478 
479  $r = $ilDB->query($q);
480 
481  while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
482  {
483  $mem_arr[] = array("id" => $row->usr_id,
484  "login" => $row->login,
485  "firstname" => $row->firstname,
486  "lastname" => $row->lastname,
487  "ilinc_id" => $row->ilinc_id
488  );
489  }
490 
491  return $mem_arr ? $mem_arr : array();
492  }
493 
500  function getLocalRoles($a_translate = false)
501  {
502  global $rbacadmin,$rbacreview;
503 
504  if (empty($this->local_roles))
505  {
506  $this->local_roles = array();
507  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
508  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
509 
510  foreach ($role_arr as $role_id)
511  {
512  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
513  {
514  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
515 
516  if ($a_translate)
517  {
518  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
519  }
520  else
521  {
522  $role_name = $role_Obj->getTitle();
523  }
524 
525  $this->local_roles[$role_name] = $role_Obj->getId();
526  }
527  }
528  }
529 
530  return $this->local_roles;
531  }
532 
539  function getMemberRolesTitle($a_user_id)
540  {
541  global $ilDB,$ilBench;
542 
543  include_once ('./Services/AccessControl/classes/class.ilObjRole.php');
544 
545  $str_member_roles ="";
546 
547  $q = "SELECT title ".
548  "FROM object_data ".
549  "LEFT JOIN rbac_ua ON object_data.obj_id=rbac_ua.rol_id ".
550  "WHERE object_data.type = 'role' ".
551  "AND rbac_ua.usr_id = ".$ilDB->quote($a_user_id)." ".
552  "AND rbac_ua.rol_id IN (".implode(',',$this->getLocalRoles()).")";
553 
554  $r = $ilDB->query($q);
555 
556  while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
557  {
558  // display human readable role names for autogenerated roles
559  $str_member_roles .= ilObjRole::_getTranslation($row["title"]).", ";
560  }
561 
562  return substr($str_member_roles,0,-2);
563  }
564 
570  {
571  $local_icrs_Roles = $this->getLocalRoles();
572 
573  return $local_icrs_Roles["il_icrs_member_".$this->getRefId()];
574  }
575 
581  {
582  $local_icrs_Roles = $this->getLocalRoles();
583 
584  return $local_icrs_Roles["il_icrs_admin_".$this->getRefId()];
585  }
586 
587  function getClassrooms()
588  {
589  global $ilErr;
590 
591  if (!$this->ilias->getSetting("ilinc_active"))
592  {
593  $this->error_msg = "ilinc_server_not_active";
594  return false;
595  }
596 
597  $this->ilincAPI->findCourseClasses($this->getiLincId());
598  $response = $this->ilincAPI->sendRequest();
599 
600  if ($response->isError())
601  {
602  if (!$response->getErrorMsg())
603  {
604  $this->error_msg = "err_get_classrooms";
605  }
606  else
607  {
608  $this->error_msg = $response->getErrorMsg();
609  }
610 
611  return false;
612  }
613 
614  if (!$response->data['classes'])
615  {
616 
617  $this->error_msg = $response->data['result']['cdata'];
618  return false;
619  }
620 
621  foreach ($response->data['classes'] as $class_id => $data)
622  {
623  $this->ilincAPI->findClass($class_id);
624  $response = $this->ilincAPI->sendRequest("findClass");
625 
626  if ($response->data['classes'])
627  {
628  $full_class_data[$class_id] = $response->data['classes'][$class_id];
629  }
630  }
631 
632  return $full_class_data;
633  }
634 
635  function updateClassrooms()
636  {
637  global $ilErr;
638 
639  $this->ilincAPI->findCourseClasses($this->getiLincId());
640  $response = $this->ilincAPI->sendRequest();
641 
642  if ($response->isError())
643  {
644  if (!$response->getErrorMsg())
645  {
646  $this->error_msg = "err_get_classrooms";
647  }
648  else
649  {
650  $this->error_msg = $response->getErrorMsg();
651  }
652 
653  return false;
654  }
655 
656  if (!$response->data['classes'])
657  {
658 
659  $this->error_msg = $response->data['result']['cdata'];
660  return false;
661  }
662 
663  if (array_key_exists('akclassvalue1',$_POST["Fobject"]))
664  {
665  $data["akclassvalue1"] = $_POST["Fobject"]["akclassvalue1"];
666  }
667 
668  if (array_key_exists('akclassvalue2',$_POST["Fobject"]))
669  {
670  $data["akclassvalue2"] = $_POST["Fobject"]["akclassvalue2"];
671  }
672 
673  foreach ($response->data['classes'] as $class_id => $data2)
674  {
675  include_once("./Modules/ILinc/classes/class.ilObjiLincClassroom.php");
676  $icla_obj = new ilObjiLincClassroom($class_id,$this->ref_id);
677 
678  if (!$icla_obj->update($data))
679  {
680  $this->error_msg = $icla_obj->getErrorMsg();
681 
682  return false;
683  }
684 
685  unset($icla_obj);
686  }
687 
688  return true;
689  }
690 
691  // checks if user account already exists at iLinc server
692  // TODO: check is only local in ILIAS not on iLinc server
693  function userExists(&$a_user_obj)
694  {
695  //$data = $a_user_obj->getiLincData();
696 
697  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
698  $ilinc_user = new ilObjiLincUser($a_user_obj);
699 
700  if (!$ilinc_user->id and !$ilinc_user->login)
701  {
702  return false;
703  }
704 
705  return true;
706  }
707 
708  // create user account on iLinc server
709  function addUser(&$a_user_obj)
710  {
711  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
712  $ilinc_user = new ilObjiLincUser($a_user_obj);
713 
714  return $ilinc_user->add();
715  }
716 
717  function isMember($a_user_id = "")
718  {
719  if (strlen($a_user_id) == 0)
720  {
721  $a_user_id = $this->ilias->account->getId();
722  }
723 
724  $arr_members = $this->getMemberIds();
725 
726  if (in_array($a_user_id, $arr_members))
727  {
728  return true;
729  }
730 
731  return false;
732  }
733 
734  function isDocent($a_user_obj = "")
735  {
736  if (!$a_user_obj)
737  {
738  $a_user_obj =& $this->ilias->account;
739  }
740 
741  $docents = $this->getiLincMemberIds(true);
742 
743  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
744  $ilinc_user = new ilObjiLincUser($a_user_obj);
745 
746  if (in_array($ilinc_user->id,$docents))
747  {
748  return true;
749  }
750 
751  return false;
752  }
753 
754  function registerUser(&$a_user_obj,$a_instructor = false)
755  {
756  if ($a_instructor === true)
757  {
758  $a_instructor = "True";
759  }
760  else
761  {
762  $a_instructor = "False";
763  }
764 
765  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
766  $ilinc_user = new ilObjiLincUser($a_user_obj);
767 
768  $user[] = array('id' => $ilinc_user->id, 'instructor' => $a_instructor);
769  $this->ilincAPI->registerUser($this->getiLincId(),$user);
770  $response = $this->ilincAPI->sendRequest("registerUser");
771 
772  if ($response->isError())
773  {
774  if (!$response->getErrorMsg())
775  {
776  $this->error_msg = "err_register_user";
777  }
778  else
779  {
780  $this->error_msg = $response->getErrorMsg();
781  }
782 
783  return false;
784  }
785 
786  return true;
787  }
788 
789  function registerUsers($a_user_arr)
790  {
791  foreach ($a_user_arr as $user_id => $instructorflag)
792  {
793  $flag = "False";
794 
795  if ($instructorflag == ILINC_MEMBER_DOCENT)
796  {
797  $flag = "True";
798  }
799 
800  $ilinc_users[] = array('id' => $user_id,'instructor' => $flag);
801  }
802 
803  $this->ilincAPI->registerUser($this->getiLincId(),$ilinc_users);
804  $response = $this->ilincAPI->sendRequest("registerUser");
805 
806  if ($response->isError())
807  {
808  if (!$response->getErrorMsg())
809  {
810  $this->error_msg = "err_register_users";
811  }
812  else
813  {
814  $this->error_msg = $response->getErrorMsg();
815  }
816 
817  return false;
818  }
819 
820  return true;
821  }
822 
823  // unregister user from course on iLinc server
824  function unregisterUser($a_user_obj)
825  {
826  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
827  $ilinc_user = new ilObjiLincUser($a_user_obj);
828 
829  // do not send request if user is not registered at iLinc server at all
830  if ($ilinc_user->id == '0')
831  {
832  return true;
833  }
834 
835  $this->ilincAPI->unregisterUser($this->getiLincId(),array($ilinc_user->id));
836  $response = $this->ilincAPI->sendRequest();
837 
838  if ($response->isError())
839  {
840  if (!$response->getErrorMsg())
841  {
842  $this->error_msg = "err_unregister_user";
843  }
844  else
845  {
846  $this->error_msg = $response->getErrorMsg();
847  }
848 
849  return false;
850  }
851 
852  return true;
853  }
854 
855  function unregisterUsers($a_ilinc_user_ids)
856  {
857  $this->ilincAPI->unregisterUser($this->getiLincId(),$a_ilinc_user_ids);
858  $response = $this->ilincAPI->sendRequest();
859 
860  if ($response->isError())
861  {
862  if (!$response->getErrorMsg())
863  {
864  $this->error_msg = "err_unregister_users";
865  }
866  else
867  {
868  $this->error_msg = $response->getErrorMsg();
869  }
870 
871  return false;
872  }
873 
874  return true;
875  }
876 
877  function userLogin(&$a_user_obj)
878  {
879  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
880  $ilinc_user = new ilObjiLincUser($a_user_obj);
881 
882  $this->ilincAPI->userLogin($ilinc_user);
883  $response = $this->ilincAPI->sendRequest("userLogin");
884 
885  if ($response->isError())
886  {
887  if (!$response->getErrorMsg())
888  {
889  $this->error_msg = "err_user_login";
890  }
891  else
892  {
893  $this->error_msg = $response->getErrorMsg();
894  }
895 
896  return false;
897  }
898 
899  // return URL to join class room
900  return $response->data['url']['cdata'];
901  }
902 
903  // not used here
904  function uploadPicture(&$a_user_obj,$a_lang)
905  {
906  $this->ilincAPI->uploadPicture($a_user_obj,$a_lang);
907  $response = $this->ilincAPI->sendRequest("uploadPicture");
908 
909  if ($response->isError())
910  {
911  if (!$response->getErrorMsg())
912  {
913  $this->error_msg = "err_upload_picture";
914  }
915  else
916  {
917  $this->error_msg = $response->getErrorMsg();
918  }
919 
920  return false;
921  }
922 
923  // return URL to user's personal page
924  return $response->data['url']['cdata'];
925  }
926 
933  function getAdminIds($a_grpId="")
934  {
935  global $rbacreview;
936 
937  if (!empty($a_grpId))
938  {
939  $grp_id = $a_grpId;
940  }
941  else
942  {
943  $grp_id = $this->getRefId();
944  }
945 
946  $usr_arr = array();
947  $roles = $this->getDefaultRoles($this->getRefId());
948 
949  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
950  {
951  array_push($usr_arr,$member_id);
952  }
953 
954  return $usr_arr;
955  }
956 
961  function removeMember(&$a_user_obj)
962  {
963  if (!isset($a_user_obj))
964  {
965  $this->error_msg = get_class($this)."::removeMember(): Missing parameters !";
966  return false;
967  }
968 
969  if (!$this->isMember($a_user_obj->getId()))
970  {
971  return true;
972  }
973 
974  if (count($this->getMemberIds()) > 1)
975  {
976  if ($this->isAdmin($a_user_obj->getId()) && count($this->getAdminIds()) < 2)
977  {
978  $this->error_msg = "ilinc_err_administrator_required";
979  return false;
980  }
981  }
982 
983  // unregister from course on iLinc server
984  if (!$this->unregisterUser($a_user_obj))
985  {
986  // error_msg already set
987  return false;
988  }
989 
990  $this->leave($a_user_obj->getId());
991 
992  return true;
993  }
994 
1001  function isAdmin($a_user_id)
1002  {
1003  global $rbacreview;
1004 
1005  $icrs_roles = $this->getDefaultRoles();
1006 
1007  if (in_array($a_user_id,$rbacreview->assignedUsers($icrs_roles["icrs_admin_role"])))
1008  {
1009  return true;
1010  }
1011  else
1012  {
1013  return false;
1014  }
1015  }
1016 
1022  function getDefaultRoles($a_grp_id="")
1023  {
1024  global $rbacadmin, $rbacreview;
1025 
1026  if (strlen($a_grp_id) > 0)
1027  {
1028  $grp_id = $a_grp_id;
1029  }
1030  else
1031  {
1032  $grp_id = $this->getRefId();
1033  }
1034 
1035  $rolf = $rbacreview->getRoleFolderOfObject($grp_id);
1036  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1037 
1038  foreach ($role_arr as $role_id)
1039  {
1040  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1041 
1042  $grp_Member ="il_icrs_member_".$grp_id;
1043  $grp_Admin ="il_icrs_admin_".$grp_id;
1044 
1045  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1046  {
1047  $arr_grpDefaultRoles["icrs_member_role"] = $role_Obj->getId();
1048  }
1049 
1050  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1051  {
1052  $arr_grpDefaultRoles["icrs_admin_role"] = $role_Obj->getId();
1053  }
1054  }
1055 
1056  return $arr_grpDefaultRoles;
1057  }
1058 
1059  // returns ilinc_user_ids of course (students=false,docents=true)
1060  function getiLincMemberIds($a_instructorflag = false)
1061  {
1062  if ($a_instructorflag == true)
1063  {
1064  if (!empty($this->docent_ids))
1065  {
1066  return $this->docent_ids;
1067  }
1068  }
1069  else
1070  {
1071  if (!empty($this->student_ids))
1072  {
1073  return $this->student_ids;
1074  }
1075  }
1076 
1077  $this->ilincAPI->findRegisteredUsersByRole($this->getiLincId(),$a_instructorflag);
1078  $response = $this->ilincAPI->sendRequest();
1079 
1080  if (is_array($response->data['users']))
1081  {
1082  if ($a_instructorflag == true)
1083  {
1084  $this->docent_ids = array_keys($response->data['users']);
1085  }
1086  else
1087  {
1088  $this->student_ids = array_keys($response->data['users']);
1089  }
1090 
1091  return array_keys($response->data['users']);
1092  }
1093 
1094  return array();
1095  }
1096 
1097  function checkiLincMemberStatus($a_ilinc_user_id,$a_docent_ids,$a_student_ids)
1098  {
1099  if (in_array($a_ilinc_user_id,$a_docent_ids))
1100  {
1101  return ILINC_MEMBER_DOCENT;
1102  }
1103 
1104  if (in_array($a_ilinc_user_id,$a_student_ids))
1105  {
1106  return ILINC_MEMBER_STUDENT;
1107  }
1108 
1109  return ILINC_MEMBER_NOTSET;
1110  }
1111 
1112  function _isActivated($a_course_obj_id)
1113  {
1114  global $ilDB,$ilias;
1115 
1116  if (!$ilias->getSetting("ilinc_active"))
1117  {
1118  return false;
1119  }
1120 
1121  $q = "SELECT activation_offline FROM ilinc_data WHERE obj_id=".$ilDB->quote($a_course_obj_id);
1122  $r = $ilDB->query($q);
1123 
1124  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
1125 
1126  return ilUtil::yn2tf($row->activation_offline);
1127  }
1128 
1129  function _getAKClassValues($a_course_obj_id)
1130  {
1131  global $ilDB,$ilias;
1132 
1133  $q = "SELECT akclassvalue1, akclassvalue2 FROM ilinc_data WHERE obj_id=".$ilDB->quote($a_course_obj_id);
1134  $r = $ilDB->query($q);
1135 
1136  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
1137 
1138  return $akclassvalues = array($row->akclassvalue1,$row->akclassvalue2);
1139  }
1140 
1141  function _isMember($a_user_id,$a_ref_id)
1142  {
1143  global $rbacreview;
1144 
1145  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
1146  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1147  $user_roles = $rbacreview->assignedRoles($a_user_id);
1148 
1149  if (!array_intersect($local_roles,$user_roles))
1150  {
1151  return false;
1152  }
1153 
1154  return true;
1155  }
1156 
1158  {
1159  // empty
1160  }
1161 
1166  function getSubItems()
1167  {
1168  $objects = array();
1169 
1170  if(!($objects = $this->getClassrooms()))
1171  {
1172  ilUtil::sendInfo($this->lng->txt($this->getErrorMsg()));
1173  return array();
1174  }
1175 
1176  foreach((array)$objects as $key => $object)
1177  {
1178  $this->items['icla'][$key] = $object;
1179  }
1180 
1181  return is_array($this->items) ? $this->items : array();
1182  }
1183 
1192  function _getLinkToObject($a_id)
1193  {
1194  return array("repository.php?ref_id=".$a_id."&set_mode=flat&cmdClass=ilobjilinccoursegui","");
1195  }
1196 } // END class.ilObjiLincCourse
1197 ?>