code_samples/back_office/notifications/src/Notification/ListRenderer.php
docs/administration/back_office/notifications.md@94:```php
docs/administration/back_office/notifications.md@95:[[= include_file('code_samples/back_office/notifications/src/Notification/ListRenderer.php') =]]
docs/administration/back_office/notifications.md@96:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\Notification;
006⫶
007⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Notification;
008⫶use Ibexa\Core\Notification\Renderer\NotificationRenderer;
009⫶use Ibexa\Core\Notification\Renderer\TypedNotificationRendererInterface;
010⫶use Symfony\Component\HttpFoundation\RequestStack;
011⫶use Symfony\Component\Routing\RouterInterface;
|
code_samples/back_office/notifications/src/Notification/ListRenderer.php
docs/administration/back_office/notifications.md@94:```php
docs/administration/back_office/notifications.md@95:[[= include_file('code_samples/back_office/notifications/src/Notification/ListRenderer.php') =]]
docs/administration/back_office/notifications.md@96:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\Notification;
006⫶
007⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Notification;
008⫶use Ibexa\Core\Notification\Renderer\NotificationRenderer;
009⫶use Ibexa\Core\Notification\Renderer\TypedNotificationRendererInterface;
010⫶use Symfony\Component\HttpFoundation\RequestStack;
011⫶use Symfony\Component\Routing\RouterInterface;
|
012⫶use Twig\Environment;
013⫶
014⫶class ListRenderer implements NotificationRenderer, TypedNotificationRendererInterface
015⫶{
016⫶ protected Environment $twig;
017⫶
018⫶ protected RouterInterface $router;
019⫶
020⫶ protected RequestStack $requestStack;
021⫶
022⫶ public function __construct(Environment $twig, RouterInterface $router, RequestStack $requestStack)
023⫶ {
024⫶ $this->twig = $twig;
025⫶ $this->router = $router;
026⫶ $this->requestStack = $requestStack;
027⫶ }
028⫶
029⫶ public function render(Notification $notification): string
030⫶ {
031⫶ $templateToExtend = '@ibexadesign/account/notifications/list_item.html.twig';
032⫶ $currentRequest = $this->requestStack->getCurrentRequest();
033⫶ if ($currentRequest && $currentRequest->attributes->getBoolean('render_all')) {
034⫶ $templateToExtend = '@ibexadesign/account/notifications/list_item_all.html.twig';
035⫶ }
036⫶
037⫶ return $this->twig->render('@ibexadesign/notification.html.twig', [
038⫶ 'notification' => $notification,
039⫶ 'template_to_extend' => $templateToExtend,
040⫶ ]);
041⫶ }
042⫶
043⫶ public function generateUrl(Notification $notification): ?string
044⫶ {
045⫶ if (array_key_exists('content_id', $notification->data)) {
046⫶ return $this->router->generate('ibexa.content.view', [
047⫶ 'contentId' => $notification->data['content_id'],
048⫶ ]);
049⫶ }
050⫶
051⫶ return null;
052⫶ }
053⫶
054⫶ public function getTypeLabel(): string
055⫶ {
056⫶ return /** @Desc("Workflow stage changed") */
057⫶ $this->translator->trans(
058⫶ 'workflow.notification.stage_change.label',
059⫶ [],
060⫶ 'ibexa_workflow'
061⫶ );
062⫶ }
063⫶}
| 012⫶use Symfony\Contracts\Translation\TranslatorInterface;
013⫶use Twig\Environment;
014⫶
015⫶class ListRenderer implements NotificationRenderer, TypedNotificationRendererInterface
016⫶{
017⫶ protected Environment $twig;
018⫶
019⫶ protected RouterInterface $router;
020⫶
021⫶ protected RequestStack $requestStack;
022⫶
023⫶ protected TranslatorInterface $translator;
024⫶
025⫶ public function __construct(Environment $twig, RouterInterface $router, RequestStack $requestStack, TranslatorInterface $translator)
026⫶ {
027⫶ $this->twig = $twig;
028⫶ $this->router = $router;
029⫶ $this->requestStack = $requestStack;
030⫶ $this->translator = $translator;
031⫶ }
032⫶
033⫶ public function render(Notification $notification): string
034⫶ {
035⫶ $templateToExtend = '@ibexadesign/account/notifications/list_item.html.twig';
036⫶ $currentRequest = $this->requestStack->getCurrentRequest();
037⫶ if ($currentRequest && $currentRequest->attributes->getBoolean('render_all')) {
038⫶ $templateToExtend = '@ibexadesign/account/notifications/list_item_all.html.twig';
039⫶ }
040⫶
041⫶ return $this->twig->render('@ibexadesign/notification.html.twig', [
042⫶ 'notification' => $notification,
043⫶ 'template_to_extend' => $templateToExtend,
044⫶ ]);
045⫶ }
046⫶
047⫶ public function generateUrl(Notification $notification): ?string
048⫶ {
049⫶ if (array_key_exists('content_id', $notification->data)) {
050⫶ return $this->router->generate('ibexa.content.view', [
051⫶ 'contentId' => $notification->data['content_id'],
052⫶ ]);
053⫶ }
054⫶
055⫶ return null;
056⫶ }
057⫶
058⫶ public function getTypeLabel(): string
059⫶ {
060⫶ return /** @Desc("Workflow stage changed") */
061⫶ $this->translator->trans(
062⫶ 'workflow.notification.stage_change.label',
063⫶ [],
064⫶ 'ibexa_workflow'
065⫶ );
066⫶ }
067⫶}
|
code_samples/back_office/notifications/src/Notification/MyRenderer.php
docs/administration/back_office/notifications.md@72:```php
docs/administration/back_office/notifications.md@73:[[= include_file('code_samples/back_office/notifications/src/Notification/MyRenderer.php') =]]
docs/administration/back_office/notifications.md@74:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\Notification;
006⫶
007⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Notification;
008⫶use Ibexa\Core\Notification\Renderer\NotificationRenderer;
009⫶use Ibexa\Core\Notification\Renderer\TypedNotificationRendererInterface;
010⫶use Symfony\Component\Routing\RouterInterface;
|
code_samples/back_office/notifications/src/Notification/MyRenderer.php
docs/administration/back_office/notifications.md@72:```php
docs/administration/back_office/notifications.md@73:[[= include_file('code_samples/back_office/notifications/src/Notification/MyRenderer.php') =]]
docs/administration/back_office/notifications.md@74:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\Notification;
006⫶
007⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Notification;
008⫶use Ibexa\Core\Notification\Renderer\NotificationRenderer;
009⫶use Ibexa\Core\Notification\Renderer\TypedNotificationRendererInterface;
010⫶use Symfony\Component\Routing\RouterInterface;
|
011⫶use Twig\Environment;
012⫶
013⫶class MyRenderer implements NotificationRenderer, TypedNotificationRendererInterface
014⫶{
015⫶ protected Environment $twig;
016⫶
017⫶ protected RouterInterface $router;
018⫶
019⫶ public function __construct(Environment $twig, RouterInterface $router)
020⫶ {
021⫶ $this->twig = $twig;
022⫶ $this->router = $router;
023⫶ }
024⫶
025⫶ public function render(Notification $notification): string
026⫶ {
027⫶ return $this->twig->render('@ibexadesign/notification.html.twig', [
028⫶ 'notification' => $notification,
029⫶ 'template_to_extend' => $templateToExtend,
030⫶ ]);
031⫶ }
032⫶
033⫶ public function generateUrl(Notification $notification): ?string
034⫶ {
035⫶ if (array_key_exists('content_id', $notification->data)) {
036⫶ return $this->router->generate('ibexa.content.view', ['contentId' => $notification->data['content_id']]);
037⫶ }
038⫶
039⫶ return null;
040⫶ }
041⫶
042⫶ }
043⫶
044⫶ public function getTypeLabel(): string
045⫶ {
046⫶ return /** @Desc("Workflow stage changed") */
047⫶ $this->translator->trans(
048⫶ 'workflow.notification.stage_change.label',
049⫶ [],
050⫶ 'ibexa_workflow'
051⫶ );
052⫶ }
053⫶}
| 011⫶use Symfony\Contracts\Translation\TranslatorInterface;
012⫶use Twig\Environment;
013⫶
014⫶class MyRenderer implements NotificationRenderer, TypedNotificationRendererInterface
015⫶{
016⫶ protected Environment $twig;
017⫶
018⫶ protected RouterInterface $router;
019⫶
020⫶ protected TranslatorInterface $translator;
021⫶
022⫶ public function __construct(Environment $twig, RouterInterface $router, TranslatorInterface $translator)
023⫶ {
024⫶ $this->twig = $twig;
025⫶ $this->router = $router;
026⫶ $this->translator = $translator;
027⫶ }
028⫶
029⫶ public function render(Notification $notification): string
030⫶ {
031⫶ return $this->twig->render('@ibexadesign/notification.html.twig', [
032⫶ 'notification' => $notification,
033⫶ 'template_to_extend' => '@ibexadesign/account/notifications/list_item.html.twig',
034⫶ ]);
035⫶ }
036⫶
037⫶ public function generateUrl(Notification $notification): ?string
038⫶ {
039⫶ if (array_key_exists('content_id', $notification->data)) {
040⫶ return $this->router->generate('ibexa.content.view', ['contentId' => $notification->data['content_id']]);
041⫶ }
042⫶
043⫶ return null;
044⫶ }
045⫶
046⫶ public function getTypeLabel(): string
047⫶ {
048⫶ return /** @Desc("Workflow stage changed") */
049⫶ $this->translator->trans(
050⫶ 'workflow.notification.stage_change.label',
051⫶ [],
052⫶ 'ibexa_workflow'
053⫶ );
054⫶ }
055⫶}
|
code_samples/notifications/Src/Query/search.php
|
code_samples/notifications/Src/Query/search.php
|
docs/search/criteria_reference/notification_datecreated_criterion.md@19:```php hl_lines="14-15 17"
| docs/search/criteria_reference/notification_datecreated_criterion.md@19:```php hl_lines="16-17 19"
|
docs/search/criteria_reference/notification_datecreated_criterion.md@20:[[= include_file('code_samples/notifications/Src/Query/search.php') =]]
docs/search/criteria_reference/notification_datecreated_criterion.md@21:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
| docs/search/criteria_reference/notification_datecreated_criterion.md@20:[[= include_file('code_samples/notifications/Src/Query/search.php') =]]
docs/search/criteria_reference/notification_datecreated_criterion.md@21:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
|
005⫶use Ibexa\Contracts\Core\Repository\Values\NotificationQuery;
006⫶
007⫶$repository = $this->getRepository();
008⫶$notificationService = $repository->getNotificationService();
009⫶$query = new NotificationQuery([], 0, 25);
010⫶
011⫶$query->addCriterion(new Type('Workflow:Review'));
012⫶$query->addCriterion(new Status(['unread']));
013⫶
014❇️$from = new \DateTimeImmutable('-7 days');
015❇️$to = new \DateTimeImmutable();
016⫶
017❇️$query->addCriterion(new DateCreated($from, $to));
| 005⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\DateCreated;
006⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\Status;
007⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\Type;
008⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\NotificationQuery;
009⫶
010⫶/** @var \Ibexa\Contracts\Core\Repository\NotificationService $notificationService */
011⫶$query = new NotificationQuery([], 0, 25);
012⫶
013⫶$query->addCriterion(new Type('Workflow:Review'));
014⫶$query->addCriterion(new Status(['unread']));
015⫶
016❇️$from = new \DateTimeImmutable('-7 days');
017❇️$to = new \DateTimeImmutable();
|
018⫶
| 018⫶
|
019⫶$notificationList = $notificationService->findNotifications($query);
| 019❇️$query->addCriterion(new DateCreated($from, $to));
020⫶
021⫶$notificationList = $notificationService->findNotifications($query);
|
|
|
docs/search/criteria_reference/notification_status_criterion.md@18:```php hl_lines="12"
| docs/search/criteria_reference/notification_status_criterion.md@18:```php hl_lines="14"
|
docs/search/criteria_reference/notification_status_criterion.md@19:[[= include_file('code_samples/notifications/Src/Query/search.php') =]]
docs/search/criteria_reference/notification_status_criterion.md@20:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
| docs/search/criteria_reference/notification_status_criterion.md@19:[[= include_file('code_samples/notifications/Src/Query/search.php') =]]
docs/search/criteria_reference/notification_status_criterion.md@20:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
|
005⫶use Ibexa\Contracts\Core\Repository\Values\NotificationQuery;
006⫶
007⫶$repository = $this->getRepository();
008⫶$notificationService = $repository->getNotificationService();
009⫶$query = new NotificationQuery([], 0, 25);
010⫶
011⫶$query->addCriterion(new Type('Workflow:Review'));
012❇️$query->addCriterion(new Status(['unread']));
013⫶
014⫶$from = new \DateTimeImmutable('-7 days');
015⫶$to = new \DateTimeImmutable();
016⫶
017⫶$query->addCriterion(new DateCreated($from, $to));
| 005⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\DateCreated;
006⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\Status;
007⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\Type;
008⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\NotificationQuery;
009⫶
010⫶/** @var \Ibexa\Contracts\Core\Repository\NotificationService $notificationService */
011⫶$query = new NotificationQuery([], 0, 25);
012⫶
013⫶$query->addCriterion(new Type('Workflow:Review'));
014❇️$query->addCriterion(new Status(['unread']));
015⫶
016⫶$from = new \DateTimeImmutable('-7 days');
017⫶$to = new \DateTimeImmutable();
|
018⫶
| 018⫶
|
019⫶$notificationList = $notificationService->findNotifications($query);
| 019⫶$query->addCriterion(new DateCreated($from, $to));
020⫶
021⫶$notificationList = $notificationService->findNotifications($query);
|
|
|
docs/search/criteria_reference/notification_type_criterion.md@18:```php hl_lines="11"
| docs/search/criteria_reference/notification_type_criterion.md@18:```php hl_lines="13"
|
docs/search/criteria_reference/notification_type_criterion.md@19:[[= include_file('code_samples/notifications/Src/Query/search.php') =]]
docs/search/criteria_reference/notification_type_criterion.md@20:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
| docs/search/criteria_reference/notification_type_criterion.md@19:[[= include_file('code_samples/notifications/Src/Query/search.php') =]]
docs/search/criteria_reference/notification_type_criterion.md@20:```
001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
|
005⫶use Ibexa\Contracts\Core\Repository\Values\NotificationQuery;
006⫶
007⫶$repository = $this->getRepository();
008⫶$notificationService = $repository->getNotificationService();
009⫶$query = new NotificationQuery([], 0, 25);
010⫶
011❇️$query->addCriterion(new Type('Workflow:Review'));
012⫶$query->addCriterion(new Status(['unread']));
013⫶
014⫶$from = new \DateTimeImmutable('-7 days');
015⫶$to = new \DateTimeImmutable();
016⫶
017⫶$query->addCriterion(new DateCreated($from, $to));
| 005⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\DateCreated;
006⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\Status;
007⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\Type;
008⫶use Ibexa\Contracts\Core\Repository\Values\Notification\Query\NotificationQuery;
009⫶
010⫶/** @var \Ibexa\Contracts\Core\Repository\NotificationService $notificationService */
011⫶$query = new NotificationQuery([], 0, 25);
012⫶
013❇️$query->addCriterion(new Type('Workflow:Review'));
014⫶$query->addCriterion(new Status(['unread']));
015⫶
016⫶$from = new \DateTimeImmutable('-7 days');
017⫶$to = new \DateTimeImmutable();
|
018⫶
| 018⫶
|
019⫶$notificationList = $notificationService->findNotifications($query);
| 019⫶$query->addCriterion(new DateCreated($from, $to));
020⫶
021⫶$notificationList = $notificationService->findNotifications($query);
|
|
|