/
UserRequest.php
108 lines (91 loc) · 3.11 KB
/
UserRequest.php
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
<?php
namespace Concrete\Core\Workflow\Request;
use HtmlObject\Element;
use URL;
use Concrete\Core\User\UserInfo;
use Core;
use Loader;
use PermissionKey;
use Concrete\Core\Workflow\Progress\Progress as WorkflowProgress;
use Concrete\Core\Workflow\Progress\Response as WorkflowProgressResponse;
use Concrete\Core\Workflow\Workflow;
use Concrete\Core\Workflow\Progress\UserProgress as UserWorkflowProgress;
abstract class UserRequest extends Request
{
public function setRequestedUserID($requestedUID)
{
$this->requestedUID = $requestedUID;
}
public function getRequestedUserID()
{
return $this->requestedUID;
}
/**
* Gets the action of user workflow request. There are four actions:
* activate, register_activate, deactivate and delete
*
* @return string
*/
public function getRequestAction()
{
return $this->requestAction;
}
public function trigger()
{
$user = UserInfo::getByID($this->requestedUID);
$pk = PermissionKey::getByID($this->pkID);
$pk->setPermissionObject($user);
return parent::triggerRequest($pk);
}
public function approve(WorkflowProgress $wp)
{
$wpr = new WorkflowProgressResponse();
$wpr->setWorkflowProgressResponseURL((string) URL::to('/dashboard/users/search/view/', $this->getRequestedUserID()));
return $wpr;
}
public function cancel(WorkflowProgress $wp)
{
$wpr = new WorkflowProgressResponse();
$wpr->setWorkflowProgressResponseURL((string) URL::to('/dashboard/users/search/view/', $this->getRequestedUserID(), '/workflow_canceled'));
return $wpr;
}
public function addWorkflowProgress(Workflow $wf)
{
Loader::model('workflow/progress/categories/user');
$uwp = UserWorkflowProgress::add($wf, $this);
$r = $uwp->start();
$uwp->setWorkflowProgressResponseObject($r);
return $uwp;
}
/**
* Override the runTask method in order to launch the cancel function
* correctly (to trigger user deletion for instance)
*/
public function runTask($task, WorkflowProgress $wp)
{
$wpr = parent::runTask($task, $wp);
if (!is_object($wpr) && method_exists($this, $task)) {
if ($task == 'cancel') {
// we check to see if any other outstanding workflowprogress requests have this id
// if they don't we proceed
$db = Loader::db();
$num = $db->GetOne('select count(wpID) as total from WorkflowProgress where wpID <> ? and wrID = ? and wpIsCompleted = 0',
array(
$wp->getWorkflowProgressID(),
$this->getWorkflowRequestID()
));
if ($num == 0) {
$wpr = call_user_func_array(array($this, $task), array($wp));
return $wpr;
}
}
}
return $wpr;
}
public function getRequestIconElement()
{
$span = new Element('i');
$span->addClass('fa fa-user');
return $span;
}
}