18
18
use Ibexa \Bundle \AdminUi \Form \Type \SearchType ;
19
19
use Ibexa \Contracts \AdminUi \Controller \Controller ;
20
20
use Ibexa \Contracts \Core \Repository \NotificationService ;
21
+ use Ibexa \Contracts \Core \Repository \Values \Notification \Query \Criterion \NotificationQuery ;
21
22
use Ibexa \Contracts \Core \SiteAccess \ConfigResolverInterface ;
22
23
use Ibexa \Core \Notification \Renderer \Registry ;
23
24
use InvalidArgumentException ;
@@ -95,15 +96,18 @@ public function renderNotificationsPageAction(Request $request, int $page): Resp
95
96
]);
96
97
$ searchForm ->handleRequest ($ request );
97
98
98
- $ query = [] ;
99
+ $ query = new NotificationQuery () ;
99
100
if ($ searchForm ->isSubmitted () && $ searchForm ->isValid ()) {
100
101
$ query = $ this ->buildQuery ($ searchForm ->getData ());
101
102
}
102
103
104
+ $ query ->offset = ($ page - 1 ) * $ this ->configResolver ->getParameter ('pagination.notification_limit ' );
105
+ $ query ->limit = $ this ->configResolver ->getParameter ('pagination.notification_limit ' );
106
+
103
107
$ pagerfanta = new Pagerfanta (
104
108
new NotificationAdapter ($ this ->notificationService , $ query )
105
109
);
106
- $ pagerfanta ->setMaxPerPage ($ this -> configResolver -> getParameter ( ' pagination.notification_limit ' ) );
110
+ $ pagerfanta ->setMaxPerPage ($ query -> limit );
107
111
$ pagerfanta ->setCurrentPage (min ($ page , $ pagerfanta ->getNbPages ()));
108
112
109
113
$ notifications = [];
@@ -127,35 +131,39 @@ public function renderNotificationsPageAction(Request $request, int $page): Resp
127
131
]);
128
132
}
129
133
130
- private function buildQuery (SearchQueryData $ data ): array
134
+ private function buildQuery (SearchQueryData $ data ): NotificationQuery
131
135
{
132
- $ query = [];
136
+ $ criteria = [];
133
137
134
138
if ($ data ->getType ()) {
135
- $ query [ ' type ' ] = $ data ->getType ();
139
+ $ criteria [ ] = new Criterion \ Type ( $ data ->getType () );
136
140
}
137
141
138
142
if (!empty ($ data ->getStatuses ())) {
139
- $ query [ ' status ' ] = [];
143
+ $ statuses = [];
140
144
if (in_array ('read ' , $ data ->getStatuses (), true )) {
141
- $ query [ ' status ' ] [] = 'read ' ;
145
+ $ statuses [] = 'read ' ;
142
146
}
143
147
if (in_array ('unread ' , $ data ->getStatuses (), true )) {
144
- $ query ['status ' ][] = 'unread ' ;
148
+ $ statuses [] = 'unread ' ;
149
+ }
150
+
151
+ if (!empty ($ statuses )) {
152
+ $ criteria [] = new Criterion \Status ($ statuses );
145
153
}
146
154
}
147
155
148
156
$ range = $ data ->getCreatedRange ();
149
157
if ($ range !== null ) {
150
- if ( $ range ->getMin () instanceof DateTimeInterface) {
151
- $ query [ ' created_from ' ] = $ range ->getMin ()-> getTimestamp () ;
152
- }
153
- if ($ range -> getMax () instanceof DateTimeInterface ) {
154
- $ query [ ' created_to ' ] = $ range -> getMax ()-> getTimestamp ( );
158
+ $ min = $ range ->getMin () instanceof DateTimeInterface ? $ range -> getMin () : null ;
159
+ $ max = $ range ->getMax () instanceof DateTimeInterface ? $ range -> getMax () : null ;
160
+
161
+ if ($ min !== null || $ max !== null ) {
162
+ $ criteria [ ] = new Criterion \ DateCreated ( $ min , $ max );
155
163
}
156
164
}
157
165
158
- return $ query ;
166
+ return new NotificationQuery ( $ criteria ) ;
159
167
}
160
168
161
169
private function createNotificationSelectionData (Pagerfanta $ pagerfanta ): NotificationSelectionData
0 commit comments