ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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->children())) {
25 $this->addError('no_assignment', null, null);
26
27 return;
28 }
29
30 foreach ($xml->children() 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 = (string) $attributes->action;
46 $user_id_type = (string) $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') {
67 } elseif ($role === 'superior') {
69 } else {
70 $this->addError('not_a_valid_role', $user_id);
71
72 return;
73 }
74
75 if ($action == 'add') {
76 $assignment = ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $org_unit_id);
77 $assignment->store();
78
79 $this->stats['created']++;
80 } elseif ($action == 'remove') {
81 $assignment = ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $org_unit_id);
82 $assignment->delete();
83 $this->stats['removed']++;
84 } else {
85 $this->addError('not_a_valid_action', $user_id);
86 }
87 }
88
89
96 private function buildUserId($id, $type)
97 {
98 global $DIC;
99 $ilDB = $DIC['ilDB'];
100 if ($type == 'ilias_login') {
101 $user_id = ilObjUser::_lookupId($id);
102
103 return $user_id ? $user_id : false;
104 } elseif ($type == 'external_id') {
106
107 return $user_id ? $user_id : false;
108 } elseif ($type == 'email') {
109 $q = 'SELECT usr_id FROM usr_data WHERE email = ' . $ilDB->quote($id, 'text');
110 $set = $ilDB->query($q);
111 $user_id = $ilDB->fetchAssoc($set);
112
113 return $user_id ? $user_id : false;
114 } elseif ($type == 'user_id') {
115 return $id;
116 } else {
117 return false;
118 }
119 }
120}
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.
static findOrCreateAssignment($user_id, $position_id, $orgu_id)
$action
if(!array_key_exists('StateId', $_REQUEST)) $id
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$type
global $DIC
Definition: saml.php:7
global $ilDB