ILIAS  release_7 Revision v7.30-3-g800a261c036
ilOrgUnitExporter Class Reference

Class ilOrgUnitExporter. More...

+ Inheritance diagram for ilOrgUnitExporter:
+ Collaboration diagram for ilOrgUnitExporter:

Public Member Functions

 simpleExport ($orgu_ref_id)
 
 simpleExportExcel ($orgu_ref_id)
 
 sendAndCreateSimpleExportFile ()
 
- Public Member Functions inherited from ilCategoryExporter
 getXmlExportHeadDependencies ($a_entity, $a_target_release, $a_ids)
 Get head dependencies. More...
 
 getXmlExportTailDependencies ($a_entity, $a_target_release, $a_ids)
 Get tail dependencies. More...
 
 getXmlRepresentation ($a_entity, $a_schema_version, $a_id)
 Get xml. More...
 
 getValidSchemaVersions ($a_entity)
 Returns schema versions that the component can export to. More...
 
 init ()
 Init method. More...
 
- Public Member Functions inherited from ilXmlExporter
 __construct ()
 Constructor. More...
 
 setExport (ilExport $a_exp)
 Set export object. More...
 
 getExport ()
 Get export. More...
 
 getXmlRepresentation ($a_entity, $a_schema_version, $a_id)
 Get xml representation. More...
 
 init ()
 
 setExportDirectories ($a_dir_relative, $a_dir_absolute)
 Export directories. More...
 
 getRelativeExportDirectory ()
 Get relative export directory. More...
 
 getAbsoluteExportDirectory ()
 Get absolute export directory. More...
 
 getXmlExportHeadDependencies ($a_entity, $a_target_release, $a_ids)
 Get head dependencies. More...
 
 getXmlExportTailDependencies ($a_entity, $a_target_release, $a_ids)
 Get tail dependencies. More...
 
 getValidSchemaVersions ($a_entity)
 Returns schema versions that the component can export to. More...
 
 determineSchemaVersion ($a_entity, $a_target_release)
 Determine schema version. More...
 

Protected Member Functions

 getExternalId ($orgu_ref_id)
 
 buildExternalId ($orgu_ref_id)
 

Private Member Functions

 getStructure ($root_node_ref)
 
 getAttributesForOrgu ($orgu)
 

Additional Inherited Members

- Static Public Member Functions inherited from ilXmlExporter
static lookupExportDirectory ($a_obj_type, $a_obj_id, $a_export_type='xml', $a_entity="")
 export directory lookup More...
 
- Protected Attributes inherited from ilXmlExporter
 $dir_relative
 
 $dir_absolute
 
 $exp
 

Detailed Description

Member Function Documentation

◆ buildExternalId()

ilOrgUnitExporter::buildExternalId (   $orgu_ref_id)
protected
Parameters
$orgu_ref_idint
Returns
string

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

56 {
57 return "orgu_" . CLIENT_ID . "_" . $orgu_ref_id;
58 }
const CLIENT_ID
Definition: constants.php:39

References CLIENT_ID.

Referenced by getExternalId().

+ Here is the caller graph for this function:

◆ getAttributesForOrgu()

ilOrgUnitExporter::getAttributesForOrgu (   $orgu)
private
Parameters
$orguilObjOrgUnit
Returns
array

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

175 {
176 global $DIC;
177 $tree = $DIC['tree'];
178 $parent_ref = $tree->getParentId($orgu->getRefId());
179 if ($parent_ref != ilObjOrgUnit::getRootOrgRefId()) {
180 $ou_parent_id = $this->getExternalId($parent_ref);
181 } else {
182 $ou_parent_id = "__ILIAS";
183 }
184 // Only the ref id is guaranteed to be unique.
185 $ref_id = $orgu->getRefId();
186 $attr = array("ou_id" => $this->getExternalId($ref_id), "ou_id_type" => "external_id", "ou_parent_id" => $ou_parent_id, "ou_parent_id_type" => "external_id", "action" => "create");
187
188 return $attr;
189 }
static getRootOrgRefId()
global $DIC
Definition: goto.php:24

References $DIC, getExternalId(), and ilObjOrgUnit\getRootOrgRefId().

Referenced by simpleExport(), and simpleExportExcel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExternalId()

ilOrgUnitExporter::getExternalId (   $orgu_ref_id)
protected
Parameters
$orgu_ref_id
Returns
string

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

