/
PageProgress.php
88 lines (75 loc) · 2.8 KB
/
PageProgress.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
<?php
namespace Concrete\Core\Workflow\Progress;
use Core;
use Database;
use Page;
use Concrete\Core\Workflow\Workflow;
use Concrete\Core\Workflow\Request\PageRequest as PageWorkflowRequest;
use Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface;
use Concrete\Core\Validation\CSRF\Token;
class PageProgress extends Progress implements SiteProgressInterface
{
protected $cID;
public function getSite()
{
$page = \Page::getByID($this->cID);
return $page->getSite();
}
public static function add(Workflow $wf, PageWorkflowRequest $wr)
{
$wp = parent::create('page', $wf, $wr);
$db = Database::connection();
$db->Replace('PageWorkflowProgress', array('cID' => $wr->getRequestedPageID(), 'wpID' => $wp->getWorkflowProgressID()), array('cID', 'wpID'), true);
$wp->cID = $wr->getRequestedPageID();
return $wp;
}
public function loadDetails()
{
$db = Database::connection();
$row = $db->GetRow('select cID from PageWorkflowProgress where wpID = ?', array($this->wpID));
$this->setPropertiesFromArray($row);
}
public function delete()
{
parent::delete();
$db = Database::connection();
$db->Execute('delete from PageWorkflowProgress where wpID = ?', array($this->wpID));
}
public static function getList(Page $c, $filters = array('wpIsCompleted' => 0), $sortBy = 'wpDateAdded asc')
{
$db = Database::connection();
$filter = '';
foreach ($filters as $key => $value) {
$filter .= ' and ' . $key . ' = ' . $value . ' ';
}
$filter .= ' order by ' . $sortBy;
$r = $db->Execute('select wp.wpID from PageWorkflowProgress pwp inner join WorkflowProgress wp on pwp.wpID = wp.wpID where cID = ? ' . $filter, array($c->getCollectionID()));
$list = array();
while ($row = $r->fetch()) {
$wp = static::getByID($row['wpID']);
if (is_object($wp)) {
$list[] = $wp;
}
}
return $list;
}
public function getWorkflowProgressFormAction()
{
$url = app(ResolverManagerInterface::class)->resolve(['/ccm/system/workflow/categories/page/save_progress']);
$token = app(Token::class);
$query = $url->getQuery();
$query->modify([
'cID' => $this->cID,
'wpID' => $this->getWorkflowProgressID(),
$token::DEFAULT_TOKEN_NAME => $token->generate('save_workflow_progress')
]);
return (string) $url->setQuery($query);
}
public function getPendingWorkflowProgressList()
{
$list = new \Concrete\Core\Page\Workflow\Progress\ProgressList();
$list->filter('wpApproved', 0);
$list->sortBy('wpDateLastAction', 'desc');
return $list;
}
}