ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilSkillExportOption.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 use ILIAS\Export\ExportHandler\I\Consumer\Context\HandlerInterface as ilExportHandlerConsumerContextInterface;
25 use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\CollectionInterface as ilExportHandlerConsumerFileIdentifierCollectionInterface;
26 use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\HandlerInterface as ilExportHandlerConsumerFileIdentifierInterface;
27 use ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface as ilExportHandlerFileInfoCollectionInterface;
28 
29 class ilSkillExportOption extends BasicExportOption
30 {
31  protected \ILIAS\Data\Factory $data_factory;
32 
33  public function init(Container $DIC): void
34  {
35  $this->data_factory = new \ILIAS\Data\Factory();
36  }
37 
38  public function getExportType(): string
39  {
40  return 'xml';
41  }
42 
43  public function getExportOptionId(): string
44  {
45  return 'il_skill_profile_exp';
46  }
47 
48  public function getSupportedRepositoryObjectTypes(): array
49  {
50  return ['skee'];
51  }
52 
53  public function getLabel(): string
54  {
55  # Return an empty label so that the export button is not displayed in the export tab.
56  return '';
57  }
58 
59  public function onExportOptionSelected(
60  ilExportHandlerConsumerContextInterface $context
61  ): void {
62  # Do nothing, the export happens in another tab.
63  }
64 
65  public function onDeleteFiles(
66  ilExportHandlerConsumerContextInterface $context,
67  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
68  ): void {
69  foreach ($this->getFileSelection($context, $file_identifiers) as $file) {
70  $exp_dir = $file->getDownloadInfo();
71  $file_path = $file->getDownloadInfo() . DIRECTORY_SEPARATOR . $file->getFileName();
72  if (is_file($file_path)) {
73  unlink($file_path);
74  }
75  }
76  }
77 
78  public function onDownloadFiles(
79  ilExportHandlerConsumerContextInterface $context,
80  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
81  ): void {
82  foreach ($this->getFileSelection($context, $file_identifiers) as $file) {
84  $file->getDownloadInfo() . DIRECTORY_SEPARATOR . $file->getFileName(),
85  $file->getFileName()
86  );
87  }
88  }
89 
90  public function onDownloadWithLink(
91  ReferenceId $reference_id,
92  ilExportHandlerConsumerFileIdentifierInterface $file_identifier
93  ): void {
94 
95  }
96 
97  public function getFiles(
98  ilExportHandlerConsumerContextInterface $context
99  ): ilExportHandlerFileInfoCollectionInterface {
100  $collection_builder = $context->fileCollectionBuilder();
101  $export_dir = ilExport::_getExportDirectory($context->exportObject()->getId(), "xml", 'skmg');
102  $file_names = file_exists($export_dir) ? scandir($export_dir) : [];
103  foreach ($file_names as $file_name) {
104  if (in_array($file_name, ['.', '..'])) {
105  continue;
106  }
107  $collection_builder = $collection_builder->withSPLFileInfo(
108  new SplFileInfo($export_dir . DIRECTORY_SEPARATOR . $file_name),
109  $this->data_factory->objId($context->exportObject()->getId()),
110  $this
111  );
112  }
113  return $collection_builder->collection();
114  }
115 
116  public function getFileSelection(
117  ilExportHandlerConsumerContextInterface $context,
118  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
119  ): ilExportHandlerFileInfoCollectionInterface {
120  $collection_builder = $context->fileCollectionBuilder();
121  foreach ($this->getFiles($context) as $file_info) {
122  if (!in_array($file_info->getFileIdentifier(), $file_identifiers->toStringArray())) {
123  continue;
124  }
125  $collection_builder = $collection_builder->withFileInfo($file_info);
126  }
127  return $collection_builder->collection();
128  }
129 }
getFileSelection(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
$context
Definition: webdav.php:31
onExportOptionSelected(ilExportHandlerConsumerContextInterface $context)
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
onDownloadFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
onDownloadWithLink(ReferenceId $reference_id, ilExportHandlerConsumerFileIdentifierInterface $file_identifier)
global $DIC
Definition: shib_login.php:25
onDeleteFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
getFiles(ilExportHandlerConsumerContextInterface $context)
ILIAS Data Factory $data_factory