67 if (!isset(self::$instance)) {
71 return self::$instance;
76 $this->valueHashToValueContainerId = new \SplObjectStorage();
77 $this->bucketHashToObserverContainerId = new \SplObjectStorage();
78 $this->taskHashToTaskContainerId = new \SplObjectStorage();
81 protected function gc() : void
83 $this->db->manipulateF(
84 "DELETE FROM il_bt_bucket WHERE user_id = %s AND (state = %s OR state = %s)",
85 [
'integer',
'integer',
'integer'],
92 $this->connector =
$c;
119 $bucketContainer->setUserId($bucket->
getUserId());
120 $bucketContainer->setState($bucket->
getState());
121 $bucketContainer->setTotalNumberoftasks(count($bucket->
getTask()->unfoldTask()));
123 $bucketContainer->setTitle($bucket->
getTitle());
130 $bucketContainer->update();
143 ->orderBy($order_by, $order_direction)
144 ->getArray(null,
'id');
159 $bucketMeta->setUserId($bucketContainer->
getUserId());
160 $bucketMeta->setState($bucketContainer->
getState());
161 $bucketMeta->setTitle($bucketContainer->
getTitle());
163 $bucketMeta->setOverallPercentage($bucketContainer->
getPercentage());
179 return $bucket_container->
getId();
195 if ($this->bucketHashToObserverContainerId->contains($bucket)) {
196 $bucketContainer =
new BucketContainer($this->bucketHashToObserverContainerId[$bucket], $this->connector);
202 $bucketContainer->setUserId($bucket->
getUserId());
203 $bucketContainer->setState($bucket->
getState());
204 $bucketContainer->setTitle($bucket->
getTitle());
206 $bucketContainer->setTotalNumberoftasks(count($bucket->
getTask()->unfoldTask()));
210 if (!$bucketContainer->getId()) {
211 $bucketContainer->create();
223 $bucketContainer->save();
224 $this->bucketHashToObserverContainerId[$bucket] = $bucketContainer->getId();
238 if ($this->taskHashToTaskContainerId->contains($task)) {
239 $taskContainer =
new TaskContainer($this->taskHashToTaskContainerId[$task], $this->connector);
245 $taskContainer->setType($task->
getType());
246 $taskContainer->setBucketId($bucketId);
247 $reflection = new \ReflectionClass(get_class($task));
248 $taskContainer->setClassName(get_class($task));
250 $absolute_class_path = $reflection->getFileName();
252 $taskContainer->setClassPath($reflection->getFileName());
255 foreach ($task->
getInput() as $k => $input) {
258 $this->saveValueToTask($task, $taskContainer, $bucketId);
261 $taskContainer->save();
262 $this->taskHashToTaskContainerId[$task] = $taskContainer->getId();
274 protected function saveValueToTask(
Task $task,
TaskContainer $taskContainer, $bucketId)
277 if ($taskContainer->
getId()) {
280 foreach ($olds as $old) {
285 $taskContainer->
save();
289 foreach ($task->
getInput() as $k => $inputValue) {
291 $v->setTaskId($taskContainer->
getId());
293 $v->setBucketId($bucketId);
310 if ($this->valueHashToValueContainerId->contains($value)) {
311 $valueContainer =
new ValueContainer($this->valueHashToValueContainerId[$value], $this->connector);
317 $reflection = new \ReflectionClass(get_class($value));
318 $valueContainer->setClassName(get_class($value));
323 $valueContainer->setType($value->
getType());
325 $valueContainer->setBucketId($bucketId);
326 $valueContainer->setPosition($position);
327 $valueContainer->setHash($value->
getHash());
328 $valueContainer->setSerialized($value->serialize());
337 $valueContainer->save();
338 $this->valueHashToValueContainerId->attach($value, $valueContainer->getId());
350 if (!$this->bucketHashToObserverContainerId->contains(($bucket))) {
352 . print_r($bucket,
true));
355 return $this->bucketHashToObserverContainerId[$bucket];
367 if (!$this->taskHashToTaskContainerId->contains($task)) {
369 . print_r($task,
true));
372 return $this->taskHashToTaskContainerId[$task];
384 if (!$this->valueHashToValueContainerId->contains($value)) {
386 . print_r($value,
true));
389 return (
int) $this->valueHashToValueContainerId[$value];
401 if (isset(self::$buckets[$bucket_id])) {
402 return self::$buckets[$bucket_id];
405 $bucketContainer = BucketContainer::find($bucket_id);
406 if (!$bucketContainer) {
407 throw new BucketNotFoundException(
"The requested bucket with container id $bucket_id could not be found in the database.");
411 $bucket->setUserId($bucketContainer->getUserId());
412 $bucket->setState($bucketContainer->getState());
413 $bucket->setTitle($bucketContainer->getTitle());
414 $bucket->setDescription($bucketContainer->getDescription());
415 $bucket->setOverallPercentage($bucketContainer->getPercentage());
416 $bucket->setLastHeartbeat($bucketContainer->getLastHeartbeat());
417 $bucket->setTask($this->loadTask($bucketContainer->getRootTaskid(), $bucket, $bucketContainer));
419 $this->bucketHashToObserverContainerId[$bucket] = $bucket_id;
439 $factory = $DIC->backgroundTasks()->taskFactory();
441 $taskContainer = TaskContainer::find($taskContainerId);
452 ->orderBy(
'position')
456 foreach ($valueToTasks as $valueToTask) {
457 $inputs[] = $this->loadValue($valueToTask->getValueId(), $bucket, $bucketContainer);
465 $this->taskHashToTaskContainerId[$task] = $taskContainerId;
474 $factory = $DIC->backgroundTasks()->injector();
477 $valueContainer = ValueContainer::find($valueContainerId);
481 $value =
$factory->createInstance($valueContainer->getClassName());
483 $value->unserialize($valueContainer->getSerialized());
484 if ($valueContainer->getHasParenttask()) {
485 $value->setParentTask($this->loadTask($valueContainer->getParentTaskid(), $bucket, $bucketContainer));
488 $this->valueHashToValueContainerId[$value] = $valueContainerId;
530 $this->bucketHashToObserverContainerId->detach($bucket);
542 foreach ($bucket_container_id as $bucket_id) {
saveObserver(Bucket $bucket)
static instance(\ilDBInterface $db)
saveValue(Value $value, $bucketId, $position)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getValueContainerId($value)
Class ChatMainBarProvider .
setConnector(\arConnector $c)
deleteBucket($bucket)
Delete the bucket and all its stuff.Bucketvoid
static where($where, $operator=null)
getBucketContainerId(Bucket $bucket)
$bucketHashToObserverContainerId
$valueHashToValueContainerId
getBucketMetaOfUser($user_id)
updateBucket(Bucket $bucket)
Updates only the bucket! Use this if e.g.
getLastHeartbeat()
When was the last time that something happened on this bucket?
saveBucketAndItsTasks(Bucket $bucket)
Fully updates or creates an Observer and all its tasks into the database.
$taskHashToTaskContainerId
getBucketIdsByState($state)
intint[] Returns a list of bucket ids for the given Observer State
saveTask(Task $task, $bucketId)
getTaskContainerId(Task $task)
deleteBucketById($bucket_id)
Deletes the Observer AND all its tasks and values.
getBucketIdsOfUser($user_id, $order_by="id", $order_direction="ASC")
[] Returns an array of bucket ids for the given user Id.
loadBucket($bucket_container_id)
loadBuckets($bucket_container_id)
__construct(\ilDBInterface $db)