Skip to content

Commit

Permalink
Merge pull request #2099 from studer-raimann/feature/6-0/plr-notifica…
Browse files Browse the repository at this point in the history
…tions

GlobalScreen: Scope Notifications
  • Loading branch information
chfsx authored Aug 26, 2019
2 parents a222f20 + d4c2225 commit 3269af8
Show file tree
Hide file tree
Showing 32 changed files with 1,195 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php namespace ILIAS\BackgroundTasks\Provider;

use ILIAS\GlobalScreen\Identification\IdentificationInterface;
use ILIAS\GlobalScreen\Scope\Notification\Provider\AbstractNotificationProvider;
use ILIAS\GlobalScreen\Scope\Notification\Provider\NotificationProvider;

/**
* Class BTNotificationProvider
*
* @author Fabian Schmid <[email protected]>
*/
class BTNotificationProvider extends AbstractNotificationProvider implements NotificationProvider
{

/**
* @inheritDoc
*/
public function getNotifications() : array
{
$id = function (string $id) : IdentificationInterface {
return $this->if->identifier($id);
};

$factory = $this->globalScreen()->notifications()->factory();

$group = $factory->standardGroup($id('bg_bucket_group'))->withTitle("Some Notifications");

for ($x = 1; $x < 10; $x++) {
$n = $factory->standard($id('bg_bucket_id_' . $x))
->withTitle("A Notification " . $x)
->withSummary("with a super summary " . $x)
->withAction("#");

$group->addNotification($n);
}

return [
$group,
];
}
}
9 changes: 7 additions & 2 deletions Services/GlobalScreen/artifacts/global_screen_providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
'ILIAS\\GlobalScreen\\Scope\\MetaBar\\Provider\\StaticMetaBarProvider' =>
array (
0 => 'ILIAS\\BackgroundTasks\\Provider\\BackgroundTasksMetaBarProvider',
1 => 'ILIAS\\Search\\Provider\\SearchMetaBarProvider',
2 => 'ILIAS\\User\\Provider\\UserMetaBarProvider',
1 => 'ILIAS\\GlobalScreen\\Scope\\MetaBar\\Provider\\NotificationCenterProvider',
2 => 'ILIAS\\Search\\Provider\\SearchMetaBarProvider',
3 => 'ILIAS\\User\\Provider\\UserMetaBarProvider',
),
'ILIAS\\GlobalScreen\\Scope\\Tool\\Provider\\DynamicToolProvider' =>
array (
Expand All @@ -38,4 +39,8 @@
0 => 'ILIAS\\Container\\Screen\\MemberViewLayoutProvider',
1 => 'ILIAS\\UICore\\PageContentProvider',
),
'ILIAS\\GlobalScreen\\Scope\\Notification\\Provider\\NotificationProvider' =>
array (
0 => 'ILIAS\\BackgroundTasks\\Provider\\BTNotificationProvider',
),
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use ILIAS\GlobalScreen\Scope\Layout\Provider\ModificationProvider;
use ILIAS\GlobalScreen\Scope\MainMenu\Provider\StaticMainMenuProvider;
use ILIAS\GlobalScreen\Scope\MetaBar\Provider\StaticMetaBarProvider;
use ILIAS\GlobalScreen\Scope\Notification\Provider\NotificationProvider;
use ILIAS\GlobalScreen\Scope\Tool\Provider\DynamicToolProvider;
use ILIAS\Setup;

Expand All @@ -28,6 +29,7 @@ public function build() : Setup\Artifact
StaticMetaBarProvider::class,
DynamicToolProvider::class,
ModificationProvider::class,
NotificationProvider::class,
];

