Blame view

common/models/Share.php 1.06 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
  <?php
  
  namespace common\models;
  
  use common\modules\product\models\Product;
  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 = date('Y-m-d H:i:s');
              $this->date = date('Y-m-d');
              return parent::beforeSave($insert);
  	}
          
          public function beforeDelete() {
              return parent::beforeDelete();
          } 
          
          public function getProduct()
          { 
            return $this->hasOne(Product::className(), ['product_id' => 'product_id']);
          }
  
          public function getShareList()
          {
              return $this->hasMany(self::className(), ['date' => 'date'])->where(['user_id'=>Yii::$app->user->id])->orderBy('id DESC');
          }
      
  }