19declare(strict_types=1);
40 $this->tree =
$DIC->repositoryTree();
48 public function aggregate(array $contexts): array
51 $frontier =
new SplQueue();
55 foreach ($contexts as $context) {
56 $strategy = $this->
getStrategy($context->getObjType());
57 if ($strategy ===
null || $strategy->shouldSkip($context)) {
60 $frontier->enqueue($context);
63 while (!$frontier->isEmpty()) {
64 $current = $frontier->dequeue();
67 if (array_key_exists($current->getObjId(), $result)) {
70 $result[$current->getObjId()] = $current;
73 $strategy = $this->
getStrategy($current->getObjType());
74 if ($strategy ===
null || $strategy->shouldSkip($current)) {
78 $children = $strategy->aggregate($current);
79 foreach ($children as $child) {
80 if ($strategy->isRecursive()) {
82 $result[$child->getObjId()] = $child;
85 $frontier->enqueue($child);
90 return array_values($result);
95 return $this->strategies[$object_type] ??
null;
103 $this->strategies[
'crs'] = $subtree_strategy;
104 $this->strategies[
'grp'] = $subtree_strategy;
105 $this->strategies[
'fold'] = $subtree_strategy;
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...
getStrategy(string $object_type)
Subtree Aggregation Strategy aggregates related contexts for groups and courses.
News Context DTO represents a context where news items can be associated with.
News Aggregation Strategy Interface defines the contract for news aggregation strategies.