ILIAS
trunk Revision v12.0_alpha-399-g579a087ced2
◀ ilDoc Overview
NewsAggregator.php
Go to the documentation of this file.
1
<?php
2
19
declare(strict_types=1);
20
21
namespace
ILIAS\News\Aggregation
;
22
23
use
ILIAS\News\Data\NewsContext
;
24
use SplQueue;
25
30
class
NewsAggregator
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
}
ILIAS\News\Aggregation\CategoryAggregationStrategy
Category Aggregation Strategy aggregates related contexts for a category context.
Definition:
CategoryAggregationStrategy.php:29
ILIAS\News\Aggregation\NewsAggregator
News Aggregator aggregates related contexts for a news context using a layer-wise Batching BFS to agg...
Definition:
NewsAggregator.php:31
ILIAS\News\Aggregation\NewsAggregator\getStrategy
getStrategy(string $object_type)
Definition:
NewsAggregator.php:89
ILIAS\News\Aggregation\NewsAggregator\initializeStrategies
initializeStrategies()
Definition:
NewsAggregator.php:94
ILIAS\News\Aggregation\NewsAggregator\__construct
__construct()
Definition:
NewsAggregator.php:36
ILIAS\News\Aggregation\NewsAggregator\$tree
ilTree $tree
Definition:
NewsAggregator.php:34
ILIAS\News\Aggregation\NewsAggregator\$strategies
array $strategies
Definition:
NewsAggregator.php:33
ILIAS\News\Aggregation\SubtreeAggregationStrategy
Subtree Aggregation Strategy aggregates related contexts for groups and courses.
Definition:
SubtreeAggregationStrategy.php:29
ILIAS\News\Data\NewsContext
News Context DTO represents a context where news items can be associated with.
Definition:
NewsContext.php:29
ILIAS\News\Aggregation\NewsAggregationStrategy
News Aggregation Strategy Interface defines the contract for news aggregation strategies.
Definition:
NewsAggregationStrategy.php:30
ILIAS\News\Aggregation
Definition:
CategoryAggregationStrategy.php:21
$DIC
global $DIC
Definition:
shib_login.php:26
$context
$context
Definition:
webdav.php:31
components
ILIAS
News
src
Aggregation
NewsAggregator.php
Generated on Mon Dec 15 2025 23:02:48 for ILIAS by
1.9.4 (using
Doxyfile
)