Blame view

common/modules/comment/Module.php 2.79 KB
e608c5f7   Yarik   Comment added
1
  <?php
c05bf005   Yarik   Comment added
2
      
e608c5f7   Yarik   Comment added
3
      namespace common\modules\comment;
c05bf005   Yarik   Comment added
4
5
6
7
8
      
      use common\modules\comment\models\CommentModel;
      use common\modules\comment\models\RatingModel;
      use Yii;
      
e608c5f7   Yarik   Comment added
9
10
11
12
13
14
      /**
       * Class Module
       * @package common\modules\comment
       */
      class Module extends \yii\base\Module
      {
c05bf005   Yarik   Comment added
15
          
e608c5f7   Yarik   Comment added
16
          /**
c05bf005   Yarik   Comment added
17
           * @var string module name
e608c5f7   Yarik   Comment added
18
           */
c05bf005   Yarik   Comment added
19
20
          public static $name = 'artbox-comment';
          
e608c5f7   Yarik   Comment added
21
          /**
c05bf005   Yarik   Comment added
22
23
           * User identity class, default to common\models\User
           * @var string|null
e608c5f7   Yarik   Comment added
24
           */
c05bf005   Yarik   Comment added
25
26
          public $userIdentityClass = NULL;
          
e608c5f7   Yarik   Comment added
27
          /**
c05bf005   Yarik   Comment added
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
           * Comment model class, default to common\modules\models\CommentModel
           * @var string comment model class
           */
          public $commentModelClass = NULL;
          
          public $ratingModelClass = NULL;
          
          /**
           * This namespace will be used to load controller classes by prepending it to the controller
           * class name.
           * @var string the namespace that controller classes are in.
           */
          public $controllerNamespace = 'common\modules\comment\controllers';
          
          /**
           * @var \yii\db\Connection DB connection, default to \Yii::$app->db
           */
          public $db = NULL;
      
          /**
           * Key, used to encrypt and decrypt comment service data.
e608c5f7   Yarik   Comment added
49
           *
c05bf005   Yarik   Comment added
50
           * @var string Encryption key
e608c5f7   Yarik   Comment added
51
           */
c05bf005   Yarik   Comment added
52
53
          public static $encryptionKey = 'artbox-comment';
      
e608c5f7   Yarik   Comment added
54
          /**
c05bf005   Yarik   Comment added
55
56
57
           * Whether to enable comment rating or not.
           *
           * @var bool
e608c5f7   Yarik   Comment added
58
           */
c05bf005   Yarik   Comment added
59
60
          public static $enableRating = true;
          
e608c5f7   Yarik   Comment added
61
          /**
c05bf005   Yarik   Comment added
62
63
64
65
66
           * 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.
e608c5f7   Yarik   Comment added
67
68
69
           */
          public function init()
          {
c05bf005   Yarik   Comment added
70
71
72
73
74
75
76
77
78
              if($this->userIdentityClass === NULL) {
                  $this->userIdentityClass = Yii::$app->getUser()->identityClass;
              }
              if($this->commentModelClass === NULL) {
                  $this->commentModelClass = CommentModel::className();
              }
              if(self::$enableRating && $this->ratingModelClass === NULL) {
                  $this->ratingModelClass = RatingModel::className();
              }
e608c5f7   Yarik   Comment added
79
80
81
              if(\Yii::$app instanceof \yii\console\Application) {
                  $this->controllerNamespace = 'common\modules\comment\commands';
              }
c05bf005   Yarik   Comment added
82
              if($this->db === NULL) {
e608c5f7   Yarik   Comment added
83
                  $this->db = \Yii::$app->db;
e608c5f7   Yarik   Comment added
84
              }
c05bf005   Yarik   Comment added
85
86
              Yii::setAlias('@artbox-comment', __DIR__);
              parent::init();
e608c5f7   Yarik   Comment added
87
          }
c05bf005   Yarik   Comment added
88
89
          
      }