aboutsummaryrefslogtreecommitdiff
path: root/app/class/event.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2019-01-15 04:04:01 +0100
committervincent-peugnet <v.peugnet@free.fr>2019-01-15 04:04:01 +0100
commit2ff846f7fb65998cd6cf151554434f56f116d4f2 (patch)
tree8106cf1744dc7545e1482fd98bae16ea3628c153 /app/class/event.php
parent8e79f279938f0fff64ddd381d073c2c277dd2d5c (diff)
parentde195c2fca2f4b77a54be68fb58cd0ccee10a5b7 (diff)
downloadwcms-2ff846f7fb65998cd6cf151554434f56f116d4f2.tar.gz
wcms-2ff846f7fb65998cd6cf151554434f56f116d4f2.zip
Merge branch 'implement-timeline' into develop
Diffstat (limited to 'app/class/event.php')
-rw-r--r--app/class/event.php156
1 files changed, 156 insertions, 0 deletions
diff --git a/app/class/event.php b/app/class/event.php
new file mode 100644
index 0000000..9fc75d2
--- /dev/null
+++ b/app/class/event.php
@@ -0,0 +1,156 @@
+<?php
+
+class Event extends Dbitem
+{
+ protected $id;
+ protected $date;
+ protected $type;
+ protected $user;
+ protected $target;
+ protected $message;
+ protected $clap = 0;
+
+ const EVENT_TYPES = ['message', 'art_add', 'art_edit', 'art_delete', 'media_add', 'media_delete', 'font_add'];
+ const EVENT_BASE = ['message'];
+ const EVENT_ART = ['art_add', 'art_edit', 'art_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;
+ }
+ }
+
+
+
+
+
+}
+
+
+?> \ No newline at end of file