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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
<?php
namespace Wcms;
use DateTime;
use DateTimeImmutable;
use DateTimeZone;
class Event extends Dbitem
{
protected $id;
protected $date;
protected $type;
protected $user;
protected $target;
protected $message;
protected $clap = 0;
const EVENT_TYPES = ['message', 'page_add', 'page_edit', 'page_delete', 'media_add', 'media_delete', 'font_add'];
const EVENT_BASE = ['message'];
const EVENT_ART = ['page_add', 'page_edit', 'page_delete'];
const EVENT_MEDIA = ['media_add', 'media_delete'];
const EVENT_FONT = ['font_add', 'font_delete'];
const MESSAGE_MAX_LENGTH = 2 ** 10;
const VAR_DATE = ['date'];
public function __construct($datas)
{
$this->hydrate($datas);
}
public function stamp()
{
$this->date = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
$this->user = idclean($this->user);
if (in_array($this->type, self::EVENT_ART)) {
$this->target = idclean($this->target);
} elseif ($this->type === 'message') {
$this->message = htmlspecialchars($this->message);
}
}
public function addclap()
{
$this->clap ++;
}
// _____________________ G E T __________________________
public function id()
{
return $this->id;
}
public function date($type = 'datetime')
{
switch ($type) {
case 'datetime':
return $this->date;
break;
case 'string':
return $this->date->format(DateTime::ISO8601);
break;
case 'hrdi':
$now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
return hrdi($this->date->diff($now));
break;
}
}
public function type()
{
return $this->type;
}
public function user()
{
return $this->user;
}
public function target()
{
return $this->target;
}
public function message()
{
return $this->message;
}
public function clap()
{
return $this->clap;
}
// ________________________ S E T ____________________
public function setid($id)
{
if (is_int($id)) {
$this->id = $id;
}
}
public function setdate($date)
{
if ($date instanceof DateTimeImmutable) {
$this->date = $date;
} elseif (is_string($date)) {
$this->date = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $date, new DateTimeZone('Europe/Paris'));
}
}
public function settype($type)
{
if (in_array($type, self::EVENT_TYPES)) {
$this->type = $type;
}
}
public function setuser($user)
{
if (is_string($user) && strlen($user) < Model::MAX_ID_LENGTH) {
$this->user = $user;
}
}
public function settarget($target)
{
if (is_string($target) && strlen($target) < Model::MAX_ID_LENGTH) {
$this->target = $target;
}
}
public function setmessage($message)
{
if (is_string($message) && strlen($message) < self::MESSAGE_MAX_LENGTH) {
$this->message = $message;
}
}
public function setclap($clap)
{
if(is_int($clap)) {
$this->clap = $clap;
}
}
}
?>
|