diff options
-rw-r--r-- | app/class/controllertimeline.php | 18 | ||||
-rw-r--r-- | app/class/dbitem.php | 15 | ||||
-rw-r--r-- | app/class/event.php | 45 | ||||
-rw-r--r-- | app/class/modeltimeline.php | 40 | ||||
-rw-r--r-- | app/class/routes.php | 1 | ||||
-rw-r--r-- | app/view/templates/backtopbar.php | 1 | ||||
-rw-r--r-- | app/view/templates/timeline.php | 65 | ||||
-rw-r--r-- | assets/css/home.css | 12 |
8 files changed, 173 insertions, 24 deletions
diff --git a/app/class/controllertimeline.php b/app/class/controllertimeline.php index 5f80fc2..b4081a4 100644 --- a/app/class/controllertimeline.php +++ b/app/class/controllertimeline.php @@ -2,7 +2,9 @@ class Controllertimeline extends Controller { - /**@var Modeltimeline */ + /** + * @var Modeltimeline + */ protected $eventmanager; public function __construct($render) { @@ -12,7 +14,19 @@ class Controllertimeline extends Controller public function desktop() { - var_dump($this->eventmanager->list()); + $eventlist = $this->eventmanager->getlister(); + + $this->showtemplate('timeline', ['eventlist' => $eventlist]); + + } + + public function add() + { + $event = new Event($_POST); + $event->stamp(); + $event->setid($this->eventmanager->getlastfreeid()); + $this->eventmanager->add($event); + $this->routedirect('timeline'); } } diff --git a/app/class/dbitem.php b/app/class/dbitem.php index ff41d6f..2035316 100644 --- a/app/class/dbitem.php +++ b/app/class/dbitem.php @@ -2,7 +2,7 @@ class Dbitem { - public function hydrate(array $datas) + public function hydrate($datas) { foreach ($datas as $key => $value) { $method = 'set' . $key; @@ -13,6 +13,19 @@ class Dbitem } } + + public function dry() + { + $array = []; + foreach (get_object_vars($this) as $var => $value) { + if (in_array($var, $this::VAR_DATE)) { + $array[$var] = $this->$var('string'); + } else { + $array[$var] = $this->$var(); + } + } + return $array; + } } 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 - + } diff --git a/app/class/modeltimeline.php b/app/class/modeltimeline.php index fd9126e..b914605 100644 --- a/app/class/modeltimeline.php +++ b/app/class/modeltimeline.php @@ -7,7 +7,47 @@ class Modeltimeline extends Modeldb { parent::__construct(); $this->storeinit('timeline'); + } + + /** + * Retrun a list of Event objects + * + * @return array array of Event where the key is the Event id. + */ + public function getlister() : array + { + $eventlist = []; + $datalist = $this->repo->findAll(); + foreach ($datalist as $eventdata) { + $event = new Event($eventdata); + $eventlist[$event->id()] = $event; + } + return $eventlist; + } + + public function add(Event $event) + { + $eventdata = new \JamesMoss\Flywheel\Document($event->dry()); + $eventdata->setId($event->id()); + $result = $this->repo->store($eventdata); + return $result; } + + public function getlastfreeid() + { + $idlist = $this->list(); + + if(!empty($idlist)) { + $id = max($idlist); + $id ++; + } else { + $id = 1; + } + + return $id; + } + + } diff --git a/app/class/routes.php b/app/class/routes.php index a90a8a1..449b8fa 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -31,6 +31,7 @@ class Routes ['POST', '/!user/update', 'Controlleruser#update', 'userupdate'], ['GET', '/!info', 'Controllerinfo#desktop', 'info'], ['GET', '/!timeline', 'Controllertimeline#desktop', 'timeline'], + ['POST', '/!timeline/add', 'Controllertimeline#add', 'timelineadd'], ['GET', '/[cid:art]/', 'Controllerart#read', 'artread/'], ['GET', '/[cid:art]', 'Controllerart#read', 'artread'], ['GET', '/[cid:art]/add', 'Controllerart#add', 'artadd'], diff --git a/app/view/templates/backtopbar.php b/app/view/templates/backtopbar.php index 78e9181..07b19e8 100644 --- a/app/view/templates/backtopbar.php +++ b/app/view/templates/backtopbar.php @@ -22,6 +22,7 @@ <?php } else { ?> <span> +<a href="<?= $this->url('timeline') ?>" <?= $tab == 'timeline' ? 'class="actualpage"' : '' ?>>timeline</a> <a href="<?= $this->url('user') ?>" <?= $tab == 'user' ? 'class="actualpage"' : '' ?>><?= $user->id() ?></a> <i><?= $user->level() ?></i> </span> diff --git a/app/view/templates/timeline.php b/app/view/templates/timeline.php new file mode 100644 index 0000000..8ddc7f1 --- /dev/null +++ b/app/view/templates/timeline.php @@ -0,0 +1,65 @@ +<?php $this->layout('layout', ['title' => 'timeline', 'css' => $css . 'home.css', 'favicon' => '']) ?> + + + + +<?php $this->start('page') ?> + + +<body> + + <?php $this->insert('backtopbar', ['user' => $user, 'tab' => 'timeline']) ?> + +<?php if($user->iseditor()) { ?> + +<main class="timeline"> + +<h1>Timeline</h1> + +<ul> + +<?php +foreach ($eventlist as $event) { + if($user->id() === $event->user()) { + $class = 'class="self event"'; + } else { + $class = 'class="event"'; + } + echo '<li '. $class .'>'; + switch ($event->type()) { + case 'message': + echo '<h3>'. $event->user() .'</h3>'; + echo '<p>'. $event->message() .'</p>'; + echo '<i>'. $event->date('hrdi') .' ago</i>'; + break; + + default: + + break; + echo '</li>'; + } +} +?> + +</ul> + +<form action="<?= $this->url('timelineadd') ?>" method="post"> + +<input type="hidden" name="type" value="message"> + +<input type="hidden" name="user" value="<?= $user->id() ?>"> + +<label for="message">message</label> +<textarea name="message" id="message" cols="30" rows="10"></textarea> +<input type="submit" value="send"> +</form> + +</main> + +<?php } ?> + +</body> + + + +<?php $this->stop() ?>
\ No newline at end of file diff --git a/assets/css/home.css b/assets/css/home.css index 9d1c5a7..b58ad5b 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -258,6 +258,16 @@ main.user table form { + + + +li.self.event { + text-align: right; +} + + + + @media (max-width: 600px) { main.home .summary, main.home .linkfrom, main.home .linkto, main.home .delete, main.home .datecreation, main.home .date, main.home .log, main.home .secure, main.home .tag { display: none; @@ -274,3 +284,5 @@ main.user table form { } + + |