|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Craft; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Task Manager. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Bob Olde Hampsink <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2015, Bob Olde Hampsink |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* |
|
12
|
|
|
* @link http://github.com/boboldehampsink |
|
13
|
|
|
*/ |
|
14
|
|
|
class TaskManagerModel extends BaseElementModel |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Element Type. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $elementType = 'TaskManager'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Define attributes. |
|
25
|
|
|
* |
|
26
|
|
|
* @return array |
|
27
|
|
|
*/ |
|
28
|
5 |
|
protected function defineAttributes() |
|
29
|
|
|
{ |
|
30
|
5 |
|
return array_merge(parent::defineAttributes(), array( |
|
31
|
5 |
|
'level' => AttributeType::Number, |
|
32
|
5 |
|
'type' => AttributeType::String, |
|
33
|
5 |
|
'description' => AttributeType::String, |
|
34
|
5 |
|
'parentId' => AttributeType::Mixed, |
|
35
|
5 |
|
'totalSteps' => AttributeType::Number, |
|
36
|
5 |
|
'currentStep' => AttributeType::Number, |
|
37
|
5 |
|
'settings' => AttributeType::Mixed, |
|
38
|
5 |
|
'status' => array(AttributeType::Enum, 'values' => array(TaskStatus::Pending, TaskStatus::Error, TaskStatus::Running), 'default' => TaskStatus::Pending), |
|
39
|
5 |
|
)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get title. |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function getTitle() |
|
46
|
|
|
{ |
|
47
|
1 |
|
return !empty($this->description) ? $this->description : Craft::t('No description'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns the element's status. |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
4 |
|
public function getStatus() |
|
56
|
|
|
{ |
|
57
|
4 |
|
switch ($this->status) { |
|
58
|
|
|
|
|
59
|
4 |
|
case TaskStatus::Pending: |
|
60
|
1 |
|
return EntryModel::PENDING; |
|
61
|
|
|
|
|
62
|
3 |
|
case TaskStatus::Error: |
|
63
|
1 |
|
return EntryModel::EXPIRED; |
|
64
|
|
|
|
|
65
|
2 |
|
case TaskStatus::Running: |
|
66
|
1 |
|
return EntryModel::LIVE; |
|
67
|
|
|
|
|
68
|
1 |
|
default: |
|
69
|
1 |
|
return EntryModel::DISABLED; |
|
70
|
|
|
|
|
71
|
1 |
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|