Issues (762)

plugins/calender/classes/calenderapi.php (1 issue)

Severity
1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
20
/**
21
 * Project: RocketCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 26.04.2018
25
 * Time: 22:51
26
 */
27
28
namespace Plugin\Calender;
29
30
use User;
31
use IllegalStateException;
32
33
class CalenderApi {
34
35
	public static function listMyCalenderIDs () : array {
36
		$res = array();
37
38
		$array = array();
39
40
		$rows = Calenders::listMyCalenderIDs(User::current()->getID());
41
42
		foreach ($rows as $calenderID=>$row) {
43
			$array[$calenderID] = $row['value'];
44
		}
45
46
		$res['calender_ids'] = $array;
47
48
		return $res;
49
	}
50
51
	public static function listMyCalenders () : array {
52
		$res = array();
53
54
		$calenders = array();
55
56
		foreach (Calenders::listMyCalenders(User::current()->getID()) as $calender) {
57
			$calender = Calender::castCalender($calender);
58
59
			$calenders[] = array(
60
				'id' => $calender->getID(),
61
				'title' => $calender->getTitle(),
62
				'description' => $calender->getDescription(),
63
				'type' => $calender->getType(),
64
				'permission' => $calender->getPermission()
65
			);
66
		}
67
68
		$res['calenders'] = $calenders;
69
70
		return $res;
71
	}
72
73
	public static function listAllEvents () : array {
74
		$res = array();
75
76
		if (!isset($_REQUEST['calenderID']) || empty($_REQUEST['calenderID'])) {
77
			$res['status'] = 400;
78
			$res['error'] = "No parameter 'calenderID' is set. Right usage: api.php?method=list-all-calender-events&calenderID=<CalenderID>";
79
80
			return $res;
81
		}
82
83
		$calenderID = intval($_REQUEST['calenderID']);
84
85
		$only_current_events = false;
86
87
		if (isset($_REQUEST['only_current'])) {
88
			$only_current_events = true;
89
		}
90
91
		//create and load calender
92
		$calender = new Calender();
93
94
		try {
95
			$calender->load($calenderID);
96
		} catch (IllegalStateException $e) {
97
			$res['status'] = 404;
98
			$res['error'] = "Couldnt found calender with id '" . $calenderID . "'!";
99
100
			return $res;
101
		}
102
103
		$events = array();
104
105
		foreach ($calender->listAllEvents($only_current_events) as $event) {
106
			//cast event
107
			$event = Event::castEvent($event);
108
109
			$events[] = array(
110
				'id' => $event->getID(),
111
				'calenderID' => $event->getCalenderID(),
112
				'title' => $event->getTitle(),
113
				'description' => $event->getDescription(),
114
				'price_info' => $event->getPriceInfo(),
115
				'image' => $event->getImage(),
116
				'all_day' => $event->isAllDay(),
117
				'from' => $event->getFromTimestamp(),
118
				'to' => $event->getToTimestamp(),
119
				'location' => $event->getLocation(),
120
				'color' => $event->getColor()
121
			);
122
		}
123
124
		$res['events'] = $events;
125
126
		return $res;
127
	}
128
129
}
130
131
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
132