-
Notifications
You must be signed in to change notification settings - Fork 20
/
Module.php
66 lines (54 loc) · 1.81 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
<?php
namespace onmotion\survey;
use yii\base\UserException;
use yii\helpers\FileHelper;
use yii\helpers\Url;
use yii\web\NotFoundHttpException;
/**
* survey module definition class
*/
class Module extends \yii\base\Module
{
/**
* @inheritdoc
*/
public $controllerNamespace;
public $userClass;
public $params = [
'uploadsUrl' => null,
'uploadsPath' => null,
];
/**
* @inheritdoc
*/
public function init()
{
if (empty($this->controllerNamespace)) {
$this->controllerNamespace = \Yii::$app->controllerNamespace === 'backend\controllers'
? 'onmotion\survey\controllers'
: 'onmotion\survey\widgetControllers';
}
parent::init();
if (empty($this->params['uploadsUrl'])) {
throw new UserException("You must set uploadsUrl param in the config. Please see the documentation for more information.");
} else {
$this->params['uploadsUrl'] = rtrim($this->params['uploadsUrl'], '/');
}
if (empty($this->params['uploadsPath'])) {
throw new UserException("You must set uploadsPath param in the config. Please see the documentation for more information.");
} else {
$this->params['uploadsPath'] = FileHelper::normalizePath($this->params['uploadsPath']);
}
$this->userClass = \Yii::$app->user->identityClass;
\Yii::setAlias('@surveyRoot', __DIR__);
// set up i8n
if (empty(\Yii::$app->i18n->translations['survey'])) {
\Yii::$app->i18n->translations['survey'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@surveyRoot/messages',
];
}
$view = \Yii::$app->getView();
SurveyAsset::register($view);
}
}