aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2019-01-12 19:49:41 +0100
committervincent-peugnet <v.peugnet@free.fr>2019-01-12 19:51:41 +0100
commiteb30a63c819ca50ebbc896eb293a0745dcd043be (patch)
tree45144b6d8e2a841de56d76c463e53c99ad029f02 /app/class
parent36d878ac00f4df0a4ff54e2ea8355b323f0a87f3 (diff)
downloadwcms-eb30a63c819ca50ebbc896eb293a0745dcd043be.tar.gz
wcms-eb30a63c819ca50ebbc896eb293a0745dcd043be.zip
timeline message working
Diffstat (limited to 'app/class')
-rw-r--r--app/class/controllertimeline.php18
-rw-r--r--app/class/dbitem.php15
-rw-r--r--app/class/event.php45
-rw-r--r--app/class/modeltimeline.php40
-rw-r--r--app/class/routes.php1
5 files changed, 95 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'],