ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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
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 24 of file class.ilOrgUnitExporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitExporter::__construct ( )

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

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

29  {
30  global $DIC;
32  $this->tree = $DIC['tree'];
33  }
global $DIC
Definition: shib_login.php:22
__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 65 of file class.ilOrgUnitExporter.php.

References CLIENT_ID.

Referenced by getExternalId().

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

◆ getAttributesForOrgu()

ilOrgUnitExporter::getAttributesForOrgu ( ilObjOrgUnit  $orgu)
private

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

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

Referenced by simpleExport(), and simpleExportExcel().

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

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

Referenced by getAttributesForOrgu(), and simpleExport().

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

Referenced by simpleExport(), and simpleExportExcel().

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

◆ sendAndCreateSimpleExportFile()

ilOrgUnitExporter::sendAndCreateSimpleExportFile ( )

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

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

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

Referenced by sendAndCreateSimpleExportFile().

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

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

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


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