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