ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilScormAiccImporter Class Reference
+ Inheritance diagram for ilScormAiccImporter:
+ Collaboration diagram for ilScormAiccImporter:

Public Member Functions

 __construct ()
 
 getResult ()
 
 init ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ?ilImportMapping $a_mapping)
 
 writeData (string $a_entity, string $a_version, int $a_id)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 
 setImport (ilImport $a_val)
 
 getImport ()
 
 init ()
 
 setInstallId (string $a_val)
 
 getInstallId ()
 
 setInstallUrl (string $a_val)
 
 getInstallUrl ()
 
 setSchemaVersion (string $a_val)
 
 getSchemaVersion ()
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setSkipEntities (array $a_val)
 
 getSkipEntities ()
 
 exportedFromSameInstallation ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 

Private Member Functions

 initResult ()
 
 publishResult (\ILIAS\Data\Result $result)
 

Private Attributes

ilScormAiccDataSet $dataset
 
ILIAS Data Result $result
 
DataTypeFactory $df
 
array $module_properties = []
 

Additional Inherited Members

- Protected Attributes inherited from ilXmlImporter
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

Detailed Description

Definition at line 23 of file class.ilScormAiccImporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilScormAiccImporter::__construct ( )

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

References ILIAS\GlobalScreen\Provider\__construct(), and initResult().

34  {
35  $this->dataset = new ilScormAiccDataSet();
36  $this->df = new DataTypeFactory();
37  $this->initResult();
38 
40  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ getResult()

ilScormAiccImporter::getResult ( )
Returns
|<array<string, string|SimpleXMLElement>>

Definition at line 57 of file class.ilScormAiccImporter.php.

References $result.

58  {
59  return $this->result;
60  }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:28

◆ importXmlRepresentation()

ilScormAiccImporter::importXmlRepresentation ( string  $a_entity,
string  $a_id,
string  $a_xml,
?ilImportMapping  $a_mapping 
)
Exceptions
ilDatabaseException
ilFileUtilsException
ilObjectNotFoundException

Definition at line 71 of file class.ilScormAiccImporter.php.

References $DIC, $message, $module_properties, ILIAS\Data\Result\error(), ilXmlImporter\getImportDirectory(), ilObjectFactory\getInstanceByObjId(), ilImportMapping\getMapping(), initResult(), null, publishResult(), ilFileUtils\rename(), ilFileUtils\renameExecutables(), and ilUtil\stripSlashes().

76  : void {
77  global $DIC;
78 
79  $this->initResult();
80 
81  $xml_directory = $a_xml;
82  $new_object = null;
83 
84  $this->publishResult(
85  $this->df
86  ->ok('Parsing started')
87  ->then(
88  function (string $message) use (
89  &$new_object,
90  &$xml_directory,
91  $a_id,
92  $a_mapping
93  ): ?\ILIAS\Data\Result {
94  if ($a_id !== '' &&
95  $a_mapping !== null &&
96  ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id))) {
97  $new_object = ilObjectFactory::getInstanceByObjId((int) $new_id, false);
98  $xml_directory = $this->getImportDirectory();
99  }
100 
101  return $this->df->ok($xml_directory);
102  }
103  )
104  ->then(function (string $xml_directory): ?\ILIAS\Data\Result {
105  if (!is_dir($xml_directory)) {
106  return $this->df->error(
107  sprintf('Directory lost while importing: %s', $xml_directory)
108  );
109  }
110 
111  return null;
112  })
113  ->then(function (string $xml_directory): ?\ILIAS\Data\Result {
114  $manifest_file = $xml_directory . '/manifest.xml';
115  if (!file_exists($manifest_file)) {
116  return $this->df->error(
117  sprintf(
118  'No manifest file found in import directory "%s": %s',
119  $xml_directory,
120  $manifest_file
121  )
122  );
123  }
124 
125  return $this->df->ok($manifest_file);
126  })
127  ->then(function (string $manifest_file): ?\ILIAS\Data\Result {
128  $manifest_file_content = file_get_contents($manifest_file);
129  if (!is_string($manifest_file_content) || $manifest_file_content === '') {
130  return $this->df->error(
131  sprintf(
132  'Could not read content from manifest file: %s',
133  $manifest_file
134  )
135  );
136  }
137 
138  return $this->df->ok($manifest_file_content);
139  })
140  ->then(function (string $manifest_file_content) use ($xml_directory): ?\ILIAS\Data\Result {
141  $properties_file = $xml_directory . '/properties.xml';
142  $properties_file_content = file_get_contents($properties_file);
143  if (!is_string($properties_file_content) || $properties_file_content === '') {
144  return $this->df->error(
145  sprintf(
146  'Could not read file: %s',
147  $properties_file
148  )
149  );
150  }
151 
152  return $this->df->ok($properties_file_content);
153  })
154  ->then(function (string $properties_file_content): ?\ILIAS\Data\Result {
155  return (new ilScormImportParser($this->df))->parse($properties_file_content);
156  })
157  ->then(
158  function (SimpleXMLElement $properties_xml_doc): ?\ILIAS\Data\Result {
159  try {
160  foreach ($this->dataset->properties as $key => $value) {
161  $this->module_properties[$key] = $properties_xml_doc->{$key};
162  }
163 
164  $this->module_properties['Title'] = $properties_xml_doc->Title;
165  $this->module_properties['Description'] = $properties_xml_doc->Description;
166 
167  foreach ($this->module_properties as $key => $property_node) {
168  $property_value = $property_node->__toString();
169  $filteredValue = preg_replace('%\s%', '', $property_value);
170  $this->module_properties[$key] = ilUtil::stripSlashes($filteredValue);
171  }
172 
173  return $this->df->ok($this->module_properties);
174  } catch (Exception $exception) {
175  return $this->df->error($exception);
176  }
177  }
178  )->then(function (array $module_properties) use (
179  $xml_directory,
180  $a_id,
181  $a_mapping,
182  $new_object,
183  $DIC
184  ): ?\ILIAS\Data\Result {
185  if ($a_id !== '' &&
186  $a_mapping !== null &&
187  ($new_id = $a_mapping->getMapping(
188  'Services/Container',
189  'objs',
190  $a_id
191  ))) {
192  $this->dataset->writeData(
193  'sahs',
194  '5.1.0',
195  $new_object->getId(),
197  );
198 
199  $new_object->createReference();
200 
201  $scormFile = 'content.zip';
202  $scormFilePath = $xml_directory . '/' . $scormFile;
203  $targetPath = $new_object->getDataDirectory() . '/' . $scormFile;
204  $file_path = $targetPath;
205 
206  ilFileUtils::rename($scormFilePath, $targetPath);
207  $DIC->legacyArchives()->unzip($file_path);
208  unlink($file_path);
209  ilFileUtils::renameExecutables($new_object->getDataDirectory());
210 
211  $new_ref_id = $new_object->getRefId();
212  $subType = $module_properties['SubType'];
213  if ($subType === 'scorm') {
214  $new_object = new ilObjSCORMLearningModule($new_ref_id);
215  } else {
216  $new_object = new ilObjSCORM2004LearningModule($new_ref_id);
217  }
218 
219  $title = $new_object->readObject();
220  $new_object->setLearningProgressSettingsAtUpload();
221  }
222 
223  return null;
224  })
225  );
226  }
Interface Observer Contains several chained tasks and infos about them.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
publishResult(\ILIAS\Data\Result $result)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static renameExecutables(string $a_dir)
global $DIC
Definition: shib_login.php:26
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObjSCORM2004LearningModule.
$message
Definition: xapiexit.php:31
static rename(string $a_source, string $a_target)
Class ilObjSCORMLearningModule.
+ Here is the call graph for this function:

