-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdcollection3.xml
516 lines (464 loc) · 17.9 KB
/
cdcollection3.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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
<process>
<name>Music CD Loans 3</name>
<isValid>1</isValid>
<version>1.0</version>
<isActive>1</isActive>
<description>Borrow CD's, browse CDs, etc...</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<sharedCode><![CDATA[<?php
// Shared code included in all activities ]]></sharedCode>
<activities>
<activity>
<name>end</name>
<type>end</type>
<description>default end activity</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>0</isInteractive>
<isAutoRouted>1</isAutoRouted>
<roles>
</roles>
<code><![CDATA[<?php
// Nothing to do here...
]]></code>
</activity>
<activity>
<name>Browse CDs</name>
<type>standalone</type>
<description>The user can browse CDs. The title and status is displayed for each CD. A button to request a CD is displayed.</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>1</isInteractive>
<isAutoRouted>0</isAutoRouted>
<roles>
<role>user</role>
<role>admin</role>
</roles>
<code><![CDATA[<?php
// Check if the current user has the 'admin' role
$isadmin = $activity->checkUserRole($user,'admin');
$data['isadmin'] = $isadmin;
// Change the status of CDs if allowed
if ($isadmin && isset($_REQUEST['status'])) {
// get the CD item
$cd = DataObjectFactory::getObject(array('name' => 'cdcollection'));
$itemid = $cd->getItem(array('itemid' => $_REQUEST['cdId']));
// update the CD status and user
if ($_REQUEST['status']=='available') {
$cd->updateItem(array('status' => 'not available',
'user' => $user));
} elseif ($_REQUEST['status'] == 'not available') {
$cd->updateItem(array('status' => 'available',
'user' => 0));
}
}
// Get the CD list
$cdlist = DataObjectFactory::getObjectList(array('name' => 'cdcollection'));
$items = $cdlist->getItems();
foreach (array_keys($items) as $index) {
// show the user name instead of the user id
if (empty($items[$index]['user'])) {
$items[$index]['user'] = '-';
} elseif (is_numeric($items[$index]['user'])) {
$items[$index]['user'] = xarUser::getVar('name', $items[$index]['user']);
}
}
// Put the CD list in a template variable
$data['cds'] = $items;
// Find the activity id for requesting CDs
$actinfo = $process->getActivityByName('Request CD');
if ($actinfo) {
$data['requestId'] = $actinfo['activityId'];
} else {
$data['requestId'] = 0;
}
// Note: current activityId, iid and return_url are automatically available in the template
]]></code>
<template><![CDATA[<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout">
<h3>Listing CDs</h3>
<table class="normal">
<tr>
<td class="heading">Title</td>
<td class="heading">Status</td>
<td class="heading">Loaner</td>
<td class="heading">Action</td>
</tr>
<xar:if condition="!empty($cds) and count($cds) gt 0">
<xar:foreach in="$cds" value="$cd">
<tr>
<form method="post" action="&xar-modurl-workflow-user-run_activity;">
<td class="odd">#$cd['title']#</td>
<td class="odd">#$cd['status']#</td>
<td class="odd">#$cd['user']#</td>
<td class="odd">
<input type="hidden" name="return_url" value="#$return_url#"/>
<xar:if condition="$isadmin">
<input type="hidden" name="activityId" value="#$activityId#"/>
<input type="hidden" name="cdId" value="#$cd['id']#"/>
<input type="hidden" name="status" value="#$cd['status']#"/>
<input type="image" name="whatever" src="#xarTpl::getImage('../lib/galaxia/img/icons/refresh2.gif','module','workflow')#" title="Change Status"/>
</xar:if>
<xar:if condition="$cd['status'] eq 'available'">
<input type="hidden" name="activityId" value="#$requestId#"/>
<input type="hidden" name="cd" value="#$cd['id']#"/>
<input type="hidden" name="request" value="1"/>
<input type="image" name="whatever" src="#xarTpl::getImage('../lib/galaxia/img/icons/next.gif','module','workflow')#" title="Request CD"/>
</xar:if>
</td>
</form>
</tr>
</xar:foreach>
</xar:if>
</table>
</xar:template> ]]></template>
</activity>
<activity>
<name>Request CD</name>
<type>start</type>
<description>The user requests a CD</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>1</isInteractive>
<isAutoRouted>1</isAutoRouted>
<roles>
<role>user</role>
<role>admin</role>
</roles>
<code><![CDATA[<?php
// Get the CDs with status 'available'
$cdlist = DataObjectFactory::getObjectList(array('name' => 'cdcollection'));
$items = $cdlist->getItems(array('where' => "status eq 'available'"));
// Put the CD list in a template variable
$data['cds'] = $items;
// Execute the request for this CD
if(!empty($_REQUEST['request']) && !empty($_REQUEST['cd'])) {
$instance->set('user',$user);
$instance->set('cdId',$_REQUEST['cd']);
$instance->complete();
}
// Put the pre-selected CD (if any) in a template variable
$data['cdId'] = isset($_REQUEST['cd']) ? $_REQUEST['cd'] : '';
// Note: current activityId, iid and return_url are automatically available in the template
]]></code>
<template><![CDATA[<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout"><h3>Request a CD</h3>
<form method="post" action="&xar-modurl-workflow-user-run_activity;">
<input type="hidden" name="activityId" value="#$activityId#"/>
<input type="hidden" name="return_url" value="#$return_url#"/>
CD to request:
<xar:if condition="!empty($cds) and count($cds) gt 0">
<select name="cd">
<xar:foreach in="$cds" value="$cd">
<xar:if condition="$cd['id'] eq $cdId">
<option value="#$cd['id']#" selected="selected">#$cd['title']#</option>
<xar:else/>
<option value="#$cd['id']#">#$cd['title']#</option>
</xar:if>
</xar:foreach>
</select>
<input type="submit" name="request" value="request"/>
<xar:else/>
There are no CDs available at the moment...
</xar:if>
</form>
</xar:template> ]]></template>
</activity>
<activity>
<name>Approve CD Request</name>
<type>switch</type>
<description>Approve or reject the CD request</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>1</isInteractive>
<isAutoRouted>1</isAutoRouted>
<roles>
<role>admin</role>
</roles>
<code><![CDATA[<?php
// Get the CD that was requested
$cd = DataObjectFactory::getObject(array('name' => 'cdcollection'));
$cd->getItem(array('itemid' => $instance->get('cdId')));
$cdinfo = $cd->getFieldValues();
// Save the CD title in the instance for later in the process
$instance->set('title',$cdinfo['title']);
// Put the CD information in a template variable
$data['info'] = $cdinfo;
$data['requestedby'] = xarUser::getVar('name',$instance->get('user'));
// Approve the CD request
if(isset($_REQUEST['approved'])) {
// save the reason in the instance for later in the process
$instance->set('reason',$_REQUEST['reason']);
// set the next activity
$instance->setNextActivity('Approve CD');
// this activity is completed
$instance->complete();
}
// Reject the CD request
if(isset($_REQUEST['rejected'])) {
// save the reason in the instance for later in the process
$instance->set('reason',$_REQUEST['reason']);
// set the next activity
$instance->setNextActivity('Reject CD');
// this activity is completed
$instance->complete();
}
// Note: current activityId, iid and return_url are automatically available in the template
]]></code>
<template><![CDATA[<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout"><h3>Approve or reject CD loan</h3>
CD: #$info['title']# <br/>
Requested by: #$requestedby# <br/>
Status: #$info['status']# <br/>
<form method="post" action="&xar-modurl-workflow-user-run_activity;">
<input type="hidden" name="activityId" value="#$activityId#"/>
<input type="hidden" name="iid" value="#$iid#"/>
<input type="hidden" name="return_url" value="#$return_url#"/>
<textarea name="reason" cols="40" rows="4"></textarea>
<br/><br/>
<input type="submit" name="rejected" value="rejected"/>
<input type="submit" name="approved" value="approved"/>
</form>
</xar:template> ]]></template>
</activity>
<activity>
<name>Approve CD</name>
<type>activity</type>
<description>Approve the request</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>0</isInteractive>
<isAutoRouted>1</isAutoRouted>
<roles>
</roles>
<code><![CDATA[<?php
// Save the status in the instance for later
$instance->set('status','approved');
// Specify who should get the next activity for this instance
$sendto = $instance->get('user');
if (!empty($sendto)) {
$instance->setNextUser($sendto);
} else {
$sendto = 0;
}
// Get the CD that was requested
$cd = DataObjectFactory::getObject(array('name' => 'cdcollection'));
$cd->getItem(array('itemid' => $instance->get('cdId')));
// Update the CD status and user
$cd->updateItem(array('status' => 'not available',
'user' => $sendto));
]]></code>
</activity>
<activity>
<name>Reject CD</name>
<type>activity</type>
<description>Reject the loan request</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>0</isInteractive>
<isAutoRouted>1</isAutoRouted>
<roles>
</roles>
<code><![CDATA[<?php
// Save the status in the instance for later
$instance->set('status','rejected');
// Specify who should get the next activity for this instance
$sendto = $instance->get('user');
if (!empty($sendto)) {
$instance->setNextUser($sendto);
}
// No need to update the CD information here
]]></code>
</activity>
<activity>
<name>Ack result</name>
<type>activity</type>
<description>The user gets the response</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>1</isInteractive>
<isAutoRouted>1</isAutoRouted>
<roles>
<role>user</role>
<role>admin</role>
</roles>
<code><![CDATA[<?php
// Handle the acknowledgement from the user
if(isset($_REQUEST['ack'])) {
// this activity is completed
$instance->complete();
}
// Get the CD title, status and reason from the instance
$data['title'] = $instance->get('title');
$data['status'] = $instance->get('status');
$data['reason'] = $instance->get('reason');
// See if we escalated this instance
$data['escalated'] = $instance->get('escalated');
// Note: current activityId, iid and return_url are automatically available in the template
]]></code>
<template><![CDATA[<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout"><h3>Loan result</h3>
Your request for #$title# was #$status#
<xar:if condition="!empty($reason)">
<p>Reason: #$reason#</p>
</xar:if>
<xar:if condition="!empty($escalated)">
<p>Escalated: #xarLocale::formatDate('%x %X %z', $escalated)#</p>
</xar:if>
<form method="post" action="&xar-modurl-workflow-user-run_activity;">
<input type="hidden" name="activityId" value="#$activityId#"/>
<input type="hidden" name="iid" value="#$iid#"/>
<input type="hidden" name="return_url" value="#$return_url#"/>
<input type="submit" name="ack" value="OK"/>
</form>
</xar:template> ]]></template>
</activity>
<activity>
<name>Handle Escalated Request</name>
<type>switch</type>
<description>When the normal delay for approval has expired, and the scheduler is executing scheduled workflow activities, we end up here. You could for instance assign another role (e.g. manager) to this activity, and let other people handle escalated requests in different ways.
Note that we need to specify a transition from Approve CD Request here, even though that transition will never be followed by regular users, because the scheduled Escalate activity needs to be able to move the instance from there to here.</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>1</isInteractive>
<isAutoRouted>1</isAutoRouted>
<roles>
<role>admin</role>
</roles>
<code><![CDATA[<?php
// See when we escalated this instance
$data['escalated'] = $instance->get('escalated');
// Get the CD that was requested
$cd = DataObjectFactory::getObject(array('name' => 'cdcollection'));
$cd->getItem(array('itemid' => $instance->get('cdId')));
$cdinfo = $cd->getFieldValues();
// Save the CD title in the instance for later in the process
$instance->set('title',$cdinfo['title']);
// Put the CD information in a template variable
$data['info'] = $cdinfo;
$data['requestedby'] = xarUser::getVar('name',$instance->get('user'));
// Approve the CD request
if(isset($_REQUEST['approved'])) {
// save the reason in the instance for later in the process
$instance->set('reason',$_REQUEST['reason']);
// set the next activity
$instance->setNextActivity('Approve CD');
// this activity is completed
$instance->complete();
}
// Reject the CD request
if(isset($_REQUEST['rejected'])) {
// save the reason in the instance for later in the process
$instance->set('reason',$_REQUEST['reason']);
// set the next activity
$instance->setNextActivity('Reject CD');
// this activity is completed
$instance->complete();
}
// Note: current activityId, iid and return_url are automatically available in the template
]]></code>
<template><![CDATA[<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout"><h3>Approve or reject CD loan</h3>
<p><span class="xar-error">It's about time you got here :-)</span></p>
CD: #$info['title']# <br/>
Requested by: #$requestedby# <br/>
Status: #$info['status']# <br/>
Escalated: #xarLocale::formatDate('%x %X %z', $escalated)# <br/>
<form method="post" action="&xar-modurl-workflow-user-run_activity;">
<input type="hidden" name="activityId" value="#$activityId#"/>
<input type="hidden" name="iid" value="#$iid#"/>
<input type="hidden" name="return_url" value="#$return_url#"/>
<textarea name="reason" cols="40" rows="4"></textarea>
<br/><br/>
<input type="submit" name="rejected" value="rejected"/>
<input type="submit" name="approved" value="approved"/>
</form>
</xar:template> ]]></template>
</activity>
<activity>
<name>Escalate</name>
<type>standalone</type>
<description>Escalate a CD request when a certain time has elapsed before the request was approved or rejected. This activity will be called by the scheduler module, so we associate a specific scheduler role to it - you can e.g. map the anonymous user to that role.
If you want to test this activity manually -without the scheduler- you can make it interactive and then run it like other stand-alone activities.</description>
<lastModif>18/04/2022 [09:40:08]</lastModif>
<isInteractive>0</isInteractive>
<isAutoRouted>0</isAutoRouted>
<roles>
<role>scheduler</role>
</roles>
<code><![CDATA[<?php
// We cannot use the $ instance object here, because this is a stand-alone activity
// Specify the deadline for escalation - adapt as you want
$now = time();
$deadline = 24*60*60;
// Find the activity id for approving CD requests in this process
$actinfo = $process->getActivityByName('Approve CD Request');
if (empty($actinfo) || empty($actinfo['activityId'])) {
return;
}
$checkId = $actinfo['activityId'];
// Find all instances that have been waiting for approval for a certain time
$findinstances = xarMod::apiFunc('workflow','user','findinstances',
array('activityId' => $checkId,
'max_started' => $now - $deadline));
if (empty($findinstances) || count($findinstances) < 1) {
return;
}
$curinstance = new Instance($activity->db);
foreach ($findinstances as $info) {
// get this particular instance
$curinstance->getInstance($info['instanceId']);
// see when we last escalated this instance
$lastescalated = $curinstance->get('escalated');
// if we stay in this activity to e.g. send a mail at escalation, skip any
// second escalation unless we hit the deadline again - adapt as needed
if (!empty($lastescalated) && $lastescalated > $now - $deadline) {
continue;
}
$curinstance->set('escalated',$now);
// set the next activity for this instance (since we're at a switch activity)
// and mark the current activity as completed
$curinstance->setNextActivity('Handle Escalated Request');
$curinstance->complete($checkId);
// or automatically reject the request with the reason "Out of Office" :-)
// $curinstance->set('reason',xarML('Out of Office'));
// $curinstance->setNextActivity('Reject CD');
// $curinstance->complete($checkId);
// or set the status of this instance to "exception"
// $curinstance->setStatus('exception');
// or abort the instance altogether
// $curinstance->abort($checkId);
// or send a mail to $info['user'] if there is one
// or send a mail to all users assigned to the role(s) for this activity
// $roles = $activity->getRoles();
// or ...
}
]]></code>
</activity>
</activities>
<transitions>
<transition>
<from>Request CD</from>
<to>Approve CD Request</to>
</transition>
<transition>
<from>Approve CD Request</from>
<to>Approve CD</to>
</transition>
<transition>
<from>Approve CD Request</from>
<to>Reject CD</to>
</transition>
<transition>
<from>Approve CD Request</from>
<to>Handle Escalated Request</to>
</transition>
<transition>
<from>Approve CD</from>
<to>Ack result</to>
</transition>
<transition>
<from>Reject CD</from>
<to>Ack result</to>
</transition>
<transition>
<from>Ack result</from>
<to>end</to>
</transition>
<transition>
<from>Handle Escalated Request</from>
<to>Approve CD</to>
</transition>
<transition>
<from>Handle Escalated Request</from>
<to>Reject CD</to>
</transition>
</transitions>
</process>