ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilDataSet Class Reference

A dataset contains in data in a common structure that can be shared and transformed for different purposes easily, examples. More...

+ Inheritance diagram for ilDataSet:
+ Collaboration diagram for ilDataSet:

Public Member Functions

 __construct ()
 Constructor.
 init ($a_entity, $a_schema_version)
 Init.
 getSupportedVersions ()
 Get supported version.
 readData ($a_entity, $a_version, $a_ids)
 Read data from DB.
 setExportDirectories ($a_relative, $a_absolute)
 Set export directories.
 setImportDirectory ($a_val)
 Set import directory.
 getImportDirectory ()
 Get import directory.
 setDSPrefix ($a_val)
 Set XML dataset namespace prefix.
 getDSPrefix ()
 Get XML dataset namespace prefix.
 getDSPrefixString ()
 getDirectDataFromQuery ($a_query, $a_convert_to_leading_upper=true)
 Get data from query.This is a standard procedure, all db field names are directly mapped to abstract fields.
 convertToLeadingUpper ($a_str)
 Make xyz_abc a XyzAbc string.
 getJsonRepresentation ()
 Get json representation.
 getXmlRepresentation ($a_entity, $a_schema_version, $a_ids, $a_field="", $a_omit_header=false, $a_omit_types=false)
 Get xml representation <dataset install_id="123" install_url="..."> <types entity="table_name" version="4.0.1"> <ftype name="field_1" type="text"> <ftype name="field_2" type="date"> <ftype name="field_3" type="integer"> </types> <types ...> ...
 addRecordsXml ($a_writer, $a_prefixes, $a_entity, $a_schema_version, $a_ids, $a_field="")
 Add records xml.
 afterXmlRecordWriting ($a_entity, $a_version, $a_set)
 After xml record writing hook record.
 getNamespaces (&$namespaces, $a_entity, $a_schema_version)
 Get xml namespaces.
 getXmlRecord ($a_entity, $a_version, $a_set)
 Get xml record for version.
 getJsonRecord ($a_set)
 Get json record for version.
 getXmlTypes ($a_entity, $a_version)
 Get xml types.
 getJsonTypes ($a_entity, $a_version)
 Get json types.
 getXMLEntityName ($a_entity, $a_version)
 Get entity name for xml (may be overwritten)
 getXMLEntityTag ($a_entity, $a_schema_version)
 Get entity tag.
 getJsonEntityName ($a_entity, $a_version)
 Get entity name for json (may be overwritten)
 setImport ($a_val)
 Set import object.
 getImport ()
 Get import object.

Data Fields

 $dircnt
const EXPORT_NO_INST_ID = 1
const EXPORT_ID_ILIAS_LOCAL = 2
const EXPORT_ID_ILIAS_LOCAL_INVALID = 3
const EXPORT_ID_ILIAS_REMOTE = 4
const EXPORT_ID_ILIAS_REMOTE_INVALID = 5
const EXPORT_ID = 6
const EXPORT_ID_INVALID = 7

Protected Member Functions

 getTypes ($a_entity, $a_version)
 Get (abstract) types for (abstract) field names.
 getXmlNamespace ($a_entity, $a_schema_version)
 Get xml namespace.
 createObjectExportId ($a_type, $a_id)
 Build ilias export id.
 parseObjectExportId ($a_id, $a_fallback_id=NULL)
 Parse export id.

Private Member Functions

 addTypesXml ($a_writer, $a_entity, $a_schema_version)
 Add types to xml writer.

Detailed Description

A dataset contains in data in a common structure that can be shared and transformed for different purposes easily, examples.

  • transform associative arrays into (set-)xml and back (e.g. for import/export)
  • transform assiciative arrays into json and back (e.g. for ajax requests)

The general structure is:

  • entity name (many times this corresponds to a table name)
  • structure (this is a set of field names and types pairs) currently supported types: text, integer, timestamp planned: date, time, clob types correspond to db types, see http://www.ilias.de/docu/goto.php?target=pg_25354_42&client_id=docu
  • records (similar to records of a database query; associative arrays)
Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 24 of file class.ilDataSet.php.

