1
|
|
|
<?php |
2
|
|
|
/* +********************************************************************************** |
3
|
|
|
* The contents of this file are subject to the vtiger CRM Public License Version 1.0 |
4
|
|
|
* ("License"); You may not use this file except in compliance with the License |
5
|
|
|
* The Original Code is: vtiger CRM Open Source |
6
|
|
|
* The Initial Developer of the Original Code is vtiger. |
7
|
|
|
* Portions created by vtiger are Copyright (C) vtiger. |
8
|
|
|
* All Rights Reserved. |
9
|
|
|
* Contributor(s): YetiForce S.A. |
10
|
|
|
* ********************************************************************************** */ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* VTiger workflow VTTask class. |
14
|
|
|
*/ |
15
|
|
|
abstract class VTTask |
16
|
|
|
{ |
17
|
|
|
/** @var int */ |
18
|
|
|
public const RECORD_EVENT_ACTIVE = 0; |
19
|
|
|
/** @var int */ |
20
|
|
|
public const RECORD_EVENT_INACTIVE = 1; |
21
|
|
|
/** @var int */ |
22
|
|
|
public const RECORD_EVENT_DOUBLE_MODE = 2; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Task contents. |
26
|
|
|
* |
27
|
|
|
* @var Vtiger_Record_Model |
28
|
|
|
*/ |
29
|
|
|
public $contents; |
30
|
|
|
|
31
|
|
|
/** @var bool The record event. */ |
32
|
|
|
public $recordEventState = self::RECORD_EVENT_ACTIVE; |
33
|
|
|
|
34
|
|
|
/** @var int Task ID */ |
35
|
|
|
public $id; |
36
|
|
|
/** @var array The array of task data. */ |
37
|
|
|
private array $data = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Restore the model after serialization. |
41
|
|
|
* |
42
|
|
|
* @param array $data |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function __unserialize(array $data) |
47
|
|
|
{ |
48
|
|
|
$this->data = $data; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Prepare the instance values for serialization. |
53
|
|
|
* |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
|
|
public function __serialize() |
57
|
|
|
{ |
58
|
|
|
$values = []; |
59
|
|
|
foreach ($this->data as $name => $value) { |
60
|
|
|
if (\is_object($value) || 'data' === $name) { |
61
|
|
|
continue; |
62
|
1 |
|
} |
63
|
|
|
$values[$name] = $value; |
64
|
1 |
|
} |
65
|
1 |
|
|
66
|
|
|
return $values; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function __isset($name) |
70
|
|
|
{ |
71
|
|
|
return isset($this->data[$name]); |
72
|
|
|
} |
73
|
|
|
|
74
|
11 |
|
/** |
75
|
|
|
* Set a piece of data on the task. |
76
|
11 |
|
* |
77
|
11 |
|
* @param string $name |
78
|
|
|
* @param mixed $value |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public function __set($name, $value) |
83
|
|
|
{ |
84
|
|
|
if (!property_exists($this, $name)) { |
85
|
|
|
$this->data[$name] = $value; |
86
|
|
|
} else { |
87
|
|
|
$this->{$name} = $value; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get a piece of data from the tesk. |
93
|
|
|
* |
94
|
|
|
* @param string $name |
95
|
|
|
* |
96
|
|
|
* @return mixed |
97
|
|
|
*/ |
98
|
|
|
public function &__get($name) |
99
|
|
|
{ |
100
|
|
|
return $this->data[$name]; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Do task. |
105
|
|
|
* |
106
|
|
|
* @param Vtiger_Record_Model |
107
|
|
|
* @param mixed $recordModel |
108
|
|
|
*/ |
109
|
|
|
abstract public function doTask($recordModel); |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Return field names. |
113
|
|
|
*/ |
114
|
|
|
abstract public function getFieldNames(); |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Return time field list. |
118
|
|
|
* |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
|
|
public function getTimeFieldList() |
122
|
|
|
{ |
123
|
|
|
return []; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Return content. |
128
|
|
|
* |
129
|
|
|
* @param Vtiger_Record_Model $recordModel |
130
|
|
|
* |
131
|
|
|
* @return Vtiger_Record_Model |
132
|
|
|
*/ |
133
|
|
|
public function getContents($recordModel) |
134
|
|
|
{ |
135
|
|
|
return $this->contents; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Set contents. |
140
|
|
|
* |
141
|
|
|
* @param Vtiger_Record_Model $recordModel |
142
|
|
|
*/ |
143
|
|
|
public function setContents($recordModel) |
144
|
|
|
{ |
145
|
|
|
$this->contents = $recordModel; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Check if has contents. |
150
|
|
|
* |
151
|
|
|
* @param Vtiger_Record_Model $recordModel |
152
|
|
|
* |
153
|
|
|
* @return bool |
154
|
|
|
*/ |
155
|
|
|
public function hasContents($recordModel) |
156
|
|
|
{ |
157
|
|
|
if ($this->getContents($recordModel)) { |
158
|
|
|
return true; |
159
|
|
|
} |
160
|
|
|
return false; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Return formatted time for timepicker. |
165
|
|
|
* |
166
|
|
|
* @param string $time |
167
|
|
|
* |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function formatTimeForTimePicker($time) |
171
|
|
|
{ |
172
|
|
|
[$h, $m] = explode(':', $time); |
173
|
|
|
$mn = str_pad($m - $m % 15, 2, 0, STR_PAD_LEFT); |
174
|
|
|
$AM_PM = ['am', 'pm']; |
175
|
|
|
|
176
|
|
|
return str_pad($h % 12, 2, 0, STR_PAD_LEFT) . ':' . $mn . $AM_PM[($h / 12) % 2]; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|