ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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

 __construct ()
 
 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)
 

Protected Attributes

ilOrgUnitPositionDBRepository $positionRepo
 
ilOrgUnitUserAssignmentDBRepository $assignmentRepo
 
- Protected Attributes inherited from ilXmlImporter
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

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)
 

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.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitSimpleUserImport::__construct ( )

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

References $dic, and ilOrgUnitLocalDIC\dic().

32  {
34  $this->positionRepo = $dic["repo.Positions"];
35  $this->assignmentRepo = $dic["repo.UserAssignments"];
36  }
$dic
Definition: ltiresult.php:33
+ Here is the call graph for this function:

Member Function Documentation

◆ buildUserId()

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

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

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

Referenced by simpleUserImportElement().

123  {
124  global $DIC;
125  $ilDB = $DIC['ilDB'];
126  if ($type == 'ilias_login') {
128 
129  return $user_id ? $user_id : false;
130  } elseif ($type == 'external_id') {
132 
133  return $user_id ? $user_id : false;
134  } elseif ($type == 'email') {
135  $q = 'SELECT usr_id FROM usr_data WHERE email = ' . $ilDB->quote($id, 'text');
136  $set = $ilDB->query($q);
137  $user_id = $ilDB->fetchAssoc($set);
138 
139  return $user_id ? $user_id : false;
140  } elseif ($type == 'user_id') {
141  return $id;
142  } else {
143  return false;
144  }
145  }
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
static _lookupId($a_user_str)
global $DIC
Definition: shib_login.php:25
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
$q
Definition: shib_logout.php:18
+ 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 41 of file class.ilOrgUnitSimpleUserImport.php.

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

42  {
43  $this->stats = array('created' => 0, 'removed' => 0);
44  $a = file_get_contents($file_path, 'r');
45  $xml = new SimpleXMLElement($a);
46 
47  if (!count($xml->children())) {
48  $this->addError('no_assignment', null, null);
49 
50  return;
51  }
52 
53  foreach ($xml->children() as $a) {
55  }
56  }
$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 61 of file class.ilOrgUnitSimpleUserImport.php.

References $user_id, ilOrgUnitImporter\addError(), ilOrgUnitImporter\buildRef(), buildUserId(), ilOrgUnitPosition\CORE_POSITION_EMPLOYEE, and ilOrgUnitPosition\CORE_POSITION_SUPERIOR.

Referenced by simpleUserImport().

62  {
63  $attributes = $a->attributes();
64  $action = $attributes->action;
65  $user_id_type = $a->User->attributes()->id_type;
66  $user_id = (string) $a->User;
67  $org_unit_id_type = $a->OrgUnit->attributes()->id_type;
68  $org_unit_id = (string) $a->OrgUnit;
69  $role = (string) $a->Role;
70 
71  if (!$user_id = $this->buildUserId($user_id, $user_id_type)) {
72  $this->addError('user_not_found', $a->User);
73 
74  return;
75  }
76 
77  if (!$org_unit_id = $this->buildRef($org_unit_id, $org_unit_id_type)) {
78  $this->addError('org_unit_not_found', $a->OrgUnit);
79 
80  return;
81  }
82  $org_unit = new ilObjOrgUnit($org_unit_id);
83 
84  if ($role === 'employee') {
85  $position_id = $this->positionRepo
86  ->getSingle(ilOrgUnitPosition::CORE_POSITION_EMPLOYEE, 'core_identifier')
87  ->getId();
88  } elseif ($role === 'superior') {
89  $position_id = $this->positionRepo
90  ->getSingle(ilOrgUnitPosition::CORE_POSITION_SUPERIOR, 'core_identifier')
91  ->getId();
92  } else {
93  //if passed a custom position.
94  $position = $this->positionRepo->getSingle($role, 'title');
95  if ($position instanceof ilOrgUnitPosition) {
96  $position_id = $position->getId();
97  } else {
98  $this->addError('not_a_valid_role', $user_id);
99  return;
100  }
101  }
102 
103  if ($action == 'add') {
104  $assignment = $this->assignmentRepo->get($user_id, $position_id, $org_unit_id);
105  $this->stats['created']++;
106  } elseif ($action == 'remove') {
107  $assignment = $this->assignmentRepo->find($user_id, $position_id, $org_unit_id);
108  if ($assignment) {
109  $this->assignmentRepo->delete($assignment);
110  $this->stats['removed']++;
111  }
112  } else {
113  $this->addError('not_a_valid_action', $user_id);
114  }
115  }
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:

Field Documentation

◆ $assignmentRepo

ilOrgUnitUserAssignmentDBRepository ilOrgUnitSimpleUserImport::$assignmentRepo
protected

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

◆ $positionRepo

ilOrgUnitPositionDBRepository ilOrgUnitSimpleUserImport::$positionRepo
protected

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


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