ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 (ilCalendarCopyDefinition $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 15 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 33 of file class.ilDownloadFilesBackgroundTask.php.

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

34  {
35  global $DIC;
36  $this->main_tpl = $DIC->ui()->mainTemplate();
37 
38  $this->logger = $DIC->logger()->cal();
39  $this->user_id = $a_usr_id;
40  $this->task_factory = $DIC->backgroundTasks()->taskFactory();
41  $this->lng = $DIC->language();
42 
43  $user = ilObjectFactory::getInstanceByObjId($a_usr_id, false);
44  if (!$user instanceof ilObjUser) {
45  throw new DomainException('Invalid or deleted user id given: ' . $this->user_id);
46  }
47  $this->user = $user;
48  }
global $DIC
Definition: feed.php:28
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:

Member Function Documentation

◆ collectFiles()

ilDownloadFilesBackgroundTask::collectFiles ( ilCalendarCopyDefinition  $def)
private

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

References ilCalendarCopyDefinition\addCopyDefinition(), 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().

120  : void
121  {
122  //filter here the objects, don't repeat the object Id
123  $object_ids = [];
124  foreach ($this->getEvents() as $event) {
125  $start = new ilDateTime($event['dstart'], IL_CAL_UNIX);
126  $cat = ilCalendarCategory::getInstanceByCategoryId($event['category_id']);
127  $obj_id = $cat->getObjId();
128 
129  $this->logger->debug('Handling event: ' . $event['event']->getPresentationTitle());
130  //22295 If the object type is exc then we need all the assignments.Otherwise we will get only one.
131  if (
132  $cat->getType() != \ilCalendarCategory::TYPE_OBJ ||
133  $cat->getObjType() == 'exc' ||
134  !in_array($obj_id, $object_ids)
135  ) {
136  $this->logger->debug('New obj_id..');
137  $object_ids[] = $obj_id;
138 
139  $folder_date = $start->get(IL_CAL_FKT_DATE, 'Y-m-d', $this->user->getTimeZone());
140 
141  if ($event['fullday']) {
142  $folder_app = ilFileUtils::getASCIIFilename($event['event']->getPresentationTitle(false)); //title formalized
143  } else {
144  $start_time = $start->get(IL_CAL_FKT_DATE, 'H.i', $this->user->getTimeZone());
145 
146  $end = new ilDateTime($event['dend'], IL_CAL_UNIX);
147  $end_time = $end->get(IL_CAL_FKT_DATE, 'H.i', $this->user->getTimeZone());
148 
149  if ($start_time != $end_time) {
150  $start_time .= (' - ' . $end_time);
151  }
152  $folder_app = $start_time . ' ' .
153  ilFileUtils::getASCIIFilename($event['event']->getPresentationTitle(false)); //title formalized
154  }
155 
156  $this->logger->debug("collecting files...event title = " . $folder_app);
157  $file_handler = ilAppointmentFileHandlerFactory::getInstance($event);
158  $this->logger->debug('Current file handler: ' . get_class($file_handler));
159 
160  if ($files = $file_handler->getFiles()) {
161  $this->has_files = true;
162  }
163 
164  $this->logger->dump($files);
165  foreach ($files as $idx => $file_property) {
166  $this->logger->debug('Filename:' . $file_property->getFileName());
167  $this->logger->debug('Absolute path: ' . $file_property->getAbsolutePath());
168 
169  $def->addCopyDefinition(
170  $file_property->getAbsolutePath(),
171  $folder_date . '/' . $folder_app . '/' . $file_property->getFileName()
172  );
173  $this->logger->debug(
174  'Added new copy definition: ' .
175  $folder_date . '/' . $folder_app . '/' . $file_property->getFileName() . ' => ' .
176  $file_property->getAbsolutePath()
177  );
178  }
179  } else {
180  $this->logger->info('Ignoring obj_id: ' . $obj_id . ' already processed.');
181  }
182  }
183  }
const IL_CAL_UNIX
static getASCIIFilename(string $a_filename)
addCopyDefinition(string $a_source, string $a_target)
Add copy definition.
const IL_CAL_FKT_DATE
static getInstanceByCategoryId(int $a_cat_id)
+ 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 69 of file class.ilDownloadFilesBackgroundTask.php.

References $bucket_title.

Referenced by run().

69  : string
70  {
71  //TODO: fix ilUtil zip stuff
72  // Error If name starts "-"
73  // error massage from ilUtil->execQuoted = ["","zip error: Invalid command arguments (short option 'a' not supported)"]
74  if (substr($this->bucket_title, 0, 1) === "-") {
75  $this->bucket_title = ltrim($this->bucket_title, "-");
76  }
77  return $this->bucket_title;
78  }
+ Here is the caller graph for this function:

◆ getEvents()

ilDownloadFilesBackgroundTask::getEvents ( )

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

References $events.

Referenced by collectFiles().

55  : array
56  {
57  return $this->events;
58  }
+ Here is the caller graph for this function:

◆ run()

ilDownloadFilesBackgroundTask::run ( )

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

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

80  : bool
81  {
82  $definition = new ilCalendarCopyDefinition();
83  $normalized_name = ilFileUtils::getASCIIFilename($this->getBucketTitle());
84  $definition->setTempDir($normalized_name);
85 
86  $this->collectFiles($definition);
87 
88  if (!$this->has_files) {
89  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("cal_down_no_files"), true);
90  return false;
91  }
92 
93  $bucket = new BasicBucket();
94  $bucket->setUserId($this->user_id);
95 
96  // move files from source dir to target directory
97  $copy_job = $this->task_factory->createTask(ilCalendarCopyFilesToTempDirectoryJob::class, [$definition]);
98  $zip_job = $this->task_factory->createTask(ilCalendarZipJob::class, [$copy_job]);
99 
100  $download_name = new StringValue();
101 
102  $this->logger->debug("Normalized name = " . $normalized_name);
103  $download_name->setValue($normalized_name . '.zip');
104 
105  $download_interaction = $this->task_factory->createTask(
106  ilCalendarDownloadZipInteraction::class,
107  [$zip_job, $download_name]
108  );
109 
110  // last task to bucket
111  $bucket->setTask($download_interaction);
112 
113  $bucket->setTitle($this->getBucketTitle());
114 
115  $task_manager = $GLOBALS['DIC']->backgroundTasks()->taskManager();
116  $task_manager->run($bucket);
117  return true;
118  }
static getASCIIFilename(string $a_filename)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
+ Here is the call graph for this function:

◆ setBucketTitle()

ilDownloadFilesBackgroundTask::setBucketTitle ( string  $a_title)

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

Referenced by ilCalendarViewGUI\downloadFiles(), and ilAppointmentPresentationGUI\downloadFiles().

60  : void
61  {
62  $this->bucket_title = $a_title;
63  }
+ Here is the caller graph for this function:

◆ setEvents()

ilDownloadFilesBackgroundTask::setEvents ( array  $a_events)

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

50  : void
51  {
52  $this->events = $a_events;
53  }

Field Documentation

◆ $bucket_title

string ilDownloadFilesBackgroundTask::$bucket_title
private

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

Referenced by getBucketTitle().

◆ $events

array ilDownloadFilesBackgroundTask::$events = []
private

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

Referenced by getEvents().

◆ $has_files

bool ilDownloadFilesBackgroundTask::$has_files = false
private

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

◆ $lng

ilLanguage ilDownloadFilesBackgroundTask::$lng
protected

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

◆ $logger

ilLogger ilDownloadFilesBackgroundTask::$logger
private

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

◆ $main_tpl

ilGlobalTemplateInterface ilDownloadFilesBackgroundTask::$main_tpl
private

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

◆ $task_factory

TaskFactory ilDownloadFilesBackgroundTask::$task_factory
protected

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

◆ $user

ilObjUser ilDownloadFilesBackgroundTask::$user
protected

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

Referenced by __construct().

◆ $user_id

int ilDownloadFilesBackgroundTask::$user_id
private

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


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