foreach ($i as $interface) {
Expand Down
16 changes: 16 additions & 0 deletions Services/GlobalScreen/classes/class.ilGSProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Information\ItemInformation;
use ILIAS\GlobalScreen\Scope\MainMenu\Provider\StaticMainMenuProvider;
use ILIAS\GlobalScreen\Scope\MetaBar\Provider\StaticMetaBarProvider;
use ILIAS\GlobalScreen\Scope\Notification\Provider\NotificationProvider;
use ILIAS\GlobalScreen\Scope\Tool\Provider\DynamicToolProvider;

/**
Expand Down Expand Up @@ -126,6 +127,21 @@ public function getToolProvider() : array
}


/**
* @inheritDoc
*/
public function getNotificationsProvider() : array
{
$providers = [];
// Core
$this->appendCore($providers, NotificationProvider::class);

$this->registerInternal($providers);

return $providers;
}


/**
* @param array $array_of_core_providers
* @param string $interface
Expand Down
13 changes: 12 additions & 1 deletion src/GlobalScreen/Collector/CollectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use ILIAS\GlobalScreen\Scope\Layout\Collector\MainLayoutCollector;
use ILIAS\GlobalScreen\Scope\MainMenu\Collector\MainMenuMainCollector;
use ILIAS\GlobalScreen\Scope\MetaBar\Collector\MetaBarMainCollector;
use ILIAS\GlobalScreen\Scope\Notification\Collector\MainNotificationCollector;
use ILIAS\GlobalScreen\Scope\Tool\Collector\MainToolCollector;
use ILIAS\GlobalScreen\SingletonTrait;

Expand Down Expand Up @@ -82,9 +83,19 @@ public function tool() : MainToolCollector

/**
* @return MainLayoutCollector
* @throws \ReflectionException
*/
public function layout() : MainLayoutCollector
{
return $this->getWithArgument(MainLayoutCollector::class, $this->provider_factory->getModificationProvider());
return $this->getWithMultipleArguments(MainLayoutCollector::class, [$this->provider_factory->getModificationProvider()]);
}


/**
* @return MainNotificationCollector
*/
public function notifications() : MainNotificationCollector
{
return $this->getWithArgument(MainNotificationCollector::class, $this->provider_factory->getNotificationsProvider());
}
}
9 changes: 9 additions & 0 deletions src/GlobalScreen/Provider/NullProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public function getMetaBarProvider() : array
}


/**
* @inheritDoc
*/
public function getNotificationsProvider() : array
{
return [];
}


/**
* @inheritDoc
*/
Expand Down
7 changes: 7 additions & 0 deletions src/GlobalScreen/Provider/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Information\ItemInformation;
use ILIAS\GlobalScreen\Scope\MainMenu\Provider\StaticMainMenuProvider;
use ILIAS\GlobalScreen\Scope\MetaBar\Provider\StaticMetaBarProvider;
use ILIAS\GlobalScreen\Scope\Notification\Provider\NotificationProvider;
use ILIAS\GlobalScreen\Scope\Tool\Provider\DynamicToolProvider;

/**
Expand Down Expand Up @@ -44,6 +45,12 @@ public function getToolProvider() : array;
public function getMetaBarProvider() : array;


/**
* @return NotificationProvider[]
*/
public function getNotificationsProvider() : array;


/**
* @param string $class_name
*
Expand Down
4 changes: 4 additions & 0 deletions src/GlobalScreen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ There are several scopes served by the GlobalScreen service. Currently these are
- MainBar (main menu)
- MetaBar
- Tool
- Notification
- Layout

A scope refers to an area on an ILIAS page. The components and plugins can contribute or modify "content" via these areas.
Expand All @@ -39,6 +40,9 @@ can be reproduced in almost the same place. However, both the `Items` and the `P

For more information see [Scope/Tools/README.md](Scope/Tool/README.md).

# Scope Notifications
For more information, see [Scope/Notification/README.md](Scope/Notification/README.md).

## Scope Layout
This area is the superordinate element and responsible for the entire structure of a page. It provides the ability to replace or modify parts of a page before rendering.

Expand Down
14 changes: 13 additions & 1 deletion src/GlobalScreen/Scope/Layout/Collector/MainLayoutCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ILIAS\GlobalScreen\Scope\Layout\Factory\MainBarModification;
use ILIAS\GlobalScreen\Scope\Layout\Factory\MetaBarModification;
use ILIAS\GlobalScreen\Scope\Layout\Factory\NullModification;
use ILIAS\GlobalScreen\Scope\Layout\MetaContent\MetaContent;
use ILIAS\GlobalScreen\Scope\Layout\ModificationHandler;
use ILIAS\GlobalScreen\Scope\Layout\Provider\ModificationProvider;
use ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts;
Expand Down Expand Up @@ -36,7 +37,7 @@ class MainLayoutCollector
/**
* MainLayoutCollector constructor.
*
* @param ModificationProvider[] $providers
* @param array $providers
*/
public function __construct(array $providers)
{
Expand Down Expand Up @@ -128,4 +129,15 @@ private function getContextStack() : CalledContexts

return $called_contexts;
}


