ILIAS  release_7 Revision v7.30-3-g800a261c036
ilDownloadFilesBackgroundTask Class Reference

Description of class class. More...

+ Collaboration diagram for ilDownloadFilesBackgroundTask:

Public Member Functions

 __construct ($a_usr_id)
 Constructor. More...
 
 setEvents (array $a_events)
 Set events. More...
 
 getEvents ()
 Get events. More...
 
 setBucketTitle ($a_title)
 set bucket title. More...
 
 getBucketTitle ()
 return bucket title. More...
 
 run ()
 Run task. More...
 

Protected Attributes

 $user_id
 
 $user = null
 
 $task_factory = null
 
 $bucket_title
 
 $has_files = false
 

Private Member Functions

 collectFiles (ilCalendarCopyDefinition $def)
 Collect files. More...
 

Private Attributes

 $logger = null
 
 $events = []
 Array of calendar event. More...
 

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 14 of file class.ilDownloadFilesBackgroundTask.php.

Constructor & Destructor Documentation

◆ __construct()

ilDownloadFilesBackgroundTask::__construct (   $a_usr_id)

Constructor.

Parameters
type$a_usr_id

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

59 {
60 global $DIC;
61 $this->logger = $DIC->logger()->cal();
62 $this->user_id = $a_usr_id;
63 $this->task_factory = $DIC->backgroundTasks()->taskFactory();
64 $this->lng = $DIC->language();
65
66 $this->user = \ilObjectFactory::getInstanceByObjId($a_usr_id, false);
67 }
user()
Definition: user.php:4
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
global $DIC
Definition: goto.php:24

References $DIC, ilObjectFactory\getInstanceByObjId(), and user().

+ Here is the call graph for this function:

Member Function Documentation

◆ collectFiles()

ilDownloadFilesBackgroundTask::collectFiles ( ilCalendarCopyDefinition  $def)
private

Collect files.

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

157 {
158 //filter here the objects, don't repeat the object Id
159 $object_ids = [];
160 foreach ($this->getEvents() as $event) {
161 $start = new ilDateTime($event['dstart'], IL_CAL_UNIX);
162 $cat = ilCalendarCategory::getInstanceByCategoryId($event['category_id']);
163 $obj_id = $cat->getObjId();
164
165 $this->logger->debug('Handling event: ' . $event['event']->getPresentationTitle());
166 //22295 If the object type is exc then we need all the assignments.Otherwise we will get only one.
167 if (
168 $cat->getType() != \ilCalendarCategory::TYPE_OBJ ||
169 $cat->getObjType() == 'exc' ||
170 !in_array($obj_id, $object_ids)
171 ) {
172
173 $this->logger->debug('New obj_id..');
174 $object_ids[] = $obj_id;
175
176 $folder_date = $start->get(IL_CAL_FKT_DATE, 'Y-m-d', $this->user->getTimeZone());
177
178
179 if ($event['fullday']) {
180 $folder_app = ilUtil::getASCIIFilename($event['event']->getPresentationTitle(false)); //title formalized
181 } else {
182 $start_time = $start->get(IL_CAL_FKT_DATE, 'H.i', $this->user->getTimeZone());
183
184 $end = new ilDateTime($event['dend'], IL_CAL_UNIX);
185 $end_time = $end->get(IL_CAL_FKT_DATE, 'H.i', $this->user->getTimeZone());
186
187 if ($start_time != $end_time) {
188 $start_time .= (' - ' . $end_time);
189 }
190 $folder_app = $start_time . ' ' .
191 ilUtil::getASCIIFilename($event['event']->getPresentationTitle(false)); //title formalized
192 }
193
194 $this->logger->debug("collecting files...event title = " . $folder_app);
195 $file_handler = ilAppointmentFileHandlerFactory::getInstance($event);
196 $this->logger->debug('Current file handler: ' . get_class($file_handler));
197
198 if ($files = $file_handler->getFiles()) {
199 $this->has_files = true;
200 }
201
202 $this->logger->dump($files);
203 foreach ($files as $idx => $file_property) {
204 $this->logger->debug('Filename:' . $file_property->getFileName());
205 $this->logger->debug('Absolute path: ' . $file_property->getAbsolutePath());
206
207 $def->addCopyDefinition(
208 $file_property->getAbsolutePath(),
209 $folder_date . '/' . $folder_app . '/' . $file_property->getFileName()
210 );
211 $this->logger->debug('Added new copy definition: ' .
212 $folder_date . '/' . $folder_app . '/' . $file_property->getFileName() . ' => ' .
213 $file_property->getAbsolutePath()
214 );
215 }
216 }
217 else {
218 $this->logger->info('Ignoring obj_id: ' . $obj_id . ' already processed.');
219 }
220 }
221 }
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
addCopyDefinition($a_source, $a_target)
Add copy definition.
@classDescription Date and time handling
static getASCIIFilename($a_filename)
convert utf8 to ascii filename

