From 36d878ac00f4df0a4ff54e2ea8355b323f0a87f3 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 12 Jan 2019 15:52:55 +0100 Subject: add timeline class and event class --- app/class/event.php | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 app/class/event.php (limited to 'app/class/event.php') diff --git a/app/class/event.php b/app/class/event.php new file mode 100644 index 0000000..7661aa3 --- /dev/null +++ b/app/class/event.php @@ -0,0 +1,133 @@ +hydrate($datas); + } + + public function conform() + { + $this->user = idclean($this->user); + if(in_array($this->type, self::EVENT_ART)) { + $this->target = idclean($this->target); + } + } + + // _____________________ 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; + } + + + + // ________________________ 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; + } else { + $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; + } + } + + + + + +} + + +?> \ No newline at end of file -- cgit v1.2.3 From eb30a63c819ca50ebbc896eb293a0745dcd043be Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 12 Jan 2019 19:49:41 +0100 Subject: timeline message working --- app/class/event.php | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'app/class/event.php') diff --git a/app/class/event.php b/app/class/event.php index 7661aa3..a23fff9 100644 --- a/app/class/event.php +++ b/app/class/event.php @@ -14,17 +14,20 @@ class Event extends Dbitem 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 MESSAGE_MAX_LENGTH = 2 ** 10; - public function __contruct($datas) + const VAR_DATE = ['date']; + + public function __construct($datas) { $this->hydrate($datas); } - public function conform() + 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)) { + if (in_array($this->type, self::EVENT_ART)) { $this->target = idclean($this->target); } } @@ -42,14 +45,14 @@ class Event extends Dbitem case 'datetime': return $this->date; break; - + case 'string': - return $this->date->format(DateTime::ISO8601); + return $this->date->format(DateTime::ISO8601); break; - + case 'hrdi': $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->date->diff($now)); + return hrdi($this->date->diff($now)); break; } @@ -81,44 +84,44 @@ class Event extends Dbitem public function setid($id) { - if(is_int($id)) { + if (is_int($id)) { $this->id = $id; } } public function setdate($date) - { - if ($date instanceof DateTimeImmutable) { - $this->date = $date; - } else { - $this->date = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $date, new DateTimeZone('Europe/Paris')); - } + { + 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)) { + if (in_array($type, self::EVENT_TYPES)) { $this->type = $type; } } public function setuser($user) { - if(is_string($user) && strlen($user) < Model::MAX_ID_LENGTH) { + 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) { + 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) { + if (is_string($message) && strlen($message) < self::MESSAGE_MAX_LENGTH) { $this->message = $message; } } @@ -126,7 +129,7 @@ class Event extends Dbitem - + } -- cgit v1.2.3 From de195c2fca2f4b77a54be68fb58cd0ccee10a5b7 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Tue, 15 Jan 2019 03:59:32 +0100 Subject: timeline is ok for messaging --- app/class/event.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/class/event.php') diff --git a/app/class/event.php b/app/class/event.php index a23fff9..9fc75d2 100644 --- a/app/class/event.php +++ b/app/class/event.php @@ -8,6 +8,7 @@ class Event extends Dbitem 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']; @@ -29,9 +30,16 @@ class Event extends Dbitem $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() @@ -78,6 +86,11 @@ class Event extends Dbitem return $this->message; } + public function clap() + { + return $this->clap; + } + // ________________________ S E T ____________________ @@ -126,6 +139,13 @@ class Event extends Dbitem } } + public function setclap($clap) + { + if(is_int($clap)) { + $this->clap = $clap; + } + } + -- cgit v1.2.3