ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilOrgUnitSimpleUserImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 simpleUserImport ($file_path)
 
 simpleUserImportElement (SimpleXMLElement $a)
 
- Public Member Functions inherited from ilOrgUnitImporter
 __construct ()
 
 hasMoreThanOneMatch (string $external_id)
 
 hasErrors ()
 
 hasWarnings ()
 
 addWarning (string $lang_var, string $import_id, ?string $action=null)
 
 addError (string $lang_var, string $import_id, ?string $action=null)
 
 getErrors ()
 
 getWarnings ()
 
 getStats ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 
 setImport (ilImport $a_val)
 
 getImport ()
 
 init ()
 
 setInstallId (string $a_val)
 
 getInstallId ()
 
 setInstallUrl (string $a_val)
 
 getInstallUrl ()
 
 setSchemaVersion (string $a_val)
 
 getSchemaVersion ()
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setSkipEntities (array $a_val)
 
 getSkipEntities ()
 
 exportedFromSameInstallation ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 

Private Member Functions

 buildUserId ($id, $type)
 

Additional Inherited Members

- Data Fields inherited from ilOrgUnitImporter
array $errors = []
 
array $warnings = []
 
array $stats
 
- Protected Member Functions inherited from ilOrgUnitImporter
 buildRef ($id, string $type)
 
- Protected Attributes inherited from ilXmlImporter
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilOrgUnitSimpleUserImport

Author
: Oskar Truffer ot@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
: Martin Studer ms@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

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

Member Function Documentation

◆ buildUserId()

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

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

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

Referenced by simpleUserImportElement().

109  {
110  global $DIC;
111  $ilDB = $DIC['ilDB'];
112  if ($type == 'ilias_login') {
113  $user_id = ilObjUser::_lookupId($id);
114 
115  return $user_id ? $user_id : false;
116  } elseif ($type == 'external_id') {
118 
119  return $user_id ? $user_id : false;
120  } elseif ($type == 'email') {
121  $q = 'SELECT usr_id FROM usr_data WHERE email = ' . $ilDB->quote($id, 'text');
122  $set = $ilDB->query($q);
123  $user_id = $ilDB->fetchAssoc($set);
124 
125  return $user_id ? $user_id : false;
126  } elseif ($type == 'user_id') {
127  return $id;
128  } else {
129  return false;
130  }
131  }
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
$type
static _lookupId($a_user_str)
global $DIC
Definition: feed.php:28
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ 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 31 of file class.ilOrgUnitSimpleUserImport.php.

References Vendor\Package\$a, $xml, ilOrgUnitImporter\addError(), and simpleUserImportElement().

32  {
33  $this->stats = array('created' => 0, 'removed' => 0);
34  $a = file_get_contents($file_path, 'r');
35  $xml = new SimpleXMLElement($a);
36 
37  if (!count($xml->children())) {
38  $this->addError('no_assignment', null, null);
39 
40  return;
41  }
42 
43  foreach ($xml->children() as $a) {
45  }
46  }
$xml
Definition: metadata.php:351
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
addError(string $lang_var, string $import_id, ?string $action=null)
+ Here is the call graph for this function:

◆ simpleUserImportElement()

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

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

References $attributes, ilOrgUnitImporter\addError(), ilOrgUnitImporter\buildRef(), buildUserId(), ilOrgUnitPosition\CORE_POSITION_EMPLOYEE, ilOrgUnitPosition\CORE_POSITION_SUPERIOR, ilOrgUnitUserAssignment\findOrCreateAssignment(), and ActiveRecord\where().

Referenced by simpleUserImport().

52  {
53  $attributes = $a->attributes();
54  $action = $attributes->action;
55  $user_id_type = $a->User->attributes()->id_type;
56  $user_id = (string) $a->User;
57  $org_unit_id_type = $a->OrgUnit->attributes()->id_type;
58  $org_unit_id = (string) $a->OrgUnit;
59  $role = (string) $a->Role;
60 
61  if (!$user_id = $this->buildUserId($user_id, $user_id_type)) {
62  $this->addError('user_not_found', $a->User);
63 
64  return;
65  }
66 
67  if (!$org_unit_id = $this->buildRef($org_unit_id, $org_unit_id_type)) {
68  $this->addError('org_unit_not_found', $a->OrgUnit);
69 
70  return;
71  }
72  $org_unit = new ilObjOrgUnit($org_unit_id);
73 
74  if ($role === 'employee') {
76  } elseif ($role === 'superior') {
78  } else {
79  //if passed a custom position.
80  $position = ilOrgUnitPosition::where(['title' => $role])->first();
81  if ($position instanceof ilOrgUnitPosition) {
82  $position_id = $position->getId();
83  } else {
84  $this->addError('not_a_valid_role', $user_id);
85  return;
86  }
87  }
88 
89  if ($action == 'add') {
90  $assignment = ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $org_unit_id);
91  $assignment->store();
92 
93  $this->stats['created']++;
94  } elseif ($action == 'remove') {
95  $assignment = ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $org_unit_id);
96  $assignment->delete();
97  $this->stats['removed']++;
98  } else {
99  $this->addError('not_a_valid_action', $user_id);
100  }
101  }
$attributes
Definition: metadata.php:248
static findOrCreateAssignment(int $user_id, int $position_id, int $orgu_id)
static where($where, $operator=null)
buildRef($id, string $type)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
addError(string $lang_var, string $import_id, ?string $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: