Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

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

Check for conflicting imported classes with local classes.

Bug Major
1
<?php
2
3
use Apps\ActiveRecord\ContentCategory;
4
use Ffcms\Core\Helper\Date;
5
use Ffcms\Core\Helper\Type\Str;
6
use Ffcms\Templex\Url\Url;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Url. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
8
/** @var \Apps\ActiveRecord\Content[]|\Illuminate\Support\Collection $records */
9
/** @var array $pagination */
10
/** @var \Ffcms\Templex\Template\Template $this */
11
/** @var string $type */
12
13
$this->layout('_layouts/default', [
14
    'title' => __('Contents'),
15
    'breadcrumbs' => [
16
        Url::to('main/index') => __('Main'),
17
        Url::to('application/index') => __('Applications'),
18
        __('Contents')
19
    ]
20
]);
21
?>
22
23
<?php $this->start('body') ?>
24
25
<?= $this->insert('content/_tabs') ?>
26
27
<h1><?= __('Content list') ?></h1>
28
<div class="row">
29
    <div class="col-md-6">
30
        <?php
31
        if ($type === 'trash') {
32
            echo Url::a(['content/clear'], '<i class="fa fa-minus"></i> ' . __('Remove all'), ['class' => 'btn btn-danger', 'html' => true]);
33
        } else {
34
            echo Url::a(['content/update'], '<i class="fa fa-plus"></i> ' . __('Add content'), ['class' => 'btn btn-primary', 'html' => true]);
35
        }
36
        ?>
37
    </div>
38
    <div class="col-md-6">
39
        <div class="pull-right">
40
            <div class="btn-group" role="group">
41
                <button id="btnCategories" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
42
                    <i class="fa fa-table"></i> <?= __('Categories') ?>
43
                </button>
44
                <div class="dropdown-menu" aria-labelledby="btnCategories">
45
                    <?php
46
                    foreach (ContentCategory::getSortedCategories() as $id=>$name) {
47
                        echo Url::a(['content/index', null, ['type' => $id]], $name, ['class' => 'dropdown-item']);
48
                    }
49
                    ?>
50
                </div>
51
            </div>
52
            <div class="btn-group" role="group">
53
                <button id="btnFilters" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
54
                    <i class="fa fa-filter"></i> <?= __('Filters') ?>
55
                </button>
56
                <div class="dropdown-menu" aria-labelledby="btnCategories">
57
                    <?= Url::a(['content/index', null, ['type' => 'all']], '<i class="fa fa-list"></i> ' . __('All'), ['class' => 'dropdown-item', 'html' => true]) ?>
58
                    <?= Url::a(['content/index', null, ['type' => 'moderate']], '<i class="fa fa-exclamation"></i> ' . __('Moderate'), ['class' => 'dropdown-item', 'html' => true]) ?>
59
                    <?= Url::a(['content/index', null, ['type' => 'trash']], '<i class="fa fa-trash"></i> ' . __('Trash'), ['class' => 'dropdown-item', 'html' => true]) ?>
60
                </div>
61
            </div>
62
        </div>
63
    </div>
64
</div>
65
66
<?php
67
if ($records->count() < 1) {
68
    echo $this->bootstrap()->alert('warning', __('Content not found'));
69
    $this->stop();
70
    return;
71
}
72
73
$table = $this->table(['class' => 'table table-striped'])
74
    ->head([
75
        ['text' => '#'],
76
        ['text' => __('Actions'), 'properties' => ['class' => 'text-center']],
77
        ['text' => __('Title')],
78
        ['text' => '<i class="fa fa-comments"></i>', 'html' => true],
79
        ['text' => __('Date')]
80
    ]);
