1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Anax\Events;
|
4
|
|
|
|
5
|
|
|
/**
|
6
|
|
|
* Model for Events.
|
7
|
|
|
*
|
8
|
|
|
*/
|
9
|
|
|
class Event extends \Anax\Events\CDatabaseModel {
|
10
|
|
|
|
11
|
|
|
public function getSource()
|
12
|
|
|
{
|
13
|
|
|
return strtolower(implode('', array_slice(explode('\\', get_class($this)), -1)));
|
14
|
|
|
}
|
15
|
|
|
|
16
|
|
|
public function getProperties()
|
17
|
|
|
{
|
18
|
|
|
$properties = get_object_vars($this);
|
19
|
|
|
unset($properties['di']);
|
20
|
|
|
unset($properties['db']);
|
21
|
|
|
|
22
|
|
|
return $properties;
|
23
|
|
|
}
|
24
|
|
|
|
25
|
|
|
public function setProperties($properties)
|
26
|
|
|
{
|
27
|
|
|
// Update object with incoming values, if any
|
28
|
|
|
if (!empty($properties)) {
|
29
|
|
|
foreach ($properties as $key => $val) {
|
30
|
|
|
$this->$key = $val;
|
31
|
|
|
}
|
32
|
|
|
}
|
33
|
|
|
}
|
34
|
|
|
|
35
|
|
|
public function findAllOfMonth($month, $year)
|
36
|
|
|
{
|
37
|
|
|
$start_date = "showdate >= '".$year ."-".$month ."-01'";
|
38
|
|
|
$end_date = "showdate <= '".$year ."-".$month ."-31'";
|
39
|
|
|
|
40
|
|
|
$this->db->select()
|
|
|
|
|
41
|
|
|
->from($this->getSource())
|
42
|
|
|
->where($start_date)
|
43
|
|
|
->andWhere($end_date)
|
44
|
|
|
->execute();
|
45
|
|
|
|
46
|
|
|
return $this->db->fetchAll($this);
|
|
|
|
|
47
|
|
|
}
|
48
|
|
|
|
49
|
|
|
public function findEventsOfDay($date){
|
50
|
|
|
|
51
|
|
|
$currentDate = "'". $date ."'" ;
|
52
|
|
|
$this->db->select()
|
|
|
|
|
53
|
|
|
->from($this->getSource())
|
54
|
|
|
->where('showdate = '.$currentDate)
|
55
|
|
|
->execute();
|
56
|
|
|
|
57
|
|
|
return $this->db->fetchAll($this);
|
|
|
|
|
58
|
|
|
}
|
59
|
|
|
|
60
|
|
|
/**
|
61
|
|
|
*
|
62
|
|
|
* @return array with eventcount per day.
|
63
|
|
|
*/
|
64
|
|
|
public function getEventCountPerDayOfMonth($month,$year = '2016'){
|
65
|
|
|
$eventsPerDayForMonth = [];
|
66
|
|
|
|
67
|
|
|
for($i = 1;$i < 32;$i++){
|
68
|
|
|
$day = sprintf('%02s', $i);
|
69
|
|
|
$date = "'".$year ."-".$month ."-".$day."'";
|
70
|
|
|
$count = $this->getEventCount($date);
|
71
|
|
|
$eventsPerDayForMonth[$i] = $count;
|
72
|
|
|
}
|
73
|
|
|
|
74
|
|
|
return $eventsPerDayForMonth;
|
75
|
|
|
}
|
76
|
|
|
public function getEventCount($date){
|
77
|
|
|
$this->db->select()
|
|
|
|
|
78
|
|
|
->from($this->getSource())
|
79
|
|
|
->where('showdate = '.$date)
|
80
|
|
|
->execute();
|
81
|
|
|
$count = $this->db->fetchAll($this);
|
|
|
|
|
82
|
|
|
|
83
|
|
|
return $result = count($count);
|
|
|
|
|
84
|
|
|
|
85
|
|
|
}
|
86
|
|
|
|
87
|
|
|
public function save($values = [])
|
88
|
|
|
{
|
89
|
|
|
$this->setProperties($values);
|
90
|
|
|
$values = $this->getProperties();
|
91
|
|
|
|
92
|
|
|
if (isset($values['id'])) {
|
93
|
|
|
return $this->update($values);
|
94
|
|
|
} else {
|
95
|
|
|
return $this->create($values);
|
96
|
|
|
}
|
97
|
|
|
}
|
98
|
|
|
|
99
|
|
|
public function create($values)
|
100
|
|
|
{
|
101
|
|
|
$keys = array_keys($values);
|
102
|
|
|
$values = array_values($values);
|
103
|
|
|
|
104
|
|
|
$this->db->insert(
|
|
|
|
|
105
|
|
|
$this->getSource(),
|
106
|
|
|
$keys
|
107
|
|
|
);
|
108
|
|
|
|
109
|
|
|
$res = $this->db->execute($values);
|
|
|
|
|
110
|
|
|
|
111
|
|
|
$this->id = $this->db->lastInsertId();
|
|
|
|
|
112
|
|
|
|
113
|
|
|
return $res;
|
114
|
|
|
}
|
115
|
|
|
|
116
|
|
|
public function update($values)
|
117
|
|
|
{
|
118
|
|
|
$keys = array_keys($values);
|
119
|
|
|
$values = array_values($values);
|
120
|
|
|
|
121
|
|
|
unset($keys['id']);
|
122
|
|
|
$values[] = $this->id;
|
123
|
|
|
|
124
|
|
|
|
125
|
|
|
$this->db->update(
|
|
|
|
|
126
|
|
|
$this->getSource(),
|
127
|
|
|
$keys,
|
128
|
|
|
"id = ?"
|
129
|
|
|
);
|
130
|
|
|
|
131
|
|
|
return $this->db->execute($values);
|
|
|
|
|
132
|
|
|
}
|
133
|
|
|
|
134
|
|
|
public function find($id)
|
135
|
|
|
{
|
136
|
|
|
$this->db->select()
|
|
|
|
|
137
|
|
|
->from($this->getSource())
|
138
|
|
|
->where("id = ?");
|
139
|
|
|
|
140
|
|
|
$this->db->execute([$id]);
|
|
|
|
|
141
|
|
|
return $this->db->fetchInto($this);
|
|
|
|
|
142
|
|
|
}
|
143
|
|
|
|
144
|
|
|
public function delete($id)
|
145
|
|
|
{
|
146
|
|
|
|
147
|
|
|
$this->db->delete(
|
|
|
|
|
148
|
|
|
$this->getSource(),
|
149
|
|
|
'id = ?'
|
150
|
|
|
);
|
151
|
|
|
|
152
|
|
|
return $this->db->execute([$id]);
|
|
|
|
|
153
|
|
|
}
|
154
|
|
|
|
155
|
|
|
|
156
|
|
|
} |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.