ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestExporter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 {
32  private ilLanguage $lng;
33  private ilLogger $log;
34  private ilTree $tree;
35  private ilCtrl $ctrl;
38 
39  public function __construct()
40  {
41  global $DIC;
42  $this->lng = $DIC['lng'];
43  $this->log = $DIC['ilLog'];
44  $this->tree = $DIC['tree'];
45  $this->ctrl = $DIC['ilCtrl'];
46  $this->component_repository = $DIC['component.repository'];
47  $this->questioninfo = $DIC->testQuestionPool()->questionInfo();
48 
50  }
51 
55  public function init(): void
56  {
57  }
58 
59  public function getXmlRepresentation(string $a_entity, string $a_schema_version, string $id): string
60  {
61  $tst = new ilObjTest((int) $id, false);
62  $tst->read();
63  $test_export_factory = new ilTestExportFactory(
64  $tst,
65  $this->lng,
66  $this->log,
67  $this->tree,
68  $this->component_repository,
69  $this->questioninfo
70  );
71  $test_export = $test_export_factory->getExporter('xml');
72 
73  $parameters = $this->ctrl->getParameterArrayByClass(ilTestExportGUI::class);
74  if (!empty($parameters['export_results'])) {
75  $test_export->setResultExportingEnabledForTestExport(true);
76  $this->ctrl->clearParameterByClass(ilTestExportGUI::class, 'export_results');
77  }
78  $zip = $test_export->buildExportFile();
79 
80  $this->log->write(__METHOD__ . ': Created zip file ' . $zip);
81  return ''; // Sagt mjansen
82  }
83 
84  public function getXmlExportHeadDependencies(string $entity, string $target_release, array $ids): array
85  {
86  if ($entity === 'tst') {
87  $mobs = [];
88  $files = [];
89  foreach ($ids as $id) {
90  $tst = new ilObjTest((int) $id, false);
91  $tst->read();
92  $intro_page_id = $tst->getMainSettings()->getIntroductionSettings()->getIntroductionPageId();
93  if ($intro_page_id !== null) {
94  $mobs = array_merge($mobs, ilObjMediaObject::_getMobsOfObject('tst:pg', $intro_page_id));
95  $files = array_merge($files, ilObjFile::_getFilesOfObject('tst:pg', $intro_page_id));
96  }
97 
98  $concluding_remarks_page_id = $tst->getMainSettings()->getFinishingSettings()->getConcludingRemarksPageId();
99  if ($concluding_remarks_page_id !== null) {
100  $mobs = array_merge($mobs, ilObjMediaObject::_getMobsOfObject('tst:pg', $concluding_remarks_page_id));
101  $files = array_merge($files, ilObjFile::_getFilesOfObject('tst:pg', $concluding_remarks_page_id));
102  }
103  }
104 
105  return [
106  [
107  'component' => 'Services/MediaObjects',
108  'entity' => 'mob',
109  'ids' => $mobs
110  ],
111  [
112  'component' => 'Modules/File',
113  'entity' => 'file',
114  'ids' => $files
115  ]
116  ];
117  }
118 
119  return parent::getXmlExportTailDependencies($entity, $target_release, $ids);
120  }
121 
126  public function getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids): array
127  {
128  if ($a_entity == 'tst') {
129  $deps = [];
130 
131  $tax_ids = $this->getDependingTaxonomyIds($a_ids);
132 
133  if (count($tax_ids)) {
134  $deps[] = [
135  'component' => 'Services/Taxonomy',
136  'entity' => 'tax',
137  'ids' => $tax_ids
138  ];
139  }
140 
141  $deps[] = [
142  'component' => 'Services/Object',
143  'entity' => 'common',
144  'ids' => $a_ids
145  ];
146 
147  return $deps;
148  }
149 
150  return parent::getXmlExportTailDependencies($a_entity, $a_target_release, $a_ids);
151  }
152 
157  private function getDependingTaxonomyIds(array $test_obj_ids): array
158  {
159  $tax_ids = [];
160 
161  foreach ($test_obj_ids as $test_obj_id) {
162  foreach (ilObjTaxonomy::getUsageOfObject($test_obj_id) as $tax_id) {
163  $tax_ids[$tax_id] = $tax_id;
164  }
165  }
166 
167  return $tax_ids;
168  }
169 
177  public function getValidSchemaVersions(string $a_entity): array
178  {
179  return [
180  '4.1.0' => [
181  'namespace' => 'http://www.ilias.de/Modules/Test/htlm/4_1',
182  'xsd_file' => 'ilias_tst_4_1.xsd',
183  'uses_dataset' => false,
184  'min' => '4.1.0',
185  'max' => ''
186  ]
187  ];
188  }
189 }
init()
Initialisation.
Readable part of repository interface to ilComponentDataDB.
getDependingTaxonomyIds(array $test_obj_ids)
ilComponentRepository $component_repository
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlRepresentation(string $a_entity, string $a_schema_version, string $id)
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
Used for container export with tests.
getXmlExportHeadDependencies(string $entity, string $target_release, array $ids)
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
QuestionInfoService $questioninfo
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getValidSchemaVersions(string $a_entity)
Returns schema versions that the component can export to.