Blame view

models/Article.php 5.94 KB
593851ec   Alexey Boroda   First commit
1
2
  <?php
      
65dd0219   Alexey Boroda   -Bar tabs
3
      namespace artbox\weblog\models;
3b1725bf   Alexey Boroda   -Bug with fill re...
4
  
ee588281   Alexey Boroda   -Blog backend ready
5
      use artbox\catalog\behaviors\ManyToManyBehavior;
3b1725bf   Alexey Boroda   -Bug with fill re...
6
      use artbox\catalog\models\Product;
ee588281   Alexey Boroda   -Blog backend ready
7
      use artbox\core\models\Image;
593851ec   Alexey Boroda   First commit
8
9
      use yii\behaviors\TimestampBehavior;
      use yii\db\ActiveRecord;
65dd0219   Alexey Boroda   -Bar tabs
10
11
      use artbox\core\behaviors\LanguageBehavior;
      use artbox\core\models\Language;
593851ec   Alexey Boroda   First commit
12
13
      use yii\db\ActiveQuery;
      use yii\web\Request;
3b1725bf   Alexey Boroda   -Bug with fill re...
14
  
593851ec   Alexey Boroda   First commit
15
16
      /**
       * This is the model class for table "blog_article".
ee588281   Alexey Boroda   -Blog backend ready
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
   
  *
  *@property integer             $id
       * @property Image         $image
       * @property integer       $created_at
       * @property integer       $updated_at
       * @property integer       $deleted_at
       * @property integer       $sort
       * @property boolean       $status
       * @property integer       $author_id
       * @property integer       $image_id
       * @property ArticleLang[] $blogArticleLangs
       * @property Language[]    $languages
       * @property Article[]     $relatedBlogArticles
       * @property Article[]     $articles
       * @property Category[]    $categories
       * @property Category      $category
       * @property Product[]     $products
       * @property Tag[]         $tags
593851ec   Alexey Boroda   First commit
36
       * * * From language behavior *
ee588281   Alexey Boroda   -Blog backend ready
37
38
39
40
41
42
43
       * @property ArticleLang   $lang
       * @property ArticleLang[] $langs
       * @property ArticleLang   $objectLang
       * @property string        $ownerKey
       * @property string        $langKey
       * @property ArticleLang[] $modelLangs
       * @property bool          $transactionStatus
593851ec   Alexey Boroda   First commit
44
45
46
47
48
49
       * @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 )
3b1725bf   Alexey Boroda   -Bug with fill re...
50
       * @method ArticleLang[]    generateLangs()
593851ec   Alexey Boroda   First commit
51
52
53
54
       * @method void             loadLangs( Request $request )
       * @method bool             linkLangs()
       * @method bool             saveLangs()
       * @method bool             getTransactionStatus()
ee588281   Alexey Boroda   -Blog backend ready
55
56
       * @method bool loadWithLangs( Request $request )
       * @method bool saveWithLangs()
593851ec   Alexey Boroda   First commit
57
       * * End language behavior *
ee588281   Alexey Boroda   -Blog backend ready
58
       * @method void linkMany( string $link, array $models )
593851ec   Alexey Boroda   First commit
59
       */
3b1725bf   Alexey Boroda   -Bug with fill re...
60
      class Article extends ActiveRecord
593851ec   Alexey Boroda   First commit
61
      {
ee588281   Alexey Boroda   -Blog backend ready
62
63
64
65
66
67
          public $categoryIds = [];
      
          public $tagIds = [];
      
          public $articleIds = [];
      
593851ec   Alexey Boroda   First commit
68
69
70
71
72
73
74
          /**
           * @inheritdoc
           */
          public static function tableName()
          {
              return 'blog_article';
          }
3b1725bf   Alexey Boroda   -Bug with fill re...
75
      
593851ec   Alexey Boroda   First commit
76
77
78
79
80
81
          public function behaviors()
          {
              return [
                  [
                      'class' => TimestampBehavior::className(),
                  ],
593851ec   Alexey Boroda   First commit
82
83
84
                  'language' => [
                      'class' => LanguageBehavior::className(),
                  ],
ee588281   Alexey Boroda   -Blog backend ready
85
86
87
                  [
                      'class' => ManyToManyBehavior::className(),
                  ],
593851ec   Alexey Boroda   First commit
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
              ];
          }
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'created_at',
                          'updated_at',
                          'deleted_at',
                          'sort',
                          'author_id',
ba196ec2   Alexey Boroda   -Blog in process
103
                          'image_id',
593851ec   Alexey Boroda   First commit
104
105
106
107
108
109
110
                      ],
                      'integer',
                  ],
                  [
                      [ 'status' ],
                      'boolean',
                  ],
