ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
 hasMoreThanOneMatch ($external_id)
 
 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 101 of file class.ilOrgUnitSimpleUserImport.php.

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

Referenced by simpleUserImportElement().

102  {
103  global $DIC;
104  $ilDB = $DIC['ilDB'];
105  if ($type == 'ilias_login') {
106  $user_id = ilObjUser::_lookupId($id);
107 
108  return $user_id ? $user_id : false;
109  } elseif ($type == 'external_id') {
110  $user_id = ilObjUser::_lookupObjIdByImportId($id);
111 
112  return $user_id ? $user_id : false;
113  } elseif ($type == 'email') {
114  $q = 'SELECT usr_id FROM usr_data WHERE email = ' . $ilDB->quote($id, 'text');
115  $set = $ilDB->query($q);
116  $user_id = $ilDB->fetchAssoc($set);
117 
118  return $user_id ? $user_id : false;
119  } elseif ($type == 'user_id') {
120  return $id;
121  } else {
122  return false;
123  }
124  }
$type
static _lookupId($a_user_str)
Lookup id by login.
global $ilDB
$DIC
Definition: xapitoken.php:46
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 Vendor\Package\$a, $xml, ilOrgUnitImporter\addError(), 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->children())) {
25  $this->addError('no_assignment', null, null);
26 
27  return;
28  }
29 
30  foreach ($xml->children() as $a) {
32  }
33  }
addError($lang_var, $import_id, $action=null)
$xml
Definition: metadata.php:332
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ 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 $attributes, $DIC, ilOrgUnitImporter\addError(), ilOrgUnitImporter\buildRef(), buildUserId(), ilOrgUnitPosition\CORE_POSITION_EMPLOYEE, ilOrgUnitPosition\CORE_POSITION_SUPERIOR, ilOrgUnitUserAssignment\findOrCreateAssignment(), and ActiveRecord\where().

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') {
67  } elseif ($role === 'superior') {
69  } else {
70  //if passed a custom position.
71  $position = ilOrgUnitPosition::where(['title' => $role])->first();
72  if ($position instanceof ilOrgUnitPosition) {
73  $position_id = $position->getId();
74  } else {
75  $this->addError('not_a_valid_role', $user_id);
76  return;
77  }
78  }
79 
80  if ($action == 'add') {
81  $assignment = ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $org_unit_id);
82  $assignment->store();
83 
84  $this->stats['created']++;
85  } elseif ($action == 'remove') {
86  $assignment = ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $org_unit_id);
87  $assignment->delete();
88  $this->stats['removed']++;
89  } else {
90  $this->addError('not_a_valid_action', $user_id);
91  }
92  }
$attributes
Definition: metadata.php:231
static findOrCreateAssignment($user_id, $position_id, $orgu_id)
static where($where, $operator=null)
addError($lang_var, $import_id, $action=null)
$DIC
Definition: xapitoken.php:46
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ 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: