Blame view

common/models/Share.php 1.01 KB
dc2cd017   Karnovsky A   -
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
  <?php
  
  namespace common\models;
  
  use Yii;
  
  class Share extends \yii\db\ActiveRecord
  {
      
      public static function tableName()
      {
          return 'share';
      }
      
      public function attributeLabels()
      {
          return [
              'product_name' => 'Название',
              'date_time'=>'Дата',
          ];
      }    
      
  	public function beforeSave($insert) {
              $this->user_id = Yii::$app->user->id;
              $this->date_time = time();
              $this->date = new \yii\db\Expression('NOW()');
              return parent::beforeSave($insert);
  	}
          
          public function beforeDelete() {
              return parent::beforeDelete();
          } 
          
          public function getProduct()
          { 
            return $this->hasOne(Products::className(), ['id' => 'product_id']);
          }
  
          public function getShareList()
          {
              return $this->hasMany(self::className(), ['date' => 'date'])->where(['user_id'=>Yii::$app->user->id])->orderBy('id DESC');
          }
      
  }