Blame view

common/models/Feedback.php 2.96 KB
d8c1a2e0   Yarik   Big commit artbox
1
  <?php
d8c1a2e0   Yarik   Big commit artbox
2
      
5c2eb7c8   Yarik   Big commit almost...
3
      namespace common\models;
d8c1a2e0   Yarik   Big commit artbox
4
      
5c2eb7c8   Yarik   Big commit almost...
5
6
7
8
      use Yii;
      use yii\behaviors\AttributeBehavior;
      use yii\behaviors\TimestampBehavior;
      use yii\db\ActiveRecord;
d8c1a2e0   Yarik   Big commit artbox
9
10
      
      /**
5c2eb7c8   Yarik   Big commit almost...
11
       * This is the model class for table "feedback".
8af13427   Yarik   For leha commit.
12
13
       *
       * @property integer $id
5c2eb7c8   Yarik   Big commit almost...
14
15
       * @property string  $name
       * @property string  $phone
8af13427   Yarik   For leha commit.
16
       * @property integer $created_at
5c2eb7c8   Yarik   Big commit almost...
17
       * @property string  $ip
d8c1a2e0   Yarik   Big commit artbox
18
       */
5c2eb7c8   Yarik   Big commit almost...
19
      class Feedback extends ActiveRecord
d8c1a2e0   Yarik   Big commit artbox
20
      {
5c2eb7c8   Yarik   Big commit almost...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
          
          const SCENARIO_FEEDBACK = 'feedback';
          const SCENARIO_CALLBACK = 'callback';
          
          /**
           * @inheritdoc
           */
          public static function tableName()
          {
              return 'feedback';
          }
          
          /**
           * @inheritdoc
           */
          public function scenarios()
          {
              $scenarios = parent::scenarios();
8af13427   Yarik   For leha commit.
39
40
41
42
43
44
45
46
47
48
              $scenarios = array_merge(
                  $scenarios,
                  [
                      self::SCENARIO_FEEDBACK => [
                          'name',
                          'phone',
                      ],
                      self::SCENARIO_CALLBACK => [ 'phone' ],
                  ]
              );
5c2eb7c8   Yarik   Big commit almost...
49
50
51
52
53
54
55
56
57
58
59
              return $scenarios;
          }
          
          /**
           * @inheritdoc
           */
          public function behaviors()
          {
              return [
                  [
                      'class'              => TimestampBehavior::className(),
5c2eb7c8   Yarik   Big commit almost...
60
61
62
63
64
65
66
                      'updatedAtAttribute' => false,
                  ],
                  [
                      'class'      => AttributeBehavior::className(),
                      'attributes' => [
                          ActiveRecord::EVENT_BEFORE_INSERT => 'ip',
                      ],
8af13427   Yarik   For leha commit.
67
                      'value'      => function ($event) {
5c2eb7c8   Yarik   Big commit almost...
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
                          return \Yii::$app->request->userIP;
                      },
                  ],
              ];
          }
          
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'phone',
                          'name',
                      ],
                      'required',
                  ],
                  [
                      [ 'phone' ],
                      'match',
                      'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/',
                  ],
                  [
                      [
                          'name',
                          'phone',
                      ],
                      'string',
                      'max' => 255,
                  ],
              ];
          }
          
          /**
           * @inheritdoc
           */
          public function attributeLabels()
          {
              return [
c70f24ea   Yarik   For Leha commit.
109
110
111
                  'id'         => Yii::t('app', 'id'),
                  'name'       => Yii::t('app', 'name'),
                  'phone'      => Yii::t('app', 'phone'),
8af13427   Yarik   For leha commit.
112
                  'created_at' => Yii::t('app', 'created_at'),
c70f24ea   Yarik   For Leha commit.
113
                  'ip'         => Yii::t('app', 'ip'),
5c2eb7c8   Yarik   Big commit almost...
114
115
              ];
          }
d8c1a2e0   Yarik   Big commit artbox
116
      }