Blame view

common/models/Job.php 2.2 KB
eb7e82fb   Administrator   29.02.16
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
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
72
73
74
75
76
77
78
79
80
  <?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]

          ];

      }

  

  

  

      public function getExpTime()

      {

          if($this->date_end && $this->date_start){

              $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))));

          } 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()));

          } else {

              return 'неизвестна дата начала';

          }

  

      }

  

  

      /**

       * @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'),

          ];

      }

  }