Blame view

common/modules/rubrication/models/TaxGroup.php 5.52 KB
d8c1a2e0   Yarik   Big commit artbox
1
  <?php

36d1807a   Yarik   Big commit.
2
3
4
      

      namespace common\modules\rubrication\models;

      

d55d2fe0   Yarik   Multilanguage
5
      use common\modules\language\behaviors\LanguageBehavior;

36d1807a   Yarik   Big commit.
6
      use common\modules\product\models\Category;

d55d2fe0   Yarik   Multilanguage
7
8
9
10
      use yii\db\ActiveQuery;

      use yii\db\ActiveRecord;

      use yii\web\Request;

  

d8c1a2e0   Yarik   Big commit artbox
11
      /**

36d1807a   Yarik   Big commit.
12
       * This is the model class for table "{{%tax_group}}".

cc658b4c   Yarik   Big commit
13
14
15
16
17
18
19
20
21
22
23
24
       * @property integer     $tax_group_id

       * @property string      $alias

       * @property string      $name

       * @property string      $description

       * @property boolean     $is_filter

       * @property integer     $level

       * @property integer     $sort

       * @property boolean     $display

       * @property boolean     $is_menu

       * @property TaxOption[] $taxOptions

       * @property Category[]  $categories

       * @property TaxOption[] $options

d55d2fe0   Yarik   Multilanguage
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
       *

       * * From language behavior *

       * @property TaxGroupLang    $lang

       * @property TaxGroupLang[]  $langs

       * @property TaxGroupLang    $object_lang

       * @property string         $ownerKey

       * @property string         $langKey

       * @method string           getOwnerKey()

       * @method void             setOwnerKey(string $value)

       * @method string           getLangKey()

       * @method void             setLangKey(string $value)

       * @method ActiveQuery      getLangs()

       * @method ActiveQuery      getLang( integer $language_id )

       * @method TaxGroupLang[]    generateLangs()

       * @method void             loadLangs(Request $request, ActiveRecord[] $model_langs)

       * @method bool             linkLangs(ActiveRecord[] $model_langs)

       * @method bool             saveLangs(ActiveRecord[] $model_langs)

       * * End language behavior *

d8c1a2e0   Yarik   Big commit artbox
43
       */

36d1807a   Yarik   Big commit.
44
      class TaxGroup extends \yii\db\ActiveRecord

d8c1a2e0   Yarik   Big commit artbox
45
      {

cc658b4c   Yarik   Big commit
46
47
48
49
      

          /**

           * @var TaxOption[] $_options

           */

36d1807a   Yarik   Big commit.
50
51
52
53
54
55
56
57
58
59
60
61
62
63
          public $_options = [];

          

          /**

           * @inheritdoc

           */

          public function behaviors()

          {

              return [

                  'slug' => [

                      'class'         => 'common\behaviors\Slug',

                      'in_attribute'  => 'name',

                      'out_attribute' => 'alias',

                      'translit'      => true,

                  ],

d55d2fe0   Yarik   Multilanguage
64
65
66
                  'language' => [

                      'class' => LanguageBehavior::className(),

                  ],

36d1807a   Yarik   Big commit.
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
              ];

          }

          

          /**

           * @inheritdoc

           */

          public static function tableName()

          {

              return 'tax_group';

          }

          

          /**

           * @inheritdoc

           */

          public function rules()

          {

              return [

                  [

                      [

                          'name',

                      ],

                      'required',

                  ],

                  [

                      [

                          'description',

                      ],

                      'string',

                  ],

                  [

                      [

                          'is_filter',

                          'display',

                          'is_menu',

                      ],

                      'boolean',

                  ],

                  [

                      [

                          'level',

                          'sort',

                      ],

                      'integer',

                  ],

                  [

                      [

                          'alias',

                      ],

                      'string',

                      'max' => 50,

                  ],

                  [

                      [ 'name' ],

                      'string',

                      'max' => 255,

                  ],

                  [

                      [ 'categories' ],

                      'safe',

                  ],

              ];

          }

          

          /**

           * @inheritdoc

           */

          public function attributeLabels()

          {

              return [

                  'tax_group_id' => 'Tax Group ID',

                  'alias'        => 'Alias',

                  'name'         => 'Name',

                  'description'  => 'Description',

                  'is_filter'    => 'Use in filter',

                  'sort'         => 'Sort',

                  'display'      => 'Display',

                  'is_menu'      => 'Отображать в меню',

              ];

          }

          

          public function getCategories()

          {

              return $this->hasMany(Category::className(), [ 'category_id' => 'category_id' ])

                          ->viaTable('tax_group_to_category', [ 'tax_group_id' => 'tax_group_id' ]);

          }

          

          public function setCategories($values)

          {

              $this->categories = $values;

          }

          

          public function afterSave($insert, $changedAttributes)

          {

              $this->unlinkAll('categories', true);

              $categories = [];

cc658b4c   Yarik   Big commit
162
              if(!empty( $this->categories )) {

36d1807a   Yarik   Big commit.
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
                  $categories = Category::findAll($this->categories);

              }

              foreach($categories as $category) {

                  $this->link('categories', $category);

              }

          }

          

          /**

           * @return \yii\db\ActiveQuery

           */

          public function getOptions()

          {

              return $this->getTaxOptions();

          }

          

          public function getTaxOptions()

          {

              return $this->hasMany(TaxOption::className(), [ 'tax_group_id' => 'tax_group_id' ])

                          ->inverseOf('taxGroup');

d8c1a2e0   Yarik   Big commit artbox
182
          }

d8c1a2e0   Yarik   Big commit artbox
183
      }