ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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

 __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 25 of file class.ilOrgUnitSimpleUserImport.php.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitSimpleUserImport::__construct ( )

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

References $dic, and ilOrgUnitLocalDIC\dic().

31  {
33  $this->positionRepo = $dic["repo.Positions"];
34  $this->assignmentRepo = $dic["repo.UserAssignments"];
35  }
$dic
Definition: result.php:31
+ 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 121 of file class.ilOrgUnitSimpleUserImport.php.

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

Referenced by simpleUserImportElement().

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

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

41  {
42  $this->stats = array('created' => 0, 'removed' => 0);
43  $a = file_get_contents($file_path, 'r');
44  $xml = new SimpleXMLElement($a);
45 
46  if (!count($xml->children())) {
47  $this->addError('no_assignment', null, null);
48 
49  return;
50  }
51 
52  foreach ($xml->children() as $a) {
54  }
55  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$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 60 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().

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

◆ $positionRepo

ilOrgUnitPositionDBRepository ilOrgUnitSimpleUserImport::$positionRepo
protected

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


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