ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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...
 
 setImport ($a_val)
 Set import. More...
 
 getImport ()
 Get import. 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...
 
 exportedFromSameInstallation ()
 Is exporting and importing installation identical? More...
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import xml representation. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 Called after all container objects have been implemented. 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()
 
 $imp
 

Detailed Description

Member Function Documentation

◆ buildUserId()

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

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

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

Referenced by simpleUserImportElement().

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  }
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
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 $xml, ilOrgUnitImporter\addError(), array, and simpleUserImportElement().

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  }
addError($lang_var, $import_id, $action=null)
$xml
Definition: metadata.php:240
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ simpleUserImportElement()

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

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

References $action, $attributes, $DIC, ilOrgUnitImporter\addError(), ilOrgUnitImporter\buildRef(), buildUserId(), and string.

Referenced by simpleUserImport().

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  }
Add rich text string
$action
global $DIC
Definition: saml.php:7
$attributes
addError($lang_var, $import_id, $action=null)
Class ilObjOrgUnit.
+ 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: