ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilOrgUnitSimpleUserImport Class Reference

Class ilOrgUnitSimpleUserImport. More...

+ Inheritance diagram for ilOrgUnitSimpleUserImport:
+ Collaboration diagram for ilOrgUnitSimpleUserImport:

Public Member Functions

 simpleUserImport ($file_path)
 
 simpleUserImportElement (SimpleXMLElement $a)
 
- Public Member Functions inherited from ilOrgUnitImporter
 hasErrors ()
 
 hasWarnings ()
 
 addWarning ($lang_var, $import_id, $action=NULL)
 
 addError ($lang_var, $import_id, $action=NULL)
 
 getErrors ()
 
 getWarnings ()
 
 getStats ()
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 Constructor. More...
 
 init ()
 Init. More...
 
 setInstallId ($a_val)
 Set installation id. More...
 
 getInstallId ()
 Get installation id. More...
 
 setInstallUrl ($a_val)
 Set installation url. More...
 
 getInstallUrl ()
 Get installation url. More...
 
 setSchemaVersion ($a_val)
 Set schema version. More...
 
 getSchemaVersion ()
 Get schema version. More...
 
 setImportDirectory ($a_val)
 Set import directory. More...
 
 getImportDirectory ()
 Get import directory. More...
 
 setSkipEntities ($a_val)
 Set skip entities. More...
 
 getSkipEntities ()
 Get skip entities. More...
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import xml representation. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 

Private Member Functions

 buildUserId ($id, $type)
 

Additional Inherited Members

- Data Fields inherited from ilOrgUnitImporter
 $errors
 
 $warnings
 
 $stats
 
- Protected Member Functions inherited from ilOrgUnitImporter
 buildRef ($id, $type)
 
- Protected Attributes inherited from ilXmlImporter
 $skip_entities = array()
 

Detailed Description

Member Function Documentation

◆ buildUserId()

ilOrgUnitSimpleUserImport::buildUserId (   $id,
  $type 
)
private
Parameters
$id
$type
Returns
bool

Definition at line 90 of file class.ilOrgUnitSimpleUserImport.php.

References $ilDB, ilObjUser\_lookupId(), and ilObject\_lookupObjIdByImportId().

Referenced by simpleUserImportElement().

90  {
91  global $ilDB;
92  if ($type == 'ilias_login') {
93  $user_id = ilObjUser::_lookupId($id);
94 
95  return $user_id ? $user_id : false;
96  } elseif ($type == 'external_id') {
97  $user_id = ilObjUser::_lookupObjIdByImportId($id);
98 
99  return $user_id ? $user_id : false;
100  } elseif ($type == 'email') {
101  $q = 'SELECT usr_id FROM usr_data WHERE email = ' . $ilDB->quote($id, 'text');
102  $set = $ilDB->query($q);
103  $user_id = $ilDB->fetchAssoc($set);
104 
105  return $user_id ? $user_id : false;
106  } elseif ($type == 'user_id') {
107  return $id;
108  } else {
109  return false;
110  }
111  }
static _lookupId($a_user_str)
lookup id by login
global $ilDB
static _lookupObjIdByImportId($a_import_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simpleUserImport()

ilOrgUnitSimpleUserImport::simpleUserImport (   $file_path)
Parameters
$file_path

Definition at line 18 of file class.ilOrgUnitSimpleUserImport.php.

References ilOrgUnitImporter\addError(), and simpleUserImportElement().

18  {
19  $this->stats = array( 'created' => 0, 'removed' => 0 );
20  $a = file_get_contents($file_path, 'r');
21  $xml = new SimpleXMLElement($a);
22 
23  if (!count($xml->Assignment)) {
24  $this->addError('no_assignment', NULL, NULL);
25 
26  return;
27  }
28 
29  foreach ($xml->Assignment as $a) {
30  $this->simpleUserImportElement($a);
31  }
32  }
addError($lang_var, $import_id, $action=NULL)
+ Here is the call graph for this function:

◆ simpleUserImportElement()

ilOrgUnitSimpleUserImport::simpleUserImportElement ( SimpleXMLElement  $a)
Parameters
SimpleXMLElement$a

Definition at line 38 of file class.ilOrgUnitSimpleUserImport.php.

References ilOrgUnitImporter\addError(), ilOrgUnitImporter\buildRef(), and buildUserId().

Referenced by simpleUserImport().

38  {
39  global $rbacadmin;
40 
41  $attributes = $a->attributes();
42  $action = $attributes->action;
43  $user_id_type = $a->User->attributes()->id_type;
44  $user_id = (string)$a->User;
45  $org_unit_id_type = $a->OrgUnit->attributes()->id_type;
46  $org_unit_id = (string)$a->OrgUnit;
47  $role = (string)$a->Role;
48 
49  if (!$user_id = $this->buildUserId($user_id, $user_id_type)) {
50  $this->addError('user_not_found', $a->User);
51 
52  return;
53  }
54 
55  if (!$org_unit_id = $this->buildRef($org_unit_id, $org_unit_id_type)) {
56  $this->addError('org_unit_not_found', $a->OrgUnit);
57 
58  return;
59  }
60  $org_unit = new ilObjOrgUnit($org_unit_id);
61 
62  if ($role == 'employee') {
63  $role_id = $org_unit->getEmployeeRole();
64  } elseif ($role == 'superior') {
65  $role_id = $org_unit->getSuperiorRole();
66  } else {
67  $this->addError('not_a_valid_role', $user_id);
68 
69  return;
70  }
71 
72  if ($action == 'add') {
73  $rbacadmin->assignUser($role_id, $user_id);
74  $this->stats['created'] ++;
75  } elseif ($action == 'remove') {
76  $rbacadmin->deassignUser($role_id, $user_id);
77  $this->stats['removed'] ++;
78  } else {
79  $this->addError('not_a_valid_action', $user_id);
80  }
81  }
Class ilObjOrgUnit.
addError($lang_var, $import_id, $action=NULL)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: