Blame view

common/models/Page.php 2.57 KB
b507d689   andryeyev   Итерация 1 (Терми...
1
2
3
4
5
  <?php
  
  namespace common\models;
  
  use Yii;
ab4d7cb1   andryeyev   Page + Языковая в...
6
  use common\models\PageLang;
b507d689   andryeyev   Итерация 1 (Терми...
7
8
9
10
11
12
  
  /**
   * This is the model class for table "page".
   *
   * @property integer $page_id
   * @property string $date_add
ab4d7cb1   andryeyev   Page + Языковая в...
13
   * @property integer $template_id
b507d689   andryeyev   Итерация 1 (Терми...
14
15
16
17
18
   * @property integer $image_id
   * @property integer $show
   */
  class Page extends \yii\db\ActiveRecord
  {
ab4d7cb1   andryeyev   Page + Языковая в...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
      private static $getAttributeLabelCache;
      
      public function getAttributeLabel($attribute)
      {
          $class = get_class($this);
      
          if (!isset(self::$getAttributeLabelCache[$class][$attribute])) {
              self::$getAttributeLabelCache[$class][$attribute] = parent::getAttributeLabel($attribute);
          }
      
          return self::$getAttributeLabelCache[$class][$attribute];
      }
      
      //public $title;
b507d689   andryeyev   Итерация 1 (Терми...
33
34
35
36
37
38
39
      /**
       * @inheritdoc
       */
      public static function tableName()
      {
          return 'page';
      }
ab4d7cb1   andryeyev   Page + Языковая в...
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
      
      // ==== EXTRA ====
      
      public function getExtraField($key)
      {
          return PageLang::find()->where(['page_id' => $this->page_id, 'lang_id' => 1])->one()->$key; 
      }
  
      public function getTitle()
      {
          return $this->getExtraField('title');
      }
  
      public function getMeta_title()
      { 
          return $this->getExtraField('meta_title');
      } 
  
      public function getMeta_description()
      {
          return $this->getExtraField('meta_description');
      }
  
      public function getText()
      {
          return $this->getExtraField('text');
      }
  
      public function getPage_alias()
      {
          return $this->getExtraField('page_alias');
      }
b507d689   andryeyev   Итерация 1 (Терми...
72
73
74
75
76
77
78
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
ab4d7cb1   andryeyev   Page + Языковая в...
79
              [['date_add', 'template_id', 'image_id', 'show'], 'required'],
b507d689   andryeyev   Итерация 1 (Терми...
80
              [['date_add'], 'safe'],
ab4d7cb1   andryeyev   Page + Языковая в...
81
              [['template_id', 'image_id', 'show'], 'integer']
b507d689   andryeyev   Итерация 1 (Терми...
82
83
84
85
86
87
88
89
90
          ];
      }
  
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
ab4d7cb1   andryeyev   Page + Языковая в...
91
92
93
94
95
96
97
98
99
100
101
102
              'page_id'       => Yii::t('field', 'page'),
              'date_add'      => Yii::t('field', 'date_add'),
              'template_id'   => Yii::t('field', 'template'),
              'image_id'      => Yii::t('field', 'image'),
              'show'          => Yii::t('field', 'show'),
                   
              'title'             => Yii::t('field', 'title'),
              'meta_title'        => Yii::t('field', 'meta_title'),
              'meta_description'  => Yii::t('field', 'meta_description'),
              'text'              => Yii::t('field', 'text'),
              'page_alias'        => Yii::t('field', 'page_alias'),
              'lang_id'           => Yii::t('field', 'lang_id'),
b507d689   andryeyev   Итерация 1 (Терми...
103
          ];
ab4d7cb1   andryeyev   Page + Языковая в...
104
105
      } 
  }