|
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: JuKuCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 26.04.2018 |
|
25
|
|
|
* Time: 21:23 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
namespace Plugin\Calender; |
|
29
|
|
|
|
|
30
|
|
|
use Cache; |
|
31
|
|
|
use Database; |
|
32
|
|
|
use PDO; |
|
33
|
|
|
use IllegalStateException; |
|
34
|
|
|
|
|
35
|
|
|
class Calender { |
|
36
|
|
|
|
|
37
|
|
|
protected $calenderID = -1; |
|
38
|
|
|
protected $row = null; |
|
39
|
|
|
protected $user_row = null; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct (array $row = null, array $user_row = null) { |
|
42
|
|
|
if (!is_null($row) && !empty($row)) { |
|
43
|
|
|
$this->calenderID = $row['id']; |
|
44
|
|
|
$this->row = $row; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (!is_null($user_row) && !empty($user_row)) { |
|
48
|
|
|
$this->user_row = $user_row; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function load (int $calenderID) { |
|
53
|
|
|
if ($calenderID <= 0) { |
|
54
|
|
|
throw new \IllegalArgumentException("calenderID has to be greater than 0."); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (Cache::contains("plugin-calender", "calender-" . $calenderID)) { |
|
58
|
|
|
$this->row = Cache::get("plugin-calender", "calender-" . $calenderID); |
|
59
|
|
|
} else { |
|
60
|
|
|
//get calender from database |
|
61
|
|
|
$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}plugin_calender_calenders` WHERE `id` = :calenderID; ", array( |
|
62
|
|
|
'calenderID' => array( |
|
63
|
|
|
'type' => PDO::PARAM_INT, |
|
64
|
|
|
'value' => $calenderID |
|
65
|
|
|
) |
|
66
|
|
|
)); |
|
67
|
|
|
|
|
68
|
|
|
if (!$row) { |
|
69
|
|
|
throw new IllegalStateException("calender with id '" . $calenderID . "' doesnt exists."); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->row = $row; |
|
73
|
|
|
|
|
74
|
|
|
//put row to cache |
|
75
|
|
|
Cache::put("plugin-calender", "calender-" . $calenderID, $row); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->calenderID = $row['id']; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getID () : int { |
|
82
|
|
|
return $this->calenderID; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getTitle () : string { |
|
86
|
|
|
return $this->row['title']; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getDescription () : string { |
|
90
|
|
|
return $this->row['description']; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getType () : string { |
|
94
|
|
|
return $this->row['type']; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function getPermission () : string { |
|
98
|
|
|
if ($this->user_row == null || empty($this->user_row)) { |
|
99
|
|
|
throw new IllegalStateException("user row wasnt set in constructor."); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $this->user_row['value']; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public static function castCalender (Calender $calender) : Calender { |
|
106
|
|
|
return $calender; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
?> |
|
|
|
|
|
|
112
|
|
|
|