-
Notifications
You must be signed in to change notification settings - Fork 2
/
Module.php
179 lines (148 loc) · 4.27 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
namespace wdmg\comments;
/**
* Yii2 Comments
*
* @category Module
* @version 2.0.0
* @author Alexsander Vyshnyvetskyy <[email protected]>
* @link https://github.com/wdmg/yii2-comments
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License
*
*/
use wdmg\helpers\ArrayHelper;
use Yii;
use wdmg\base\BaseModule;
/**
* comments module definition class
*/
class Module extends BaseModule
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'wdmg\comments\controllers';
/**
* {@inheritdoc}
*/
public $defaultRoute = 'comments/index';
/**
* @var string, the name of module
*/
public $name = "Comments";
/**
* @var string, the description of module
*/
public $description = "Tree comments system";
/**
* The default frontend controller
*
* @var string
*/
public $defaultController = "admin/comments/default";
/**
* The default routes to default controller in frontend.
*
* @var string or array, use "/" - for root
*/
public $baseRoute = "/comments";
/**
* Default layout for listing comments in frontend.
*
* @var string
*/
public $defaultListView = '@vendor/wdmg/yii2-comments/widgets/views/_list';
/**
* Default layout for outputting the form for adding / editing comments to the frontend.
*
* @var string
*/
public $defaultFormView = '@vendor/wdmg/yii2-comments/widgets/views/_form';
/**
* The time during which the comment is available for editing by its author.
*
* @var int, in seconds. Use `0` for disable option.
*/
public $editCommentTimeout = 300; // (5 min.)
/**
* The time during which the comment is available for removal by the author.
*
* @var int, in seconds. Use `0` for disable option.
*/
public $deleteCommentTimeout = 3600; // (1 hour)
/**
* Moderate all new comments.
*
* @var bool, if `true` - all new comments be marked as awaiting moderation status.
*/
public $newCommentsModeration = true;
/**
* Auto approve all new comments from registered users.
*
* @var bool, if `true` - all new comments from registered users be marked as published
*/
public $approveFromRegistered = true;
/**
* @var string the module version
*/
private $version = "2.0.0";
/**
* @var integer, priority of initialization
*/
private $priority = 8;
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// Set version of current module
$this->setVersion($this->version);
// Set priority of current module
$this->setPriority($this->priority);
}
/**
* {@inheritdoc}
*/
public function dashboardNavItems($options = null)
{
$items = [
'label' => $this->name,
'url' => [$this->routePrefix . '/'. $this->id],
'icon' => 'fa fa-fw fa-comments',
'active' => in_array(\Yii::$app->controller->module->id, [$this->id])
];
if (!is_null($options)) {
if (isset($options['count'])) {
$items['label'] .= '<span class="badge badge-default float-right">' . $options['count'] . '</span>';
unset($options['count']);
}
if (is_array($options))
$items = ArrayHelper::merge($items, $options);
}
return $items;
}
/**
* {@inheritdoc}
*/
public function bootstrap($app)
{
parent::bootstrap($app);
// Configure comments component
$app->setComponents([
'comments' => [
'class' => \wdmg\comments\components\Comments::class
]
]);
// UrlManager rules for frontend
if (!$this->isBackend()) {
$app->getUrlManager()->addRules([
[
'pattern' => (($this->baseRoute) ? $this->baseRoute : '/comments') . '/<action>',
'route' => (($this->defaultController) ? $this->defaultController : 'comments/default') . '/<action>'
]
], true);
}
}
}