ILIAS  Release_5_0_x_branch Revision 61816
 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  $r = $ilDB->queryf('
73  SELECT * FROM ilinc_data
74  WHERE obj_id = %s',
75  array('integer'), array($this->id));
76 
77  if($ilDB->numRows($r) > 0)
78  {
79  $data = $ilDB->fetchObject($r);
80 
81  $this->ilinc_id = $data->course_id;
82  $this->activated = ilUtil::yn2tf($data->activation_offline);
83  $this->akclassvalue1 = $data->akclassvalue1;
84  $this->akclassvalue2 = $data->akclassvalue2;
85  }
86  else
87  {
88  $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);
89  }
90  }
91 
92  function getiLincId()
93  {
94  return $this->ilinc_id;
95  }
96 
97  function getErrorMsg()
98  {
99  $err_msg = $this->error_msg;
100  $this->error_msg = "";
101 
102  return $err_msg;
103  }
104 
105  function getAKClassValue1()
106  {
107  return $this->akclassvalue1;
108  }
109 
110  function getAKClassValue2()
111  {
112  return $this->akclassvalue2;
113  }
114 
115  function setAKClassValue1($a_str)
116  {
117  $this->akclassvalue1 = $a_str;
118  }
119 
120  function setAKClassValue2($a_str)
121  {
122  $this->akclassvalue2 = $a_str;
123  }
124 
131  function update()
132  {
133  global $ilDB;
134 
135  $this->ilincAPI->editCourse($this->getiLincId(),$_POST["Fobject"]);
136  $response = $this->ilincAPI->sendRequest();
137 
138  if ($response->isError())
139  {
140  $this->error_msg = $response->getErrorMsg();
141  return false;
142  }
143 
144  // TODO: alter akclassvalues of classes here
145 
146  if (!parent::update())
147  {
148  $this->error_msg = "database_error";
149  return false;
150  }
151 
152  $db_activated_value = is_bool($this->activated) ? ($this->activated ? 'y' : 'n') : $this->activated;
153 
154  $r = $ilDB->manipulateF('
155  UPDATE ilinc_data
156  SET activation_offline = %s,
157  akclassvalue1 = %s,
158  akclassvalue2 = %s
159  WHERE obj_id = %s',
160  array('text', 'text', 'text', 'integer'),
161  array($db_activated_value, $this->getAKClassValue1(), $this->getAKClassValue2(), $this->getId()));
162 
163  return true;
164  }
165 
172  function addCourse()
173  {
174  $this->ilincAPI->addCourse($_POST["Fobject"]);
175  $response = $this->ilincAPI->sendRequest();
176 
177  if ($response->isError())
178  {
179  $this->error_msg = $response->getErrorMsg();
180  return false;
181  }
182 
183  $this->ilinc_id = $response->getFirstID();
184 
185  return true;
186  }
187 
188 
195  function delete()
196  {
197  global $ilDB;
198 
199  // always call parent delete function first!!
200  if (!parent::delete())
201  {
202  return false;
203  }
204 
205  //put here your module specific stuff
206  $statement = $ilDB->manipulateF('
207  DELETE FROM ilinc_data WHERE course_id = %s',
208  array('integer'), array($this->getiLincId()));
209 
210 
211  // TODO: delete data in ilinc_registration table
212  /*
213  * not tested yet
214  */
215 /* $statement = $ilDB->manipulateF('
216  DELETE FROM ilinc_registration
217  WHERE obj_id = %s',
218  array('integer'), array($this->getId()));
219 
220 */
221 
222  // remove course from ilinc server
223  $this->ilincAPI->removeCourse($this->getiLincId());
224  $response = $this->ilincAPI->sendRequest();
225 
226  return true;
227  }
228 
229  // store iLinc Id in ILIAS and set variable
230  function storeiLincId($a_icrs_id)
231  {
232  global $ilDB;
233 
234  $statement = $ilDB->manipulateF('
235  INSERT INTO ilinc_data (
236  obj_id, i_type, course_id, activation_offline)
237  VALUES (%s, %s, %s, %s)',
238  array('integer', 'text', 'integer', 'text'),
239  array($this->id,'icrs',$a_icrs_id,$this->activated));
240 
241  $this->ilinc_id = $a_icrs_id;
242  }
243 
244  // saveActivationStatus()
245  function saveActivationStatus($a_activated)
246  {
247  global $ilDB;
248 
249  $statement = $ilDB->manipulateF('
250  UPDATE ilinc_data
251  SET activation_offline = %s
252  WHERE obj_id = %s',
253  array('text', 'integer'),
254  array($a_activated, $this->getId()));
255 
256  }
257 
258  // saveAKClassValues
259  function saveAKClassValues($a_akclassvalue1,$a_akclassvalue2)
260  {
261  global $ilDB;
262 
263  $statement = $ilDB->manipulateF('
264  UPDATE ilinc_data
265  SET akclassvalue1 = %s,
266  akclassvalue2 = %s
267  WHERE obj_id = %s',
268  array('text', 'text', 'integer'),
269  array($a_akclassvalue1, $a_akclassvalue2, $this->getId()));
270 
271  }
272 
273 
287  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
288  {
289  return true;
290  }
291 
299  function addMember(&$a_user_obj, $a_mem_role, $a_instructor = false)
300  {
301  global $rbacadmin;
302 //echo "0";
303  if (!isset($a_user_obj) && !isset($a_mem_role))
304  {
305  $this->error_msg = get_class($this)."::addMember(): Missing parameters !";
306  return false;
307  }
308 //echo "1";
309  // check if user is registered at iLinc server
310  if (!$this->userExists($a_user_obj))
311  {
312  // if not, add user on iLinc server
313  if ($this->addUser($a_user_obj) == false)
314  {
315  // error_msg already set
316  return false;
317  }
318  }
319 //echo "2";
320  // assign membership to icourse on iLinc server
321  if (!$this->registerUser($a_user_obj,$a_instructor))
322  {
323  // error_msg already set
324  return false;
325  }
326 //echo "3";
327  // finally assign user to member role in ILIAS
328  $this->join($a_user_obj->getId(),$a_mem_role);
329 //echo "4";
330  return true;
331  }
332 
338  function join($a_user_id, $a_mem_role="")
339  {
340  global $rbacadmin;
341 
342  if (is_array($a_mem_role))
343  {
344  foreach ($a_mem_role as $role)
345  {
346  $rbacadmin->assignUser($role,$a_user_id, false);
347  }
348  }
349  else
350  {
351  $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
352  }
353 
354  return true;
355  }
356 
361  function leave($a_user_id)
362  {
363  global $rbacadmin;
364 
365  $arr_groupRoles = $this->getMemberRoles($a_user_id);
366 
367  if (is_array($arr_groupRoles))
368  {
369  foreach ($arr_groupRoles as $groupRole)
370  {
371  $rbacadmin->deassignUser($groupRole, $a_user_id);
372  }
373  }
374  else
375  {
376  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
377  }
378 
379  return true;
380  }
381 
388  function getMemberRoles($a_user_id)
389  {
390  global $rbacadmin, $rbacreview;
391 
392  $arr_assignedRoles = array();
393 
394  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalRoles());
395 
396  return $arr_assignedRoles;
397  }
398 
405  function getMemberIds()
406  {
407  global $rbacadmin, $rbacreview;
408 
409  $usr_arr= array();
410 
411  $rol = $this->getLocalRoles();
412 
413  foreach ($rol as $value)
414  {
415  foreach ($rbacreview->assignedUsers($value) as $member_id)
416  {
417  array_push($usr_arr,$member_id);
418  }
419  }
420 
421  $mem_arr = array_unique($usr_arr);
422 
423  return $mem_arr ? $mem_arr : array();
424  }
425 
433  function getMemberData($a_mem_ids, $active = 1)
434  {
435  global $rbacadmin, $rbacreview, $ilBench, $ilDB;
436 
437  $usr_arr= array();
438 
439  $data_types = array();
440  $data_values = array();
441  $cnt_mem_ids = count($a_mem_ids);
442 
443  $query = 'SELECT login,firstname,lastname,title,usr_id,ilinc_id
444  FROM usr_data WHERE usr_id IN ';
445 
446  if (is_array($a_mem_ids) &&
447  $cnt_mem_ids > 0)
448  {
449  $in = '(';
450  $counter = 0;
451  foreach($a_mem_ids as $mem_id)
452  {
453  array_push($data_values, $mem_id);
454  array_push($data_types, 'integer');
455 
456  if($counter > 0) $in .= ',';
457  $in .= '%s';
458  ++$counter;
459  }
460  $in .= ')';
461  $query .= $in;
462  }
463 
464  if (is_numeric($active) && $active > -1)
465  {
466  $query .= ' AND active = %s';
467  array_push($data_values,$active);
468  array_push($data_types, 'integer');
469  }
470 
471  $r = $ilDB->queryf($query, $data_types, $data_values);
472 
473  while($row = $ilDB->fetchObject($r))
474  {
475  $mem_arr[] = array("id" => $row->usr_id,
476  "login" => $row->login,
477  "firstname" => $row->firstname,
478  "lastname" => $row->lastname,
479  "ilinc_id" => $row->ilinc_id
480  );
481  }
482 
483  return $mem_arr ? $mem_arr : array();
484  }
485 
492  function getLocalRoles($a_translate = false)
493  {
494  global $rbacadmin,$rbacreview;
495 
496  if (empty($this->local_roles))
497  {
498  $this->local_roles = array();
499  $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
500 
501  foreach ($role_arr as $role_id)
502  {
503  if ($rbacreview->isAssignable($role_id,$this->getRefId()) == true)
504  {
505  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
506 
507  if ($a_translate)
508  {
509  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
510  }
511  else
512  {
513  $role_name = $role_Obj->getTitle();
514  }
515 
516  $this->local_roles[$role_name] = $role_Obj->getId();
517  }
518  }
519  }
520 
521  return $this->local_roles;
522  }
523 
530  function getMemberRolesTitle($a_user_id)
531  {
532  global $ilDB,$ilBench;
533 
534  include_once ('./Services/AccessControl/classes/class.ilObjRole.php');
535 
536  $str_member_roles ="";
537 
538  $data_types = array();
539  $data_values = array();
540 
541  $query = 'SELECT title FROM object_data
542  LEFT JOIN rbac_ua ON object_data.obj_id = rbac_ua.rol_id
543  WHERE object_data.type = %s
544  AND rbac_ua.usr_id = %s
545  AND rbac_ua.rol_id IN';
546 
547  array_push($data_types, 'text', 'integer');
548  array_push($data_values,'role', $a_user_id);
549 
550  $local_roles = $this->getLocalRoles();
551  $cnt_local_roles = count($local_roles);
552 
553  if (is_array($local_roles) &&
554  $cnt_local_roles > 0)
555  {
556  $in = '(';
557  $counter = 0;
558  foreach($local_roles as $local_role)
559  {
560  array_push($data_values, $local_role);
561  array_push($data_types, 'integer');
562 
563  if($counter > 0) $in .= ',';
564  $in .= '%s';
565  ++$counter;
566  }
567  $in .= ')';
568  $query .= $in;
569  }
570  $cnt_data_values = count($data_values);
571  $cnt_data_types = count($data_types);
572 
573  $r = $ilDB->queryf($query, $data_types, $data_values);
574 
575  while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
576  {
577  // display human readable role names for autogenerated roles
578  $str_member_roles .= ilObjRole::_getTranslation($row["title"]).", ";
579  }
580 
581  return substr($str_member_roles,0,-2);
582  }
583 
589  {
590  $local_icrs_Roles = $this->getLocalRoles();
591 
592  return $local_icrs_Roles["il_icrs_member_".$this->getRefId()];
593  }
594 
600  {
601  $local_icrs_Roles = $this->getLocalRoles();
602 
603  return $local_icrs_Roles["il_icrs_admin_".$this->getRefId()];
604  }
605 
606  function getClassrooms()
607  {
608  global $ilErr;
609 
610  if (!$this->ilias->getSetting("ilinc_active"))
611  {
612  $this->error_msg = "ilinc_server_not_active";
613  return false;
614  }
615 
616  $this->ilincAPI->findCourseClasses($this->getiLincId());
617  $response = $this->ilincAPI->sendRequest();
618 
619  if ($response->isError())
620  {
621  if (!$response->getErrorMsg())
622  {
623  $this->error_msg = "err_get_classrooms";
624  }
625  else
626  {
627  $this->error_msg = $response->getErrorMsg();
628  }
629 
630  return false;
631  }
632 
633  if (!$response->data['classes'])
634  {
635 
636  $this->error_msg = $response->data['result']['cdata'];
637  return false;
638  }
639 
640  foreach ($response->data['classes'] as $class_id => $data)
641  {
642  $this->ilincAPI->findClass($class_id);
643  $response = $this->ilincAPI->sendRequest("findClass");
644 
645  if ($response->data['classes'])
646  {
647  $full_class_data[$class_id] = $response->data['classes'][$class_id];
648  }
649  }
650 
651  return $full_class_data;
652  }
653 
654  function updateClassrooms()
655  {
656  global $ilErr;
657 
658  $this->ilincAPI->findCourseClasses($this->getiLincId());
659  $response = $this->ilincAPI->sendRequest();
660 
661  if ($response->isError())
662  {
663  if (!$response->getErrorMsg())
664  {
665  $this->error_msg = "err_get_classrooms";
666  }
667  else
668  {
669  $this->error_msg = $response->getErrorMsg();
670  }
671 
672  return false;
673  }
674 
675  if (!$response->data['classes'])
676  {
677 
678  $this->error_msg = $response->data['result']['cdata'];
679  return false;
680  }
681 
682  if (array_key_exists('akclassvalue1',$_POST["Fobject"]))
683  {
684  $data["akclassvalue1"] = $_POST["Fobject"]["akclassvalue1"];
685  }
686 
687  if (array_key_exists('akclassvalue2',$_POST["Fobject"]))
688  {
689  $data["akclassvalue2"] = $_POST["Fobject"]["akclassvalue2"];
690  }
691 
692  foreach ($response->data['classes'] as $class_id => $data2)
693  {
694  include_once("./Modules/ILinc/classes/class.ilObjiLincClassroom.php");
695  $icla_obj = new ilObjiLincClassroom($class_id,$this->ref_id);
696 
697  if (!$icla_obj->update($data))
698  {
699  $this->error_msg = $icla_obj->getErrorMsg();
700 
701  return false;
702  }
703 
704  unset($icla_obj);
705  }
706 
707  return true;
708  }
709 
710  // checks if user account already exists at iLinc server
711  // TODO: check is only local in ILIAS not on iLinc server
712  function userExists(&$a_user_obj)
713  {
714  //$data = $a_user_obj->getiLincData();
715 
716  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
717  $ilinc_user = new ilObjiLincUser($a_user_obj);
718 
719  if (!$ilinc_user->id and !$ilinc_user->login)
720  {
721  return false;
722  }
723 
724  return true;
725  }
726 
727  // create user account on iLinc server
728  function addUser(&$a_user_obj)
729  {
730  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
731  $ilinc_user = new ilObjiLincUser($a_user_obj);
732 
733  return $ilinc_user->add();
734  }
735 
736  function isMember($a_user_id = "")
737  {
738  if (strlen($a_user_id) == 0)
739  {
740  $a_user_id = $this->ilias->account->getId();
741  }
742 
743  $arr_members = $this->getMemberIds();
744 
745  if (in_array($a_user_id, $arr_members))
746  {
747  return true;
748  }
749 
750  return false;
751  }
752 
753  function isDocent($a_user_obj = "")
754  {
755  if (!$a_user_obj)
756  {
757  $a_user_obj =& $this->ilias->account;
758  }
759 
760  $docents = $this->getiLincMemberIds(true);
761 
762  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
763  $ilinc_user = new ilObjiLincUser($a_user_obj);
764 
765  if (in_array($ilinc_user->id,$docents))
766  {
767  return true;
768  }
769 
770  return false;
771  }
772 
773  function registerUser(&$a_user_obj,$a_instructor = false)
774  {
775  if ($a_instructor === true)
776  {
777  $a_instructor = "True";
778  }
779  else
780  {
781  $a_instructor = "False";
782  }
783 
784  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
785  $ilinc_user = new ilObjiLincUser($a_user_obj);
786 
787  $user[] = array('id' => $ilinc_user->id, 'instructor' => $a_instructor);
788  $this->ilincAPI->registerUser($this->getiLincId(),$user);
789  $response = $this->ilincAPI->sendRequest("registerUser");
790 
791  if ($response->isError())
792  {
793  if (!$response->getErrorMsg())
794  {
795  $this->error_msg = "err_register_user";
796  }
797  else
798  {
799  $this->error_msg = $response->getErrorMsg();
800  }
801 
802  return false;
803  }
804 
805  return true;
806  }
807 
808  function registerUsers($a_user_arr)
809  {
810  foreach ($a_user_arr as $user_id => $instructorflag)
811  {
812  $flag = "False";
813 
814  if ($instructorflag == ILINC_MEMBER_DOCENT)
815  {
816  $flag = "True";
817  }
818 
819  $ilinc_users[] = array('id' => $user_id,'instructor' => $flag);
820  }
821 
822  $this->ilincAPI->registerUser($this->getiLincId(),$ilinc_users);
823  $response = $this->ilincAPI->sendRequest("registerUser");
824 
825  if ($response->isError())
826  {
827  if (!$response->getErrorMsg())
828  {
829  $this->error_msg = "err_register_users";
830  }
831  else
832  {
833  $this->error_msg = $response->getErrorMsg();
834  }
835 
836  return false;
837  }
838 
839  return true;
840  }
841 
842  // unregister user from course on iLinc server
843  function unregisterUser($a_user_obj)
844  {
845  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
846  $ilinc_user = new ilObjiLincUser($a_user_obj);
847 
848  // do not send request if user is not registered at iLinc server at all
849  if ($ilinc_user->id == '0')
850  {
851  return true;
852  }
853 
854  $this->ilincAPI->unregisterUser($this->getiLincId(),array($ilinc_user->id));
855  $response = $this->ilincAPI->sendRequest();
856 
857  if ($response->isError())
858  {
859  if (!$response->getErrorMsg())
860  {
861  $this->error_msg = "err_unregister_user";
862  }
863  else
864  {
865  $this->error_msg = $response->getErrorMsg();
866  }
867 
868  return false;
869  }
870 
871  return true;
872  }
873 
874  function unregisterUsers($a_ilinc_user_ids)
875  {
876  $this->ilincAPI->unregisterUser($this->getiLincId(),$a_ilinc_user_ids);
877  $response = $this->ilincAPI->sendRequest();
878 
879  if ($response->isError())
880  {
881  if (!$response->getErrorMsg())
882  {
883  $this->error_msg = "err_unregister_users";
884  }
885  else
886  {
887  $this->error_msg = $response->getErrorMsg();
888  }
889 
890  return false;
891  }
892 
893  return true;
894  }
895 
896  function userLogin(&$a_user_obj)
897  {
898  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
899  $ilinc_user = new ilObjiLincUser($a_user_obj);
900 
901  $this->ilincAPI->userLogin($ilinc_user);
902  $response = $this->ilincAPI->sendRequest("userLogin");
903 
904  if ($response->isError())
905  {
906  if (!$response->getErrorMsg())
907  {
908  $this->error_msg = "err_user_login";
909  }
910  else
911  {
912  $this->error_msg = $response->getErrorMsg();
913  }
914 
915  return false;
916  }
917 
918  // return URL to join class room
919  return $response->data['url']['cdata'];
920  }
921 
922  // not used here
923  function uploadPicture(&$a_user_obj,$a_lang)
924  {
925  $this->ilincAPI->uploadPicture($a_user_obj,$a_lang);
926  $response = $this->ilincAPI->sendRequest("uploadPicture");
927 
928  if ($response->isError())
929  {
930  if (!$response->getErrorMsg())
931  {
932  $this->error_msg = "err_upload_picture";
933  }
934  else
935  {
936  $this->error_msg = $response->getErrorMsg();
937  }
938 
939  return false;
940  }
941 
942  // return URL to user's personal page
943  return $response->data['url']['cdata'];
944  }
945 
952  function getAdminIds($a_grpId="")
953  {
954  global $rbacreview;
955 
956  if (!empty($a_grpId))
957  {
958  $grp_id = $a_grpId;
959  }
960  else
961  {
962  $grp_id = $this->getRefId();
963  }
964 
965  $usr_arr = array();
966  $roles = $this->getDefaultRoles($this->getRefId());
967 
968  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
969  {
970  array_push($usr_arr,$member_id);
971  }
972 
973  return $usr_arr;
974  }
975 
980  function removeMember(&$a_user_obj)
981  {
982  if (!isset($a_user_obj))
983  {
984  $this->error_msg = get_class($this)."::removeMember(): Missing parameters !";
985  return false;
986  }
987 
988  if (!$this->isMember($a_user_obj->getId()))
989  {
990  return true;
991  }
992 
993  if (count($this->getMemberIds()) > 1)
994  {
995  if ($this->isAdmin($a_user_obj->getId()) && count($this->getAdminIds()) < 2)
996  {
997  $this->error_msg = "ilinc_err_administrator_required";
998  return false;
999  }
1000  }
1001 
1002  // unregister from course on iLinc server
1003  if (!$this->unregisterUser($a_user_obj))
1004  {
1005  // error_msg already set
1006  return false;
1007  }
1008 
1009  $this->leave($a_user_obj->getId());
1010 
1011  return true;
1012  }
1013 
1020  function isAdmin($a_user_id)
1021  {
1022  global $rbacreview;
1023 
1024  $icrs_roles = $this->getDefaultRoles();
1025 
1026  if (in_array($a_user_id,$rbacreview->assignedUsers($icrs_roles["icrs_admin_role"])))
1027  {
1028  return true;
1029  }
1030  else
1031  {
1032  return false;
1033  }
1034  }
1035 
1041  function getDefaultRoles($a_grp_id="")
1042  {
1043  global $rbacadmin, $rbacreview;
1044 
1045  if (strlen($a_grp_id) > 0)
1046  {
1047  $grp_id = $a_grp_id;
1048  }
1049  else
1050  {
1051  $grp_id = $this->getRefId();
1052  }
1053 
1054  $role_arr = $rbacreview->getRolesOfRoleFolder($grp_id);
1055 
1056  foreach ($role_arr as $role_id)
1057  {
1058  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1059 
1060  $grp_Member ="il_icrs_member_".$grp_id;
1061  $grp_Admin ="il_icrs_admin_".$grp_id;
1062 
1063  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1064  {
1065  $arr_grpDefaultRoles["icrs_member_role"] = $role_Obj->getId();
1066  }
1067 
1068  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1069  {
1070  $arr_grpDefaultRoles["icrs_admin_role"] = $role_Obj->getId();
1071  }
1072  }
1073 
1074  return $arr_grpDefaultRoles;
1075  }
1076 
1077  // returns ilinc_user_ids of course (students=false,docents=true)
1078  function getiLincMemberIds($a_instructorflag = false)
1079  {
1080  if ($a_instructorflag == true)
1081  {
1082  if (!empty($this->docent_ids))
1083  {
1084  return $this->docent_ids;
1085  }
1086  }
1087  else
1088  {
1089  if (!empty($this->student_ids))
1090  {
1091  return $this->student_ids;
1092  }
1093  }
1094 
1095  $this->ilincAPI->findRegisteredUsersByRole($this->getiLincId(),$a_instructorflag);
1096  $response = $this->ilincAPI->sendRequest();
1097 
1098  if (is_array($response->data['users']))
1099  {
1100  if ($a_instructorflag == true)
1101  {
1102  $this->docent_ids = array_keys($response->data['users']);
1103  }
1104  else
1105  {
1106  $this->student_ids = array_keys($response->data['users']);
1107  }
1108 
1109  return array_keys($response->data['users']);
1110  }
1111 
1112  return array();
1113  }
1114 
1115  function checkiLincMemberStatus($a_ilinc_user_id,$a_docent_ids,$a_student_ids)
1116  {
1117  if (in_array($a_ilinc_user_id,$a_docent_ids))
1118  {
1119  return ILINC_MEMBER_DOCENT;
1120  }
1121 
1122  if (in_array($a_ilinc_user_id,$a_student_ids))
1123  {
1124  return ILINC_MEMBER_STUDENT;
1125  }
1126 
1127  return ILINC_MEMBER_NOTSET;
1128  }
1129 
1130  function _isActivated($a_course_obj_id)
1131  {
1132  global $ilDB,$ilias;
1133 
1134  if (!$ilias->getSetting("ilinc_active"))
1135  {
1136  return false;
1137  }
1138 
1139  $r = $ilDB->queryf('
1140  SELECT activation_offline FROM ilinc_data WHERE obj_id = %s',
1141  array('integer'), array($a_course_obj_id));
1142 
1143  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
1144 
1145  return ilUtil::yn2tf($row->activation_offline);
1146  }
1147 
1148  function _getAKClassValues($a_course_obj_id)
1149  {
1150  global $ilDB,$ilias;
1151 
1152  $r = $ilDB->queryf('
1153  SELECT akclassvalue1, akclassvalue2 FROM ilinc_data WHERE obj_id = %s',
1154  array('integer'), array($a_course_obj_id));
1155 
1156  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
1157 
1158  return $akclassvalues = array($row->akclassvalue1,$row->akclassvalue2);
1159  }
1160 
1170  function _isMember($a_user_id,$a_ref_id)
1171  {
1172  global $rbacreview;
1173 
1174  $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
1175  $user_roles = $rbacreview->assignedRoles($a_user_id);
1176 
1177  if (!array_intersect($local_roles,$user_roles))
1178  {
1179  return false;
1180  }
1181 
1182  return true;
1183  }
1184 
1186  {
1187  // empty
1188  }
1189 
1194  function getSubItems()
1195  {
1196  $objects = array();
1197 
1198  if(!($objects = $this->getClassrooms()))
1199  {
1200  ilUtil::sendInfo($this->lng->txt($this->getErrorMsg()));
1201  return array();
1202  }
1203 
1204  foreach((array)$objects as $key => $object)
1205  {
1206  $this->items['icla'][$key] = $object;
1207  }
1208 
1209  return is_array($this->items) ? $this->items : array();
1210  }
1211 
1212 } // END class.ilObjiLincCourse
1213 ?>