ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilOrgUnitExporter 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 ilOrgUnitExporter:
+ Collaboration diagram for ilOrgUnitExporter:

Public Member Functions

 __construct ()
 
 simpleExport (int $orgu_ref_id)
 
 simpleExportExcel (int $orgu_ref_id)
 
 sendAndCreateSimpleExportFile ()
 
- Public Member Functions inherited from ilCategoryExporter
 getXmlExportHeadDependencies (string $a_entity, string $a_target_release, array $a_ids)
 Get head dependencies. More...
 
 getXmlExportTailDependencies (string $a_entity, string $a_target_release, array $a_ids)
 
 getXmlRepresentation (string $a_entity, string $a_schema_version, string $a_id)
 
 getValidSchemaVersions (string $a_entity)
 Returns schema versions that the component can export to. More...
 
 init ()
 Init method. More...
 
- Public Member Functions inherited from ilXmlExporter
 __construct ()
 
 setExport (ilExport $a_exp)
 
 getExport ()
 
 getXmlRepresentation (string $a_entity, string $a_schema_version, string $a_id)
 
 init ()
 
 setExportDirectories (string $a_dir_relative, string $a_dir_absolute)
 
 getRelativeExportDirectory ()
 
 getAbsoluteExportDirectory ()
 
 getXmlExportHeadDependencies (string $a_entity, string $a_target_release, array $a_ids)
 Get head dependencies. More...
 
 getXmlExportTailDependencies (string $a_entity, string $a_target_release, array $a_ids)
 Get tail dependencies. More...
 
 getValidSchemaVersions (string $a_entity)
 Returns schema versions that the component can export to. More...
 
 determineSchemaVersion (string $a_entity, string $a_target_release)
 

Protected Member Functions

 getExternalId (int $orgu_ref_id)
 
 buildExternalId (int $orgu_ref_id)
 

Private Member Functions

 getStructure (int $root_node_ref)
 
 getAttributesForOrgu (ilObjOrgUnit $orgu)
 

Private Attributes

ilTree $tree
 

Additional Inherited Members

- Static Public Member Functions inherited from ilXmlExporter
static lookupExportDirectory (string $a_obj_type, int $a_obj_id, string $a_export_type='xml', string $a_entity="")
 
- Protected Attributes inherited from ilXmlExporter
string $dir_relative = ""
 
string $dir_absolute = ""
 
ilExport $exp
 

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 ilOrgUnitExporter

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

Definition at line 25 of file class.ilOrgUnitExporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitExporter::__construct ( )

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

References $DIC, and ILIAS\GlobalScreen\Provider\__construct().

30  {
31  global $DIC;
33  $this->tree = $DIC['tree'];
34  }
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ buildExternalId()

ilOrgUnitExporter::buildExternalId ( int  $orgu_ref_id)
protected

Definition at line 66 of file class.ilOrgUnitExporter.php.

References CLIENT_ID.

Referenced by getExternalId().

66  : string
67  {
68  return "orgu_" . CLIENT_ID . "_" . $orgu_ref_id;
69  }
const CLIENT_ID
Definition: constants.php:41
+ Here is the caller graph for this function:

◆ getAttributesForOrgu()

ilOrgUnitExporter::getAttributesForOrgu ( ilObjOrgUnit  $orgu)
private

Definition at line 171 of file class.ilOrgUnitExporter.php.

References $ref_id, getExternalId(), ilObject\getRefId(), and ilObjOrgUnit\getRootOrgRefId().

Referenced by simpleExport(), and simpleExportExcel().

171  : array
172  {
173  $parent_ref = $this->tree->getParentId($orgu->getRefId());
174  if ($parent_ref != ilObjOrgUnit::getRootOrgRefId()) {
175  $ou_parent_id = $this->getExternalId($parent_ref);
176  } else {
177  $ou_parent_id = "__ILIAS";
178  }
179  // Only the ref id is guaranteed to be unique.
180  $ref_id = $orgu->getRefId();
181  $attr = array("ou_id" => $this->getExternalId($ref_id),
182  "ou_id_type" => "external_id",
183  "ou_parent_id" => $ou_parent_id,
184  "ou_parent_id_type" => "external_id",
185  "action" => "create"
186  );
187 
188  return $attr;
189  }
getExternalId(int $orgu_ref_id)
$ref_id
Definition: ltiauth.php:67
static getRootOrgRefId()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExternalId()

