18
18
use Claroline \ForumBundle \Form \SubjectType ;
19
19
use Claroline \ForumBundle \Form \CategoryType ;
20
20
use Claroline \ForumBundle \Form \EditTitleType ;
21
+ use Claroline \ForumBundle \Event \Log \ReadSubjectEvent ;
21
22
use Claroline \CoreBundle \Library \Resource \ResourceCollection ;
22
23
use Claroline \CoreBundle \Entity \Workspace \Workspace ;
23
24
use Claroline \CoreBundle \Entity \User ;
@@ -92,7 +93,8 @@ public function openAction(Forum $forum)
92
93
'_resource ' => $ forum ,
93
94
'isModerator ' => $ isModerator ,
94
95
'categories ' => $ categories ,
95
- 'hasSubscribed ' => $ hasSubscribed
96
+ 'hasSubscribed ' => $ hasSubscribed ,
97
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
96
98
);
97
99
}
98
100
@@ -132,14 +134,38 @@ public function subjectsAction(Category $category, $page, $max)
132
134
$ isModerator = $ this ->authorization ->isGranted ('moderate ' , $ collection ) &&
133
135
!$ isAnon ;
134
136
137
+ $ logs = array ();
138
+
139
+ if (!$ isAnon ) {
140
+ $ securityToken = $ this ->tokenStorage ->getToken ();
141
+
142
+ if (!is_null ($ securityToken )) {
143
+ $ user = $ securityToken ->getUser ();
144
+ $ logs = $ this ->manager ->getSubjectsReadingLogs ($ user , $ forum ->getResourceNode ());
145
+ }
146
+ }
147
+ $ lastAccessDates = array ();
148
+
149
+ foreach ($ logs as $ log ) {
150
+ $ details = $ log ->getDetails ();
151
+ $ subjectId = $ details ['subject ' ]['id ' ];
152
+
153
+ if (!isset ($ lastAccessDates [$ subjectId ])) {
154
+ $ lastAccessDates [$ subjectId ] = $ log ->getDateLog ();
155
+ }
156
+ }
157
+
135
158
return array (
136
159
'pager ' => $ pager ,
137
160
'_resource ' => $ forum ,
138
161
'canCreateSubject ' => $ canCreateSubject ,
139
162
'isModerator ' => $ isModerator ,
140
163
'category ' => $ category ,
141
164
'max ' => $ max ,
142
- 'lastMessages ' => $ lastMessages
165
+ 'lastMessages ' => $ lastMessages ,
166
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace (),
167
+ 'lastAccessDates ' => $ lastAccessDates ,
168
+ 'isAnon ' => $ isAnon
143
169
);
144
170
}
145
171
@@ -167,7 +193,8 @@ public function subjectFormAction(Category $category)
167
193
return array (
168
194
'_resource ' => $ forum ,
169
195
'form ' => $ formSubject ->createView (),
170
- 'category ' => $ category
196
+ 'category ' => $ category ,
197
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
171
198
);
172
199
}
173
200
@@ -193,7 +220,8 @@ public function categoryFormAction(Forum $forum)
193
220
194
221
return array (
195
222
'_resource ' => $ forum ,
196
- 'form ' => $ formCategory ->createView ()
223
+ 'form ' => $ formCategory ->createView (),
224
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
197
225
);
198
226
}
199
227
@@ -283,7 +311,8 @@ public function createSubjectAction(Category $category)
283
311
284
312
return array (
285
313
'form ' => $ form ->createView (),
286
- '_resource ' => $ forum
314
+ '_resource ' => $ forum ,
315
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
287
316
);
288
317
}
289
318
@@ -314,6 +343,17 @@ public function messagesAction(Subject $subject, $page, $max)
314
343
$ canPost = $ this ->authorization ->isGranted ('post ' , $ collection );
315
344
$ form = $ this ->get ('form.factory ' )->create (new MessageType ());
316
345
346
+ if (!$ isAnon ) {
347
+ $ securityToken = $ this ->tokenStorage ->getToken ();
348
+
349
+ if (!is_null ($ securityToken )) {
350
+ $ user = $ securityToken ->getUser ();
351
+ $ event = new ReadSubjectEvent ($ subject );
352
+ $ event ->setDoer ($ user );
353
+ $ this ->dispatch ($ event );
354
+ }
355
+ }
356
+
317
357
return array (
318
358
'subject ' => $ subject ,
319
359
'pager ' => $ pager ,
@@ -322,7 +362,8 @@ public function messagesAction(Subject $subject, $page, $max)
322
362
'form ' => $ form ->createView (),
323
363
'category ' => $ subject ->getCategory (),
324
364
'max ' => $ max ,
325
- 'canPost ' => $ canPost
365
+ 'canPost ' => $ canPost ,
366
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
326
367
);
327
368
}
328
369
@@ -375,7 +416,8 @@ public function editMessageFormAction(Message $message)
375
416
'subject ' => $ subject ,
376
417
'form ' => $ form ->createView (),
377
418
'message ' => $ message ,
378
- '_resource ' => $ forum
419
+ '_resource ' => $ forum ,
420
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
379
421
);
380
422
}
381
423
@@ -415,7 +457,8 @@ public function editMessageAction(Message $message)
415
457
'subject ' => $ subject ,
416
458
'form ' => $ form ->createView (),
417
459
'message ' => $ message ,
418
- '_resource ' => $ forum
460
+ '_resource ' => $ forum ,
461
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
419
462
);
420
463
}
421
464
@@ -442,7 +485,8 @@ public function editCategoryFormAction(Category $category)
442
485
return array (
443
486
'category ' => $ category ,
444
487
'form ' => $ form ->createView (),
445
- '_resource ' => $ category ->getForum ()
488
+ '_resource ' => $ forum ,
489
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
446
490
);
447
491
}
448
492
@@ -471,7 +515,7 @@ public function editCategoryAction(Category $category)
471
515
$ this ->manager ->editCategory ($ category , $ oldName , $ newName );
472
516
473
517
return new RedirectResponse (
474
- $ this ->generateUrl ('claro_forum_categories ' , array ('forum ' => $ category -> getForum () ->getId ()))
518
+ $ this ->generateUrl ('claro_forum_categories ' , array ('forum ' => $ forum ->getId ()))
475
519
);
476
520
}
477
521
}
@@ -516,7 +560,13 @@ public function searchAction(Forum $forum, $page, $search)
516
560
{
517
561
$ pager = $ this ->manager ->searchPager ($ forum , $ search , $ page );
518
562
519
- return array ('pager ' => $ pager , '_resource ' => $ forum , 'search ' => $ search , 'page ' => $ page );
563
+ return array (
564
+ 'pager ' => $ pager ,
565
+ '_resource ' => $ forum ,
566
+ 'search ' => $ search ,
567
+ 'page ' => $ page ,
568
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
569
+ );
520
570
}
521
571
522
572
/**
@@ -534,7 +584,8 @@ public function searchAction(Forum $forum, $page, $search)
534
584
*/
535
585
public function editSubjectFormAction (Subject $ subject )
536
586
{
537
- $ isModerator = $ this ->authorization ->isGranted ('moderate ' , new ResourceCollection (array ($ subject ->getCategory ()->getForum ()->getResourceNode ())));
587
+ $ forum = $ subject ->getCategory ()->getForum ();
588
+ $ isModerator = $ this ->authorization ->isGranted ('moderate ' , new ResourceCollection (array ($ forum ->getResourceNode ())));
538
589
539
590
if (!$ isModerator && $ this ->tokenStorage ->getToken ()->getUser () !== $ subject ->getCreator ()) {
540
591
throw new AccessDeniedException ();
@@ -545,8 +596,9 @@ public function editSubjectFormAction(Subject $subject)
545
596
return array (
546
597
'form ' => $ form ->createView (),
547
598
'subject ' => $ subject ,
548
- 'forumId ' => $ subject ->getCategory ()->getForum ()->getId (),
549
- '_resource ' => $ subject ->getCategory ()->getForum ()
599
+ 'forumId ' => $ forum ->getId (),
600
+ '_resource ' => $ forum ,
601
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
550
602
);
551
603
}
552
604
@@ -565,8 +617,9 @@ public function editSubjectFormAction(Subject $subject)
565
617
*/
566
618
public function editSubjectAction (Subject $ subject )
567
619
{
620
+ $ forum = $ subject ->getCategory ()->getForum ();
568
621
$ isModerator = $ this ->authorization ->isGranted (
569
- 'moderate ' , new ResourceCollection (array ($ subject -> getCategory ()-> getForum () ->getResourceNode ()))
622
+ 'moderate ' , new ResourceCollection (array ($ forum ->getResourceNode ()))
570
623
);
571
624
572
625
if (!$ isModerator && $ this ->tokenStorage ->getToken ()->getUser () !== $ subject ->getCreator ()) {
@@ -589,8 +642,9 @@ public function editSubjectAction(Subject $subject)
589
642
return array (
590
643
'form ' => $ form ->createView (),
591
644
'subjectId ' => $ subject ->getId (),
592
- 'forumId ' => $ subject ->getCategory ()->getForum ()->getId (),
593
- '_resource ' => $ subject ->getCategory ()->getForum ()
645
+ 'forumId ' => $ forum ->getId (),
646
+ '_resource ' => $ forum ,
647
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
594
648
);
595
649
}
596
650
@@ -784,7 +838,8 @@ public function moveSubjectFormAction(Subject $subject)
784
838
'_resource ' => $ forum ,
785
839
'categories ' => $ categories ,
786
840
'category ' => $ category ,
787
- 'subject ' => $ subject
841
+ 'subject ' => $ subject ,
842
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
788
843
);
789
844
}
790
845
@@ -813,7 +868,8 @@ public function moveMessageFormAction(Message $message, $page)
813
868
'category ' => $ category ,
814
869
'subject ' => $ subject ,
815
870
'pager ' => $ pager ,
816
- 'message ' => $ message
871
+ 'message ' => $ message ,
872
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
817
873
);
818
874
}
819
875
@@ -976,7 +1032,8 @@ public function replyMessageAction(Message $message)
976
1032
'subject ' => $ subject ,
977
1033
'form ' => $ form ->createView (),
978
1034
'message ' => $ message ,
979
- '_resource ' => $ forum
1035
+ '_resource ' => $ forum ,
1036
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
980
1037
);
981
1038
982
1039
}
@@ -1014,7 +1071,8 @@ public function quoteMessageAction(Message $message)
1014
1071
'subject ' => $ subject ,
1015
1072
'form ' => $ form ->createView (),
1016
1073
'message ' => $ message ,
1017
- '_resource ' => $ forum
1074
+ '_resource ' => $ forum ,
1075
+ 'workspace ' => $ forum ->getResourceNode ()->getWorkspace ()
1018
1076
);
1019
1077
}
1020
1078
0 commit comments