ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilOrgUnitSimpleUserImport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
14
18 public function simpleUserImport($file_path)
19 {
20 $this->stats = array( 'created' => 0, 'removed' => 0 );
21 $a = file_get_contents($file_path, 'r');
22 $xml = new SimpleXMLElement($a);
23
24 if (!count($xml->Assignment)) {
25 $this->addError('no_assignment', null, null);
26
27 return;
28 }
29
30 foreach ($xml->Assignment as $a) {
31 $this->simpleUserImportElement($a);
32 }
33 }
34
35
39 public function simpleUserImportElement(SimpleXMLElement $a)
40 {
41 global $DIC;
42 $rbacadmin = $DIC['rbacadmin'];
43
44 $attributes = $a->attributes();
45 $action = $attributes->action;
46 $user_id_type = $a->User->attributes()->id_type;
47 $user_id = (string) $a->User;
48 $org_unit_id_type = $a->OrgUnit->attributes()->id_type;
49 $org_unit_id = (string) $a->OrgUnit;
50 $role = (string) $a->Role;
51
52 if (!$user_id = $this->buildUserId($user_id, $user_id_type)) {
53 $this->addError('user_not_found', $a->User);
54
55 return;
56 }
57
58 if (!$org_unit_id = $this->buildRef($org_unit_id, $org_unit_id_type)) {
59 $this->addError('org_unit_not_found', $a->OrgUnit);
60
61 return;
62 }
63 $org_unit = new ilObjOrgUnit($org_unit_id);
64
65 if ($role == 'employee') {
66 $role_id = $org_unit->getEmployeeRole();
67 } elseif ($role == 'superior') {
68 $role_id = $org_unit->getSuperiorRole();
69 } else {
70 $this->addError('not_a_valid_role', $user_id);
71
72 return;
73 }
74
75 if ($action == 'add') {
76 $rbacadmin->assignUser($role_id, $user_id);
77 $this->stats['created']++;
78 } elseif ($action == 'remove') {
79 $rbacadmin->deassignUser($role_id, $user_id);
80 $this->stats['removed']++;
81 } else {
82 $this->addError('not_a_valid_action', $user_id);
83 }
84 }
85
86
93 private function buildUserId($id, $type)
94 {
95 global $DIC;
96 $ilDB = $DIC['ilDB'];
97 if ($type == 'ilias_login') {
98 $user_id = ilObjUser::_lookupId($id);
99
100 return $user_id ? $user_id : false;
101 } elseif ($type == 'external_id') {
103
104 return $user_id ? $user_id : false;
105 } elseif ($type == 'email') {
106 $q = 'SELECT usr_id FROM usr_data WHERE email = ' . $ilDB->quote($id, 'text');
107 $set = $ilDB->query($q);
108 $user_id = $ilDB->fetchAssoc($set);
109
110 return $user_id ? $user_id : false;
111 } elseif ($type == 'user_id') {
112 return $id;
113 } else {
114 return false;
115 }
116 }
117}
An exception for terminatinating execution or to throw for unit testing.
Class ilObjOrgUnit.
static _lookupId($a_user_str)
Lookup id by login.
static _lookupObjIdByImportId($a_import_id)
Class ilOrgUnitImporter.
addError($lang_var, $import_id, $action=null)
Class ilOrgUnitSimpleUserImport.
$action
if(!array_key_exists('StateId', $_REQUEST)) $id
$xml
Definition: metadata.php:240
$type
global $DIC
Definition: saml.php:7
$attributes
global $ilDB