ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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

 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 41 of file class.ilOrgUnitExporter.php.

Referenced by getAttributesForOrgu(), and simpleExport().

41  {
42  return "orgu_".CLIENT_ID."_".$orgu_ref_id;
43  }
+ Here is the caller graph for this function:

◆ getAttributesForOrgu()

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

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

References $DIC, $ref_id, array, buildExternalId(), and ilObjOrgUnit\getRootOrgRefId().

Referenced by simpleExport(), and simpleExportExcel().

152  {
153  global $DIC;
154  $tree = $DIC['tree'];
155  $parent_ref = $tree->getParentId($orgu->getRefId());
156  if($parent_ref != ilObjOrgUnit::getRootOrgRefId()){
157  $ou_parent_id = $this->buildExternalId($parent_ref);
158  } else {
159  $ou_parent_id = "__ILIAS";
160  }
161  // Only the ref id is guaranteed to be unique.
162  $ref_id = $orgu->getRefId();
163  $attr = array("ou_id" => $this->buildExternalId($ref_id), "ou_id_type" => "external_id", "ou_parent_id" => $ou_parent_id, "ou_parent_id_type" => "external_id", "action" => "create");
164  return $attr;
165  }
Create styles array
The data for the language used.
static getRootOrgRefId()
$ref_id
Definition: sahs_server.php:39
global $DIC
+ 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 132 of file class.ilOrgUnitExporter.php.

References $DIC, $new, and array.

Referenced by simpleExport(), and simpleExportExcel().

132  {
133  global $DIC;
134  $tree = $DIC['tree'];
135  $open = array($root_node_ref);
136  $closed = array();
137  while(count($open)){
138  $current = array_shift($open);
139  $closed[] = $current;
140  foreach($tree->getChildsByType($current, "orgu") as $new){
141  if(!in_array($new["child"], $closed) && !in_array($new["child"], $open))
142  $open[] = $new["child"];
143  }
144  }
145  return $closed;
146  }
Create styles array
The data for the language used.
global $DIC
+ Here is the caller graph for this function:

◆ sendAndCreateSimpleExportFile()

ilOrgUnitExporter::sendAndCreateSimpleExportFile ( )

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

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

91  {
92  $orgu_id = ilObjOrgUnit::getRootOrgId();
93  $orgu_ref_id = ilObjOrgUnit::getRootOrgRefId();
94 
95  ilExport::_createExportDirectory($orgu_id, "xml", "orgu");
96  $export_dir = ilExport::_getExportDirectory($orgu_id, "xml", "orgu");
97  $ts = time();
98 
99  // Workaround for test assessment
100  $sub_dir = $ts.'__'.IL_INST_ID.'__'."orgu".'_'.$orgu_id."";
101  $new_file = $sub_dir.'.zip';
102 
103  $export_run_dir = $export_dir."/".$sub_dir;
104  ilUtil::makeDirParents($export_run_dir);
105 
106  $writer = $this->simpleExport($orgu_ref_id);
107  $writer->xmlDumpFile($export_run_dir."/manifest.xml", false);
108 
109  // zip the file
110  ilUtil::zip($export_run_dir , $export_dir."/".$new_file);
111  ilUtil::delDir($export_run_dir );
112 
113  // Store info about export
114  include_once './Services/Export/classes/class.ilExportFileInfo.php';
115  $exp = new ilExportFileInfo($orgu_id);
116  $exp->setVersion(ILIAS_VERSION_NUMERIC);
117  $exp->setCreationDate(new ilDateTime($ts,IL_CAL_UNIX));
118  $exp->setExportType('xml');
119  $exp->setFilename($new_file);
120  $exp->create();
121 
122  ilUtil::deliverFile($export_dir."/".$new_file,
123  $new_file);
124 
125  return array(
126  "success" => true,
127  "file" => $new_file,
128  "directory" => $export_dir
129  );
130  }
static _createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
static makeDirParents($a_dir)
Create a new directory and all parent directories.
const ILIAS_VERSION_NUMERIC
const IL_CAL_UNIX
Stores information of creation date and versions of export files
Date and time handling
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
Create styles array
The data for the language used.
static getRootOrgRefId()
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:

◆ simpleExport()

ilOrgUnitExporter::simpleExport (   $orgu_ref_id)

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

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

Referenced by sendAndCreateSimpleExportFile().

17  {
18  $nodes = $this->getStructure($orgu_ref_id);
19  $writer = new ilXmlWriter();
20  $writer->xmlHeader();
21  $writer->xmlStartTag("OrgUnits");
22  foreach($nodes as $orgu_ref_id){
23  $orgu = new ilObjOrgUnit($orgu_ref_id);
24  if($orgu->getRefId() == ilObjOrgUnit::getRootOrgRefId())
25  continue;
26  $attributes = $this->getAttributesForOrgu($orgu);
27  $writer->xmlStartTag("OrgUnit", $attributes);
28  $writer->xmlElement("external_id", null, $this->buildExternalId($orgu_ref_id));
29  $writer->xmlElement("title", null, $orgu->getTitle());
30  $writer->xmlElement("description", null, $orgu->getDescription());
31  $writer->xmlEndTag("OrgUnit");
32  }
33  $writer->xmlEndTag("OrgUnits");
34  return $writer;
35  }
XML writer class.
Class ilObjOrgUnit.
static getRootOrgRefId()
+ 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 49 of file class.ilOrgUnitExporter.php.

References $row, $worksheet, getAttributesForOrgu(), ilObjOrgUnit\getRootOrgRefId(), and getStructure().

49  {
50  // New File and Sheet
51  $file_name = "org_unit_export_" . $orgu_ref_id;
52  require_once('./Services/Excel/classes/class.ilExcel.php');
53  $worksheet = new ilExcel();
54  $worksheet->addSheet('org_units');
55  $row = 1;
56 
57  // Headers
58  $worksheet->setCell($row, 0, "ou_id");
59  $worksheet->setCell($row, 1, "ou_id_type");
60  $worksheet->setCell($row, 2, "ou_parent_id");
61  $worksheet->setCell($row, 3, "ou_parent_id_type");
62  $worksheet->setCell($row, 4, "reference_id");
63  $worksheet->setCell($row, 5, "external_id");
64  $worksheet->setCell($row, 6, "title");
65  $worksheet->setCell($row, 7, "description");
66  $worksheet->setCell($row, 8, "action");
67 
68  // Rows
69  $nodes = $this->getStructure($orgu_ref_id);
70 
71  foreach ($nodes as $node) {
72  $orgu = new ilObjOrgUnit($node);
73  if ($orgu->getRefId() == ilObjOrgUnit::getRootOrgRefId()) {
74  continue;
75  }
76  $row ++;
77  $attrs = $this->getAttributesForOrgu($orgu);
78  $worksheet->setCell($row, 0, $attrs["ou_id"]);
79  $worksheet->setCell($row, 1, $attrs["ou_id_type"]);
80  $worksheet->setCell($row, 2, $attrs["ou_parent_id"]);
81  $worksheet->setCell($row, 3, $attrs["ou_parent_id_type"]);
82  $worksheet->setCell($row, 4, $orgu->getRefId());
83  $worksheet->setCell($row, 5, $orgu->getImportId());
84  $worksheet->setCell($row, 6, $orgu->getTitle());
85  $worksheet->setCell($row, 7, $orgu->getDescription());
86  $worksheet->setCell($row, 8, "create");
87  }
88  $worksheet->sendToClient($file_name);
89  }
$worksheet
Class ilObjOrgUnit.
static getRootOrgRefId()
+ Here is the call graph for this function:

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