593851ec   Alexey Boroda   First commit
111
112
              ];
          }
3b1725bf   Alexey Boroda   -Bug with fill re...
113
      
593851ec   Alexey Boroda   First commit
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
          /**
           * @inheritdoc
           */
          public function attributeLabels()
          {
              return [
                  'id'         => 'ID',
                  'image'      => 'Image',
                  'created_at' => 'Created At',
                  'updated_at' => 'Updated At',
                  'deleted_at' => 'Deleted At',
                  'sort'       => 'Sort',
                  'status'     => 'Status',
                  'author_id'  => 'Author ID',
              ];
          }
3b1725bf   Alexey Boroda   -Bug with fill re...
130
      
593851ec   Alexey Boroda   First commit
131
132
133
134
135
          /**
           * @return \yii\db\ActiveQuery
           */
          public function getRelatedBlogArticles()
          {
3b1725bf   Alexey Boroda   -Bug with fill re...
136
              return $this->hasMany(Article::className(), [ 'id' => 'related_blog_article_id' ])
593851ec   Alexey Boroda   First commit
137
138
                          ->viaTable('blog_article_to_article', [ 'blog_article_id' => 'id' ]);
          }
3b1725bf   Alexey Boroda   -Bug with fill re...
139
      
593851ec   Alexey Boroda   First commit
140
141
142
          /**
           * @return \yii\db\ActiveQuery
           */
ee588281   Alexey Boroda   -Blog backend ready
143
144
145
146
147
148
149
150
          public function getImage()
          {
              return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]);
          }
      
          /**
           * @return \yii\db\ActiveQuery
           */
3b1725bf   Alexey Boroda   -Bug with fill re...
151
          public function getArticles()
593851ec   Alexey Boroda   First commit
152
          {
3b1725bf   Alexey Boroda   -Bug with fill re...
153
              return $this->hasMany(Article::className(), [ 'id' => 'blog_article_id' ])
593851ec   Alexey Boroda   First commit
154
155
                          ->viaTable('blog_article_to_article', [ 'related_blog_article_id' => 'id' ]);
          }
3b1725bf   Alexey Boroda   -Bug with fill re...
156
      
593851ec   Alexey Boroda   First commit
157
158
159
          /**
           * @return \yii\db\ActiveQuery
           */
ee588281   Alexey Boroda   -Blog backend ready
160
          public function getCategories()
593851ec   Alexey Boroda   First commit
161
          {
ee588281   Alexey Boroda   -Blog backend ready
162
              return $this->hasMany(Category::className(), [ 'id' => 'blog_category_id' ])
593851ec   Alexey Boroda   First commit
163
164
                          ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]);
          }
3b1725bf   Alexey Boroda   -Bug with fill re...
165
      
593851ec   Alexey Boroda   First commit
166
167
168
          /**
           * @return \yii\db\ActiveQuery
           */
ee588281   Alexey Boroda   -Blog backend ready
169
          public function getCategory()
593851ec   Alexey Boroda   First commit
170
          {
ee588281   Alexey Boroda   -Blog backend ready
171
172
              return $this->hasOne(Category::className(), [ 'id' => 'blog_category_id' ])
                          ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]);
593851ec   Alexey Boroda   First commit
173
          }
3b1725bf   Alexey Boroda   -Bug with fill re...
174
      
593851ec   Alexey Boroda   First commit
175
176
177
178
179
180
          /**
           * @return \yii\db\ActiveQuery
           */
          public function getProducts()
          {
              return $this->hasMany(Product::className(), [ 'id' => 'product_id' ])
ee588281   Alexey Boroda   -Blog backend ready
181
                          ->viaTable('blog_article_to_product', [ 'blog_article_id' => 'id' ]);
593851ec   Alexey Boroda   First commit
182
          }
3b1725bf   Alexey Boroda   -Bug with fill re...
183
      
593851ec   Alexey Boroda   First commit
184
185
186
          /**
           * @return \yii\db\ActiveQuery
           */
ee588281   Alexey Boroda   -Blog backend ready
187
          public function getTags()
593851ec   Alexey Boroda   First commit
188
          {
ee588281   Alexey Boroda   -Blog backend ready
189
190
              return $this->hasMany(Tag::className(), [ 'id' => 'blog_tag_id' ])
                          ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]);
593851ec   Alexey Boroda   First commit
191
192
          }
      }