Blame view

common/models/Job.php 2.91 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
  <?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';

      }

  

9fd076e8   Administrator   01.03.16
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
  

      /**

       * @inheritdoc

       */

      public function behaviors()

      {

          return [

              'slug' => [

                  'class' => 'common\behaviors\Slug',

                  'in_attribute' => 'name',

                  'out_attribute' => 'link',

                  'translit' => true

              ]

          ];

      }

  

      public function beforeSave($insert)

      {

          $this->date_start = \Yii::$app->formatter->asDatetime($this->date_start, 'Y-MM-d HH:mm:ss');

  

          if($this->date_end) {

              $this->date_end = \Yii::$app->formatter->asDatetime($this->date_end, 'Y-MM-d HH:mm:ss');

          }

  

  

          return parent::beforeSave($insert); // TODO: Change the autogenerated stub

      }

  

eb7e82fb   Administrator   29.02.16
59
60
61
62
63
64
65
66
67
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
      /**

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

          ];

      }

  }