ILIAS  release_8 Revision v8.24
class.ilObjFileAbstractProcessor.php
Go to the documentation of this file.
1<?php
2
22
29{
33 protected Services $storage;
36 protected array $invalid_file_names = [];
37
38 public function __construct(
43 ) {
44 $this->storage = $storage;
45 $this->stakeholder = $stakeholder;
46 $this->gui_object = $gui_object;
47 $this->page_counter = new ilCountPDFPages();
48 $this->settings = $settings;
49 $this->policy = new ilFileServicesPolicy($this->settings);
50 }
51
56 protected function createFileObj(
58 int $parent_id,
59 array $options = [],
60 bool $create_reference = false
61 ): ilObjFile {
62 $revision = $this->storage->manage()->getCurrentRevision($rid);
63 $file_obj = new ilObjFile();
64 $file_obj->setResourceId($rid);
65 if ($this->page_counter->isAvailable()) {
66 $file_obj->setPageCount($this->page_counter->extractAmountOfPagesByRID($rid) ?? 0);
67 }
68
69 $file_name = $revision->getInformation()->getTitle();
70 $title = $file_obj->appendSuffixToTitle(
71 empty($options[self::OPTION_FILENAME]) ? $file_name : $options[self::OPTION_FILENAME],
72 $file_name
73 );
74
75 $revision->setTitle($title);
76 $this->storage->manage()->updateRevision($revision);
77
78 if (!$this->policy->isValidExtension($revision->getInformation()->getSuffix())) {
79 $this->invalid_file_names[] = $title;
80 }
81 $file_obj->setTitle($title);
82 $file_obj->setFileName($title);
83 $file_obj->setVersion($revision->getVersionNumber());
84
85 if (!empty($options)) {
86 $this->applyOptions($file_obj, $options);
87 }
88
89 $file_obj->create();
90
91 ilPreview::createPreview($file_obj, true);
92 if ($create_reference) {
93 $file_obj->createReference();
94 }
95
96 $file_obj->processAutoRating();
97 $this->gui_object->putObjectInTree($file_obj, $parent_id);
98
99 return $file_obj;
100 }
101
105 protected function applyOptions(ilObject $obj, array $options): void
106 {
107 foreach ($options as $key => $option) {
108 if (in_array($key, self::OPTIONS, true)) {
109 if (!empty($option)) {
110 $setter = "set" . ucfirst($key);
111 $obj->{$setter}($option);
112 }
113 } else {
114 throw new LogicException("Option '$key' is not declared in " . static::class . "::OPTIONS.");
115 }
116 }
117 }
118
119 public function getInvalidFileNames(): array
120 {
121 return $this->invalid_file_names;
122 }
123}
Class ilCountPDFPages.
Class ilFileServicesPolicy.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFileAbstractProcessorInterface.
applyOptions(ilObject $obj, array $options)
Apply provided options to the given object.
__construct(ResourceStakeholder $stakeholder, ilObjFileGUI $gui_object, Services $storage, ilFileServicesSettings $settings)
createFileObj(ResourceIdentification $rid, int $parent_id, array $options=[], bool $create_reference=false)
Creates an ilObjFile instance for the provided information.
GUI class for file objects.
Class ilObjFile.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static createPreview(\ilObject $a_obj, bool $a_force=false)
Creates the preview for the object with the specified id.
string $key
Consumer key/client ID value.
Definition: System.php:193