ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilDownloadFilesBackgroundTask Class Reference

Description of class class. More...

+ Collaboration diagram for ilDownloadFilesBackgroundTask:

Public Member Functions

 __construct ($a_usr_id)
 ilDownloadFilesBackgroundTask constructor. More...
 
 setEvents (array $a_events)
 
 getEvents ()
 
 setBucketTitle (string $a_title)
 
 getBucketTitle ()
 
 run ()
 

Protected Attributes

ilLanguage $lng
 
ilObjUser $user
 
TaskFactory $task_factory
 

Private Member Functions

 collectFiles (ilCalendarRessourceStorageCopyDefinition $def)
 

Private Attributes

ilLogger $logger
 
int $user_id
 
array $events = []
 
string $bucket_title
 
bool $has_files = false
 
ilGlobalTemplateInterface $main_tpl
 

Detailed Description

Description of class class.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 29 of file class.ilDownloadFilesBackgroundTask.php.

Constructor & Destructor Documentation

◆ __construct()

ilDownloadFilesBackgroundTask::__construct (   $a_usr_id)

ilDownloadFilesBackgroundTask constructor.

Parameters
$a_usr_id
Exceptions
ilDatabaseException| DomainException

Definition at line 47 of file class.ilDownloadFilesBackgroundTask.php.

48 {
49 global $DIC;
50 $this->main_tpl = $DIC->ui()->mainTemplate();
51
52 $this->logger = $DIC->logger()->cal();
53 $this->user_id = $a_usr_id;
54 $this->task_factory = $DIC->backgroundTasks()->taskFactory();
55 $this->lng = $DIC->language();
56
58 if (!$user instanceof ilObjUser) {
59 throw new DomainException('Invalid or deleted user id given: ' . $this->user_id);
60 }
61 $this->user = $user;
62 }
User class.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
global $DIC
Definition: shib_login.php:26

References $DIC, $user, ilObjectFactory\getInstanceByObjId(), ILIAS\Repository\lng(), ILIAS\Repository\logger(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ collectFiles()

ilDownloadFilesBackgroundTask::collectFiles ( ilCalendarRessourceStorageCopyDefinition  $def)
private

Definition at line 134 of file class.ilDownloadFilesBackgroundTask.php.

134 : void
135 {
136 //filter here the objects, don't repeat the object Id
137 $object_ids = [];
138 foreach ($this->getEvents() as $event) {
139 $start = new ilDateTime($event['dstart'], IL_CAL_UNIX);
140 $cat = ilCalendarCategory::getInstanceByCategoryId($event['category_id']);
141 $obj_id = $cat->getObjId();
142
143 $this->logger->debug('Handling event: ' . $event['event']->getPresentationTitle());
144 //22295 If the object type is exc then we need all the assignments.Otherwise we will get only one.
145 if (
146 $cat->getType() != \ilCalendarCategory::TYPE_OBJ ||
147 $cat->getObjType() == 'exc' ||
148 !in_array($obj_id, $object_ids)
149 ) {
150 $this->logger->debug('New obj_id..');
151 $object_ids[] = $obj_id;
152
153 $folder_date = $start->get(IL_CAL_FKT_DATE, 'Y-m-d', $this->user->getTimeZone());
154
155 if ($event['fullday']) {
156 $folder_app = ilFileUtils::getASCIIFilename($event['event']->getPresentationTitle(false)); //title formalized
157 } else {
158 $start_time = $start->get(IL_CAL_FKT_DATE, 'H.i', $this->user->getTimeZone());
159
160 $end = new ilDateTime($event['dend'], IL_CAL_UNIX);
161 $end_time = $end->get(IL_CAL_FKT_DATE, 'H.i', $this->user->getTimeZone());
162
163 if ($start_time != $end_time) {
164 $start_time .= (' - ' . $end_time);
165 }
166 $folder_app = $start_time . ' ' .
167 ilFileUtils::getASCIIFilename($event['event']->getPresentationTitle(false)); //title formalized
168 }
169
170 $this->logger->debug("collecting files...event title = " . $folder_app);
171 $file_handler = ilAppointmentFileHandlerFactory::getInstance($event);
172 $this->logger->debug('Current file handler: ' . get_class($file_handler));
173
174 if ($files = $file_handler->getFiles()) {
175 $this->has_files = true;
176 }
177
178 $this->logger->dump($files);
179 foreach ($files as $idx => $file_property) {
180 $this->logger->debug('Filename:' . $file_property->getFileName());
181 $ressource = '';
182 $target = $folder_date . '/' . $folder_app . '/' . $file_property->getFileName();
183 if (!is_null($file_property->getFileRId())) {
184 $this->logger->debug('Ressource Id: ' . $file_property->getFileRId());
185 $ressource = $file_property->getFileRId();
186 $def->addCopyDefinitionRId($file_property->getFileRId(), $target);
187 } else {
188 $this->logger->debug('Absolute Path: ' . $file_property->getAbsolutePath());
189 $ressource = $file_property->getAbsolutePath();
190 $def->addCopyDefinition($file_property->getAbsolutePath(), $target);
191 }
192 $this->logger->debug(
193 'Added new copy definition: ' .
194 $folder_date . '/' . $folder_app . '/' . $file_property->getFileName() . ' => ' .
195 $ressource
196 );
197 }
198 } else {
199 $this->logger->info('Ignoring obj_id: ' . $obj_id . ' already processed.');
200 }
201 }
202 }
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
static getInstanceByCategoryId(int $a_cat_id)
addCopyDefinition(string $a_path, string $a_target)
Add copy definition.
@classDescription Date and time handling
static getASCIIFilename(string $a_filename)

References ilCalendarRessourceStorageCopyDefinition\addCopyDefinition(), ilCalendarRessourceStorageCopyDefinition\addCopyDefinitionRId(), ilFileUtils\getASCIIFilename(), getEvents(), ilAppointmentFileHandlerFactory\getInstance(), ilCalendarCategory\getInstanceByCategoryId(), IL_CAL_FKT_DATE, IL_CAL_UNIX, ILIAS\Repository\logger(), ilCalendarCategory\TYPE_OBJ, and ILIAS\Repository\user().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBucketTitle()

ilDownloadFilesBackgroundTask::getBucketTitle ( )
Returns
string
Todo:
see comments

Definition at line 83 of file class.ilDownloadFilesBackgroundTask.php.

83 : string
84 {
85 //TODO: fix ilUtil zip stuff
86 // Error If name starts "-"
87 // error massage from ilUtil->execQuoted = ["","zip error: Invalid command arguments (short option 'a' not supported)"]
88 if (substr($this->bucket_title, 0, 1) === "-") {
89 $this->bucket_title = ltrim($this->bucket_title, "-");
90 }
92 }

References $bucket_title.

Referenced by run().

+ Here is the caller graph for this function:

◆ getEvents()

ilDownloadFilesBackgroundTask::getEvents ( )

Definition at line 69 of file class.ilDownloadFilesBackgroundTask.php.

References $events.

Referenced by collectFiles().

+ Here is the caller graph for this function:

◆ run()

ilDownloadFilesBackgroundTask::run ( )

Definition at line 94 of file class.ilDownloadFilesBackgroundTask.php.

94 : bool
95 {
97 $normalized_name = ilFileUtils::getASCIIFilename($this->getBucketTitle());
98 $definition->setTempDir($normalized_name);
99
100 $this->collectFiles($definition);
101
102 if (!$this->has_files) {
103 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("cal_down_no_files"), true);
104 return false;
105 }
106
107 $bucket = new BasicBucket();
108 $bucket->setUserId($this->user_id);
109
110 // move files from source dir to target directory
111 $copy_job = $this->task_factory->createTask(ilCalendarCopyFilesToTempDirectoryJob::class, [$definition]);
112 $zip_job = $this->task_factory->createTask(ilCalendarZipJob::class, [$copy_job]);
113
114 $download_name = new StringValue();
115
116 $this->logger->debug("Normalized name = " . $normalized_name);
117 $download_name->setValue($normalized_name . '.zip');
118
119 $download_interaction = $this->task_factory->createTask(
120 ilCalendarDownloadZipInteraction::class,
121 [$zip_job, $download_name]
122 );
123
124 // last task to bucket
125 $bucket->setTask($download_interaction);
126
127 $bucket->setTitle($this->getBucketTitle());
128
129 $task_manager = $GLOBALS['DIC']->backgroundTasks()->taskManager();
130 $task_manager->run($bucket);
131 return true;
132 }
collectFiles(ilCalendarRessourceStorageCopyDefinition $def)
$GLOBALS["DIC"]
Definition: wac.php:54