81
82
$hiddenExist = false;
83
foreach ($records as $content) {
84
    // prevent display items with broken category id
85
    if (!$content->category) {
86
        continue;
87
    }
88
    $frontLink = \App::$Alias->scriptUrl . '/content/read';
89
    if (!Str::likeEmpty($content->category->path)) {
90
        $frontLink .= '/' . $content->category->path;
91
    }
92
    $frontLink .= '/' . $content->path;
93
94
    $actionMenu = $this->bootstrap()->btngroup(['class' => 'btn-group btn-group-sm', 'dropdown' => ['class' => 'btn-group btn-group-sm']], 2);
95
    if (!(bool)$content->display) {
96
        $actionMenu->add('<i class="fa fa-eye-slash" style="color: #ff0000;"></i>', ['content/display', [$content->id], ['status' => 1]], [
97
            'html' => true,
98
            'class' => 'btn btn-light',
99
            'data-toggle' => 'tooltip',
100
            'title' =>  __('Content hidden from regular users')
101
        ]);
102
    } else {
103
        $actionMenu->add('<i class="fa fa-eye" style="color: #008000;"></i>', ['content/display', [$content->id], ['status' => 0]], [
104
            'html' => true,
105
            'class' => 'btn btn-light',
106
            'data-toggle' => 'tooltip',
107
            'title' =>  __('Content is public')
108
        ]);
109
    }
110
111
    if (!(bool)$content->important) {
112
        $actionMenu->add('<i class="fa fa-star-o"></i>', ['content/important', [$content->id], ['status' => 1]], [
113
            'html' => true,
114
            'class' => 'btn btn-light',
115
            'data-toggle' => 'tooltip',
116
            'title' =>  __('Content are not in favorite top. Mark as favorite?')
117
        ]);
118
    } else {
119
        $actionMenu->add('<i class="fa fa-star" style="color: #c7a922"></i>', ['content/important', [$content->id], ['status' => 0]], [
120
            'html' => true,
121
            'class' => 'btn btn-light',
122
            'data-toggle' => 'tooltip',
123
            'title' =>  __('Content marked as favorite. Unset this?')
124
        ]);
125
    }
126
127
    $actionMenu->add(__('Edit'), ['content/update', [$content->id]]);
128
    $actionMenu->add(__('See as user'), [$frontLink], ['target' => '_blank']);
129
130
    $actionMenu->add(__('Clone'), ['content/update', null, ['from' => $content->id]]);
131
132
    if ($type === 'trash') {
133
        $actionMenu->add(__('Restore'), ['content/restore', [$content->id]]);
134
    } else {
135
        $actionMenu->add(__('Delete'), ['content/delete', [$content->id]]);
136
    }
137
138
    // set hidden trigger to true if exist hidden items
139
    if (!$content->display) {
140
        $hiddenExist = true;
141
    }
142
143
    $contentInfo = '<div>' . Url::a(['content/update', [$content->id]], $content->getLocaled('title')) . '</div>';
144
    $contentInfo .= '<div class="small">';
145
    $contentInfo .= __('Category: <a href="%url%">%name%</a>', ['name' => $content->category->getLocaled('title'), 'url' => Url::to('content/categoryupdate', [$content->category_id])]);
146
    $contentInfo .= '</div>';
147
148
    $table->row([
149
        ['text' => $content->id, 'html' => true, '!secure' => true],
150
        ['text' => $actionMenu->display(), 'html' => true, 'properties' => ['class' => 'text-center']],
151
        ['text' => $contentInfo, 'html' => true],
152
        ['text' => $content->commentPosts->count()],
153
        ['text' => Date::convertToDatetime($content->updated_at, Date::FORMAT_TO_SECONDS)]
154
    ]);
155
}
156
$table->selectize(0, 'selected');
157
?>
158
159
<div class="table-responsive">
160
    <?= $table->display() ?>
161
</div>
162
163
<?php if ($type !== 'trash') {
164
    echo $this->javascript()->submitSelectizeTable('input[name="selected[]"]', 'selected', __('Delete selected'), ['content/globdelete'], ['class' => 'btn btn-danger']);
165
} ?>
166
<?php if ($hiddenExist) {
167
    echo $this->javascript()->submitSelectizeTable('input[name="selected[]"]', 'selected', __('Publish'), ['content/publish'], ['class' => 'btn btn-warning']);
168
} ?>
169
170
<?= $this->bootstrap()->pagination($pagination['url'], ['class' => 'pagination justify-content-center'])
171
    ->size($pagination['total'], $pagination['page'], $pagination['step'])
172
    ->display(); ?>
173
174
175
<?php $this->stop() ?>