SchedulerTask::attributeLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 2
rs 9.9332
1
<?php
2
/**
3
 * @copyright Copyright(c) 2016 Webtools Ltd
4
 * @copyright Copyright(c) 2018 Thamtech, LLC
5
 * @link https://github.com/thamtech/yii2-scheduler
6
 * @license https://opensource.org/licenses/MIT
7
**/
8
9
namespace thamtech\scheduler\models\base;
10
11
use Yii;
12
use yii\data\ActiveDataProvider;
13
14
/**
15
 * This is the base-model class for table "scheduler_task".
16
 *
17
 * @property integer $id
18
 * @property string $name
19
 * @property string $display_name
20
 * @property string $schedule
21
 * @property string $description
22
 * @property integer $status_id
23
 * @property string $started_at
24
 * @property string $last_run
25
 * @property string $next_run
26
 * @property integer $active
27
 *
28
 * @property \thamtech\scheduler\models\SchedulerLog[] $schedulerLogs
29
 */
30
class SchedulerTask extends \yii\db\ActiveRecord
31
{
32
    /**
33
     * @inheritdoc
34
     */
35 1
    public static function tableName()
36
    {
37 1
        return 'scheduler_task';
38
    }
39
40
    /**
41
     *
42
     */
43
    public static function label($n = 1)
44
    {
45
        return Yii::t('app', '{n, plural, =1{Scheduler Task} other{Scheduler Tasks}}', ['n' => $n]);
46
    }
47
48
    /**
49
     *
50
     */
51
    public function __toString()
52
    {
53
        return (string) $this->id;
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function rules()
60
    {
61
        return [
62
            [['name', 'display_name', 'schedule', 'description', 'status_id'], 'required'],
63
            [['description', 'display_name'], 'string'],
64
            [['status_id'], 'integer'],
65
            [['started_at', 'last_run', 'next_run'], 'safe'],
66
            [['name', 'schedule'], 'string', 'max' => 255],
67
            [['name'], 'unique']
68
        ];
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function attributeLabels()
75
    {
76
        return [
77
            'id' => Yii::t('app', 'ID'),
78
            'name' => Yii::t('app', 'Name'),
79
            'display_name' => Yii::t('app', 'Display Name'),
80
            'schedule' => Yii::t('app', 'Schedule'),
81
            'description' => Yii::t('app', 'Description'),
82
            'status_id' => Yii::t('app', 'Status ID'),
83
            'started_at' => Yii::t('app', 'Started At'),
84
            'last_run' => Yii::t('app', 'Last Run'),
85
            'next_run' => Yii::t('app', 'Next Run'),
86
        ];
87
    }
88
89
    /**
90
     * @return \yii\db\ActiveQuery
91
     */
92
    public function getSchedulerLogs()
93
    {
94
        return $this->hasMany(\thamtech\scheduler\models\SchedulerLog::className(), ['scheduled_task_id' => 'id']);
0 ignored issues
show
Deprecated Code introduced by
The function yii\base\BaseObject::className() has been deprecated: since 2.0.14. On PHP >=5.5, use `::class` instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

94
        return $this->hasMany(/** @scrutinizer ignore-deprecated */ \thamtech\scheduler\models\SchedulerLog::className(), ['scheduled_task_id' => 'id']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
95
    }
96
97
    /**
98
     * Creates data provider instance with search query applied
99
     *
100
     * @param array $params
101
     *
102
     * @return ActiveDataProvider
103
     */
104
    public function search($params = null)
105
    {
106
        $formName = $this->formName();
107
        $params = !$params ? Yii::$app->request->get($formName, array()) : $params;
108
        $query = self::find();
109
110
        $dataProvider = new ActiveDataProvider([
111
            'query' => $query,
112
            'sort' => ['defaultOrder'=>['id'=>SORT_DESC]],
113
        ]);
114
115
        $this->load($params, $formName);
116
117
        $query->andFilterWhere([
118
            'id' => $this->id,
119
            'status_id' => $this->status_id,
120
        ]);
121
122
        $query
123
            ->andFilterWhere(['like', 'name', $this->name])
124
            ->andFilterWhere(['like', 'display_name', $this->display_name])
125
            ->andFilterWhere(['like', 'schedule', $this->schedule])
126
            ->andFilterWhere(['like', 'description', $this->description])
127
            ->andFilterWhere(['like', 'started_at', $this->started_at])
128
            ->andFilterWhere(['like', 'last_run', $this->last_run])
129
            ->andFilterWhere(['like', 'next_run', $this->next_run]);
130
131
        return $dataProvider;
132
    }
133
}
134
135