ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilHTMLLearningModuleDataSet.php
Go to the documentation of this file.
1 <?php
2 
21 
27 {
30 
31  public function __construct()
32  {
33  global $DIC;
34 
36  $this->irss_wrapper = $DIC->htmlLearningModule()->internal()->repo()->irss();
37  }
38 
39  public function getSupportedVersions(): array
40  {
41  return array("4.1.0");
42  }
43 
44  protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
45  {
46  return "https://www.ilias.de/xml/Modules/HTMLLearningModule/" . $a_entity;
47  }
48 
49  protected function getTypes(string $a_entity, string $a_version): array
50  {
51  if ($a_entity === "htlm") {
52  switch ($a_version) {
53  case "4.1.0":
54  return array(
55  "Id" => "integer",
56  "Title" => "text",
57  "Description" => "text",
58  "StartFile" => "text",
59  "Dir" => "rscontainer");
60  }
61  }
62  return [];
63  }
64 
65  public function readData(string $a_entity, string $a_version, array $a_ids): void
66  {
67  $ilDB = $this->db;
68 
69  if ($a_entity === "htlm") {
70  switch ($a_version) {
71  case "4.1.0":
72  $this->getDirectDataFromQuery("SELECT id, title, description, " .
73  " startfile start_file" .
74  " FROM file_based_lm JOIN object_data ON (file_based_lm.id = object_data.obj_id) " .
75  "WHERE " .
76  $ilDB->in("id", $a_ids, false, "integer"));
77  break;
78  }
79  }
80  }
81 
82  public function getXmlRecord(string $a_entity, string $a_version, array $a_set): array
83  {
84  $lm = new ilObjFileBasedLM($a_set["Id"], false);
85  $a_set["Dir"] = $lm->getResource()->getIdentification();
86 
87  return $a_set;
88  }
89 
90  public function getContainerExportConfig(
91  array $record,
92  string $entity,
93  string $schema_version,
94  string $field,
95  string $value
97  if ($entity === "htlm" && $field === "Dir") {
98  $lm = new ilObjFileBasedLM($record["Id"], false);
99  $container = $lm->getResource();
100  if ($container) {
101  return
103  $container,
104  ""
105  );
106  }
107  }
108  return null;
109  }
110 
111  public function importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version): void
112  {
113  $a_rec = $this->stripTags($a_rec);
114  switch ($a_entity) {
115  case "htlm":
116 
117  if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_rec['Id'])) {
119  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
120  } else {
121  $newObj = new ilObjFileBasedLM();
122  $newObj->setType("htlm");
123  $newObj->create(true);
124  }
125 
126  $newObj->setTitle($a_rec["Title"]);
127  $newObj->setDescription($a_rec["Description"]);
128  $newObj->setStartFile($a_rec["StartFile"], true);
129 
130  $dir = str_replace("..", "", $a_rec["Dir"]);
131  if ($dir !== "" && $this->getImportDirectory() !== "") {
132  $source_dir = $this->getImportDirectory() . "/" . $dir;
133  $rid = $this->irss_wrapper->createContainerFromLocalDir(
134  $source_dir,
135  new ilHTLMStakeholder(),
136  "",
137  true,
138  $newObj->getTitle()
139  );
140  $newObj->setRID($rid);
141  }
142 
143  $newObj->update(true);
144  $this->current_obj = $newObj;
145 
146  $a_mapping->addMapping("components/ILIAS/HTMLLearningModule", "htlm", $a_rec["Id"], $newObj->getId());
147  $a_mapping->addMapping(
148  "components/ILIAS/MetaData",
149  "md",
150  $a_rec["Id"] . ":0:htlm",
151  $newObj->getId() . ":0:htlm"
152  );
153  break;
154  }
155  }
156 }
getXmlNamespace(string $a_entity, string $a_schema_version)
string $schema_version
File Based Learning Module (HTML) object.
getContainerExportConfig(array $record, string $entity, string $schema_version, string $field, string $value)
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
readData(string $a_entity, string $a_version, array $a_ids)
getIRSSContainerExportConfig(StorableResource $source_container, string $source_path, string $target_path="")
$container
Definition: wac.php:36
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getMapping(string $a_comp, string $a_entity, string $a_old_id)
ilDBInterface $db
getXmlRecord(string $a_entity, string $a_version, array $a_set)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
global $DIC
Definition: shib_login.php:26
getTypes(string $a_entity, string $a_version)
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
__construct(Container $dic, ilPlugin $plugin)
HTML learning module data set class.
string $entity
stripTags(array $rec, array $omit_keys=[])