Blame view

common/modules/blog/models/ArticleCategoryLang.php 2.92 KB
4253cbec   root   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
  <?php

  

  namespace common\modules\blog\models;

  

  use common\modules\blog\behaviors\Autocomplete;

  use Yii;

  

  /**

   * This is the model class for table "article_category_lang".

   *

   * @property integer $article_category_language_id

   * @property integer $language_id

   * @property integer $article_category_id

   * @property string $text

   * @property string $preview

   * @property string $seo_url

   * @property string $name

   * @property string $meta_title

   * @property string $meta_descr

   * @property string $meta_keyword

   * @property string $h1_tag

   * @property string $tag

   *

   * @property ArticleCategory $category

   * @property Language $lang

   */

  class ArticleCategoryLang extends \yii\db\ActiveRecord

  {

      /**

       * @inheritdoc

       */

      public static function tableName()

      {

          return 'article_category_lang';

      }

  

      public function behaviors()

      {

          return [

              [

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

                  'attributes' => [

                      'repeat' => [['preview', 'text', false, 5, true, '...']],

                  ]

              ]

          ];

      }

      /**

       * @inheritdoc

       */

      public function rules()

      {

          return [

              [['language_id', 'article_category_id'], 'integer'],

              [['text', 'name'], 'required'],

              [['text', 'preview', 'seo_url', 'name', 'meta_title', 'meta_descr', 'meta_keyword', 'h1_tag', 'tag'], 'string'],

              ['seo_url', function($attribute, $params) {

                  $pattern = "/^[a-zA-Z\d_-]+$/";

                  if(!preg_match($pattern, $this->$attribute)) {

                      $this->addError($attribute, Yii::t('app', "Pattern doesn't match."));

                  }

              }]

          ];

      }

  

      /**

       * @inheritdoc

       */

      public function attributeLabels()

      {

          return [

              'article_category_language_id' => Yii::t('app', 'ID'),

              'language_id' => Yii::t('app', 'Lang ID'),

              'article_category_id' => Yii::t('app', 'Category ID'),

              'text' => Yii::t('app', 'Text'),

              'preview' => Yii::t('app', 'Preview'),

              'seo_url' => Yii::t('app', 'Seo Url'),

              'name' => Yii::t('app', 'Name'),

              'meta_title' => Yii::t('app', 'Meta Title'),

              'meta_descr' => Yii::t('app', 'Meta Descr'),

              'meta_keyword' => Yii::t('app', 'Meta Keywords'),

              'h1_tag' => Yii::t('app', 'H1 Tag'),

              'tag' => Yii::t('app', 'Tags'),

          ];

      }

  

      /**

       * @return \yii\db\ActiveQuery

       */

      public function getCategory()

      {

          return $this->hasOne(ArticleCategory::className(), ['article_category_id' => 'article_category_id']);

      }

  

      /**

       * @return \yii\db\ActiveQuery

       */

      public function getLang()

      {

          return $this->hasOne(Language::className(), ['language_id' => 'language_id']);

      }

  }