References $GLOBALS, collectFiles(), ilFileUtils\getASCIIFilename(), getBucketTitle(), ILIAS\Repository\lng(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

◆ setBucketTitle()

ilDownloadFilesBackgroundTask::setBucketTitle ( string  $a_title)

Definition at line 74 of file class.ilDownloadFilesBackgroundTask.php.

74 : void
75 {
76 $this->bucket_title = $a_title;
77 }

◆ setEvents()

ilDownloadFilesBackgroundTask::setEvents ( array  $a_events)

Definition at line 64 of file class.ilDownloadFilesBackgroundTask.php.

64 : void
65 {
66 $this->events = $a_events;
67 }

Field Documentation

◆ $bucket_title

string ilDownloadFilesBackgroundTask::$bucket_title
private

Definition at line 38 of file class.ilDownloadFilesBackgroundTask.php.

Referenced by getBucketTitle().

◆ $events

array ilDownloadFilesBackgroundTask::$events = []
private

Definition at line 37 of file class.ilDownloadFilesBackgroundTask.php.

Referenced by getEvents().

◆ $has_files

bool ilDownloadFilesBackgroundTask::$has_files = false
private

Definition at line 39 of file class.ilDownloadFilesBackgroundTask.php.

◆ $lng

ilLanguage ilDownloadFilesBackgroundTask::$lng
protected

Definition at line 32 of file class.ilDownloadFilesBackgroundTask.php.

◆ $logger

ilLogger ilDownloadFilesBackgroundTask::$logger
private

Definition at line 31 of file class.ilDownloadFilesBackgroundTask.php.

◆ $main_tpl

ilGlobalTemplateInterface ilDownloadFilesBackgroundTask::$main_tpl
private

Definition at line 40 of file class.ilDownloadFilesBackgroundTask.php.

◆ $task_factory

TaskFactory ilDownloadFilesBackgroundTask::$task_factory
protected

Definition at line 34 of file class.ilDownloadFilesBackgroundTask.php.

◆ $user

ilObjUser ilDownloadFilesBackgroundTask::$user
protected

Definition at line 33 of file class.ilDownloadFilesBackgroundTask.php.

Referenced by __construct().

◆ $user_id

int ilDownloadFilesBackgroundTask::$user_id
private

Definition at line 36 of file class.ilDownloadFilesBackgroundTask.php.


The documentation for this class was generated from the following file: