ILIAS  trunk Revision v12.0_alpha-399-g579a087ced2
NewsAggregator.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use SplQueue;
25
31{
33 protected array $strategies = [];
34 protected \ilTree $tree;
35
36 public function __construct()
37 {
38 global $DIC;
39
40 $this->tree = $DIC->repositoryTree();
41 $this->initializeStrategies();
42 }
43
48 public function aggregate(array $contexts): array
49 {
51 $frontier = new SplQueue();
52 $result = [];
53
54 // Prepare queue
55 foreach ($contexts as $context) {
56 $frontier->enqueue($context);
57 }
58
59 while (!$frontier->isEmpty()) {
60 $current = $frontier->dequeue();
61
62 // Ensure each context is only visited once
63 if (array_key_exists($current->getRefId(), $result)) {
64 continue;
65 }
66 $result[$current->getRefId()] = $current;
67
68 // Skip if no processing necessary
69 $strategy = $this->getStrategy($current->getObjType());
70 if ($strategy === null || $strategy->shouldSkip($current)) {
71 continue;
72 }
73
74 $children = $strategy->aggregate($current);
75 foreach ($children as $child) {
76 if ($strategy->isRecursive()) {
77 // Recursive items will be added directly
78 $result[$child->getRefId()] = $child;
79 } else {
80 // Iterative items will be queued for further processing
81 $frontier->enqueue($child);
82 }
83 }
84 }
85
86 return array_values($result);
87 }
88
89 protected function getStrategy(string $object_type): ?NewsAggregationStrategy
90 {
91 return $this->strategies[$object_type] ?? null;
92 }
93
94 protected function initializeStrategies(): void
95 {
96 $subtree_strategy = new SubtreeAggregationStrategy($this->tree);
97
98 $this->strategies['cat'] = new CategoryAggregationStrategy($this->tree);
99 $this->strategies['crs'] = $subtree_strategy;
100 $this->strategies['grp'] = $subtree_strategy;
101 }
102}
Category Aggregation Strategy aggregates related contexts for a category context.
News Aggregator aggregates related contexts for a news context using a layer-wise Batching BFS to agg...
Subtree Aggregation Strategy aggregates related contexts for groups and courses.
News Context DTO represents a context where news items can be associated with.
Definition: NewsContext.php:29
News Aggregation Strategy Interface defines the contract for news aggregation strategies.
global $DIC
Definition: shib_login.php:26
$context
Definition: webdav.php:31