forked from vova07/yii2-start-comments-module
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModule.php
More file actions
executable file
·119 lines (103 loc) · 3.77 KB
/
Module.php
File metadata and controls
executable file
·119 lines (103 loc) · 3.77 KB
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
<?php
namespace stepancher\comments;
use Yii;
use yii\base\InvalidConfigException;
/**
* Comments module.
*/
class Module extends \yii\base\Module
{
/**
* @inheritdoc
*/
public static $name = 'comments';
public $widgetViewPath='./';
/**
* Путь до папки модуля рейтинга
* @var string
*/
public $ratePath = '';
public $allowRate = false;
/**
* @var boolean Whether module is used for backend or not
*/
public $isBackend = false;
/**
* @var boolean Whether module is used for backend or not
*/
/**
* @var string Module author
*/
public static $author = 'stepancher';
public $options = [];
/**
* @inheritdoc
*/
public function init()
{
if (static::$name === null) {
throw new InvalidConfigException('The "name" property must be set.');
}
$this->ratePath = $this->ratePath ? $this->ratePath : $this->getDefaultModelRate();
if ($this->isBackend === true) {
$this->setViewPath('@' . static::$author . '/' . static::$name . '/views/backend');
if ($this->controllerNamespace === null) {
$this->controllerNamespace = static::$author . '\\' . static::$name . '\controllers\backend';
}
} else {
$this->setViewPath('@' . static::$author . '/' . static::$name . '/views/frontend');
if ($this->controllerNamespace === null) {
$this->controllerNamespace = static::$author . '\\' . static::$name . '\controllers\frontend';
}
}
//устанавливаем опции
$this->options = array_merge(self::getDefaultOptions(), $this->options);
parent::init();
}
/**
* Get default model Rating
*/
protected function getDefaultModelRate()
{
return '\\ubasma\\rating\\models\\';
}
/**
* Translates a message to the specified language.
*
* This is a shortcut method of [[\yii\i18n\I18N::translate()]].
*
* The translation will be conducted according to the message category and the target language will be used.
*
* You can add parameters to a translation message that will be substituted with the corresponding value after
* translation. The format for this is to use curly brackets around the parameter name as you can see in the following example:
*
* ```php
* $username = 'Alexander';
* echo \Yii::t('app', 'Hello, {username}!', ['username' => $username]);
* ```
*
* Further formatting of message parameters is supported using the [PHP intl extensions](http://www.php.net/manual/en/intro.intl.php)
* message formatter. See [[\yii\i18n\I18N::translate()]] for more details.
*
* @param string $category the message category.
* @param string $message the message to be translated.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en-US`, `en`). If this is null, the current
* [[\yii\base\Application::language|application language]] will be used.
*
* @return string the translated message.
*/
public static function t($category, $message, $params = [], $language = null)
{
return Yii::t(static::$author . '/' . $category, $message, $params, $language);
}
/**
* Параметры по умолчанию
* @return array
*/
public static function getDefaultOptions(){
return [
'comments-order' => ['created_at' => SORT_DESC, 'parent_id' => SORT_ASC]
];
}
}