◆ init()

ilScormAiccImporter::init ( )

Definition at line 62 of file class.ilScormAiccImporter.php.

62  : void
63  {
64  }

◆ initResult()

ilScormAiccImporter::initResult ( )
private

Definition at line 42 of file class.ilScormAiccImporter.php.

References publishResult().

Referenced by __construct(), and importXmlRepresentation().

42  : void
43  {
44  $this->publishResult($this->df->error('No XML parsed, yet'));
45  $this->module_properties = [];
46  }
publishResult(\ILIAS\Data\Result $result)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ publishResult()

ilScormAiccImporter::publishResult ( \ILIAS\Data\Result  $result)
private

Definition at line 48 of file class.ilScormAiccImporter.php.

References $result.

Referenced by importXmlRepresentation(), and initResult().

49  {
50  $this->result = $result;
51  return $this->result;
52  }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:28
+ Here is the caller graph for this function:

◆ writeData()

ilScormAiccImporter::writeData ( string  $a_entity,
string  $a_version,
int  $a_id 
)

Definition at line 228 of file class.ilScormAiccImporter.php.

228  : void
229  {
230  $this->dataset->writeData($a_entity, $a_version, $a_id, $this->module_properties);
231  }

Field Documentation

◆ $dataset

ilScormAiccDataSet ilScormAiccImporter::$dataset
private

Definition at line 25 of file class.ilScormAiccImporter.php.

◆ $df

DataTypeFactory ilScormAiccImporter::$df
private

Definition at line 27 of file class.ilScormAiccImporter.php.

◆ $module_properties

array ilScormAiccImporter::$module_properties = []
private

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

Referenced by importXmlRepresentation().

◆ $result

ILIAS Data Result ilScormAiccImporter::$result
private

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

Referenced by getResult(), and publishResult().


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