ilOrgUnitExporter::getExternalId ( int  $orgu_ref_id)
protected

Definition at line 59 of file class.ilOrgUnitExporter.php.

References ilObject\_lookupObjectId(), and buildExternalId().

Referenced by getAttributesForOrgu(), and simpleExport().

59  : string
60  {
61  $import_id = ilObjOrgunit::_lookupImportId(ilObjOrgUnit::_lookupObjectId($orgu_ref_id));
62 
63  return $import_id ?: $this->buildExternalId($orgu_ref_id);
64  }
buildExternalId(int $orgu_ref_id)
static _lookupObjectId(int $ref_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStructure()

ilOrgUnitExporter::getStructure ( int  $root_node_ref)
private

Definition at line 154 of file class.ilOrgUnitExporter.php.

Referenced by simpleExport(), and simpleExportExcel().

154  : array
155  {
156  $open = array($root_node_ref);
157  $closed = array();
158  while (count($open)) {
159  $current = array_shift($open);
160  $closed[] = $current;
161  foreach ($this->tree->getChildsByType($current, "orgu") as $new) {
162  if (in_array($new["child"], $closed, true) === false && in_array($new["child"], $open, true) === false) {
163  $open[] = $new["child"];
164  }
165  }
166  }
167 
168  return $closed;
169  }
+ Here is the caller graph for this function:

◆ sendAndCreateSimpleExportFile()

ilOrgUnitExporter::sendAndCreateSimpleExportFile ( )

Definition at line 111 of file class.ilOrgUnitExporter.php.

References ilXmlExporter\$exp, ilExport\_createExportDirectory(), ilExport\_getExportDirectory(), ilFileUtils\delDir(), ilFileDelivery\deliverFileLegacy(), ilObjOrgUnit\getRootOrgId(), ilObjOrgUnit\getRootOrgRefId(), IL_CAL_UNIX, IL_INST_ID, ILIAS_VERSION_NUMERIC, ilFileUtils\makeDirParents(), simpleExport(), and ilFileUtils\zip().

111  : array
112  {
113  $orgu_id = ilObjOrgUnit::getRootOrgId();
114  $orgu_ref_id = ilObjOrgUnit::getRootOrgRefId();
115 
116  ilExport::_createExportDirectory($orgu_id, "xml", "orgu");
117  $export_dir = ilExport::_getExportDirectory($orgu_id, "xml", "orgu");
118  $ts = time();
119 
120  // Workaround for test assessment
121  $sub_dir = $ts . '__' . IL_INST_ID . '__' . "orgu" . '_' . $orgu_id . "";
122  $new_file = $sub_dir . '.zip';
123 
124  $export_run_dir = $export_dir . "/" . $sub_dir;
125  ilFileUtils::makeDirParents($export_run_dir);
126 
127  $writer = $this->simpleExport($orgu_ref_id);
128  $writer->xmlDumpFile($export_run_dir . "/manifest.xml", false);
129 
130  // zip the file
131  ilFileUtils::zip($export_run_dir, $export_dir . "/" . $new_file);
132  ilFileUtils::delDir($export_run_dir);
133 
134  // Store info about export
135  $exp = new ilExportFileInfo($orgu_id);
136  $exp->setVersion(ILIAS_VERSION_NUMERIC);
137  $exp->setCreationDate(new ilDateTime($ts, IL_CAL_UNIX));
138  $exp->setExportType('xml');
139  $exp->setFilename($new_file);
140  $exp->create();
141 
143  $export_dir . "/" . $new_file,
144  $new_file
145  );
146 
147  return array(
148  "success" => true,
149  "file" => $new_file,
150  "directory" => $export_dir,
151  );
152  }
const IL_INST_ID
Definition: constants.php:40
const ILIAS_VERSION_NUMERIC
simpleExport(int $orgu_ref_id)
const IL_CAL_UNIX
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static _createExportDirectory(int $a_obj_id, string $a_export_type="xml", string $a_obj_type="")
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRootOrgRefId()
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
+ Here is the call graph for this function:

