-
Notifications
You must be signed in to change notification settings - Fork 454
/
events.php
130 lines (112 loc) · 5.03 KB
/
events.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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Calendar;
use Concrete\Core\Tree\Node\Node;
use Concrete\Core\Tree\Node\Type\Topic;
use Concrete\Core\Page\Controller\DashboardCalendarPageController;
use Concrete\Core\Calendar\Calendar;
use Concrete\Core\Calendar\CalendarServiceProvider;
use URL;
use Concrete\Core\Calendar\Utility\Preferences;
use Punic\Calendar as PunicCalendar;
class Events extends DashboardCalendarPageController
{
public function view($caID = null, $year = null, $month = null)
{
/**
* @var $preferences Preferences
*/
$preferences = $this->app->make(Preferences::class);
$preferences->setPreferredViewToGrid();
list($calendar, $calendars) = $this->getCalendars($caID);
$this->set('calendars', $calendars);
$this->set('calendarPermissions', new \Permissions($calendar));
$this->set('calendar', $calendar);
$dh = $this->app->make('date');
if (!$year) {
$year = date('Y');
}
if (!$month) {
$month = date('m');
}
$monthYearTimestamp = strtotime($year . '-' . substr('0' . $month, -2) . '-01');
$firstDayInMonthNum = date('N', $monthYearTimestamp) % 7;
$previousLinkMonth = $month == 1 ? 12 : $month - 1;
$previousLinkYear = $month == 1 ? $year - 1 : $year;
$nextLinkMonth = $month == 12 ? 1 : $month + 1;
$nextLinkYear = $month == 12 ? $year + 1: $year;
$session = \Core::make('session');
$topic_id = $this->request->get('topic_id', $session->get('dashboard_calendar_events_topic_list', null));
$nextLink = URL::to('/dashboard/calendar/events/view', $calendar->getID(), $nextLinkYear, $nextLinkMonth);
$previousLink = URL::to('/dashboard/calendar/events/view', $calendar->getID(), $previousLinkYear, $previousLinkMonth);
$todayLink = URL::to('/dashboard/calendar/events/view', $calendar->getID());
$this->set('topic', null);
if ($topic_id) {
$topic_id = intval($topic_id, 10);
$topic = Node::getByID($topic_id);
if ($topic instanceof Topic) {
$this->set('topic', $topic);
$query = "?topic_id={$topic_id}";
$nextLink .= $query;
$previousLink .= $query;
$todayLink .= $query;
$session->set('dashboard_calendar_events_topic_list', $topic_id);
}
} elseif (is_numeric($topic_id) && $topic_id == '0') {
$session->remove('dashboard_calendar_events_topic_list');
}
// Set the date picker and keep the time zone properly available. Sigh.
$timezone = $calendar->getTimezone();
$todayDate = new \DateTime($year . '-' . substr('0' . $month, -2) . '-01 00:00:00', new \DateTimeZone($timezone));
$todayDateTimestamp = $todayDate->getTimestamp();
$this->set('monthText', $dh->date('F', $monthYearTimestamp, $todayDate->getTimezone()));
$this->set('month', $month);
$this->set('year', $year);
$this->set('daysInMonth', (int) date('t', $monthYearTimestamp));
$this->set('firstDayInMonthNum', $firstDayInMonthNum);
$this->set('nextLink', $nextLink);
$this->set('previousLink', $previousLink);
$this->set('todayLink', $todayLink);
$this->set('todayDateTimestamp', $todayDateTimestamp);
$serviceProvider = $this->app->make(CalendarServiceProvider::class);
$this->set('dateFormatter', $serviceProvider->getDateFormatter());
$this->set('linkFormatter', $serviceProvider->getLinkFormatter());
$weekdays = [PunicCalendar::getFirstWeekday()];
for ($index = 1; $index <= 6; $index++) {
$weekdays[$index] = ($weekdays[$index - 1] + 1) % 7;
}
$this->set('weekdays', $weekdays);
// Process the given edit ID if there is one
$initialEdit = (int) $this->request->get('edit');
$this->set('initialEdit', $initialEdit > 0 ? $initialEdit : null);
$editor = $this->app->make('editor');
$editor->requireEditorAssets();
}
public function calendar_deleted()
{
$this->set('success', t('Calendar deleted successfully.'));
$this->view();
}
public function delete_calendar()
{
$caID = $this->request->request->get('caID');
if (\Core::make("helper/validation/numbers")->integer($caID)) {
if ($caID > 0) {
$calendar = Calendar::getByID($caID);
$cp = new \Permissions($calendar);
if (!$cp->canDeleteCalendar()) {
unset($calendar);
}
}
}
if (!is_object($calendar)) {
$this->error->add(t('Invalid calendar.'));
}
if (!$this->token->validate('delete_calendar')) {
$this->error->add($this->token->getErrorMessage());
}
if (!$this->error->has()) {
Calendar::delete($calendar);
$this->redirect('/dashboard/calendar/events', 'calendar_deleted');
}
}
}