Blame view

models/Category.php 4.05 KB
593851ec   Alexey Boroda   First commit
1
2
  <?php
      
65dd0219   Alexey Boroda   -Bar tabs
3
      namespace artbox\weblog\models;
ee588281   Alexey Boroda   -Blog backend ready
4
5
  
      use artbox\core\models\Image;
593851ec   Alexey Boroda   First commit
6
      use yii\db\ActiveRecord;
65dd0219   Alexey Boroda   -Bar tabs
7
8
      use artbox\core\behaviors\LanguageBehavior;
      use artbox\core\models\Language;
593851ec   Alexey Boroda   First commit
9
10
      use yii\db\ActiveQuery;
      use yii\web\Request;
ee588281   Alexey Boroda   -Blog backend ready
11
  
593851ec   Alexey Boroda   First commit
12
13
      /**
       * This is the model class for table "blog_category".
ee588281   Alexey Boroda   -Blog backend ready
14
15
16
17
18
19
20
21
22
23
24
       *
       * @property integer        $id
       * @property integer        $sort
       * @property integer        $parent_id
       * @property boolean        $status
       * @property Article[]      $articles
       * @property CategoryLang[] $blogCategoryLangs
       * @property Language[]     $languages
       * @property Category       $parent
       * @property Image          $image
       * @property integer        $image_id
593851ec   Alexey Boroda   First commit
25
       * * From language behavior *
ee588281   Alexey Boroda   -Blog backend ready
26
27
28
29
30
31
32
       * @property CategoryLang   $lang
       * @property CategoryLang[] $langs
       * @property CategoryLang   $objectLang
       * @property string         $ownerKey
       * @property string         $langKey
       * @property CategoryLang[] $modelLangs
       * @property bool           $transactionStatus
593851ec   Alexey Boroda   First commit
33
34
35
36
37
38
       * @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 )
ee588281   Alexey Boroda   -Blog backend ready
39
       * @method CategoryLang[]    generateLangs()
593851ec   Alexey Boroda   First commit
40
41
42
43
       * @method void             loadLangs( Request $request )
       * @method bool             linkLangs()
       * @method bool             saveLangs()
       * @method bool             getTransactionStatus()
ee588281   Alexey Boroda   -Blog backend ready
44
45
       * @method bool loadWithLangs( Request $request )
       * @method bool saveWithLangs()
593851ec   Alexey Boroda   First commit
46
47
       * * End language behavior *
       * * From SaveImgBehavior *
ee588281   Alexey Boroda   -Blog backend ready
48
49
       * @property string|null    $imageFile
       * @property string|null    $imageUrl
593851ec   Alexey Boroda   First commit
50
51
52
53
       * @method string|null getImageFile( int $field )
       * @method string|null getImageUrl( int $field )
       * * End SaveImgBehavior
       */
ba196ec2   Alexey Boroda   -Blog in process
54
      class Category extends ActiveRecord
593851ec   Alexey Boroda   First commit
55
56
57
58
59
60
61
62
      {
          /**
           * @inheritdoc
           */
          public static function tableName()
          {
              return 'blog_category';
          }
ee588281   Alexey Boroda   -Blog backend ready
63
      
593851ec   Alexey Boroda   First commit
64
65
66
67
68
69
          /**
           * @inheritdoc
           */
          public function behaviors()
          {
              return [
593851ec   Alexey Boroda   First commit
70
71
72
                  'language' => [
                      'class' => LanguageBehavior::className(),
                  ],
593851ec   Alexey Boroda   First commit
73
74
              ];
          }
ee588281   Alexey Boroda   -Blog backend ready
75
      
593851ec   Alexey Boroda   First commit
76
77
78
79
80
81
82
83
84
85
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'sort',
                          'parent_id',
ee588281   Alexey Boroda   -Blog backend ready
86
                          'image_id',
593851ec   Alexey Boroda   First commit
87
88
89
90
91
92
93
94
                      ],
                      'integer',
                  ],
                  [
                      [ 'status' ],
                      'boolean',
                  ],
                  [
593851ec   Alexey Boroda   First commit
95
96
97
98
99
100
                      [ 'parent_id' ],
                      'default',
                      'value' => 0,
                  ],
              ];
          }
ee588281   Alexey Boroda   -Blog backend ready
101
      
593851ec   Alexey Boroda   First commit
102
103
104
105
106
107
108
109
110
111
112
113
114
          /**
           * @inheritdoc
           */
          public function attributeLabels()
          {
              return [
                  'id'        => 'ID',
                  'sort'      => 'Sort',
                  'image'     => 'Image',
                  'parent_id' => 'Parent ID',
                  'status'    => 'Status',
              ];
          }
ee588281   Alexey Boroda   -Blog backend ready
115
      
593851ec   Alexey Boroda   First commit
116
117
118
          /**
           * @return \yii\db\ActiveQuery
           */
ee588281   Alexey Boroda   -Blog backend ready
119
          public function getArticles()
593851ec   Alexey Boroda   First commit
120
          {
ee588281   Alexey Boroda   -Blog backend ready
121
              return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ])
593851ec   Alexey Boroda   First commit
122
123
                          ->viaTable('blog_article_to_category', [ 'blog_category_id' => 'id' ]);
          }
ee588281   Alexey Boroda   -Blog backend ready
124
125
126
127
      
          /**
           * @return \yii\db\ActiveQuery
           */
593851ec   Alexey Boroda   First commit
128
129
          public function getParent()
          {
ee588281   Alexey Boroda   -Blog backend ready
130
131
132
133
134
135
136
137
138
              return $this->hasOne(Category::className(), [ 'id' => 'parent_id' ]);
          }
      
          /**
           * @return \yii\db\ActiveQuery
           */
          public function getImage()
          {
              return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]);
593851ec   Alexey Boroda   First commit
139
140
          }
      }