43 {
44 $import_id = ilObjOrgunit::_lookupImportId(ilObjOrgUnit::_lookupObjectId($orgu_ref_id));
45
46 return $import_id ?: $this->buildExternalId($orgu_ref_id);
47 }
static _lookupObjectId($a_ref_id)
lookup object id

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

Referenced by getAttributesForOrgu(), and simpleExport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStructure()

ilOrgUnitExporter::getStructure (   $root_node_ref)
private

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

150 {
151 global $DIC;
152 $tree = $DIC['tree'];
153 $open = array($root_node_ref);
154 $closed = array();
155 while (count($open)) {
156 $current = array_shift($open);
157 $closed[] = $current;
158 foreach ($tree->getChildsByType($current, "orgu") as $new) {
159 if (!in_array($new["child"], $closed) && !in_array($new["child"], $open)) {
160 $open[] = $new["child"];
161 }
162 }
163 }
164
165 return $closed;
166 }

References $DIC.

Referenced by simpleExport(), and simpleExportExcel().

+ Here is the caller graph for this function:

◆ sendAndCreateSimpleExportFile()

ilOrgUnitExporter::sendAndCreateSimpleExportFile ( )

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

106 {
107 $orgu_id = ilObjOrgUnit::getRootOrgId();
108 $orgu_ref_id = ilObjOrgUnit::getRootOrgRefId();
109
110 ilExport::_createExportDirectory($orgu_id, "xml", "orgu");
111 $export_dir = ilExport::_getExportDirectory($orgu_id, "xml", "orgu");
112 $ts = time();
113
114 // Workaround for test assessment
115 $sub_dir = $ts . '__' . IL_INST_ID . '__' . "orgu" . '_' . $orgu_id . "";
116 $new_file = $sub_dir . '.zip';
117
118 $export_run_dir = $export_dir . "/" . $sub_dir;
119 ilUtil::makeDirParents($export_run_dir);
120
121 $writer = $this->simpleExport($orgu_ref_id);
122 $writer->xmlDumpFile($export_run_dir . "/manifest.xml", false);
123
124 // zip the file
125 ilUtil::zip($export_run_dir, $export_dir . "/" . $new_file);
126 ilUtil::delDir($export_run_dir);
127
128 // Store info about export
129 $exp = new ilExportFileInfo($orgu_id);
130 $exp->setVersion(ILIAS_VERSION_NUMERIC);
131 $exp->setCreationDate(new ilDateTime($ts, IL_CAL_UNIX));
132 $exp->setExportType('xml');
133 $exp->setFilename($new_file);
134 $exp->create();
135
137 $export_dir . "/" . $new_file,
138 $new_file
139 );
140
141 return array(
142 "success" => true,
143 "file" => $new_file,
144 "directory" => $export_dir,
145 );
146 }
const IL_CAL_UNIX
@classDescription Date and time handling
@classDescription Stores information of creation date and versions of export files
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static _createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
const IL_INST_ID
Definition: constants.php:38
const ILIAS_VERSION_NUMERIC

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

+ Here is the call graph for this function:

◆ simpleExport()

ilOrgUnitExporter::simpleExport (   $orgu_ref_id)

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

14 {
15 $nodes = $this->getStructure($orgu_ref_id);
16 $writer = new ilXmlWriter();
17 $writer->xmlHeader();
18 $writer->xmlStartTag("OrgUnits");
19 foreach ($nodes as $orgu_ref_id) {
20 $orgu = new ilObjOrgUnit($orgu_ref_id);
21 if ($orgu->getRefId() == ilObjOrgUnit::getRootOrgRefId()) {
22 continue;
23 }
24 $attributes = $this->getAttributesForOrgu($orgu);
25 $writer->xmlStartTag("OrgUnit", $attributes);
26 $writer->xmlElement("external_id", null, $this->getExternalId($orgu_ref_id));
27 $writer->xmlElement("title", null, $orgu->getTitle());
28 $writer->xmlElement("description", null, $orgu->getDescription());
29 $writer->xmlEndTag("OrgUnit");
30 }
31 $writer->xmlEndTag("OrgUnits");
32
33 return $writer;
34 }
Class ilObjOrgUnit.
XML writer class.
$attributes
Definition: metadata.php:231

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

Referenced by sendAndCreateSimpleExportFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simpleExportExcel()

ilOrgUnitExporter::simpleExportExcel (   $orgu_ref_id)
Parameters
$orgu_ref_id

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

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

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

+ Here is the call graph for this function:

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