ILIAS  Release_4_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 
279  function initDefaultRoles()
280  {
281  global $rbacadmin, $rbacreview, $ilDB;
282 
283 
284  // create a local role folder
285  $rfoldObj =& $this->createRoleFolder();
286 
287  // ADMIN ROLE
288  // create role and assign role to rolefolder...
289  $roleObj = $rfoldObj->createRole("il_icrs_admin_".$this->getRefId(),"LearnLinc admin of seminar obj_no.".$this->getId());
290  $this->m_roleAdminId = $roleObj->getId();
291 
292  //set permission template of new local role
293  $res = $ilDB->queryf('
294  SELECT obj_id FROM object_data WHERE type= %s AND title= %s',
295  array('text', 'text'), array('rolt', 'il_icrs_admin'));
296 
297  $r = $ilDB->fetchObject($res);
298 
299  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
300 
301  // set object permissions of icrs object
302  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"icrs",$rfoldObj->getRefId());
303  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
304 
305  // set object permissions of role folder object
306  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
307  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
308 
309  // MEMBER ROLE
310  // create role and assign role to rolefolder...
311  $roleObj = $rfoldObj->createRole("il_icrs_member_".$this->getRefId(),"LearnLinc admin of seminar obj_no.".$this->getId());
312  $this->m_roleMemberId = $roleObj->getId();
313 
314  //set permission template of new local role
315  $res = $ilDB->queryf('
316  SELECT obj_id FROM object_data WHERE type= %s AND title= %s',
317  array('text', 'text'), array('rolt', 'il_icrs_member'));
318 
319  $r = $ilDB->fetchObject($res);
320 
321  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
322 
323  // set object permissions of icrs object
324  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"icrs",$rfoldObj->getRefId());
325  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
326 
327  // set object permissions of role folder object
328  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
329  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
330 
331  unset($rfoldObj);
332  unset($roleObj);
333 
334  $roles[] = $this->m_roleAdminId;
335  $roles[] = $this->m_roleMemberId;
336 
337  // Break inheritance and initialize permission settings using intersection method with a non_member_template
338  // not implemented for ilinc. maybe never will...
339  $this->__setCourseStatus();
340 
341  return $roles ? $roles : array();
342  }
343 
357  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
358  {
359  return true;
360  }
361 
369  function addMember(&$a_user_obj, $a_mem_role, $a_instructor = false)
370  {
371  global $rbacadmin;
372 //echo "0";
373  if (!isset($a_user_obj) && !isset($a_mem_role))
374  {
375  $this->error_msg = get_class($this)."::addMember(): Missing parameters !";
376  return false;
377  }
378 //echo "1";
379  // check if user is registered at iLinc server
380  if (!$this->userExists($a_user_obj))
381  {
382  // if not, add user on iLinc server
383  if ($this->addUser($a_user_obj) == false)
384  {
385  // error_msg already set
386  return false;
387  }
388  }
389 //echo "2";
390  // assign membership to icourse on iLinc server
391  if (!$this->registerUser($a_user_obj,$a_instructor))
392  {
393  // error_msg already set
394  return false;
395  }
396 //echo "3";
397  // finally assign user to member role in ILIAS
398  $this->join($a_user_obj->getId(),$a_mem_role);
399 //echo "4";
400  return true;
401  }
402 
408  function join($a_user_id, $a_mem_role="")
409  {
410  global $rbacadmin;
411 
412  if (is_array($a_mem_role))
413  {
414  foreach ($a_mem_role as $role)
415  {
416  $rbacadmin->assignUser($role,$a_user_id, false);
417  }
418  }
419  else
420  {
421  $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
422  }
423 
424  return true;
425  }
426 
431  function leave($a_user_id)
432  {
433  global $rbacadmin;
434 
435  $arr_groupRoles = $this->getMemberRoles($a_user_id);
436 
437  if (is_array($arr_groupRoles))
438  {
439  foreach ($arr_groupRoles as $groupRole)
440  {
441  $rbacadmin->deassignUser($groupRole, $a_user_id);
442  }
443  }
444  else
445  {
446  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
447  }
448 
449  return true;
450  }
451 
458  function getMemberRoles($a_user_id)
459  {
460  global $rbacadmin, $rbacreview;
461 
462  $arr_assignedRoles = array();
463 
464  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalRoles());
465 
466  return $arr_assignedRoles;
467  }
468 
475  function getMemberIds()
476  {
477  global $rbacadmin, $rbacreview;
478 
479  $usr_arr= array();
480 
481  $rol = $this->getLocalRoles();
482 
483  foreach ($rol as $value)
484  {
485  foreach ($rbacreview->assignedUsers($value) as $member_id)
486  {
487  array_push($usr_arr,$member_id);
488  }
489  }
490 
491  $mem_arr = array_unique($usr_arr);
492 
493  return $mem_arr ? $mem_arr : array();
494  }
495 
503  function getMemberData($a_mem_ids, $active = 1)
504  {
505  global $rbacadmin, $rbacreview, $ilBench, $ilDB;
506 
507  $usr_arr= array();
508 
509  $data_types = array();
510  $data_values = array();
511  $cnt_mem_ids = count($a_mem_ids);
512 
513  $query = 'SELECT login,firstname,lastname,title,usr_id,ilinc_id
514  FROM usr_data WHERE usr_id IN ';
515 
516  if (is_array($a_mem_ids) &&
517  $cnt_mem_ids > 0)
518  {
519  $in = '(';
520  $counter = 0;
521  foreach($a_mem_ids as $mem_id)
522  {
523  array_push($data_values, $mem_id);
524  array_push($data_types, 'integer');
525 
526  if($counter > 0) $in .= ',';
527  $in .= '%s';
528  ++$counter;
529  }
530  $in .= ')';
531  $query .= $in;
532  }
533 
534  if (is_numeric($active) && $active > -1)
535  {
536  $query .= ' AND active = %s';
537  array_push($data_values,$active);
538  array_push($data_types, 'integer');
539  }
540 
541  $r = $ilDB->queryf($query, $data_types, $data_values);
542 
543  while($row = $ilDB->fetchObject($r))
544  {
545  $mem_arr[] = array("id" => $row->usr_id,
546  "login" => $row->login,
547  "firstname" => $row->firstname,
548  "lastname" => $row->lastname,
549  "ilinc_id" => $row->ilinc_id
550  );
551  }
552 
553  return $mem_arr ? $mem_arr : array();
554  }
555 
562  function getLocalRoles($a_translate = false)
563  {
564  global $rbacadmin,$rbacreview;
565 
566  if (empty($this->local_roles))
567  {
568  $this->local_roles = array();
569  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
570  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
571 
572  foreach ($role_arr as $role_id)
573  {
574  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
575  {
576  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
577 
578  if ($a_translate)
579  {
580  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
581  }
582  else
583  {
584  $role_name = $role_Obj->getTitle();
585  }
586 
587  $this->local_roles[$role_name] = $role_Obj->getId();
588  }
589  }
590  }
591 
592  return $this->local_roles;
593  }
594 
601  function getMemberRolesTitle($a_user_id)
602  {
603  global $ilDB,$ilBench;
604 
605  include_once ('./Services/AccessControl/classes/class.ilObjRole.php');
606 
607  $str_member_roles ="";
608 
609  $data_types = array();
610  $data_values = array();
611 
612  $query = 'SELECT title FROM object_data
613  LEFT JOIN rbac_ua ON object_data.obj_id = rbac_ua.rol_id
614  WHERE object_data.type = %s
615  AND rbac_ua.usr_id = %s
616  AND rbac_ua.rol_id IN';
617 
618  array_push($data_types, 'text', 'integer');
619  array_push($data_values,'role', $a_user_id);
620 
621  $local_roles = $this->getLocalRoles();
622  $cnt_local_roles = count($local_roles);
623 
624  if (is_array($local_roles) &&
625  $cnt_local_roles > 0)
626  {
627  $in = '(';
628  $counter = 0;
629  foreach($local_roles as $local_role)
630  {
631  array_push($data_values, $local_role);
632  array_push($data_types, 'integer');
633 
634  if($counter > 0) $in .= ',';
635  $in .= '%s';
636  ++$counter;
637  }
638  $in .= ')';
639  $query .= $in;
640  }
641  $cnt_data_values = count($data_values);
642  $cnt_data_types = count($data_types);
643 
644  $r = $ilDB->queryf($query, $data_types, $data_values);
645 
646  while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
647  {
648  // display human readable role names for autogenerated roles
649  $str_member_roles .= ilObjRole::_getTranslation($row["title"]).", ";
650  }
651 
652  return substr($str_member_roles,0,-2);
653  }
654 
660  {
661  $local_icrs_Roles = $this->getLocalRoles();
662 
663  return $local_icrs_Roles["il_icrs_member_".$this->getRefId()];
664  }
665 
671  {
672  $local_icrs_Roles = $this->getLocalRoles();
673 
674  return $local_icrs_Roles["il_icrs_admin_".$this->getRefId()];
675  }
676 
677  function getClassrooms()
678  {
679  global $ilErr;
680 
681  if (!$this->ilias->getSetting("ilinc_active"))
682  {
683  $this->error_msg = "ilinc_server_not_active";
684  return false;
685  }
686 
687  $this->ilincAPI->findCourseClasses($this->getiLincId());
688  $response = $this->ilincAPI->sendRequest();
689 
690  if ($response->isError())
691  {
692  if (!$response->getErrorMsg())
693  {
694  $this->error_msg = "err_get_classrooms";
695  }
696  else
697  {
698  $this->error_msg = $response->getErrorMsg();
699  }
700 
701  return false;
702  }
703 
704  if (!$response->data['classes'])
705  {
706 
707  $this->error_msg = $response->data['result']['cdata'];
708  return false;
709  }
710 
711  foreach ($response->data['classes'] as $class_id => $data)
712  {
713  $this->ilincAPI->findClass($class_id);
714  $response = $this->ilincAPI->sendRequest("findClass");
715 
716  if ($response->data['classes'])
717  {
718  $full_class_data[$class_id] = $response->data['classes'][$class_id];
719  }
720  }
721 
722  return $full_class_data;
723  }
724 
725  function updateClassrooms()
726  {
727  global $ilErr;
728 
729  $this->ilincAPI->findCourseClasses($this->getiLincId());
730  $response = $this->ilincAPI->sendRequest();
731 
732  if ($response->isError())
733  {
734  if (!$response->getErrorMsg())
735  {
736  $this->error_msg = "err_get_classrooms";
737  }
738  else
739  {
740  $this->error_msg = $response->getErrorMsg();
741  }
742 
743  return false;
744  }
745 
746  if (!$response->data['classes'])
747  {
748 
749  $this->error_msg = $response->data['result']['cdata'];
750  return false;
751  }
752 
753  if (array_key_exists('akclassvalue1',$_POST["Fobject"]))
754  {
755  $data["akclassvalue1"] = $_POST["Fobject"]["akclassvalue1"];
756  }
757 
758  if (array_key_exists('akclassvalue2',$_POST["Fobject"]))
759  {
760  $data["akclassvalue2"] = $_POST["Fobject"]["akclassvalue2"];
761  }
762 
763  foreach ($response->data['classes'] as $class_id => $data2)
764  {
765  include_once("./Modules/ILinc/classes/class.ilObjiLincClassroom.php");
766  $icla_obj = new ilObjiLincClassroom($class_id,$this->ref_id);
767 
768  if (!$icla_obj->update($data))
769  {
770  $this->error_msg = $icla_obj->getErrorMsg();
771 
772  return false;
773  }
774 
775  unset($icla_obj);
776  }
777 
778  return true;
779  }
780 
781  // checks if user account already exists at iLinc server
782  // TODO: check is only local in ILIAS not on iLinc server
783  function userExists(&$a_user_obj)
784  {
785  //$data = $a_user_obj->getiLincData();
786 
787  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
788  $ilinc_user = new ilObjiLincUser($a_user_obj);
789 
790  if (!$ilinc_user->id and !$ilinc_user->login)
791  {
792  return false;
793  }
794 
795  return true;
796  }
797 
798  // create user account on iLinc server
799  function addUser(&$a_user_obj)
800  {
801  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
802  $ilinc_user = new ilObjiLincUser($a_user_obj);
803 
804  return $ilinc_user->add();
805  }
806 
807  function isMember($a_user_id = "")
808  {
809  if (strlen($a_user_id) == 0)
810  {
811  $a_user_id = $this->ilias->account->getId();
812  }
813 
814  $arr_members = $this->getMemberIds();
815 
816  if (in_array($a_user_id, $arr_members))
817  {
818  return true;
819  }
820 
821  return false;
822  }
823 
824  function isDocent($a_user_obj = "")
825  {
826  if (!$a_user_obj)
827  {
828  $a_user_obj =& $this->ilias->account;
829  }
830 
831  $docents = $this->getiLincMemberIds(true);
832 
833  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
834  $ilinc_user = new ilObjiLincUser($a_user_obj);
835 
836  if (in_array($ilinc_user->id,$docents))
837  {
838  return true;
839  }
840 
841  return false;
842  }
843 
844  function registerUser(&$a_user_obj,$a_instructor = false)
845  {
846  if ($a_instructor === true)
847  {
848  $a_instructor = "True";
849  }
850  else
851  {
852  $a_instructor = "False";
853  }
854 
855  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
856  $ilinc_user = new ilObjiLincUser($a_user_obj);
857 
858  $user[] = array('id' => $ilinc_user->id, 'instructor' => $a_instructor);
859  $this->ilincAPI->registerUser($this->getiLincId(),$user);
860  $response = $this->ilincAPI->sendRequest("registerUser");
861 
862  if ($response->isError())
863  {
864  if (!$response->getErrorMsg())
865  {
866  $this->error_msg = "err_register_user";
867  }
868  else
869  {
870  $this->error_msg = $response->getErrorMsg();
871  }
872 
873  return false;
874  }
875 
876  return true;
877  }
878 
879  function registerUsers($a_user_arr)
880  {
881  foreach ($a_user_arr as $user_id => $instructorflag)
882  {
883  $flag = "False";
884 
885  if ($instructorflag == ILINC_MEMBER_DOCENT)
886  {
887  $flag = "True";
888  }
889 
890  $ilinc_users[] = array('id' => $user_id,'instructor' => $flag);
891  }
892 
893  $this->ilincAPI->registerUser($this->getiLincId(),$ilinc_users);
894  $response = $this->ilincAPI->sendRequest("registerUser");
895 
896  if ($response->isError())
897  {
898  if (!$response->getErrorMsg())
899  {
900  $this->error_msg = "err_register_users";
901  }
902  else
903  {
904  $this->error_msg = $response->getErrorMsg();
905  }
906 
907  return false;
908  }
909 
910  return true;
911  }
912 
913  // unregister user from course on iLinc server
914  function unregisterUser($a_user_obj)
915  {
916  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
917  $ilinc_user = new ilObjiLincUser($a_user_obj);
918 
919  // do not send request if user is not registered at iLinc server at all
920  if ($ilinc_user->id == '0')
921  {
922  return true;
923  }
924 
925  $this->ilincAPI->unregisterUser($this->getiLincId(),array($ilinc_user->id));
926  $response = $this->ilincAPI->sendRequest();
927 
928  if ($response->isError())
929  {
930  if (!$response->getErrorMsg())
931  {
932  $this->error_msg = "err_unregister_user";
933  }
934  else
935  {
936  $this->error_msg = $response->getErrorMsg();
937  }
938 
939  return false;
940  }
941 
942  return true;
943  }
944 
945  function unregisterUsers($a_ilinc_user_ids)
946  {
947  $this->ilincAPI->unregisterUser($this->getiLincId(),$a_ilinc_user_ids);
948  $response = $this->ilincAPI->sendRequest();
949 
950  if ($response->isError())
951  {
952  if (!$response->getErrorMsg())
953  {
954  $this->error_msg = "err_unregister_users";
955  }
956  else
957  {
958  $this->error_msg = $response->getErrorMsg();
959  }
960 
961  return false;
962  }
963 
964  return true;
965  }
966 
967  function userLogin(&$a_user_obj)
968  {
969  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
970  $ilinc_user = new ilObjiLincUser($a_user_obj);
971 
972  $this->ilincAPI->userLogin($ilinc_user);
973  $response = $this->ilincAPI->sendRequest("userLogin");
974 
975  if ($response->isError())
976  {
977  if (!$response->getErrorMsg())
978  {
979  $this->error_msg = "err_user_login";
980  }
981  else
982  {
983  $this->error_msg = $response->getErrorMsg();
984  }
985 
986  return false;
987  }
988 
989  // return URL to join class room
990  return $response->data['url']['cdata'];
991  }
992 
993  // not used here
994  function uploadPicture(&$a_user_obj,$a_lang)
995  {
996  $this->ilincAPI->uploadPicture($a_user_obj,$a_lang);
997  $response = $this->ilincAPI->sendRequest("uploadPicture");
998 
999  if ($response->isError())
1000  {
1001  if (!$response->getErrorMsg())
1002  {
1003  $this->error_msg = "err_upload_picture";
1004  }
1005  else
1006  {
1007  $this->error_msg = $response->getErrorMsg();
1008  }
1009 
1010  return false;
1011  }
1012 
1013  // return URL to user's personal page
1014  return $response->data['url']['cdata'];
1015  }
1016 
1023  function getAdminIds($a_grpId="")
1024  {
1025  global $rbacreview;
1026 
1027  if (!empty($a_grpId))
1028  {
1029  $grp_id = $a_grpId;
1030  }
1031  else
1032  {
1033  $grp_id = $this->getRefId();
1034  }
1035 
1036  $usr_arr = array();
1037  $roles = $this->getDefaultRoles($this->getRefId());
1038 
1039  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
1040  {
1041  array_push($usr_arr,$member_id);
1042  }
1043 
1044  return $usr_arr;
1045  }
1046 
1051  function removeMember(&$a_user_obj)
1052  {
1053  if (!isset($a_user_obj))
1054  {
1055  $this->error_msg = get_class($this)."::removeMember(): Missing parameters !";
1056  return false;
1057  }
1058 
1059  if (!$this->isMember($a_user_obj->getId()))
1060  {
1061  return true;
1062  }
1063 
1064  if (count($this->getMemberIds()) > 1)
1065  {
1066  if ($this->isAdmin($a_user_obj->getId()) && count($this->getAdminIds()) < 2)
1067  {
1068  $this->error_msg = "ilinc_err_administrator_required";
1069  return false;
1070  }
1071  }
1072 
1073  // unregister from course on iLinc server
1074  if (!$this->unregisterUser($a_user_obj))
1075  {
1076  // error_msg already set
1077  return false;
1078  }
1079 
1080  $this->leave($a_user_obj->getId());
1081 
1082  return true;
1083  }
1084 
1091  function isAdmin($a_user_id)
1092  {
1093  global $rbacreview;
1094 
1095  $icrs_roles = $this->getDefaultRoles();
1096 
1097  if (in_array($a_user_id,$rbacreview->assignedUsers($icrs_roles["icrs_admin_role"])))
1098  {
1099  return true;
1100  }
1101  else
1102  {
1103  return false;
1104  }
1105  }
1106 
1112  function getDefaultRoles($a_grp_id="")
1113  {
1114  global $rbacadmin, $rbacreview;
1115 
1116  if (strlen($a_grp_id) > 0)
1117  {
1118  $grp_id = $a_grp_id;
1119  }
1120  else
1121  {
1122  $grp_id = $this->getRefId();
1123  }
1124 
1125  $rolf = $rbacreview->getRoleFolderOfObject($grp_id);
1126  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1127 
1128  foreach ($role_arr as $role_id)
1129  {
1130  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1131 
1132  $grp_Member ="il_icrs_member_".$grp_id;
1133  $grp_Admin ="il_icrs_admin_".$grp_id;
1134 
1135  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1136  {
1137  $arr_grpDefaultRoles["icrs_member_role"] = $role_Obj->getId();
1138  }
1139 
1140  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1141  {
1142  $arr_grpDefaultRoles["icrs_admin_role"] = $role_Obj->getId();
1143  }
1144  }
1145 
1146  return $arr_grpDefaultRoles;
1147  }
1148 
1149  // returns ilinc_user_ids of course (students=false,docents=true)
1150  function getiLincMemberIds($a_instructorflag = false)
1151  {
1152  if ($a_instructorflag == true)
1153  {
1154  if (!empty($this->docent_ids))
1155  {
1156  return $this->docent_ids;
1157  }
1158  }
1159  else
1160  {
1161  if (!empty($this->student_ids))
1162  {
1163  return $this->student_ids;
1164  }
1165  }
1166 
1167  $this->ilincAPI->findRegisteredUsersByRole($this->getiLincId(),$a_instructorflag);
1168  $response = $this->ilincAPI->sendRequest();
1169 
1170  if (is_array($response->data['users']))
1171  {
1172  if ($a_instructorflag == true)
1173  {
1174  $this->docent_ids = array_keys($response->data['users']);
1175  }
1176  else
1177  {
1178  $this->student_ids = array_keys($response->data['users']);
1179  }
1180 
1181  return array_keys($response->data['users']);
1182  }
1183 
1184  return array();
1185  }
1186 
1187  function checkiLincMemberStatus($a_ilinc_user_id,$a_docent_ids,$a_student_ids)
1188  {
1189  if (in_array($a_ilinc_user_id,$a_docent_ids))
1190  {
1191  return ILINC_MEMBER_DOCENT;
1192  }
1193 
1194  if (in_array($a_ilinc_user_id,$a_student_ids))
1195  {
1196  return ILINC_MEMBER_STUDENT;
1197  }
1198 
1199  return ILINC_MEMBER_NOTSET;
1200  }
1201 
1202  function _isActivated($a_course_obj_id)
1203  {
1204  global $ilDB,$ilias;
1205 
1206  if (!$ilias->getSetting("ilinc_active"))
1207  {
1208  return false;
1209  }
1210 
1211  $r = $ilDB->queryf('
1212  SELECT activation_offline FROM ilinc_data WHERE obj_id = %s',
1213  array('integer'), array($a_course_obj_id));
1214 
1215  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
1216 
1217  return ilUtil::yn2tf($row->activation_offline);
1218  }
1219 
1220  function _getAKClassValues($a_course_obj_id)
1221  {
1222  global $ilDB,$ilias;
1223 
1224  $r = $ilDB->queryf('
1225  SELECT akclassvalue1, akclassvalue2 FROM ilinc_data WHERE obj_id = %s',
1226  array('integer'), array($a_course_obj_id));
1227 
1228  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
1229 
1230  return $akclassvalues = array($row->akclassvalue1,$row->akclassvalue2);
1231  }
1232 
1233  function _isMember($a_user_id,$a_ref_id)
1234  {
1235  global $rbacreview;
1236 
1237  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
1238  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1239  $user_roles = $rbacreview->assignedRoles($a_user_id);
1240 
1241  if (!array_intersect($local_roles,$user_roles))
1242  {
1243  return false;
1244  }
1245 
1246  return true;
1247  }
1248 
1250  {
1251  // empty
1252  }
1253 
1258  function getSubItems()
1259  {
1260  $objects = array();
1261 
1262  if(!($objects = $this->getClassrooms()))
1263  {
1264  ilUtil::sendInfo($this->lng->txt($this->getErrorMsg()));
1265  return array();
1266  }
1267 
1268  foreach((array)$objects as $key => $object)
1269  {
1270  $this->items['icla'][$key] = $object;
1271  }
1272 
1273  return is_array($this->items) ? $this->items : array();
1274  }
1275 
1284  function _getLinkToObject($a_id)
1285  {
1286  return array("repository.php?ref_id=".$a_id."&set_mode=flat&cmdClass=ilobjilinccoursegui","");
1287  }
1288 } // END class.ilObjiLincCourse
1289 ?>