forked from Combodo/approval-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datamodel.approval-base.xml
464 lines (462 loc) · 17.2 KB
/
datamodel.approval-base.xml
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
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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<classes>
<class id="ApprovalScheme" _delta="define">
<parent>DBObject</parent>
<php_parent>
<name>_ApprovalScheme_</name>
</php_parent>
<properties>
<comment>/**
* An approval process associated to an object
* Derive this class to implement an approval process
* - A few abstract functions have to be defined to implement parallel and/or serialize approvals
* - Advanced behavior can be implemented by overloading some of the methods (e.g. GetDisplayStatus to change the way it is displayed)
*
**/</comment>
<category>application</category>
<abstract>true</abstract>
<key_type>autoincrement</key_type>
<db_table>approval_scheme</db_table>
<db_key_field>id</db_key_field>
<db_final_class_field>finalclass</db_final_class_field>
<naming>
<format>%1$s %2$s</format>
<attributes>
<attribute id="obj_class"/>
<attribute id="obj_key"/>
</attributes>
</naming>
<display_template></display_template>
<icon></icon>
<reconciliation>
<attributes>
<attribute id="label"/>
</attributes>
</reconciliation>
<indexes>
<index id="1">
<attributes>
<attribute id="obj_class"/>
<attribute id="obj_key"/>
</attributes>
</index>
</indexes>
</properties>
<fields>
<field id="obj_class" xsi:type="AttributeString">
<sql>obj_class</sql>
<default_value></default_value>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="obj_key" xsi:type="AttributeObjectKey">
<sql>obj_key</sql>
<is_null_allowed>false</is_null_allowed>
<class_attcode>obj_class</class_attcode>
</field>
<field id="started" xsi:type="AttributeDateTime">
<sql>started</sql>
<default_value></default_value>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="ended" xsi:type="AttributeDateTime">
<sql>ended</sql>
<default_value></default_value>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="timeout" xsi:type="AttributeDeadline">
<sql>timeout</sql>
<default_value></default_value>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="current_step" xsi:type="AttributeInteger">
<sql>current_step</sql>
<default_value>0</default_value>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="status" xsi:type="AttributeEnum">
<values>
<value>ongoing</value>
<value>accepted</value>
<value>rejected</value>
</values>
<sql>status</sql>
<default_value>ongoing</default_value>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="last_error" xsi:type="AttributeString">
<sql>last_error</sql>
<default_value></default_value>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="abort_comment" xsi:type="AttributeText">
<sql>abort_comment</sql>
<default_value></default_value>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="abort_user_id" xsi:type="AttributeExternalKey">
<sql>abort_user_id</sql>
<target_class>User</target_class>
<is_null_allowed>true</is_null_allowed>
<on_target_delete>DEL_MANUAL</on_target_delete>
</field>
<field id="abort_date" xsi:type="AttributeDateTime">
<sql>abort_date</sql>
<default_value></default_value>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="label" xsi:type="AttributeString">
<sql>label</sql>
<default_value></default_value>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="steps" xsi:type="AttributeText">
<sql>steps</sql>
<default_value></default_value>
<is_null_allowed>false</is_null_allowed>
</field>
</fields>
<methods>
<method id="GetApprovalScheme">
<comment>/**
* Called when an object is entering a new state (or just created), and before it gets saved
* The approval scheme should be prepared depending on the target object:
* find the relevant approvers
* perform parallel approval (several approvers in one step)
* perform serialized approval (several steps)
* tune the timeouts
* Available helpers:
* AddStep(aApprovers, iTimeoutSec, bApproveOnTimeout)
*
* @param object oObject The object concerned
* @param string sReachingState The state that this object has just reached
* @return null if no approval process is needed, an instance of ApprovalScheme otherwise
*/</comment>
<static>true</static>
<access>public</access>
<type>OQLMenuNode</type>
<code> public static function GetApprovalScheme($oObject, $sReachingState)
{
return null;
}</code>
</method>
<method id="GetFormBody">
<comment>/**
* Called when the form is being created for a given approver
*
* @param string sContactClass The approver object class
* @param string iContactId The approver object id
* @return string The form body in HTML
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function GetFormBody($sContactClass, $iContactId)
{
return 'this is the form body... to be overriden!';
}]]></code>
</method>
<method id="DoApprove">
<comment>/**
* Called when the approval is being completed with success
*
* @param object oObject The object being under approval process
* @return void The object can be modified within this handler, it will be saved later on
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ abstract public function DoApprove(&$oObject);]]></code>
</method>
<method id="DoReject">
<comment>/**
* Called when the approval is being completed with failure
*
* @param object oObject The object being under approval process
* @return void The object can be modified within this handler, it will be saved later on
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ abstract public function DoReject(&$oObject);]]></code>
</method>
<method id="DisplayObjectDetails">
<comment>/**
* Optionaly override this verb to change the way object details are displayed
* Appeared in Version 1.2 of the module
*
* @return void
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function DisplayObjectDetails($oPage, $oApprover, $oObject, $oSubstitute = null)
{
if ($this->IsLoginMandatoryToSeeObjectDetails($oApprover, $oObject))
{
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
LoginWebPage::DoLoginEx(); // Check user rights and prompt if needed
}
$oObject->DisplayBareProperties($oPage/*, $bEditMode = false*/);
}]]></code>
</method>
<method id="GetIssuerInfo">
<comment>/**
* Optionaly override this verb to change the way the changes are tracked in the object history and in the case log (if the comment are copied there)
* Appeared in Version 1.2 of the module
*
* @return void
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function GetIssuerInfo($bApproved, $oApprover, $oSubstitute = null)
{
if ($oSubstitute)
{
if ($bApproved)
{
$sRes = Dict::Format('Approval:Approved-On-behalf-of', $oSubstitute->Get('friendlyname'), $oApprover->Get('friendlyname'));
}
else
{
$sRes = Dict::Format('Approval:Rejected-On-behalf-of', $oSubstitute->Get('friendlyname'), $oApprover->Get('friendlyname'));
}
}
else
{
if ($bApproved)
{
$sRes = Dict::Format('Approval:Approved-By', $oApprover->Get('friendlyname'));
}
else
{
$sRes = Dict::Format('Approval:Rejected-By', $oApprover->Get('friendlyname'));
}
}
return $sRes;
}]]></code>
</method>
<method id="GetWorkingTimeComputer">
<comment>/**
* Optionaly override this verb to change the way working hours will be computed
* Appeared in Version 1.1 of the module
*
* @return string Name of a class implementing the interface iWorkingTimeComputer
*/</comment>
<static>false</static>
<access>protected</access>
<type>OQLMenuNode</type>
<code><![CDATA[ protected function GetWorkingTimeComputer()
{
// This class is provided as the default way to compute the active time, aka 24x7, 24 hours a day!
return 'DefaultWorkingTimeComputer';
}]]></code>
</method>
<method id="RecordComment">
<comment>/**
* Overridable helper to store the replier comment
* Actually, it does record something even if the comment is left empty, which is the expected behavior
*/</comment>
<static>false</static>
<access>protected</access>
<type>OQLMenuNode</type>
<code><![CDATA[ protected function RecordComment($sComment, $sIssuerInfo)
{
$sAttCode = MetaModel::GetModuleSetting('approval-base', 'comment_attcode');
if ($sAttCode != '')
{
if (MetaModel::IsValidAttCode($this->Get('obj_class'), $sAttCode))
{
if ($oObject = MetaModel::GetObject($this->Get('obj_class'), $this->Get('obj_key'), false, true))
{
$value = $oObject->Get($sAttCode);
$oAttDef = MetaModel::GetAttributeDef($this->Get('obj_class'), $sAttCode);
if ($oAttDef instanceof AttributeCaseLog)
{
$sHtml = utils::TextToHtml($sComment);
$value->AddLogEntry('<b>'.$sIssuerInfo.'</b><br>'.$sHtml );
}
else
{
// Cumulate into the given (hopefully) text attribute
$sDate = date(Dict::S('UI:CaseLog:DateFormat'));
$value .= "\n$sDate - ".$sIssuerInfo." :";
$value .= "\n".$sComment;
}
$oObject->Set($sAttCode, $value);
$oObject->DBUpdate();
}
}
}
}]]></code>
</method>
<method id="MakeReplyUrl">
<comment>/**
* Helper to make the URL to approve/reject the ticket
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function MakeReplyUrl($sContactClass, $iContactId, $bFromGUI = true)
{
$sPassCode = $this->GetContactPassCode($sContactClass, $iContactId);
if (is_null($sPassCode))
{
$sReplyUrl = null;
}
else
{
$sToken = $this->GetKey().'-'.$this->Get('current_step').'-'.$sContactClass.'-'.$iContactId.'-'.$sPassCode;
$sReplyUrl = utils::GetAbsoluteUrlModulesRoot().'approval-base/approve.php?token='.$sToken;
if ($bFromGUI)
{
$sReplyUrl .= '&from=object_details';
}
}
return $sReplyUrl;
}]]></code>
</method>
<method id="IsActiveApprover">
<comment>/**
* Helper to determine if a given user is expected to give her answer
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function IsActiveApprover($sContactClass, $iContactId)
{
$sPassCode = $this->GetContactPassCode($sContactClass, $iContactId);
return (!is_null($sPassCode));
} ]]></code>
</method>
<method id="MakeAbortUrl">
<comment>/**
* Helper to make the URL to abort the process
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function MakeAbortUrl($bFromGUI = true)
{
$sAbortUrl = utils::GetAbsoluteUrlModulesRoot().'approval-base/approve.php?abort=1&approval_id='.$this->GetKey();
if ($bFromGUI)
{
$sAbortUrl .= '&from=object_details';
}
return $sAbortUrl;
} ]]></code>
</method>
<method id="SendApprovalRequest">
<comment>/**
* Build and send the message for a given approver (can be a forwarded approval request)
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function SendApprovalRequest($oToPerson, $oObj, $sPassCode, $oSubstituteTo = null, $bReminder = false)
{
$sReplyUrl = $this->MakeReplyUrl(get_class($oToPerson), $oToPerson->GetKey(), false);
$sReplyLink = '<a href="'.$sReplyUrl.'">'.Dict::S('Approval:Action-ApproveOrReject').'</a>';
$aContext = array(
'this->object()' => $oObj,
'approval_scheme->object()' => $this,
'approval_step' => $this->Get('current_step') + 1,
'approver->object()' => $oToPerson,
'approver_type' => is_null($oSubstituteTo) ? 'main' : 'substitute',
'approval_url' => $sReplyUrl,
'approval_link' => $sReplyLink,
'message_type' => $bReminder ? 'reminder' : 'initial',
);
if (!is_null($oSubstituteTo))
{
$aContext['on_behalf_of'] = $oSubstituteTo;
}
$sClassList = implode("', '", MetaModel::EnumParentClasses(get_class($oObj), ENUM_PARENT_CLASSES_ALL));
$oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnApprovalRequest AS t WHERE t.target_class IN ('$sClassList')"));
while ($oTrigger = $oSet->Fetch())
{
$oTrigger->DoActivate($aContext);
}
}]]></code>
</method>
<method id="GetApproverEmailAddress">
<comment>/**
* Overridable to determine the approver email address in a different way
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function GetApproverEmailAddress($oApprover)
{
// Find out which attribute is the email attribute
//
$sEmailAttCode = 'email';
foreach(MetaModel::ListAttributeDefs(get_class($oApprover)) as $sAttCode => $oAttDef)
{
if ($oAttDef instanceof AttributeEmailAddress)
{
$sEmailAttCode = $sAttCode;
}
}
$sAddress = $oApprover->Get($sEmailAttCode);
return $sAddress;
}]]></code>
</method>
<method id="IsAllowedToSeeObjectDetails">
<comment>/**
* Overridable to disable the link to view more information on the object
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code><![CDATA[ public function IsAllowedToSeeObjectDetails($oApprover, $oObject)
{
if (get_class($oApprover) != 'Person')
{
return false;
}
$oSearch = DBObjectSearch::FromOQL_AllData("SELECT User WHERE contactid = :approver_id");
$oSet = new DBObjectSet($oSearch, array(), array('approver_id' => $oApprover->GetKey()));
if ($oSet->Count() > 0)
{
// The approver has a login: show the link!
return true;
}
else
{
return false;
}
}]]></code>
</method>
<method id="IsLoginMandatoryToSeeObjectDetails">
<comment>/**
* Overridable to force the login when viewing object details
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code> public function IsLoginMandatoryToSeeObjectDetails($oApprover, $oObject)
{
return false;
}</code>
</method>
<method id="IsAllowedToAbort">
<comment>/**
* Overridable to implement the abort feature
* @param oUser (implicitely the current user if null)
* Return true if the given user is allowed to abort
*/</comment>
<static>false</static>
<access>public</access>
<type>OQLMenuNode</type>
<code> public function IsAllowedToAbort($oUser = null)
{
return false;
}</code>
</method>
</methods>
<presentation/>
</class>
</classes>
</itop_design>