ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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
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 26 of file class.ilOrgUnitExporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitExporter::__construct ( )

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

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

31  {
32  global $DIC;
34  $this->tree = $DIC['tree'];
35  }
global $DIC
Definition: shib_login.php:25
__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 67 of file class.ilOrgUnitExporter.php.

References CLIENT_ID.

Referenced by getExternalId().

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

◆ getAttributesForOrgu()

ilOrgUnitExporter::getAttributesForOrgu ( ilObjOrgUnit  $orgu)
private

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

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

Referenced by simpleExport(), and simpleExportExcel().

172  : array
173  {
174  $parent_ref = $this->tree->getParentId($orgu->getRefId());
175  if ($parent_ref != ilObjOrgUnit::getRootOrgRefId()) {
176  $ou_parent_id = $this->getExternalId($parent_ref);
177  } else {
178  $ou_parent_id = "__ILIAS";
179  }
180  // Only the ref id is guaranteed to be unique.
181  $ref_id = $orgu->getRefId();
182  $attr = array("ou_id" => $this->getExternalId($ref_id),
183  "ou_id_type" => "external_id",
184  "ou_parent_id" => $ou_parent_id,
185  "ou_parent_id_type" => "external_id",
186  "action" => "create"
187  );
188 
189  return $attr;
190  }
getExternalId(int $orgu_ref_id)
$ref_id
Definition: ltiauth.php:66
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 60 of file class.ilOrgUnitExporter.php.

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

Referenced by getAttributesForOrgu(), and simpleExport().

60  : string
61  {
62  $import_id = ilObjOrgunit::_lookupImportId(ilObjOrgUnit::_lookupObjectId($orgu_ref_id));
63 
64  return $import_id ?: $this->buildExternalId($orgu_ref_id);
65  }
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 155 of file class.ilOrgUnitExporter.php.

Referenced by simpleExport(), and simpleExportExcel().

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

◆ sendAndCreateSimpleExportFile()

ilOrgUnitExporter::sendAndCreateSimpleExportFile ( )

Definition at line 112 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().

112  : array
113  {
114  $orgu_id = ilObjOrgUnit::getRootOrgId();
115  $orgu_ref_id = ilObjOrgUnit::getRootOrgRefId();
116 
117  ilExport::_createExportDirectory($orgu_id, "xml", "orgu");
118  $export_dir = ilExport::_getExportDirectory($orgu_id, "xml", "orgu");
119  $ts = time();
120 
121  // Workaround for test assessment
122  $sub_dir = $ts . '__' . IL_INST_ID . '__' . "orgu" . '_' . $orgu_id . "";
123  $new_file = $sub_dir . '.zip';
124 
125  $export_run_dir = $export_dir . "/" . $sub_dir;
126  ilFileUtils::makeDirParents($export_run_dir);
127 
128  $writer = $this->simpleExport($orgu_ref_id);
129  $writer->xmlDumpFile($export_run_dir . "/manifest.xml", false);
130 
131  // zip the file
132  ilFileUtils::zip($export_run_dir, $export_dir . "/" . $new_file);
133  ilFileUtils::delDir($export_run_dir);
134 
135  // Store info about export
136  $exp = new ilExportFileInfo($orgu_id);
137  $exp->setVersion(ILIAS_VERSION_NUMERIC);
138  $exp->setCreationDate(new ilDateTime($ts, IL_CAL_UNIX));
139  $exp->setExportType('xml');
140  $exp->setFilename($new_file);
141  $exp->create();
142 
144  $export_dir . "/" . $new_file,
145  $new_file
146  );
147 
148  return array(
149  "success" => true,
150  "file" => $new_file,
151  "directory" => $export_dir,
152  );
153  }
const IL_INST_ID
Definition: constants.php:40
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)
const ILIAS_VERSION_NUMERIC
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)
+ Here is the call graph for this function:

◆ simpleExport()

ilOrgUnitExporter::simpleExport ( int  $orgu_ref_id)

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

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

Referenced by sendAndCreateSimpleExportFile().

37  : ilXmlWriter
38  {
39  $nodes = $this->getStructure($orgu_ref_id);
40  $writer = new ilXmlWriter();
41  $writer->xmlHeader();
42  $writer->xmlStartTag("OrgUnits");
43  foreach ($nodes as $node_ref_id) {
44  $orgu = new ilObjOrgUnit($node_ref_id);
45  if ($orgu->getRefId() == ilObjOrgUnit::getRootOrgRefId()) {
46  continue;
47  }
48  $attributes = $this->getAttributesForOrgu($orgu);
49  $writer->xmlStartTag("OrgUnit", $attributes);
50  $writer->xmlElement("external_id", null, $this->getExternalId($node_ref_id));
51  $writer->xmlElement("title", null, $orgu->getTitle());
52  $writer->xmlElement("description", null, $orgu->getDescription());
53  $writer->xmlEndTag("OrgUnit");
54  }
55  $writer->xmlEndTag("OrgUnits");
56 
57  return $writer;
58  }
getAttributesForOrgu(ilObjOrgUnit $orgu)
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 72 of file class.ilOrgUnitExporter.php.

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

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


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