ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 91 of file class.ilOrgUnitSimpleUserImport.php.

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

Referenced by simpleUserImportElement().

91  {
92  global $DIC;
93  $ilDB = $DIC['ilDB'];
94  if ($type == 'ilias_login') {
95  $user_id = ilObjUser::_lookupId($id);
96 
97  return $user_id ? $user_id : false;
98  } elseif ($type == 'external_id') {
99  $user_id = ilObjUser::_lookupObjIdByImportId($id);
100 
101  return $user_id ? $user_id : false;
102  } elseif ($type == 'email') {
103  $q = 'SELECT usr_id FROM usr_data WHERE email = ' . $ilDB->quote($id, 'text');
104  $set = $ilDB->query($q);
105  $user_id = $ilDB->fetchAssoc($set);
106 
107  return $user_id ? $user_id : false;
108  } elseif ($type == 'user_id') {
109  return $id;
110  } else {
111  return false;
112  }
113  }
static _lookupId($a_user_str)
Lookup id by login.
global $ilDB
global $DIC
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(), array, 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  }
Create styles array
The data for the language used.
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 $DIC, ilOrgUnitImporter\addError(), ilOrgUnitImporter\buildRef(), buildUserId(), and string.

Referenced by simpleUserImport().

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