/
controller.php
131 lines (117 loc) · 4.4 KB
/
controller.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
namespace Concrete\Block\DesktopDraftList;
use Concrete\Core\Block\BlockController;
use Concrete\Core\Block\View\BlockView;
use Concrete\Core\Page\Page;
use Concrete\Core\Page\PageList;
use Concrete\Core\User\UserInfo;
use Permissions;
use URL;
defined('C5_EXECUTE') or die('Access Denied.');
class Controller extends BlockController
{
public $helpers = ['form'];
protected $btTable = 'btDesktopDraftList';
protected $defaultDraftsPerPage = 10;
public function getBlockTypeDescription()
{
return t('Displays a list of all drafts.');
}
public function getBlockTypeName()
{
return t('Draft List');
}
public function add()
{
$this->set('defaultDraftsPerPage', $this->defaultDraftsPerPage);
}
public function edit()
{
$this->set('defaultDraftsPerPage', $this->defaultDraftsPerPage);
}
public function validate($args)
{
$e = $this->app->make('helper/validation/error');
if (!empty($args['draftsPerPage'])) {
$numbersValidation = $this->app->make('helper/validation/numbers');
if (!$numbersValidation->integer($args['draftsPerPage'])) {
$e->add(t('You must specify an integer value for the number of drafts per page.'));
}
}
return $e;
}
public function save($args)
{
if (empty($args['draftsPerPage'])) {
$args['draftsPerPage'] = $this->defaultDraftsPerPage;
}
parent::save($args);
}
public function registerViewAssets($outputContent = '')
{
$this->requireAsset('core/draft_list');
}
public function view()
{
$myDrafts = [];
$pagination = null;
$site = $this->app->make('site')->getSite();
if (is_object($site)) {
$draftsParentPage = Page::getDraftsParentPage($site);
if (is_object($draftsParentPage) && !empty($draftsParentPage->getCollectionID())) {
$list = new PageList();
$list->setNameSpace('b' . $this->bID);
$list->filterByParentID($draftsParentPage->getCollectionID());
$list->includeSystemPages();
$list->includeInactivePages();
$list->sortBy('cDateAdded', 'desc');
$list->setPageVersionToRetrieve($list::PAGE_VERSION_RECENT);
$list->setItemsPerPage((!empty($this->draftsPerPage)) ? $this->draftsPerPage : $this->defaultDraftsPerPage);
$pagination = $list->getPagination();
$drafts = $pagination->getCurrentPageResults();
}
}
if (!empty($drafts)) {
$date = $this->app->make('helper/date');
$navigation = $this->app->make('helper/navigation');
foreach ($drafts as $draft) {
$dp = new Permissions($draft);
if ($dp->canEditPageContents()) {
$draftName = $draft->getCollectionName();
if (empty($draftName)) {
$draftName = t('(Untitled)');
}
$draftUser = null;
$draftUserID = $draft->getCollectionUserID();
if (!empty($draftUserID)) {
$user = UserInfo::getByID($draftUserID);
if (is_object($user)) {
$draftUser = $user->getUserName();
}
}
$deleteLink = null;
if ($dp->canDeletePage()) {
$deleteLink = URL::to('/ccm/system/dialogs/page/delete_from_sitemap') . '?cID=' . $draft->getCollectionID();
}
$myDrafts[] = [
'link' => $navigation->getLinkToCollection($draft),
'id' => $draft->getCollectionID(),
'name' => $draftName,
'dateAdded' => $date->formatDateTime($draft->getCollectionDateAdded(), false),
'user' => $draftUser,
'deleteLink' => $deleteLink,
];
}
}
}
$this->set('drafts', $myDrafts);
$this->set('pagination', $pagination);
}
public function action_reload_drafts()
{
$b = $this->getBlockObject();
$bv = new BlockView($b);
$bv->render('view');
$this->app->shutdown();
}
}