Skip to content

Commit eb95b12

Browse files
Format conversations before sending notifications.
1 parent 960ffc7 commit eb95b12

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

src/Controller/Admin/CheckerController.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use App\Model\ActivityModel;
1010
use App\Model\Admin\CheckerModel;
1111
use App\Model\CommunityNewsModel;
12+
use App\Utilities\ItemsPerPageTraits;
13+
use Doctrine\ORM\EntityManagerInterface;
1214
use InvalidArgumentException;
1315
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1416
use Symfony\Component\Form\FormError;
@@ -20,15 +22,19 @@
2022

2123
class CheckerController extends AbstractController
2224
{
25+
use ItemsPerPageTraits;
26+
2327
private const MESSAGES_REPORTED = 1;
2428
private const MESSAGES_PROCESSED = 2;
2529
private const MESSAGES_BLOCK_WORDS = 3;
2630

2731
private CheckerModel $checkerModel;
32+
private EntityManagerInterface $entityManager;
2833

29-
public function __construct(CheckerModel $checkerModel)
34+
public function __construct(CheckerModel $checkerModel, EntityManagerInterface $entityManager)
3035
{
3136
$this->checkerModel = $checkerModel;
37+
$this->entityManager = $entityManager;
3238
}
3339

3440
/**
@@ -197,7 +203,7 @@ private function getSubmenuItems()
197203
];
198204
}
199205

200-
private function handleMessages(Request $request, int $type)
206+
private function handleMessages(Request $request, int $type): Response
201207
{
202208
if (
203209
!$this->isGranted(Member::ROLE_ADMIN_CHECKER)
@@ -207,7 +213,9 @@ private function handleMessages(Request $request, int $type)
207213
}
208214

209215
$page = $request->query->get('page', 1);
210-
$limit = $request->query->get('limit', 10);
216+
/** @var Member $member */
217+
$member = $this->getUser();
218+
$limit = $this->getItemsPerPage($member);
211219

212220
switch ($type) {
213221
case self::MESSAGES_REPORTED:

src/Model/Admin/CheckerModel.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Model\Admin;
44

5+
use App\Doctrine\InFolderType;
56
use App\Doctrine\MessageStatusType;
67
use App\Doctrine\SpamInfoType;
78
use App\Entity\Message;
@@ -53,6 +54,9 @@ public function unmarkAsSpamByChecker(array $messageIds): void
5354
$message->setStatus(MessageStatusType::SEND);
5455
} else {
5556
$message->setStatus(MessageStatusType::CHECKED);
57+
if (strpos($message->getSpamInfo(), SpamInfoType::SPAM_BLOCKED_WORD) !== false) {
58+
$message->setFolder(InFolderType::NORMAL);
59+
}
5660
}
5761
$this->entityManager->persist($message);
5862
}

src/Model/ConversationModel.php

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ public function formatConversation(Message $message): Message
295295

296296
if ($found != 0) {
297297
$message->setSpamInfo(SpamInfoType::SPAM_BLOCKED_WORD);
298+
$message->setFolder(InFolderType::SPAM);
298299
$message->setStatus(MessageStatusType::CHECK);
299300
$message->setMessage($messageText);
300301
}

templates/admin/checker/messages.html.twig

+25-12
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@
33

44
{% block javascripts %}
55
<script type="text/javascript">
6-
$(window).on('load', function () {
7-
$('#checkAllNoSpam').click(function () {
8-
$('input:checkbox.checkableNoSpam').prop('checked', this.checked);
9-
});
10-
$('#checkAllSpam').click(function () {
11-
$('input:checkbox.checkableSpam').prop('checked', this.checked);
12-
});
6+
const checkAllSpam = document.getElementById('checkAllSpam');
7+
const checkAllNoSpam = document.getElementById('checkAllNoSpam');
8+
const spam = document.querySelectorAll('.checkableSpam');
9+
const noSpam = document.querySelectorAll('.checkableNoSpam');
10+
checkAllSpam.addEventListener('click', function() {
11+
const status = checkAllSpam.checked;
12+
spam.forEach((checkbox) => {checkbox.checked = status;});
13+
if (status) {
14+
checkAllNoSpam.checked = false;
15+
noSpam.forEach((checkbox) => {checkbox.checked = false;});
16+
}
17+
});
18+
checkAllNoSpam.addEventListener('click', function() {
19+
console.log(checkAllNoSpam.checked);
20+
const status = checkAllNoSpam.checked;
21+
noSpam.forEach((checkbox) => {checkbox.checked = status;});
22+
if (status) {
23+
checkAllSpam.checked = false;
24+
spam.forEach((checkbox) => {checkbox.checked = false;});
25+
}
1326
});
1427
</script>
1528
{% endblock %}
@@ -33,13 +46,13 @@
3346
<th>Receiver</th>
3447
<th>Created</th>
3548
<th>Comment</th>
36-
<th>{{ 'ok' | trans }}</th>
37-
<th>{{ 'spam' | trans }}</th>
49+
<th style="writing-mode: vertical-lr">ok</th>
50+
<th style="writing-mode: vertical-lr">spam</th>
3851
</tr>
3952
<tr>
40-
<th colspan="5"></th>
41-
<th><input type="checkbox" id="checkAllNoSpam"></th>
42-
<th><input type="checkbox" id="checkAllSpam"></th>
53+
<td colspan="5">&nbsp;</td>
54+
<td><div class="o-checkbox"><input type="checkbox" id="checkAllNoSpam" class="o-checkbox__input"><label class="o-checkbox__label"></label></div></td>
55+
<td><div class="o-checkbox"><input type="checkbox" id="checkAllSpam" class="o-checkbox__input"><label class="o-checkbox__label"></label></div></td>
4356
</tr>
4457
{% for message in reported.currentPageResults %}
4558
<tr>

0 commit comments

Comments
 (0)