References ilCalendarCopyDefinition\addCopyDefinition(), ilUtil\getASCIIFilename(), getEvents(), ilAppointmentFileHandlerFactory\getInstance(), ilCalendarCategory\getInstanceByCategoryId(), IL_CAL_FKT_DATE, IL_CAL_UNIX, ilCalendarCategory\TYPE_OBJ, and user().

Referenced by run().

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

◆ getBucketTitle()

ilDownloadFilesBackgroundTask::getBucketTitle ( )

return bucket title.

Returns
string

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

101 {
102 //TODO: fix ilUtil zip stuff
103 // Error If name starts "-"
104 // error massage from ilUtil->execQuoted = ["","zip error: Invalid command arguments (short option 'a' not supported)"]
105 if (substr($this->bucket_title, 0, 1) === "-") {
106 $this->bucket_title = ltrim($this->bucket_title, "-");
107 }
108
109 return $this->bucket_title;
110 }

References $bucket_title.

Referenced by run().

+ Here is the caller graph for this function:

◆ getEvents()

ilDownloadFilesBackgroundTask::getEvents ( )

Get events.

Returns
type

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

83 {
84 return $this->events;
85 }

References $events.

Referenced by collectFiles().

+ Here is the caller graph for this function:

◆ run()

ilDownloadFilesBackgroundTask::run ( )

Run task.

Returns
bool

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

117 {
118 $definition = new ilCalendarCopyDefinition();
119 $normalized_name = ilUtil::getASCIIFilename($this->getBucketTitle());
120 $definition->setTempDir($normalized_name);
121
122 $this->collectFiles($definition);
123
124 if (!$this->has_files) {
125 ilUtil::sendInfo($this->lng->txt("cal_down_no_files"), true);
126 return false;
127 }
128
129 $bucket = new BasicBucket();
130 $bucket->setUserId($this->user_id);
131
132 // move files from source dir to target directory
133 $copy_job = $this->task_factory->createTask(ilCalendarCopyFilesToTempDirectoryJob::class, [$definition]);
134 $zip_job = $this->task_factory->createTask(ilCalendarZipJob::class, [$copy_job]);
135
136 $download_name = new StringValue();
137
138 $this->logger->debug("Normalized name = " . $normalized_name);
139 $download_name->setValue($normalized_name . '.zip');
140
141 $download_interaction = $this->task_factory->createTask(ilCalendarDownloadZipInteraction::class, [$zip_job, $download_name]);
142
143 // last task to bucket
144 $bucket->setTask($download_interaction);
145
146 $bucket->setTitle($this->getBucketTitle());
147
148 $task_manager = $GLOBALS['DIC']->backgroundTasks()->taskManager();
149 $task_manager->run($bucket);
150 return true;
151 }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
collectFiles(ilCalendarCopyDefinition $def)
Collect files.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

References $GLOBALS, collectFiles(), ilUtil\getASCIIFilename(), getBucketTitle(), and ilUtil\sendInfo().

+ Here is the call graph for this function:

◆ setBucketTitle()

ilDownloadFilesBackgroundTask::setBucketTitle (   $a_title)

set bucket title.

Parameters
$a_title

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

92 {
93 $this->bucket_title = $a_title;
94 }

◆ setEvents()

ilDownloadFilesBackgroundTask::setEvents ( array  $a_events)

Set events.

Parameters
array$a_events

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

74 {
75 $this->events = $a_events;
76 }

Field Documentation

◆ $bucket_title

ilDownloadFilesBackgroundTask::$bucket_title
protected

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

Referenced by getBucketTitle().

◆ $events

ilDownloadFilesBackgroundTask::$events = []
private

Array of calendar event.

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

Referenced by getEvents().

◆ $has_files

ilDownloadFilesBackgroundTask::$has_files = false
protected

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

◆ $logger

ilDownloadFilesBackgroundTask::$logger = null
private

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

◆ $task_factory

ilDownloadFilesBackgroundTask::$task_factory = null
protected

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

◆ $user

ilDownloadFilesBackgroundTask::$user = null
protected

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

◆ $user_id

ilDownloadFilesBackgroundTask::$user_id
protected

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


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