ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilExport Class Reference
+ Inheritance diagram for ilExport:
+ Collaboration diagram for ilExport:

Public Member Functions

 __construct ()
 Default constructor.
 _getExportFiles ($a_obj_id, $a_export_types="", $a_obj_type="")
 Get Export Files.
 _createExportDirectory ($a_obj_id, $a_export_type="xml", $a_obj_type="")
 Create export directory.
 _generateIndexFile ($a_filename, $a_obj_id, $a_files, $a_type="")
 Generates an index.html file including links to all xml files included (for container exports)
 exportObject ($a_type, $a_id, $a_target_release, $a_config="")
 Export an ILIAS object (the object type must be known by objDefinition)
 processExporter ($a_comp, $a_class, $a_entity, $a_target_release, $a_id)
 Process exporter.

Static Public Member Functions

static _getFileTypeString ($a_obj_type)
 Get file type string.
static _getValidExportSubItems ($a_ref_id)
 Get a list of subitems of a repository resource, that implement the export.
static _getLastExportFileDate ($a_obj_id, $a_type="", $a_obj_type="")
 Get date of last export file.
static _getLastExportFileInformation ($a_obj_id, $a_type="", $a_obj_type="")
 Get last export file information.
static _getExportDirectory ($a_obj_id, $a_type="xml", $a_obj_type="")
 Get export directory.

Static Public Attributes

static $new_file_structure = array('exc','crs','sess','file','grp','frm')
static $export_implementer = array("tst", "lm", "glo")
static $file_type_str

Detailed Description

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

Constructor & Destructor Documentation

ilExport::__construct ( )

Default constructor.

Returns

Definition at line 32 of file class.ilExport.php.

Referenced by ilExportContainer\__construct().

{
}

+ Here is the caller graph for this function:

Member Function Documentation

ilExport::_createExportDirectory (   $a_obj_id,
  $a_export_type = "xml",
  $a_obj_type = "" 
)

Create export directory.

Definition at line 214 of file class.ilExport.php.

References $ilErr, _getExportDirectory(), ilObject\_lookupType(), ilUtil\getDataDir(), ilUtil\makeDir(), and ilUtil\makeDirParents().

Referenced by ilObjGlossary\createExportDirectory(), ilExportContainer\exportObject(), and exportObject().

