ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMediaPoolExportOptionXMLMasterNoMedia.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;
29 
30 class ilMediaPoolExportOptionXMLMasterNoMedia extends ilBasicLegacyExportOption
31 {
32  protected ilLanguage $lng;
33 
34  public function init(Container $DIC): void
35  {
36  $this->lng = $DIC->language();
37  parent::init($DIC);
38  }
39 
40  public function getExportType(): string
41  {
42  return 'xml_masternomedia';
43  }
44 
45  public function getExportOptionId(): string
46  {
47  return 'mep_exp_option_xml_masternomedia';
48  }
49 
50  public function getSupportedRepositoryObjectTypes(): array
51  {
52  return ['mep'];
53  }
54 
55  public function getLabel(): string
56  {
57  $this->lng->loadLanguageModule('exp');
58  return "XML (" . $this->lng->txt("mep_master_language_only_no_media") . ")";
59  }
60 
61  public function onDownloadFiles(
62  ilExportHandlerConsumerContextInterface $context,
63  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
64  ): void {
65  foreach ($file_identifiers as $file_identifier) {
66  $file = explode(":", trim($file_identifier->getIdentifier()));
67  $export_dir = ilExport::_getExportDirectory(
68  $context->exportObject()->getId(),
69  "",
70  $context->exportObject()->getType()
71  );
72  $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
73  $file[1] = basename($file[1]);
75  $export_dir . "/" . $file[1],
76  $file[1]
77  );
78  }
79  }
80 
81  public function onDownloadWithLink(
82  ReferenceId $reference_id,
83  ilExportHandlerConsumerFileIdentifierInterface $file_identifier
84  ): void {
85  $object_id = $reference_id->toObjectId()->toInt();
86  $type = ilObject::_lookupType($object_id);
87  $file = explode(":", trim($file_identifier->getIdentifier()));
88  $export_dir = ilExport::_getExportDirectory(
89  $object_id,
90  "",
91  $type
92  );
93  $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
94  $file[1] = basename($file[1]);
96  $export_dir . "/" . $file[1],
97  $file[1]
98  );
99  }
100 
101  public function onDeleteFiles(
102  ilExportHandlerConsumerContextInterface $context,
103  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
104  ): void {
105  foreach ($file_identifiers as $file_identifier) {
106  $file = explode(":", $file_identifier->getIdentifier());
107  $file[1] = basename($file[1]);
108  $export_dir = ilExport::_getExportDirectory(
109  $context->exportObject()->getId(),
110  "",
111  $context->exportObject()->getType()
112  );
113  $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
114  $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]);
115  $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4);
116  if (is_file($exp_file)) {
117  unlink($exp_file);
118  }
119  if (
120  is_dir($exp_dir) and
121  count(scandir($exp_dir)) === 2
122  ) {
123  ilFileUtils::delDir($exp_dir);
124  }
125  }
126  }
127 
128  public function getFiles(
129  ilExportHandlerConsumerContextInterface $context
130  ): ilExportHandlerFileInfoCollectionInterface {
131  # The export files of ilMediaPoolExportOptionXMLMaster and ilMediaPoolExportOptionXMLMasterNoMedia
132  # cannot be differentiated, therefore only ilMediaPoolExportOptionXMLMaster returns files.
133  return $context->fileCollectionBuilder()->collection();
134  }
135 
136  public function isObjectSupported(ObjectId $object_id): bool
137  {
138  $ot = ilObjectTranslation::getInstance($object_id->toInt());
139  return $ot->getContentActivated();
140  }
141 
142  public function onExportOptionSelected(ilExportHandlerConsumerContextInterface $context): void
143  {
144  if ($this->isObjectSupported(new ObjectId($context->exportObject()->getId()))) {
145  $opt = ilUtil::stripSlashes("masternomedia");
146  $context->exportObject()->exportXML($opt);
147  }
148  $this->ctrl->redirectByClass(ilExportGUI::class, ilExportGUI::CMD_LIST_EXPORT_FILES);
149  }
150 }
$context
Definition: webdav.php:31
onDownloadFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onExportOptionSelected(ilExportHandlerConsumerContextInterface $context)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
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
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)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
onDeleteFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
static getInstance(int $obj_id)
global $DIC
Definition: shib_login.php:22
language()
Get interface to the i18n service.
Definition: Container.php:95
const CMD_LIST_EXPORT_FILES
static _lookupType(int $id, bool $reference=false)
getFiles(ilExportHandlerConsumerContextInterface $context)