/
DashboardCalendarPageController.php
54 lines (46 loc) · 1.63 KB
/
DashboardCalendarPageController.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
<?php
namespace Concrete\Core\Page\Controller;
use Concrete\Core\Entity\Site\Site;
use Concrete\Core\Tree\Node\Node;
use Concrete\Core\Tree\Node\Type\Category;
use Concrete\Core\Calendar\Calendar;
class DashboardCalendarPageController extends DashboardSitePageController
{
public function getCalendars($caID)
{
$calendars = array_filter(Calendar::getList($this->site), function ($calendar) {
$p = new \Permissions($calendar);
return $p->canViewCalendarInEditInterface();
});
if (count($calendars) == 0) {
$this->redirect('/dashboard/calendar/add');
}
$defaultCalendar = reset($calendars);
if ($caID) {
$calendar = Calendar::getByID(intval($caID));
$cp = new \Permissions($calendar);
if (!$cp->canViewCalendarInEditInterface()) {
unset($calendar);
}
} else {
$calendar = null;
}
if (!$calendar) {
$calendar = $defaultCalendar;
}
$filterTopics = array();
$ak = $calendar->getCalendarTopicsAttributeKey();
if (is_object($ak)) {
$node = Node::getByID($ak->getController()->getTopicParentNode());
if ($node instanceof Category) {
$node->populateChildren();
$filterTopics = $node->getChildNodes();
$validIDs = array_map(function (Node $node) {
return $node->getTreeNodeID();
}, $filterTopics);
}
$this->set('topics', $filterTopics);
}
return array($calendar, $calendars);
}
}