Blame view

Module.php 3.41 KB
a2cde075   Yarik   first commit
1
2
  <?php
      
faff2c48   Yarik   Artbox comment cr...
3
      namespace artbox\webcomment;
a2cde075   Yarik   first commit
4
      
faff2c48   Yarik   Artbox comment cr...
5
6
      use artbox\webcomment\models\CommentModel;
      use artbox\webcomment\models\RatingModel;
a2cde075   Yarik   first commit
7
      use Yii;
faff2c48   Yarik   Artbox comment cr...
8
      use yii\base\InvalidConfigException;
a2cde075   Yarik   first commit
9
      use yii\console\Application;
faff2c48   Yarik   Artbox comment cr...
10
      
a2cde075   Yarik   first commit
11
12
      /**
       * Class Module
faff2c48   Yarik   Artbox comment cr...
13
       *
a2cde075   Yarik   first commit
14
15
16
17
18
       * @package artweb\artbox\comment
       */
      class Module extends \yii\base\Module
      {
          
a2cde075   Yarik   first commit
19
20
21
22
23
24
          /**
           * @var string module name
           */
          public static $name = 'artbox-comment';
          
          /**
faff2c48   Yarik   Artbox comment cr...
25
26
           * User identity class, default to artbox\order\models\Customer
           *
a2cde075   Yarik   first commit
27
28
           * @var string|null
           */
faff2c48   Yarik   Artbox comment cr...
29
          public $userIdentityClass = null;
a2cde075   Yarik   first commit
30
31
          
          /**
faff2c48   Yarik   Artbox comment cr...
32
33
           * Comment model class, default to artbox\webcomment\modules\models\CommentModel
           *
a2cde075   Yarik   first commit
34
35
           * @var string comment model class
           */
faff2c48   Yarik   Artbox comment cr...
36
37
38
          public $commentModelClass = null;
      
          public $ratingModelClass = null;
a2cde075   Yarik   first commit
39
40
41
42
          
          /**
           * This namespace will be used to load controller classes by prepending it to the controller
           * class name.
faff2c48   Yarik   Artbox comment cr...
43
           *
a2cde075   Yarik   first commit
44
45
           * @var string the namespace that controller classes are in.
           */
faff2c48   Yarik   Artbox comment cr...
46
          public $controllerNamespace = 'artbox\webcomment\controllers';
a2cde075   Yarik   first commit
47
48
49
50
          
          /**
           * @var \yii\db\Connection DB connection, default to \Yii::$app->db
           */
faff2c48   Yarik   Artbox comment cr...
51
          public $db = null;
a2cde075   Yarik   first commit
52
53
54
          
          /**
           * Key, used to encrypt and decrypt comment service data.
faff2c48   Yarik   Artbox comment cr...
55
           *
a2cde075   Yarik   first commit
56
57
58
59
60
61
           * @var string Encryption key
           */
          public static $encryptionKey = 'artbox-comment';
          
          /**
           * Whether to enable comment rating or not.
faff2c48   Yarik   Artbox comment cr...
62
           *
a2cde075   Yarik   first commit
63
64
           * @var bool
           */
fd5e93c2   Yarik   Artbox comment pr...
65
66
67
68
69
70
71
72
          public $enableRating = true;
      
          /**
           * Whether to enable comment premoderate or not.
           *
           * @var bool
           */
          public $enablePremoderate = true;
a2cde075   Yarik   first commit
73
74
75
76
77
78
79
80
81
82
          
          /**
           * Initializes the module.
           * This method is called after the module is created and initialized with property values
           * given in configuration. The default implementation will initialize
           * [[controllerNamespace]] if it is not set. If you override this method, please make sure
           * you call the parent implementation.
           */
          public function init()
          {
faff2c48   Yarik   Artbox comment cr...
83
              if ($this->commentModelClass === null) {
a2cde075   Yarik   first commit
84
85
                  $this->commentModelClass = CommentModel::className();
              }
fd5e93c2   Yarik   Artbox comment pr...
86
              if ($this->enableRating && $this->ratingModelClass === null) {
a2cde075   Yarik   first commit
87
88
                  $this->ratingModelClass = RatingModel::className();
              }
faff2c48   Yarik   Artbox comment cr...
89
90
91
              if (\Yii::$app instanceof Application) {
                  $this->controllerNamespace = 'artbox\webcomment\commands';
              } elseif ($this->userIdentityClass === null) {
395a7b37   Yarik   Module fix
92
                  $this->userIdentityClass = Yii::$app->getUser()->identityClass;
a2cde075   Yarik   first commit
93
              }
faff2c48   Yarik   Artbox comment cr...
94
              if ($this->db === null) {
a2cde075   Yarik   first commit
95
96
                  $this->db = \Yii::$app->db;
              }
faff2c48   Yarik   Artbox comment cr...
97
98
99
              if (!Yii::getAlias('@artbox/webcomment', false)) {
                  Yii::setAlias('@artbox/webcomment', __DIR__);
              }
a2cde075   Yarik   first commit
100
101
              parent::init();
          }
faff2c48   Yarik   Artbox comment cr...
102
103
104
105
106
107
108
109
110
111
      
          /**
           * Prompt to register current module
           *
           * @throws \yii\base\InvalidConfigException
           */
          public static function registerMe()
          {
              throw new InvalidConfigException(\Yii::t('artbox-comment', 'Register artbox-comment module'));
          }
a2cde075   Yarik   first commit
112
113
          
      }