Blame view

common/models/Job.php 2.12 KB
e9013fc3   Yarik   test
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
  <?php
  
  namespace common\models;
  
  use Yii;
  
  /**
   * This is the model class for table "job".
   *
   * @property integer $job_id
   * @property string $name
   * @property string $link
   * @property string $date_start
   * @property string $date_end
   * @property string $position
   * @property integer $user_id
   * @property integer $total_count
   * @property integer $complete_count
   * @property integer $current
   */
  class Job extends \yii\db\ActiveRecord
  {
      /**
       * @inheritdoc
       */
      public static function tableName()
      {
          return 'job';
      }
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              [['name'], 'required'],
              [['date_start', 'date_end'], 'safe'],
              [['user_id', 'total_count', 'complete_count', 'current'], 'integer'],
              [['name', 'link', 'position'], 'string', 'max' => 255]
          ];
      }
  
f6ea8941   Administrator   09.02.16
44
45
46
47
  
  
      public function getExpTime()
      {
9e040221   Yarik   test
48
          if($this->date_end && $this->date_start){
f6ea8941   Administrator   09.02.16
49
50
              $date = new \DateTime(date('Y-m-d H:i:s', $this->date_start));
              return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime(date('Y-m-d H:i:s', $this->date_end))));
9e040221   Yarik   test
51
52
53
54
          } elseif($this->date_start) {
              $now = new \DateTime();
              $date = new \DateTime(date('Y-m-d H:i:s', strtotime($this->date_start)));
              return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime()));
f6ea8941   Administrator   09.02.16
55
          } else {
9e040221   Yarik   test
56
              return 'неизвестна дата начала';
f6ea8941   Administrator   09.02.16
57
58
59
60
61
          }
  
      }
  
  
e9013fc3   Yarik   test
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
              'job_id' => Yii::t('app', 'Job ID'),
              'name' => Yii::t('app', 'Name'),
              'link' => Yii::t('app', 'Link'),
              'date_start' => Yii::t('app', 'Date Start'),
              'date_end' => Yii::t('app', 'Date End'),
              'position' => Yii::t('app', 'Position'),
              'user_id' => Yii::t('app', 'User ID'),
              'total_count' => Yii::t('app', 'Total Count'),
              'complete_count' => Yii::t('app', 'Complete Count'),
              'current' => Yii::t('app', 'Current'),
          ];
      }
  }