{
global $ilErr;
if ($a_obj_type == "")
{
$a_obj_type = ilObject::_lookupType($a_obj_id);
}
if(in_array($a_obj_type, self::$new_file_structure))
{
$edir = ilExport::_getExportDirectory($a_obj_id,$a_export_type,$a_obj_type);
return true;
}
$data_dir = ilUtil::getDataDir()."/".$a_obj_type."_data";
ilUtil::makeDir($data_dir);
if(!is_writable($data_dir))
{
$ilErr->raiseError("Data Directory (".$data_dir
.") not writeable.",$ilErr->FATAL);
}
// create resource data directory
$res_dir = $data_dir."/".$a_obj_type."_".$a_obj_id;
ilUtil::makeDir($res_dir);
if(!@is_dir($res_dir))
{
$ilErr->raiseError("Creation of Glossary Directory failed.",$ilErr->FATAL);
}
// create Export subdirectory (data_dir/glo_data/glo_<id>/Export)
if ($a_export_type != "xml")
{
$export_dir = $res_dir."/export_".$a_export_type;
}
else
{
$export_dir = $res_dir."/export";
}
ilUtil::makeDir($export_dir);
if(!@is_dir($export_dir))
{
$ilErr->raiseError("Creation of Export Directory failed.",$ilErr->FATAL);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilExport::_generateIndexFile (   $a_filename,
  $a_obj_id,
  $a_files,
  $a_type = "" 
)

Generates an index.html file including links to all xml files included (for container exports)

Definition at line 269 of file class.ilExport.php.

References $f, $file, $lng, ilObject\_lookupTitle(), ilObject\_lookupType(), and ilUtil\getStyleSheetLocation().

Referenced by ilCourseArchives\addXML().

{
global $lng;
$lng->loadLanguageModule("export");
if ($a_type == "")
{
$a_type = ilObject::_lookupType($a_obj_id);
}
$a_tpl = new ilTemplate("tpl.main.html", true, true);
$location_stylesheet = ilUtil::getStyleSheetLocation();
$a_tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
$a_tpl->getStandardTemplate();
$a_tpl->setTitle(ilObject::_lookupTitle($a_obj_id));
$a_tpl->setDescription($lng->txt("export_export_date").": ".
date('Y-m-d H:i:s', time())." (".date_default_timezone_get().")");
$f_tpl = new ilTemplate("tpl.export_list.html", true, true, "Services/Export");
foreach ($a_files as $file)
{
$f_tpl->setCurrentBlock("file_row");
$f_tpl->setVariable("TITLE", $file["title"]);
$f_tpl->setVariable("TYPE", $lng->txt("obj_".$file["type"]));
$f_tpl->setVariable("FILE", $file["file"]);
$f_tpl->parseCurrentBlock();
}
$a_tpl->setContent($f_tpl->get());
$index_content = $a_tpl->get("DEFAULT", false, false, false, true, false, false);
$f = fopen ($a_filename, "w");
fwrite($f, $index_content);
fclose($f);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilExport::_getExportDirectory (   $a_obj_id,
  $a_type = "xml",
  $a_obj_type = "" 
)
static

Get export directory.

Parameters
integerObject ID
stringExport Type ("xml", "html", ...)
stringObject Type

Definition at line 114 of file class.ilExport.php.

References $dir, $GLOBALS, ilFileSystemStorage\_createPathFromId(), ilObject\_lookupType(), and ilUtil\getDataDir().

Referenced by ilCourseArchives\__addZipFiles(), _createExportDirectory(), _getExportFiles(), ilExportContainer\addSubitems(), ilExportGUI\delete(), ilExportGUI\download(), ilObjFileBasedLMGUI\exportHTML(), ilExportContainer\exportObject(), exportObject(), and ilObjGlossary\getExportDirectory().

{
global $objDefinition;
if ($a_obj_type == "")
{
$a_obj_type = ilObject::_lookupType($a_obj_id);
}
if(in_array($a_obj_type, self::$new_file_structure))
{
include_once './Services/FileSystemStorage/classes/class.ilFileSystemStorage.php';
$dir = ilUtil::getDataDir().DIRECTORY_SEPARATOR;
$dir .= 'il'.$objDefinition->getClassName($a_obj_type).DIRECTORY_SEPARATOR;
$dir .= ilFileSystemStorage::_createPathFromId($a_obj_id, $a_obj_type).DIRECTORY_SEPARATOR;
$dir .= ($a_type == 'xml' ? 'export' : 'export_'.$a_type);
return $dir;
}
if ($a_type != "xml")
{
$export_dir = ilUtil::getDataDir()."/".$a_obj_type."_data"."/".$a_obj_type."_".$a_obj_id."/export_".$a_type;
}
else
{
$export_dir = ilUtil::getDataDir()."/".$a_obj_type."_data"."/".$a_obj_type."_".$a_obj_id."/export";
}
$GLOBALS['ilLog']->write(__METHOD__.': Export dir is '.$export_dir);
return $export_dir;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilExport::_getExportFiles (   $a_obj_id,
  $a_export_types = "",
  $a_obj_type = "" 
)

Get Export Files.

Definition at line 150 of file class.ilExport.php.

References $dir, $file, $type, _getExportDirectory(), _getFileTypeString(), and ilObject\_lookupType().

Referenced by _getLastExportFileDate(), _getLastExportFileInformation(), ilExportTableGUI\getExportFiles(), and ilObjGlossary\getExportFiles().

{
if ($a_obj_type == "")
{
$a_obj_type = ilObject::_lookupType($a_obj_id);
}
if ($a_export_types == "")
{
$a_export_types = array("xml");
}
if (!is_array($a_export_types))
{
$a_export_types = array($a_export_types);
}
// initialize array
$file = array();
$types = $a_export_types;
foreach($types as $type)
{
$dir = ilExport::_getExportDirectory($a_obj_id, $type, $a_obj_type);
// quit if import dir not available
if (!@is_dir($dir) or
!is_writeable($dir))
{
continue;
}
// open directory
$h_dir = dir($dir);
// get files and save the in the array
while ($entry = $h_dir->read())
{
if ($entry != "." and
$entry != ".." and
substr($entry, -4) == ".zip" and
ereg("^[0-9]{10}_{2}[0-9]+_{2}(".ilExport::_getFileTypeString($a_obj_type)."_)*[0-9]+\.zip\$", $entry))
{
$ts = substr($entry, 0, strpos($entry, "__"));
$file[$entry.$type] = array("type" => $type, "file" => $entry,
"size" => filesize($dir."/".$entry),
"timestamp" => $ts);
}
}
// close import directory
$h_dir->close();
}
// sort files
ksort ($file);
reset ($file);
return $file;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilExport::_getFileTypeString (   $a_obj_type)
static

Get file type string.

Parameters
stringObject Type

Definition at line 43 of file class.ilExport.php.

Referenced by _getExportFiles(), and exportObject().

{
if (!empty(self::$file_type_str[$a_obj_type]))
{
return self::$file_type_str[$a_obj_type];
}
else
{
return $a_obj_type;
}
}

+ Here is the caller graph for this function:

static ilExport::_getLastExportFileDate (   $a_obj_id,
  $a_type = "",
  $a_obj_type = "" 
)
static

Get date of last export file.

Definition at line 82 of file class.ilExport.php.

References $files, _getExportFiles(), and ilUtil\sortArray().

Referenced by _getValidExportSubItems().

{
$files = ilExport::_getExportFiles($a_obj_id, $a_type, $a_obj_type);
if (is_array($files))
{
$files = ilUtil::sortArray($files, "timestamp", "desc");
return $files[0]["timestamp"];
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilExport::_getLastExportFileInformation (   $a_obj_id,
  $a_type = "",
  $a_obj_type = "" 
)
static

Get last export file information.

Definition at line 96 of file class.ilExport.php.

References $files, _getExportFiles(), and ilUtil\sortArray().

Referenced by ilCourseArchives\__addZipFiles().

{
$files = ilExport::_getExportFiles($a_obj_id, $a_type, $a_obj_type);
if (is_array($files))
{
$files = ilUtil::sortArray($files, "timestamp", "desc");
return $files[0];
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilExport::_getValidExportSubItems (   $a_ref_id)
static

Get a list of subitems of a repository resource, that implement the export.

Includes also information on last export file.

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

References _getLastExportFileDate().

Referenced by ilSubItemSelectionTableGUI\ilSubItemSelectionTableGUI().

{
global $tree;
$valid_items = array();
$sub_items = $tree->getSubTree($tree->getNodeData($a_ref_id));
foreach ($sub_items as $sub_item)
{
if (in_array($sub_item["type"], self::$export_implementer))
{
$valid_items[] = array("type" => $sub_item["type"],
"title" => $sub_item["title"], "ref_id" => $sub_item["child"],
"obj_id" => $sub_item["obj_id"],
"timestamp" =>
ilExport::_getLastExportFileDate($sub_item["obj_id"], "xml", $sub_item["type"]));
}
}
return $valid_items;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilExport::exportObject (   $a_type,
  $a_id,
  $a_target_release,
  $a_config = "" 
)

Export an ILIAS object (the object type must be known by objDefinition)

Parameters
@return

Definition at line 327 of file class.ilExport.php.

References $filename, $tpl, _createExportDirectory(), _getExportDirectory(), _getFileTypeString(), ilObject\_lookupTitle(), ilUtil\delDir(), IL_CAL_UNIX, ilUtil\makeDirParents(), processExporter(), and ilUtil\zip().

{
global $objDefinition, $tpl;
$comp = $objDefinition->getComponentForType($a_type);
$c = explode("/", $comp);
$class = "il".$c[1]."Exporter";
// manifest writer
include_once "./Services/Xml/classes/class.ilXmlWriter.php";
$this->manifest_writer = new ilXmlWriter();
$this->manifest_writer->xmlHeader();
$this->manifest_writer->xmlStartTag(
'Manifest',
array(
"MainEntity" => $a_type,
"Title" => ilObject::_lookupTitle($a_id),
"TargetRelease" => $a_target_release,
"InstallationId" => IL_INST_ID,
"InstallationUrl" => ILIAS_HTTP_PATH));
// get export class
ilExport::_createExportDirectory($a_id, "xml", $a_type);
$export_dir = ilExport::_getExportDirectory($a_id, "xml", $a_type);
$ts = time();
// Workaround for test assessment
$sub_dir = $ts.'__'.IL_INST_ID.'__'.self::_getFileTypeString($a_type).'_'.$a_id;
$new_file = $sub_dir.'.zip';
$this->export_run_dir = $export_dir."/".$sub_dir;
ilUtil::makeDirParents($this->export_run_dir);
$this->cnt = array();
$success = $this->processExporter($comp, $class, $a_type, $a_target_release, $a_id);
$this->manifest_writer->xmlEndTag('Manifest');
//$tpl->setContent($tpl->main_content."<pre>".htmlentities($manifest_writer->xmlDumpMem(true))."</pre>");
$this->manifest_writer->xmlDumpFile($this->export_run_dir."/manifest.xml", false);
//echo "-".$export_run_dir."-";
// zip the file
ilUtil::zip($this->export_run_dir, $export_dir."/".$new_file);
ilUtil::delDir($this->export_run_dir);
// Store info about export
if($success)
{
include_once './Services/Export/classes/class.ilExportFileInfo.php';
$exp = new ilExportFileInfo($a_id);
$exp->setVersion($a_target_release);
$exp->setCreationDate(new ilDateTime($ts,IL_CAL_UNIX));
$exp->setExportType('xml');
$exp->setFilename($new_file);
$exp->create();
}
//exit;
return array(
"success" => $success,
"file" => $filename,
"directory" => $directory
);
}

+ Here is the call graph for this function:

ilExport::processExporter (   $a_comp,
  $a_class,
  $a_entity,
  $a_target_release,
  $a_id 
)

Process exporter.

Parameters
@return

Definition at line 400 of file class.ilExport.php.

References exit, and ilUtil\makeDirParents().

Referenced by exportObject().

{
$success = true;
if (!is_array($a_id))
{
if ($a_id == "")
{
return;
}
$a_id = array($a_id);
}
// get exporter object
$export_class_file = "./".$a_comp."/classes/class.".$a_class.".php";
//echo "1-".$export_class_file."-"; exit;
if (!is_file($export_class_file))
{
echo "1-not found:".$export_class_file."-"; exit;
return false;
}
include_once($export_class_file);
$exp = new $a_class();
if (!isset($this->cnt[$a_comp]))
{
$this->cnt[$a_comp] = 1;
}
else
{
$this->cnt[$a_comp]++;
}
$set_dir_relative = $a_comp."/set_".$this->cnt[$a_comp];
$set_dir_absolute = $this->export_run_dir."/".$set_dir_relative;
ilUtil::makeDirParents($set_dir_absolute);
$exp->init();
$sv = $exp->determineSchemaVersion($a_entity, $a_target_release);
// process head dependencies
$sequence = $exp->getXmlExportHeadDependencies($a_entity, $a_target_release, $a_id);
foreach ($sequence as $s)
{
$comp = explode("/", $s["component"]);
$exp_class = "il".$comp[1]."Exporter";
$s = $this->processExporter($s["component"], $exp_class,
$s["entity"], $a_target_release, $s["ids"]);
if (!$s)
{
$success = false;
}
}
// write export.xml file
$export_writer = new ilXmlWriter();
$export_writer->xmlHeader();
$attribs = array("InstallationId" => IL_INST_ID,
"InstallationUrl" => ILIAS_HTTP_PATH,
"Entity" => $a_entity, "SchemaVersion" => $sv["schema_version"], "TargetRelease" => $a_target_release,
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:exp" => "http://www.ilias.de/Services/Export/exp/4_1",
"xsi:schemaLocation" => "http://www.ilias.de/Services/Export/exp/4_1 ".ILIAS_HTTP_PATH."/xml/ilias_export_4_1.xsd"
);
if ($sv["namespace"] != "" && $sv["xsd_file"] != "")
{
$attribs["xsi:schemaLocation"].= " ".$sv["namespace"]." ".
ILIAS_HTTP_PATH."/xml/".$sv["xsd_file"];
$attribs["xmlns"] = $sv["namespace"];
}
if ($sv["uses_dataset"])
{
$attribs["xsi:schemaLocation"].= " ".
"http://www.ilias.de/Services/DataSet/ds/4_1 ".ILIAS_HTTP_PATH."/xml/ilias_ds_4_1.xsd";
$attribs["xmlns:ds"] = "http://www.ilias.de/Services/DataSet/ds/4_1";
}
$export_writer->xmlStartTag('exp:Export', $attribs);
$dir_cnt = 1;
foreach ($a_id as $id)
{
$exp->setExportDirectories($set_dir_relative."/expDir_".$dir_cnt,
$set_dir_absolute."/expDir_".$dir_cnt);
$export_writer->xmlStartTag('exp:ExportItem', array("Id" => $id));
$xml = $exp->getXmlRepresentation($a_entity, $a_target_release, $id);
$export_writer->appendXml($xml);
$export_writer->xmlEndTag('exp:ExportItem');
$dir_cnt++;
}
$export_writer->xmlEndTag('exp:Export');
$export_writer->xmlDumpFile($set_dir_absolute."/export.xml", false);
$this->manifest_writer->xmlElement("ExportFile",
array("Component" => $a_comp, "Path" => $set_dir_relative."/export.xml"));
// process tail dependencies
$sequence = $exp->getXmlExportTailDependencies($a_entity, $a_target_release, $a_id);
foreach ($sequence as $s)
{
$comp = explode("/", $s["component"]);
$exp_class = "il".$comp[1]."Exporter";
$s = $this->processExporter($s["component"], $exp_class,
$s["entity"], $a_target_release, $s["ids"]);
if (!$s)
{
$success = false;
}
}
return $success;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilExport::$export_implementer = array("tst", "lm", "glo")
static

Definition at line 18 of file class.ilExport.php.

ilExport::$file_type_str
static
Initial value:
array(
"tst" => "test_",
'svy' => 'survey_'
)

Definition at line 22 of file class.ilExport.php.

ilExport::$new_file_structure = array('exc','crs','sess','file','grp','frm')
static

Definition at line 15 of file class.ilExport.php.


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