Skip to content

Commit 0b5653c

Browse files
committed
Merge branch '5.x-stable' of https://github.com/claroline/ForumBundle into 5.x-stable
2 parents f789952 + 924977d commit 0b5653c

15 files changed

+188
-14
lines changed

Event/Log/CreateMessageEvent.php

+71-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
use Claroline\CoreBundle\Event\Log\AbstractLogResourceEvent;
1515
use Claroline\ForumBundle\Entity\Message;
16+
use Claroline\CoreBundle\Event\Log\NotifiableInterface;
1617

17-
class CreateMessageEvent extends AbstractLogResourceEvent
18+
class CreateMessageEvent extends AbstractLogResourceEvent implements NotifiableInterface
1819
{
1920
const ACTION = 'resource-claroline_forum-create_message';
2021

@@ -23,6 +24,8 @@ class CreateMessageEvent extends AbstractLogResourceEvent
2324
*/
2425
public function __construct(Message $message)
2526
{
27+
$this->message = $message;
28+
2629
$details = array(
2730
'message' => array(
2831
'id' => $message->getId()
@@ -48,4 +51,71 @@ public static function getRestriction()
4851
{
4952
return array(self::DISPLAYED_WORKSPACE, self::DISPLAYED_ADMIN);
5053
}
54+
55+
/**
56+
* Get if event is allowed to create notification or not
57+
*
58+
* @return boolean
59+
*/
60+
public function isAllowedToNotify()
61+
{
62+
return true;
63+
}
64+
65+
public function getSendToFollowers()
66+
{
67+
return true;
68+
}
69+
70+
/**
71+
* Get includeUsers array of user ids.
72+
*
73+
* @return array
74+
*/
75+
public function getIncludeUserIds()
76+
{
77+
return array();
78+
}
79+
80+
/**
81+
* Get excludeUsers array of user ids.
82+
*
83+
* @return array
84+
*/
85+
public function getExcludeUserIds()
86+
{
87+
return array();
88+
}
89+
90+
/**
91+
* Get actionKey string.
92+
*
93+
* @return string
94+
*/
95+
public function getActionKey()
96+
{
97+
return $this::ACTION;
98+
}
99+
/**
100+
* Get iconKey string.
101+
*
102+
* @return string
103+
*/
104+
public function getIconKey()
105+
{
106+
return "forum";
107+
}
108+
109+
/**
110+
* Get details
111+
*
112+
* @return array
113+
*/
114+
public function getNotificationDetails()
115+
{
116+
$details = $this->details;
117+
$details['forum']['name'] = $this->message->getSubject()->getCategory()->getForum()->getResourceNode()->getName();
118+
119+
return $details;
120+
}
51121
}

Listener/NotificationListener.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Claroline\ForumBundle\Listener;
4+
5+
use Claroline\CoreBundle\Event\Log\CreateFormResourceEvent;
6+
use Icap\NotificationBundle\Event\Notification\NotificationCreateDelegateViewEvent;
7+
use Symfony\Component\DependencyInjection\ContainerAware;
8+
use JMS\DiExtraBundle\Annotation as DI;
9+
10+
/**
11+
* @DI\Service()
12+
*/
13+
class NotificationListener extends ContainerAware
14+
{
15+
/**
16+
* Constructor.
17+
*
18+
* @DI\InjectParams({
19+
* "templating" = @DI\Inject("templating")
20+
* })
21+
*/
22+
public function __construct(
23+
$templating
24+
)
25+
{
26+
$this->templating = $templating;
27+
}
28+
29+
/**
30+
* @param NotificationUserParametersEvent $event
31+
*
32+
* @DI\Observe("create_notification_item_resource-claroline_forum-create_message")
33+
*/
34+
public function onCreateNotificationItem(NotificationCreateDelegateViewEvent $event)
35+
{
36+
$notificationView = $event->getNotificationView();
37+
$notification = $notificationView->getNotification();
38+
$content = $this->templating->render(
39+
'ClarolineForumBundle:Notification:notification.html.twig',
40+
array(
41+
'notification' => $notification,
42+
'status' => $notificationView->getStatus(),
43+
'systemName' => $event->getSystemName()
44+
)
45+
);
46+
$event->setResponseContent($content);
47+
$event->stopPropagation();
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* This file is part of the Claroline Connect package
4+
*
5+
* (c) Claroline Consortium <[email protected]>
6+
*/
7+
8+
namespace Claroline\ForumBundle\Listener;
9+
10+
use Claroline\CoreBundle\Event\Notification\NotificationUserParametersEvent;
11+
use JMS\DiExtraBundle\Annotation as DI;
12+
13+
/**
14+
* @DI\Service()
15+
*/
16+
class NotificationUserParametersListener
17+
{
18+
/**
19+
* @param NotificationUserParametersEvent $event
20+
*
21+
* @DI\Observe("icap_notification_user_parameters_event")
22+
*/
23+
public function onGetTypesForParameters(NotificationUserParametersEvent $event)
24+
{
25+
$event->addTypes("forum");
26+
}
27+
}

Repository/ForumRepository.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ public function findCategories(Forum $forum, $getQuery = false)
7979
{
8080
$dql = "
8181
SELECT c.id as id,
82-
count(m) as count_messages,
82+
count(s) as count_subjects,
8383
c.name as name
8484
FROM Claroline\ForumBundle\Entity\Category c
8585
LEFT JOIN c.subjects s
86-
LEFT JOIN s.messages m
8786
JOIN c.forum forum
8887
WHERE forum.id = :forumId
8988
GROUP BY c

Resources/translations/forum.en.yml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ started_by: Initiated by
3939
stick: Stick
4040
stuck: Stuck
4141
subject: Topic
42+
subjects: Topics
4243
subjets_per_page: Subjects per page
4344
subscribe_mail_list: Subscribe to notifications
4445
unstick: Unstick

Resources/translations/forum.es.yml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ started_by: 'Iniciado por'
3838
stick: Anclar
3939
stuck: Anclado
4040
subject: Tema
41+
subjects: Temas
4142
subjets_per_page: 'Temas por pagina'
4243
subscribe_mail_list: 'Suscríbase a las notificaciones'
4344
unstick: Desanclar

Resources/translations/forum.fr.yml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ started_by: Initié par
3939
stick: Épingler
4040
stuck: Épinglé
4141
subject: Sujet
42+
subjects: Sujets
4243
subjets_per_page: Sujets par page
4344
subscribe_mail_list: Recevoir les notifications
4445
unstick: Désépingler
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
forum: Forum
2+
resource-claroline_forum-create_message: A new message was posted in the forum forum <a href="%url%"> %forum% </a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
forum: Foro
2+
resource-claroline_forum-create_message: claroline_forum
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
forum: Forum
2+
resource-claroline_forum-create_message: Un nouveau message a été posté dans le forum <a href="%url%"> %forum% </a>

Resources/views/Forum/messages.html.twig

+6-5
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
</table>
138138
<div>
139139
{{ renderPager(subject.getId(), pager, max) }}
140-
140+
141141
{% if canPost %}
142142
<btn id='fast-reply-btn' class='btn btn-primary pull-right'>{{ 'fast_reply'|trans({}, 'forum')}}</btn>
143143
{% endif %}
@@ -148,7 +148,8 @@
148148
<div>
149149
{% if not subject.isClosed() %}
150150
<textarea class="forum-answer claroline-tiny-mce hide"></textarea>
151-
{{ form_widget(form._token) }}
151+
{# something may be wrong here because _token doesn't always exists #}
152+
{% if form._token is defined %} {{ form_widget(form._token) }} {% endif %}
152153
{% endif %}
153154
</div>
154155
{% endif %}
@@ -182,7 +183,7 @@
182183
});
183184
})();
184185
</script>
185-
186+
186187
{% if canPost %}
187188
<script>
188189
(function () {
@@ -216,7 +217,7 @@
216217
})();
217218
</script>
218219
{% endif %}
219-
220+
220221
{% if isModerator %}
221222
<script>
222223
function createValidationBox() {
@@ -249,7 +250,7 @@
249250
});
250251
</script>
251252
{% endif %}
252-
253+
253254
{% if canPost %}
254255
<script>
255256
(function () {

Resources/views/Forum/subjects.html.twig

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
{{ subject['subject_created']|intl_date_format() }}
129129
</td>
130130
<td>
131-
{{ subject['count_messages'] }}
131+
{{ subject['count_messages'] - 1 }}
132132
</td>
133133
<td>
134134
{% if lastMessages[subject['id']] is defined and lastMessages[subject['id']] is not empty %}
@@ -145,7 +145,7 @@
145145
{{ lastMessages[subject['id']].getAuthor() }}
146146
<br>
147147
{{ lastMessages[subject['id']].getModificationDate()|intl_date_format() }}
148-
148+
149149
{% if isNew %}
150150
</b>
151151
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends 'IcapNotificationBundle:Templates:notification.html.twig' %}
2+
3+
{% block notificationText %}
4+
{% if notification.userId is not empty and notification.details.doer is defined %}
5+
<a href="{{ path('claro_public_profile_view', {'publicUrl' : notification.userId}) }}"><strong>{{ notification.details.doer.firstName ~ ' ' ~ notification.details.doer.lastName }}</strong></a>
6+
{% else %}
7+
<strong>{{ systemName }}</strong>
8+
{% endif %}
9+
10+
{% if notification.details is defined and notification.details.forum.name is defined %}
11+
{% set url = path('claro_forum_messages', {'subject': notification.details.subject.id}) %}
12+
{{ 'resource-claroline_forum-create_message'|trans({'%forum%': notification.details.forum.name, '%url%': url}, 'notification')|raw }}
13+
{% endif %}
14+
{% endblock %}

Resources/views/index.html.twig

+7-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
{% endif %}
3636
{% endif %}
3737
{% endif %}
38+
{% render controller(
39+
'IcapNotificationBundle:FollowerResource:renderForm',
40+
{'resourceId': _resource.resourceNode.id, 'resourceClass': _resource.resourceNode.class}
41+
) %}
3842
</div>
3943
<div class="col-md-4">
4044
<div class="input-group">
@@ -67,7 +71,7 @@
6771
{{ 'activate_global_notifications'|trans({}, 'forum') }}
6872
</a>
6973
{% endif %}
70-
74+
7175
{% if hasSubscribed %}
7276
<a class="btn btn-primary" href="{{ path('claro_forum_unsubscribe', {'forum': _resource.getId()}) }}">
7377
{{ 'unsubscribe_mail_list'|trans({}, 'forum') }}
@@ -86,7 +90,7 @@
8690
<thead>
8791
<tr>
8892
<th>{{ 'category'|trans({}, 'forum') }}</th>
89-
<th>{{ 'messages'|trans({}, 'forum') }} </th>
93+
<th>{{ 'subjects'|trans({}, 'forum') }} </th>
9094
<th>{{ 'last_message'|trans({}, 'forum') }}</th>
9195
{% if isModerator %}
9296
<th></th>
@@ -109,7 +113,7 @@
109113
{% endif %}
110114
<br>
111115
<td>
112-
{{ category['count_messages'] }}
116+
{{ category['count_subjects'] }}
113117
</td>
114118
<td>
115119
{{ category['last_message_author'] }}

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"require": {
1616
"php": ">=5.4.1",
1717
"claroline/core-bundle": "~5.0",
18-
"claroline/message-bundle": "~5.0"
18+
"claroline/message-bundle": "~5.0",
19+
"icap/notification-bundle": "~5.0"
1920
},
2021
"autoload": {
2122
"psr-0": { "Claroline\\ForumBundle": "" }

0 commit comments

Comments
 (0)