ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestExporter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 use ILIAS\Test\ExportImport\Types as ExportImportTypes;
26 
35 {
36  private readonly ilLanguage $lng;
38  private readonly TestLogger $logger;
39  private readonly ilTree $tree;
40  private readonly ilCtrl $ctrl;
43 
44  public function __construct()
45  {
46  global $DIC;
47  $this->lng = $DIC['lng'];
48  $local_dic = TestDIC::dic();
49  $this->export_factory = $local_dic['exportimport.factory'];
50  $this->logger = $local_dic['logging.logger'];
51  $this->questionrepository = $local_dic['question.general_properties.repository'];
52  $this->tree = $DIC['tree'];
53  $this->ctrl = $DIC['ilCtrl'];
54  $this->component_repository = $DIC['component.repository'];
55 
57  }
58 
62  public function init(): void
63  {
64  }
65 
66  public function getXmlRepresentation(string $a_entity, string $a_schema_version, string $id): string
67  {
68  $parameters = $this->ctrl->getParameterArrayByClass(ilTestExportGUI::class);
69  $export_type = ExportImportTypes::XML;
70  if (!empty($parameters['export_results'])) {
71  $export_type = ExportImportTypes::XML_WITH_RESULTS;
72  $this->ctrl->clearParameterByClass(ilTestExportGUI::class, 'export_results');
73  }
74  $tst = new ilObjTest((int) $id, false);
75  $tst->read();
76  $zip = $this->export_factory->getExporter($tst, $export_type)
77  ->withExportDirInfo($this->getAbsoluteExportDirectory())
78  ->write();
79 
80  $this->logger->info(__METHOD__ . ': Created zip file ' . $zip);
81  return '';
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 
93  $intro_page_id = $tst->getMainSettings()->getIntroductionSettings()->getIntroductionPageId();
94  if ($intro_page_id !== null) {
95  $mobs = array_merge($mobs, ilObjMediaObject::_getMobsOfObject('tst:pg', $intro_page_id));
96  $files = array_merge($files, ilObjFile::_getFilesOfObject('tst:pg', $intro_page_id));
97  }
98 
99  $concluding_remarks_page_id = $tst->getMainSettings()->getFinishingSettings()->getConcludingRemarksPageId();
100  if ($concluding_remarks_page_id !== null) {
101  $mobs = array_merge($mobs, ilObjMediaObject::_getMobsOfObject('tst:pg', $concluding_remarks_page_id));
102  $files = array_merge($files, ilObjFile::_getFilesOfObject('tst:pg', $concluding_remarks_page_id));
103  }
104  }
105 
106  return [
107  [
108  'component' => 'components/ILIAS/MediaObjects',
109  'entity' => 'mob',
110  'ids' => $mobs
111  ],
112  [
113  'component' => 'components/ILIAS/File',
114  'entity' => 'file',
115  'ids' => $files
116  ]
117  ];
118  }
119 
120  return parent::getXmlExportTailDependencies($entity, $target_release, $ids);
121  }
122 
127  public function getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids): array
128  {
129  if ($a_entity == 'tst') {
130  $deps = [];
131 
132  $tax_ids = $this->getDependingTaxonomyIds($a_ids);
133 
134  if (count($tax_ids)) {
135  $deps[] = [
136  'component' => 'components/ILIAS/Taxonomy',
137  'entity' => 'tax',
138  'ids' => $tax_ids
139  ];
140  }
141 
142  $deps[] = [
143  'component' => 'components/ILIAS/ILIASObject',
144  'entity' => 'common',
145  'ids' => $a_ids
146  ];
147 
148 
149  $md_ids = [];
150  foreach ($a_ids as $id) {
151  $md_ids[] = $id . ':0:tst';
152  }
153  if ($md_ids !== []) {
154  $deps[] = [
155  'component' => 'components/ILIAS/MetaData',
156  'entity' => 'md',
157  'ids' => $md_ids
158  ];
159  }
160 
161  return $deps;
162  }
163 
164  return parent::getXmlExportTailDependencies($a_entity, $a_target_release, $a_ids);
165  }
166 
171  private function getDependingTaxonomyIds(array $test_obj_ids): array
172  {
173  $tax_ids = [];
174 
175  foreach ($test_obj_ids as $test_obj_id) {
176  foreach (ilObjTaxonomy::getUsageOfObject($test_obj_id) as $tax_id) {
177  $tax_ids[$tax_id] = $tax_id;
178  }
179  }
180 
181  return $tax_ids;
182  }
183 
191  public function getValidSchemaVersions(string $a_entity): array
192  {
193  return [
194  '4.1.0' => [
195  'namespace' => 'http://www.ilias.de/Modules/Test/htlm/4_1',
196  'xsd_file' => 'ilias_tst_4_1.xsd',
197  'uses_dataset' => false,
198  'min' => '4.1.0',
199  'max' => ''
200  ]
201  ];
202  }
203 }
init()
Initialisation.
Readable part of repository interface to ilComponentDataDB.
readonly ilCtrl $ctrl
getDependingTaxonomyIds(array $test_obj_ids)
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids)
readonly ilLanguage $lng
readonly GeneralQuestionPropertiesRepository $questionrepository
getXmlRepresentation(string $a_entity, string $a_schema_version, string $id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Used for container export with tests.
readonly ExportImportFactory $export_factory
global $DIC
Definition: shib_login.php:22
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="-")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
readonly ilComponentRepository $component_repository
readonly ilTree $tree
getValidSchemaVersions(string $a_entity)
Returns schema versions that the component can export to.
readonly TestLogger $logger