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
|
|||
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 |
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.