◆ simpleExport()

ilOrgUnitExporter::simpleExport ( int  $orgu_ref_id)

Definition at line 36 of file class.ilOrgUnitExporter.php.

References $attributes, getAttributesForOrgu(), getExternalId(), ilObjOrgUnit\getRootOrgRefId(), and getStructure().

Referenced by sendAndCreateSimpleExportFile().

36  : ilXmlWriter
37  {
38  $nodes = $this->getStructure($orgu_ref_id);
39  $writer = new ilXmlWriter();
40  $writer->xmlHeader();
41  $writer->xmlStartTag("OrgUnits");
42  foreach ($nodes as $node_ref_id) {
43  $orgu = new ilObjOrgUnit($node_ref_id);
44  if ($orgu->getRefId() == ilObjOrgUnit::getRootOrgRefId()) {
45  continue;
46  }
47  $attributes = $this->getAttributesForOrgu($orgu);
48  $writer->xmlStartTag("OrgUnit", $attributes);
49  $writer->xmlElement("external_id", null, $this->getExternalId($node_ref_id));
50  $writer->xmlElement("title", null, $orgu->getTitle());
51  $writer->xmlElement("description", null, $orgu->getDescription());
52  $writer->xmlEndTag("OrgUnit");
53  }
54  $writer->xmlEndTag("OrgUnits");
55 
56  return $writer;
57  }
$attributes
Definition: metadata.php:248
getAttributesForOrgu(ilObjOrgUnit $orgu)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getExternalId(int $orgu_ref_id)
static getRootOrgRefId()
getStructure(int $root_node_ref)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simpleExportExcel()

ilOrgUnitExporter::simpleExportExcel ( int  $orgu_ref_id)

Definition at line 71 of file class.ilOrgUnitExporter.php.

References getAttributesForOrgu(), ilObjOrgUnit\getRootOrgRefId(), and getStructure().

71  : void
72  {
73  // New File and Sheet
74  $file_name = "org_unit_export_" . $orgu_ref_id;
75  $worksheet = new ilExcel();
76  $worksheet->addSheet('org_units');
77  $row = 1;
78 
79  // Headers
80  $worksheet->setCell($row, 0, "ou_id");
81  $worksheet->setCell($row, 1, "ou_id_type");
82  $worksheet->setCell($row, 2, "ou_parent_id");
83  $worksheet->setCell($row, 3, "ou_parent_id_type");
84  $worksheet->setCell($row, 4, "reference_id");
85  $worksheet->setCell($row, 5, "title");
86  $worksheet->setCell($row, 6, "description");
87  $worksheet->setCell($row, 7, "action");
88 
89  // Rows
90  $nodes = $this->getStructure($orgu_ref_id);
91 
92  foreach ($nodes as $node) {
93  $orgu = new ilObjOrgUnit($node);
94  if ($orgu->getRefId() == ilObjOrgUnit::getRootOrgRefId()) {
95  continue;
96  }
97  $row++;
98  $attrs = $this->getAttributesForOrgu($orgu);
99  $worksheet->setCell($row, 0, $attrs["ou_id"]);
100  $worksheet->setCell($row, 1, $attrs["ou_id_type"]);
101  $worksheet->setCell($row, 2, $attrs["ou_parent_id"]);
102  $worksheet->setCell($row, 3, $attrs["ou_parent_id_type"]);
103  $worksheet->setCell($row, 4, $orgu->getRefId());
104  $worksheet->setCell($row, 5, $orgu->getTitle());
105  $worksheet->setCell($row, 6, $orgu->getDescription());
106  $worksheet->setCell($row, 7, "create");
107  }
108  $worksheet->sendToClient($file_name);
109  }
getAttributesForOrgu(ilObjOrgUnit $orgu)
static getRootOrgRefId()
getStructure(int $root_node_ref)
+ Here is the call graph for this function:

Field Documentation

◆ $tree

ilTree ilOrgUnitExporter::$tree
private

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


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