/**
* @return MetaContent
*/
private function getMetaContent() : MetaContent
{
global $DIC;

return $DIC->globalScreen()->layout()->meta();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php namespace ILIAS\GlobalScreen\Scope\MetaBar\Collector\Renderer;

use ILIAS\GlobalScreen\Collector\Renderer\isSupportedTrait;
use ILIAS\GlobalScreen\Scope\MetaBar\Factory\isItem;
use ILIAS\GlobalScreen\Scope\MetaBar\Factory\NotificationCenter;
use ILIAS\UI\Component\Component;

/**
* Class NotificationCenterRenderer
*
* @author Fabian Schmid <[email protected]>
*/
class NotificationCenterRenderer implements MetaBarItemRenderer
{

use isSupportedTrait;
/**
* @var \ILIAS\GlobalScreen\Services
*/
private $ui;
/**
* @var \ILIAS\GlobalScreen\Services
*/
private $gs;


/**
* BaseMetaBarItemRenderer constructor.
*/
public function __construct()
{
global $DIC;
$this->ui = $DIC->ui();
$this->gs = $DIC->globalScreen();
}


/**
* @param NotificationCenter $item
*
* @return Component
*/
public function getComponentForItem(isItem $item) : Component
{
$f = $this->ui->factory();

$combined = $f->mainControls()->slate()->combined("Notification Center", $item->getSymbol());

foreach ($this->gs->collector()->notifications()->getNotifications() as $notification) {
$component = $notification->getRenderer()->getComponentForItem($notification);
if ($this->isComponentSupportedForCombinedSlate($component)) {
$combined = $combined->withAdditionalEntry($component);
}
}

return $combined;
}
}
17 changes: 17 additions & 0 deletions src/GlobalScreen/Scope/MetaBar/Factory/MetaBarItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,21 @@ public function topLinkItem(IdentificationInterface $identification) : TopLinkIt
{
return new TopLinkItem($identification);
}


/**
* @param IdentificationInterface $identification
*
* @return NotificationCenter
*/
public function notificationCenter(IdentificationInterface $identification)
{
static $created;
if ($created === true) {
throw new \LogicException("only one NotificationCenter can exist");
}
$created = true;

return new NotificationCenter($identification);
}
}
90 changes: 90 additions & 0 deletions src/GlobalScreen/Scope/MetaBar/Factory/NotificationCenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php namespace ILIAS\GlobalScreen\Scope\MetaBar\Factory;

use ILIAS\GlobalScreen\Identification\IdentificationInterface;
use ILIAS\GlobalScreen\Scope\MetaBar\Collector\Renderer\NotificationCenterRenderer;
use ILIAS\UI\Component\Symbol\Symbol;

/**
* Class NotificationCenter
*
* @author Fabian Schmid <[email protected]>
*/
class NotificationCenter extends AbstractBaseItem implements isItem, hasSymbol
{

/**
* @var isItem[]
*/
private $notifications = [];


/**
* @inheritDoc
*/
public function __construct(IdentificationInterface $provider_identification)
{
parent::__construct($provider_identification);
$this->renderer = new NotificationCenterRenderer();
}


/**
* @param isItem[] $notifications
*
* @return NotificationCenter
*/
public function withNotifications(array $notifications) : NotificationCenter
{
$this->notifications = $notifications;

return $this;
}


/**
* @return isItem[]
*/
public function getNotifications() : array
{
return $this->notifications;
}


/**
* @inheritDoc
*/
public function withSymbol(Symbol $symbol) : hasSymbol
{
return $this;
}


/**
* @inheritDoc
*/
public function hasSymbol() : bool
{
return true;
}


/**
* @return Symbol
*/
public function getSymbol() : Symbol
{
global $DIC;

// TODO implement counter
return $DIC->ui()->factory()->symbol()->glyph()->notification();
}


/**
* @inheritDoc
*/
public function getPosition() : int
{
return 1;
}
}
Loading

0 comments on commit 3269af8

Please sign in to comment.