Skip to content

Commit ca0e86d

Browse files
committed
Add modified query examples
1 parent a03ba22 commit ca0e86d

File tree

6 files changed

+92
-16
lines changed

6 files changed

+92
-16
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Notification;
6+
7+
use Ibexa\Contracts\Core\Repository\Values\Notification\Notification;
8+
use Ibexa\Core\Notification\Renderer\NotificationRenderer;
9+
use Symfony\Component\HttpFoundation\RequestStack;
10+
use Symfony\Component\Routing\RouterInterface;
11+
use Twig\Environment;
12+
13+
class ListRenderer implements NotificationRenderer
14+
{
15+
protected Environment $twig;
16+
17+
protected RouterInterface $router;
18+
19+
protected RequestStack $requestStack;
20+
21+
public function __construct(Environment $twig, RouterInterface $router, RequestStack $requestStack)
22+
{
23+
$this->twig = $twig;
24+
$this->router = $router;
25+
$this->requestStack = $requestStack;
26+
}
27+
28+
public function render(Notification $notification): string
29+
{
30+
$templateToExtend = '@ibexadesign/account/notifications/list_item.html.twig';
31+
$currentRequest = $this->requestStack->getCurrentRequest();
32+
if ($currentRequest && $currentRequest->attributes->getBoolean('render_all')) {
33+
$templateToExtend = '@ibexadesign/account/notifications/list_item_all.html.twig';
34+
}
35+
return $this->twig->render('@ibexadesign/notification.html.twig', [
36+
'notification' => $notification,
37+
'template_to_extend' => $templateToExtend,
38+
]);
39+
}
40+
41+
public function generateUrl(Notification $notification): ?string
42+
{
43+
if (array_key_exists('content_id', $notification->data)) {
44+
return $this->router->generate('ibexa.content.view', [
45+
'contentId' => $notification->data['content_id'],
46+
]);
47+
}
48+
return null;
49+
}
50+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use DateTimeImmutable;
6+
use Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion;
7+
use Ibexa\Contracts\Core\Repository\Values\NotificationQuery;
8+
9+
$repository = $this->getRepository();
10+
$notificationService = $repository->getNotificationService();
11+
$query = new NotificationQuery([], 0, 25);
12+
13+
$query->addCriterion(new Type('Workflow:Review'));
14+
$query->addCriterion(new Status(['unread']));
15+
16+
$from = new \DateTimeImmutable('-7 days');
17+
$to = new \DateTimeImmutable();
18+
19+
$query->addCriterion(new DateCreated($from, $to));
20+
21+
$notificationList = $notificationService->findNotifications($query);

docs/administration/back_office/notifications.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ Example:
6363
[[= include_file('code_samples/back_office/notifications/src/EventListener/ContentPublishEventListener.php') =]]
6464
```
6565

66-
To display the notification, write a renderer and tag it as a service.
66+
### Display single notification
67+
68+
To display a single notification, write a renderer and tag it as a service.
6769

6870
The example below presents a renderer that uses Twig to render a view:
6971

@@ -83,6 +85,18 @@ Finally, you need to add an entry to `config/services.yaml`:
8385
[[= include_file('code_samples/back_office/notifications/config/custom_services.yaml') =]]
8486
```
8587

88+
### Display notification list
89+
90+
To display a list of notifications, expand the above renderer.
91+
92+
The example below presents a modified renderer that uses Twig to render a list view:
93+
94+
```php
95+
[[= include_file('code_samples/back_office/notifications/src/Notification/ListRenderer.php') =]]
96+
```
97+
98+
Then, add the templates that are defined above as a response to `render_all` request:
99+
86100
## Notification timeout
87101

88102
To define the timeout for hiding Back-Office notification bars, per notification type, use the `ibexa.system.<scope>.notifications.<notification_type>.timeout` [configuration key](configuration.md#configuration-files):

docs/search/criteria_reference/notification_datecreated_criterion.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ The `DateCreated` Search Criterion searches for notifications based on the date
1616

1717
### PHP
1818

19-
``` php
20-
$criteria = new Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\DateCreated(
21-
new DateTime('2023-03-01 14:07:02'),
22-
'GTE'
23-
);
24-
25-
$query = new NotificationQuery($criteria);
19+
```php hl_lines="19"
20+
[[= include_file('code_samples/notifications/src/Query/Search.php') =]]
2621
```

docs/search/criteria_reference/notification_status_criterion.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ The `Status` Search Criterion searches for notifications based on notification s
1515

1616
### PHP
1717

18-
``` php
19-
$criteria = new Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\(0);
20-
21-
$query = new NotificationQuery($criteria);
18+
```php hl_lines="14"
19+
[[= include_file('code_samples/notifications/src/Query/Search.php') =]]
2220
```

docs/search/criteria_reference/notification_type_criterion.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ The `Type` Search Criterion searches for notifications by their types.
1515

1616
### PHP
1717

18-
``` php
19-
$criteria = new Ibexa\Contracts\Core\Repository\Values\Notification\Query\Criterion\Type('Workflow:Reject');
20-
21-
$query = new NotificationQuery($criteria);
18+
```php hl_lines="13"
19+
[[= include_file('code_samples/notifications/src/Query/Search.php') =]]
2220
```

0 commit comments

Comments
 (0)