Constructor & Destructor Documentation

ilDataSet::__construct ( )

Constructor.

Definition at line 40 of file class.ilDataSet.php.

{
}

Member Function Documentation

ilDataSet::addRecordsXml (   $a_writer,
  $a_prefixes,
  $a_entity,
  $a_schema_version,
  $a_ids,
  $a_field = "" 
)

Add records xml.

Parameters
@return

Definition at line 308 of file class.ilDataSet.php.

References $d, $dircnt, afterXmlRecordWriting(), getDSPrefixString(), getXmlRecord(), getXmlTypes(), ilUtil\makeDirParents(), ilUtil\rCopy(), and readData().

Referenced by getXmlRepresentation().

{
$types = $this->getXmlTypes($a_entity, $a_schema_version);
$this->readData($a_entity, $a_schema_version, $a_ids, $a_field);
if (is_array($this->data))
{
foreach ($this->data as $d)
{
$a_writer->xmlStartTag($this->getDSPrefixString()."Rec",
array("Entity" => $this->getXmlEntityName($a_entity, $a_schema_version)));
// entity tag
$a_writer->xmlStartTag($this->getXmlEntityTag($a_entity, $a_schema_version));
$rec = $this->getXmlRecord($a_entity, $a_schema_version, $d);
foreach ($rec as $f => $c)
{
switch ($types[$f])
{
case "directory":
if ($this->absolute_export_dir != "" && $this->relative_export_dir != "")
{
ilUtil::makeDirParents($this->absolute_export_dir."/dsDir_".$this->dircnt);
ilUtil::rCopy($c, $this->absolute_export_dir."/dsDir_".$this->dircnt);
//echo "<br>copy-".$c."-".$this->absolute_export_dir."/dsDir_".$this->dircnt."-";
$c = $this->relative_export_dir."/dsDir_".$this->dircnt;
$this->dircnt++;
}
break;
}
// this changes schema/dtd
//$a_writer->xmlElement($a_prefixes[$a_entity].":".$f,
// array(), $c);
$a_writer->xmlElement($f, array(), $c);
}
$a_writer->xmlEndTag($this->getXmlEntityTag($a_entity, $a_schema_version));
$a_writer->xmlEndTag($this->getDSPrefixString()."Rec");
$this->afterXmlRecordWriting($a_entity, $a_schema_version, $d);
// foreach record records of dependent entities (no record)
$deps = $this->getDependencies($a_entity, $a_schema_version, $rec, $a_ids);
if (is_array($deps))
{
foreach ($deps as $dp => $par)
{
$this->addRecordsXml($a_writer, $a_prefixes, $dp, $a_schema_version, $par["ids"], $par["field"]);
}
}
}
}
else if ($this->data === false)
{
// false -> add records of dependent entities (no record)
$deps = $this->getDependencies($a_entity, $a_schema_version, null, $a_ids);
if (is_array($deps))
{
foreach ($deps as $dp => $par)
{
$this->addRecordsXml($a_writer, $a_prefixes, $dp, $a_schema_version, $par["ids"], $par["field"]);
}
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataSet::addTypesXml (   $a_writer,
  $a_entity,
  $a_schema_version 
)
private

Add types to xml writer.

Parameters

Definition at line 391 of file class.ilDataSet.php.

References $t, getDSPrefixString(), and getXmlTypes().

Referenced by getXmlRepresentation().

{
$types = $this->getXmlTypes($a_entity, $a_schema_version);
// add types of current entity
if (is_array($types))
{
$a_writer->xmlStartTag($this->getDSPrefixString()."Types",
array("Entity" => $this->getXmlEntityName($a_entity, $a_schema_version),
"SchemaVersion" => $a_schema_version));
foreach ($this->getXmlTypes($a_entity, $a_schema_version) as $f => $t)
{
$a_writer->xmlElement($this->getDSPrefixString().'FieldType',
array("Name" => $f, "Type" => $t));
}
$a_writer->xmlEndTag($this->getDSPrefixString()."Types");
}
// add types of dependent entities
$deps = $this->getDependencies($a_entity, $a_schema_version, null, null);
if (is_array($deps))
{
foreach ($deps as $dp => $w)
{
$this->addTypesXml($a_writer, $dp, $a_schema_version);
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataSet::afterXmlRecordWriting (   $a_entity,
  $a_version,
  $a_set 
)

After xml record writing hook record.

Parameters
@return

Reimplemented in ilUserDataSet.

Definition at line 382 of file class.ilDataSet.php.

Referenced by addRecordsXml().

{
}

+ Here is the caller graph for this function:

ilDataSet::convertToLeadingUpper (   $a_str)

Make xyz_abc a XyzAbc string.

Parameters
@return

Definition at line 190 of file class.ilDataSet.php.

Referenced by getDirectDataFromQuery(), getXMLEntityTag(), and ilUserDataSet\importRecord().

{
$a_str = strtoupper(substr($a_str, 0, 1)).substr($a_str, 1);
while (is_int($pos = strpos($a_str, "_")))
{
$a_str = substr($a_str, 0, $pos).
strtoupper(substr($a_str, $pos+1, 1)).
substr($a_str, $pos+2);
}
return $a_str;
}

+ Here is the caller graph for this function:

ilDataSet::createObjectExportId (   $a_type,
  $a_id 
)
protected

Build ilias export id.

Parameters
string$a_type
int$a_id
Returns
string

Definition at line 546 of file class.ilDataSet.php.

Referenced by ilBlogDataSet\readData().

{
return "il_".IL_INST_ID."_".$a_type."_".$a_id;
}

+ Here is the caller graph for this function:

ilDataSet::getDirectDataFromQuery (   $a_query,
  $a_convert_to_leading_upper = true 
)

Get data from query.This is a standard procedure, all db field names are directly mapped to abstract fields.

Parameters
@return

Definition at line 161 of file class.ilDataSet.php.

References convertToLeadingUpper().

Referenced by ilExternalFeedDataSet\readData(), ilHTMLLearningModuleDataSet\readData(), ilMediaCastDataSet\readData(), ilRatingDataSet\readData(), ilCOPageDataSet\readData(), ilNotesDataSet\readData(), ilNewsDataSet\readData(), ilItemGroupDataSet\readData(), ilPollDataSet\readData(), ilBookmarkDataSet\readData(), ilHelpDataSet\readData(), ilExerciseDataSet\readData(), ilBlogDataSet\readData(), ilSessionDataSet\readData(), ilMediaPoolDataSet\readData(), ilWikiDataSet\readData(), ilTaxonomyDataSet\readData(), ilCalendarDataSet\readData(), ilMediaObjectDataSet\readData(), and ilUserDataSet\readData().

{
global $ilDB;
$set = $ilDB->query($a_query);
$this->data = array();
while ($rec = $ilDB->fetchAssoc($set))
{
if ($a_convert_to_leading_upper)
{
$tmp = array();
foreach ($rec as $k => $v)
{
$tmp[$this->convertToLeadingUpper($k)]
= $v;
}
$rec = $tmp;
}
$this->data[] = $rec;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataSet::getDSPrefix ( )

Get XML dataset namespace prefix.

Returns
string XML dataset namespace prefix

Definition at line 141 of file class.ilDataSet.php.

Referenced by getDSPrefixString().

{
return $this->var;
}

+ Here is the caller graph for this function:

ilDataSet::getDSPrefixString ( )

Definition at line 146 of file class.ilDataSet.php.

References getDSPrefix().

Referenced by addRecordsXml(), addTypesXml(), and getXmlRepresentation().

{
if ($this->getDSPrefix() != "")
{
return $this->getDSPrefix().":";
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataSet::getImport ( )

Get import object.

Returns
object import object

Definition at line 534 of file class.ilDataSet.php.

{
return $this->import;
}
ilDataSet::getImportDirectory ( )

Get import directory.

Returns
string import directory

Definition at line 121 of file class.ilDataSet.php.

Referenced by ilHTMLLearningModuleDataSet\importRecord(), ilPollDataSet\importRecord(), ilBlogDataSet\importRecord(), ilExerciseDataSet\importRecord(), ilUserDataSet\importRecord(), and ilMediaObjectDataSet\importRecord().

{
return $this->import_directory;
}

+ Here is the caller graph for this function:

ilDataSet::getJsonEntityName (   $a_entity,
  $a_version 
)

Get entity name for json (may be overwritten)

Definition at line 514 of file class.ilDataSet.php.

Referenced by getJsonRepresentation().

{
return $a_entity;
}

+ Here is the caller graph for this function:

ilDataSet::getJsonRecord (   $a_set)

Get json record for version.

Parameters
arrayabstract data record
Returns
array json record

Definition at line 463 of file class.ilDataSet.php.

Referenced by getJsonRepresentation().

{
return $a_set;
}

+ Here is the caller graph for this function:

ilDataSet::getJsonRepresentation ( )
final

Get json representation.

Definition at line 206 of file class.ilDataSet.php.

References $d, ilJsonUtil\encode(), getJsonEntityName(), getJsonRecord(), and getJsonTypes().

{
if ($this->version === false)
{
return false;
}
$arr["entity"] = $this->getJsonEntityName();
$arr["version"] = $this->version;
$arr["install_id"] = IL_INST_ID;
$arr["install_url"] = ILIAS_HTTP_PATH;
$arr["types"] = $this->getJsonTypes();
$arr["set"] = array();
foreach ($this->data as $d)
{
$arr["set"][] = $this->getJsonRecord($d);
}
include_once("./Services/JSON/classes/class.ilJsonUtil.php");
return ilJsonUtil::encode($arr);
}

+ Here is the call graph for this function:

ilDataSet::getJsonTypes (   $a_entity,
  $a_version 
)

Get json types.

Returns
array types array for json/version set in constructor

Definition at line 483 of file class.ilDataSet.php.

References getTypes().

Referenced by getJsonRepresentation().

{
return $this->getTypes($a_entity, $a_version);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataSet::getNamespaces ( $namespaces,
  $a_entity,
  $a_schema_version 
)

Get xml namespaces.

Parameters
arraynamespaces per entity
stringentity
stringtarget release

Definition at line 428 of file class.ilDataSet.php.

References getXmlNamespace().

Referenced by getXmlRepresentation().

{
$ns = $this->getXmlNamespace($a_entity, $a_schema_version);
if ($ns != "")
{
$namespaces[$a_entity] = $ns;
}
// add types of dependent entities
$deps = $this->getDependencies($a_entity, $a_schema_version, null, null);
if (is_array($deps))
{
foreach ($deps as $dp => $w)
{
$this->getNamespaces($namespaces, $dp, $a_schema_version);
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataSet::getTypes (   $a_entity,
  $a_version 
)
abstractprotected

Get (abstract) types for (abstract) field names.

Please note that the abstract fields/types only depend on the version! Not on a choosen representation!

Returns
array types array, e.g. array("field_1" => "text", "field_2" => "integer", ...)

Reimplemented in ilCOPageDataSet, ilMediaObjectDataSet, ilTaxonomyDataSet, ilMediaPoolDataSet, ilWikiDataSet, ilRatingDataSet, ilNotesDataSet, ilUserDataSet, ilHelpDataSet, ilExerciseDataSet, ilExternalFeedDataSet, ilHTMLLearningModuleDataSet, ilItemGroupDataSet, ilMediaCastDataSet, ilSessionDataSet, ilBookmarkDataSet, ilCalendarDataSet, ilNewsDataSet, ilBlogDataSet, and ilPollDataSet.

Referenced by getJsonTypes(), and getXmlTypes().

+ Here is the caller graph for this function:

ilDataSet::getXMLEntityName (   $a_entity,
  $a_version 
)

Get entity name for xml (may be overwritten)

Returns
string

Definition at line 494 of file class.ilDataSet.php.

{
return $a_entity;
}
ilDataSet::getXMLEntityTag (   $a_entity,
  $a_schema_version 
)

Get entity tag.

Parameters
@return

Definition at line 505 of file class.ilDataSet.php.

References convertToLeadingUpper().

{
return $this->convertToLeadingUpper($a_entity);
}

+ Here is the call graph for this function:

ilDataSet::getXmlRecord (   $a_entity,
  $a_version,
  $a_set 
)

Get xml record for version.

Parameters
arrayabstract data record
Returns
array xml record

Reimplemented in ilMediaObjectDataSet, ilBlogDataSet, ilPollDataSet, ilSessionDataSet, ilExerciseDataSet, ilItemGroupDataSet, ilUserDataSet, and ilHTMLLearningModuleDataSet.

Definition at line 452 of file class.ilDataSet.php.

Referenced by addRecordsXml().

{
return $a_set;
}

+ Here is the caller graph for this function:

ilDataSet::getXmlRepresentation (   $a_entity,
  $a_schema_version,
  $a_ids,
  $a_field = "",
  $a_omit_header = false,
  $a_omit_types = false 
)
final

Get xml representation <dataset install_id="123" install_url="..."> <types entity="table_name" version="4.0.1"> <ftype name="field_1" type="text"> <ftype name="field_2" type="date"> <ftype name="field_3" type="integer"> </types> <types ...> ...

</types> <set entity="table_name"> <rec> <field_1>content</field_1> <field_2>my_date</field_2> <field_3>my_number</field_3> </rec> ... </set> </dataset>

Definition at line 250 of file class.ilDataSet.php.

References addRecordsXml(), addTypesXml(), getDSPrefixString(), and getNamespaces().

{
$this->dircnt = 1;
// step 1: check target release and supported versions
// step 2: init writer
include_once "./Services/Xml/classes/class.ilXmlWriter.php";
$writer = new ilXmlWriter();
if (!$a_omit_header)
{
$writer->xmlHeader();
}
// collect namespaces
$namespaces = $prefixes = array();
$this->getNamespaces($namespaces, $a_entity, $a_schema_version);
$atts = array("InstallationId" => IL_INST_ID,
"InstallationUrl" => ILIAS_HTTP_PATH, "TopEntity" => $a_entity);
$cnt = 1;
foreach ($namespaces as $entity => $ns)
{
$prefix = "ns".$cnt;
$prefixes[$entity] = $prefix;
// $atts["xmlns:".$prefix] = $ns;
$cnt++;
}
$writer->xmlStartTag($this->getDSPrefixString().'DataSet', $atts);
// add types
if (!$a_omit_types)
{
$this->addTypesXml($writer, $a_entity, $a_schema_version);
}
// add records
$this->addRecordsXml($writer, $prefixes, $a_entity, $a_schema_version, $a_ids, $a_field = "");
$writer->xmlEndTag($this->getDSPrefixString()."DataSet");
//if ($a_entity == "mep")
//{
// echo "<pre>".htmlentities($writer->xmlDumpMem(true))."</pre>"; exit;
//}
return $writer->xmlDumpMem(false);
}

+ Here is the call graph for this function:

ilDataSet::getXmlTypes (   $a_entity,
  $a_version 
)

Get xml types.

Returns
array types array for xml/version set in constructor

Definition at line 473 of file class.ilDataSet.php.

References getTypes().

Referenced by addRecordsXml(), and addTypesXml().

{
return $this->getTypes($a_entity, $a_version);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataSet::init (   $a_entity,
  $a_schema_version 
)
final

Init.

Parameters
string(abstract) entity name
stringversion string, always the ILIAS release versions that defined the a structure or made changes to it, never use another version. Example: structure is defined in 4.1.0 and changed in 4.3.0 -> use these values only, not 4.2.0 (ask for the 4.1.0 version in ILIAS 4.2.0)

Definition at line 56 of file class.ilDataSet.php.

{
$this->entity = $a_entity;
$this->schema_version = $a_schema_version;
$this->data = array();
}
ilDataSet::parseObjectExportId (   $a_id,
  $a_fallback_id = NULL 
)
protected

Parse export id.

Parameters
string$a_id
int$a_fallback_id
Returns
array type, id

Definition at line 558 of file class.ilDataSet.php.

References ilObject\_getIdForImportId(), and ilObject\_lookupType().

Referenced by ilBlogDataSet\importRecord().

{
// ilias export id?
if(substr($a_id, 0, 3) == "il_")
{
$parts = explode("_", $a_id);
$inst_id = $parts[1];
$type = $parts[2];
$id = $parts[3];
// missing installation ids?
if(($inst_id == 0 || IL_INST_ID == 0) && !DEVMODE)
{
return array("type"=>self::EXPORT_NO_INST_ID, "id"=>$a_fallback_id);
}
// same installation?
if($inst_id == IL_INST_ID)
{
// still existing?
if(ilObject::_lookupType($id) == $type)
{
return array("type"=>self::EXPORT_ID_ILIAS_LOCAL, "id"=>$id);
}
// not found
else
{
return array("type"=>self::EXPORT_ID_ILIAS_LOCAL_INVALID, "id"=>$a_fallback_id);
}
}
// different installation
else
{
// matching type?
if($id && ilObject::_lookupType($id) == $type)
{
return array("type"=>self::EXPORT_ID_ILIAS_REMOTE, "id"=>$id);
}
// not found
else
{
return array("type"=>self::EXPORT_ID_ILIAS_REMOTE_INVALID, "id"=>$a_fallback_id);
}
}
}
// external id
if($id)
{
return array("type"=>self::EXPORT_ID, "id"=>$id);
}
else
{
return array("type"=>self::EXPORT_ID_INVALID, "id"=>$a_fallback_id);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataSet::readData (   $a_entity,
  $a_version,
  $a_ids 
)
abstract

Read data from DB.

This should result in the abstract field structure of the version set in the constructor.

Parameters
arrayone or multiple ids

Referenced by addRecordsXml().

+ Here is the caller graph for this function:

ilDataSet::setDSPrefix (   $a_val)

Set XML dataset namespace prefix.

Parameters
stringXML dataset namespace prefix

Definition at line 131 of file class.ilDataSet.php.

{
$this->var = $a_val;
}
ilDataSet::setExportDirectories (   $a_relative,
  $a_absolute 
)

Set export directories.

Parameters
@return

Definition at line 100 of file class.ilDataSet.php.

{
$this->relative_export_dir = $a_relative;
$this->absolute_export_dir = $a_absolute;
}
ilDataSet::setImport (   $a_val)

Set import object.

Parameters
objectimport object

Definition at line 524 of file class.ilDataSet.php.

{
$this->import = $a_val;
}
ilDataSet::setImportDirectory (   $a_val)

Set import directory.

Parameters
stringimport directory

Definition at line 111 of file class.ilDataSet.php.

{
$this->import_directory = $a_val;
}

Field Documentation

ilDataSet::$dircnt

Definition at line 26 of file class.ilDataSet.php.

Referenced by addRecordsXml().

const ilDataSet::EXPORT_ID = 6

Definition at line 33 of file class.ilDataSet.php.

const ilDataSet::EXPORT_ID_ILIAS_LOCAL = 2

Definition at line 29 of file class.ilDataSet.php.

const ilDataSet::EXPORT_ID_ILIAS_LOCAL_INVALID = 3

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

const ilDataSet::EXPORT_ID_ILIAS_REMOTE = 4

Definition at line 31 of file class.ilDataSet.php.

const ilDataSet::EXPORT_ID_ILIAS_REMOTE_INVALID = 5

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

const ilDataSet::EXPORT_ID_INVALID = 7

Definition at line 34 of file class.ilDataSet.php.

const ilDataSet::EXPORT_NO_INST_ID = 1

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


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