13
13
use ApiPlatform \Metadata \Delete ;
14
14
use ApiPlatform \Metadata \Get ;
15
15
use ApiPlatform \Metadata \GetCollection ;
16
+ use ApiPlatform \Metadata \Link ;
16
17
use ApiPlatform \Metadata \Post ;
17
18
use ApiPlatform \Metadata \Put ;
18
19
use ApiPlatform \Serializer \Filter \PropertyFilter ;
19
20
use Chamilo \CoreBundle \Entity \Listener \SessionListener ;
20
21
use Chamilo \CoreBundle \Repository \SessionRepository ;
22
+ use Chamilo \CoreBundle \State \UserSessionSubscriptionsStateProvider ;
21
23
use DateTime ;
22
24
use Doctrine \Common \Collections \ArrayCollection ;
23
25
use Doctrine \Common \Collections \Collection ;
39
41
),
40
42
new Put (security: "is_granted('ROLE_ADMIN') " ),
41
43
new GetCollection (security: "is_granted('ROLE_ADMIN') " ),
44
+ new GetCollection (
45
+ uriTemplate: '/user/{id}/session_subscriptions/past.{_format} ' ,
46
+ uriVariables: [
47
+ 'id ' => new Link (
48
+ fromClass: User::class,
49
+ ),
50
+ ],
51
+ normalizationContext: [
52
+ 'groups ' => [
53
+ 'user_subscriptions:sessions ' ,
54
+ ],
55
+ ],
56
+ security: "is_granted('ROLE_USER') " ,
57
+ name: 'user_session_subscriptions_past ' ,
58
+ provider: UserSessionSubscriptionsStateProvider::class,
59
+ ),
60
+ new GetCollection (
61
+ uriTemplate: '/user/{id}/session_subscriptions/current.{_format} ' ,
62
+ uriVariables: [
63
+ 'id ' => new Link (
64
+ fromClass: User::class,
65
+ ),
66
+ ],
67
+ normalizationContext: [
68
+ 'groups ' => [
69
+ 'user_subscriptions:sessions ' ,
70
+ ],
71
+ ],
72
+ security: "is_granted('ROLE_USER') " ,
73
+ name: 'user_session_subscriptions_current ' ,
74
+ provider: UserSessionSubscriptionsStateProvider::class,
75
+ ),
76
+ new GetCollection (
77
+ uriTemplate: '/user/{id}/session_subscriptions/upcoming.{_format} ' ,
78
+ uriVariables: [
79
+ 'id ' => new Link (
80
+ fromClass: User::class,
81
+ ),
82
+ ],
83
+ normalizationContext: [
84
+ 'groups ' => [
85
+ 'user_subscriptions:sessions ' ,
86
+ ],
87
+ ],
88
+ security: "is_granted('ROLE_USER') " ,
89
+ name: 'user_session_subscriptions_upcoming ' ,
90
+ provider: UserSessionSubscriptionsStateProvider::class,
91
+ ),
42
92
new Post (security: "is_granted('ROLE_ADMIN') " ),
43
93
new Delete (security: "is_granted('DELETE', object) " ),
44
94
],
@@ -72,6 +122,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
72
122
'session_rel_course_rel_user:read ' ,
73
123
'course:read ' ,
74
124
'track_e_exercise:read ' ,
125
+ 'user_subscriptions:sessions ' ,
75
126
])]
76
127
#[ORM \Column(name: 'id ' , type: 'integer ' )]
77
128
#[ORM \Id]
@@ -85,6 +136,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
85
136
'session:read ' ,
86
137
'session_rel_user:read ' ,
87
138
'session_rel_course_rel_user:read ' ,
139
+ 'user_subscriptions:sessions ' ,
88
140
])]
89
141
#[ORM \OrderBy(['position ' => 'ASC ' ])]
90
142
#[ORM \OneToMany(
@@ -171,6 +223,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
171
223
'course:read ' ,
172
224
'track_e_exercise:read ' ,
173
225
'calendar_event:read ' ,
226
+ 'user_subscriptions:sessions ' ,
174
227
])]
175
228
#[ORM \Column(name: 'title ' , type: 'string ' , length: 150 )]
176
229
protected string $ title ;
@@ -189,7 +242,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
189
242
#[ORM \Column(name: 'show_description ' , type: 'boolean ' , nullable: true )]
190
243
protected ?bool $ showDescription ;
191
244
192
- #[Groups(['session:read ' , 'session:write ' ])]
245
+ #[Groups(['session:read ' , 'session:write ' , ' user_subscriptions:sessions ' ])]
193
246
#[ORM \Column(name: 'duration ' , type: 'integer ' , nullable: true )]
194
247
protected ?int $ duration = null ;
195
248
@@ -221,6 +274,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
221
274
'session:write ' ,
222
275
'session_rel_user:read ' ,
223
276
'session_rel_course_rel_user:read ' ,
277
+ 'user_subscriptions:sessions ' ,
224
278
])]
225
279
#[ORM \Column(name: 'display_start_date ' , type: 'datetime ' , unique: false , nullable: true )]
226
280
protected ?DateTime $ displayStartDate ;
@@ -230,6 +284,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
230
284
'session:write ' ,
231
285
'session_rel_user:read ' ,
232
286
'session_rel_course_rel_user:read ' ,
287
+ 'user_subscriptions:sessions ' ,
233
288
])]
234
289
#[ORM \Column(name: 'display_end_date ' , type: 'datetime ' , unique: false , nullable: true )]
235
290
protected ?DateTime $ displayEndDate ;
@@ -277,7 +332,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
277
332
#[ORM \Column(name: 'status ' , type: 'integer ' , nullable: false )]
278
333
protected int $ status ;
279
334
280
- #[Groups(['session:read ' , 'session:write ' , 'session_rel_user:read ' ])]
335
+ #[Groups(['session:read ' , 'session:write ' , 'session_rel_user:read ' , ' user_subscriptions:sessions ' ])]
281
336
#[ORM \ManyToOne(targetEntity: SessionCategory::class, inversedBy: 'sessions ' )]
282
337
#[ORM \JoinColumn(name: 'session_category_id ' , referencedColumnName: 'id ' )]
283
338
protected ?SessionCategory $ category = null ;
@@ -293,6 +348,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
293
348
/**
294
349
* Image illustrating the session (was extra field 'image' in 1.11).
295
350
*/
351
+ #[Groups(['user_subscriptions:sessions ' ])]
296
352
#[ORM \ManyToOne(targetEntity: Asset::class, cascade: ['remove ' ])]
297
353
#[ORM \JoinColumn(name: 'image_id ' , referencedColumnName: 'id ' , onDelete: 'SET NULL ' )]
298
354
protected ?Asset $ image = null ;
@@ -530,6 +586,9 @@ public function setNbrUsers(int $nbrUsers): self
530
586
return $ this ;
531
587
}
532
588
589
+ /**
590
+ * @return Collection<SessionRelCourseRelUser>
591
+ */
533
592
public function getAllUsersFromCourse (int $ status ): Collection
534
593
{
535
594
$ criteria = Criteria::create ()->where (Criteria::expr ()->eq ('status ' , $ status ));
@@ -686,6 +745,7 @@ public function getGeneralCoaches(): ReadableCollection
686
745
;
687
746
}
688
747
748
+ #[Groups(['user_subscriptions:sessions ' ])]
689
749
public function getGeneralCoachesSubscriptions (): Collection
690
750
{
691
751
$ criteria = Criteria::create ()->where (Criteria::expr ()->eq ('relationType ' , self ::GENERAL_COACH ));
@@ -1193,4 +1253,13 @@ protected function compareDates(?DateTime $start, ?DateTime $end = null): bool
1193
1253
1194
1254
return !empty ($ end ) && $ now <= $ end ;
1195
1255
}
1256
+
1257
+ /**
1258
+ * @return Collection<SessionRelCourseRelUser>
1259
+ */
1260
+ #[Groups(['user_subscriptions:sessions ' ])]
1261
+ public function getCourseCoachesSubscriptions (): Collection
1262
+ {
1263
+ return $ this ->getAllUsersFromCourse (self ::COURSE_COACH );
1264
+ }
1196
1265
}
0 commit comments