Passed
Push — master ( fa3542...0a3787 )
by Mihail
05:11
created

Apps/View/Admin/default/comments/index.php (1 issue)

Labels
1
<?php
2
use Ffcms\Core\Helper\Date;
3
use Ffcms\Core\Helper\Simplify;
4
use Ffcms\Core\Helper\Text;
5
use Ffcms\Templex\Url\Url;
6
7
/** @var \Ffcms\Templex\Template\Template $this */
8
/** @var \Apps\ActiveRecord\CommentPost[]|\Illuminate\Support\Collection $records */
9
/** @var array $pagination */
10
11
$this->layout('_layouts/default', [
12
    'title' => __('Comments list'),
13
    'breadcrumbs' => [
14
        Url::to('main/index') => __('Main'),
15
        Url::to('widget/index') => __('Widgets'),
16
        __('Comments')
17
    ]
18
]);
19
?>
20
21
<?php $this->start('body') ?>
22
23
<?= $this->insert('comments/_tabs'); ?>
24
25
<h1><?= __('Comments list') ?></h1>
26
27
<?php
28
if (!$records || $records->count() < 1) {
29
    echo $this->bootstrap()->alert('warning', __('Comments is not founded'));
30
    $this->stop();
31
    return;
32
}
33
$items = [];
34
$moderateIsFound = false;
35
$table = $this->table(['class' => 'table table-striped'])
36
    ->head([
37
        ['text' => '#'],
38
        ['text' => __('Comment')],
39
        ['text' => __('Answers')],
40
        ['text' => __('Author')],
41
        ['text' => __('Page')],
42
        ['text' => __('Date')],
43
        ['text' => __('Actions')],
44
    ]);
45
46
foreach ($records as $item) {
47
    $message = Text::cut(\App::$Security->strip_tags($item->message), 0, 75);
0 ignored issues
show
It seems like App::Security->strip_tags($item->message) can also be of type array and null; however, parameter $text of Ffcms\Core\Helper\Text::cut() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
    $message = Text::cut(/** @scrutinizer ignore-type */ \App::$Security->strip_tags($item->message), 0, 75);
Loading history...
48
49
    $moderate = (bool)$item->moderate;
50
    // if even one moderate item is found - change global flag to true
51
    if ($moderate) {
52
        $moderateIsFound = true;
53
    }
54
55
    $btngrp = $this->bootstrap()->btngroup(['class' => 'btn-group btn-group-sm']);
56
57
    if ($moderate) {
58
        $btngrp->add('<i class="fa fa-eye-slash" style="color: #aa2222;"></i>', ['comments/display', ['comment', $item->id]], ['class' => 'btn btn-light', 'data-toggle' => 'tooltip', 'title' => __('Comment is hidden'), 'html' => true]);
59
    } else {
60
        $btngrp->add('<i class="fa fa-eye" style="color: #1a8007"></i>', ['comments/display', ['comment', $item->id]], ['class' => 'btn btn-light', 'data-toggle' => 'tooltip', 'title' => __('Comment is public'), 'html' => true]);
61
    }
62
63
    $btngrp->add('<i class="fa fa-list"></i>', ['comments/read', [$item->id]], ['class' => 'btn btn-primary', 'html' => true])
64
        ->add('<i class="fa fa-trash-o"></i>', ['comments/delete', ['comment', $item->id]], ['class' => 'btn btn-danger', 'html' => true]);
65
66
    $table->row([
67
        ['text' => $item->id],
68
        ['text' => Url::a(['comments/read', [$item->id]], $message), 'html' => true],
69
        ['text' => '<span class="badge badge-light">' . $item->getAnswerCount() . '</span>', 'html' => true],
70
        ['text' => Simplify::parseUserLink((int)$item->user_id, $item->guest_name, 'user/update'), 'html' => true],
71
        ['text' => '<a href="'.Url::stringUrl($item->app_name . '/comments/' . $item->app_relation_id).'" target="_blank">' . $item->app_name . '/' . $item->app_relation_id . '</a>', 'html' => true],
72
        ['text' => Date::convertToDatetime($item->created_at, Date::FORMAT_TO_HOUR)],
73
        ['text' => $btngrp->display(), 'html' => true
74
        ],
75
        'properties' => ['class' => 'checbox-row']
76
    ]);
77
}
78
79
$table->selectize(0, 'selected');
80
?>
81
82
<div class="table-responsive">
83
    <?= $table->display() ?>
84
</div>
85
86
<?= $this->javascript()->submitSelectizeTable('input[name="selected[]"]', 'selected', __('Delete selected'), ['comments/delete', ['comment']], ['class' => 'btn btn-danger']) ?>
87
<?php if ($moderateIsFound) {
88
    echo $this->javascript()->submitSelectizeTable('input[name="selected[]"]', 'selected', __('Publish'), ['comments/publish', ['comment']], ['class' => 'btn btn-warning']);
89
} ?>
90
91
<?= $this->bootstrap()->pagination($pagination['url'], ['class' => 'pagination justify-content-center'])
92
    ->size($pagination['total'], $pagination['page'], $pagination['step'])
93
    ->display(); ?>
94
95
96
<?php $this->stop() ?>