aboutsummaryrefslogtreecommitdiff
path: root/app/class/Optlist.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-04-07 19:43:58 +0200
committervincent-peugnet <v.peugnet@free.fr>2020-04-07 19:43:58 +0200
commitb49830232096951202688bd775193424880bbd11 (patch)
treeb41d9b23fd853b45ece6c3f9b9e255e0da364ca7 /app/class/Optlist.php
parent7c9ceb23b415eb6863c51ac1eb1fab8d50e2aa99 (diff)
downloadwcms-b49830232096951202688bd775193424880bbd11.tar.gz
wcms-b49830232096951202688bd775193424880bbd11.zip
refactor LIST fix #74
Diffstat (limited to 'app/class/Optlist.php')
-rw-r--r--app/class/Optlist.php120
1 files changed, 83 insertions, 37 deletions
diff --git a/app/class/Optlist.php b/app/class/Optlist.php
index 122072b..37f9343 100644
--- a/app/class/Optlist.php
+++ b/app/class/Optlist.php
@@ -10,16 +10,13 @@ class Optlist extends Opt
protected $date = 0;
protected $time = 0;
protected $author = 0;
- protected $style = 0;
-
- /** @var Modelrender Render engine used to generate pages urls */
- protected $render = null;
-
+ protected $style = 'list';
+ protected $render;
public function parsehydrate(string $encoded)
{
- if(is_string($encoded)) {
+ if (is_string($encoded)) {
parse_str($encoded, $datas);
$this->hydrate($datas);
}
@@ -28,40 +25,94 @@ class Optlist extends Opt
/**
* Get the code to insert directly
*/
- public function getcode() : string
+ public function getcode(): string
{
return '%LIST?' . $this->getquery() . '%';
}
- public function listhtml(array $pagelist)
- {
- if(!empty($this->render)) {
- $content = '<ul class="pagelist">' . PHP_EOL;
- foreach ($pagelist as $page) {
- $content .= '<li>' . PHP_EOL;
- $content .= '<a href="' . $this->render->upage($page->id()) . '">' . $page->title() . '</a>' . PHP_EOL;
- if ($this->description()) {
- $content .= '<em>' . $page->description() . '</em>' . PHP_EOL;
- }
- if ($this->date()) {
- $content .= '<code>' . $page->date('pdate') . '</code>' . PHP_EOL;
- }
- if ($this->time()) {
- $content .= '<code>' . $page->date('ptime') . '</code>' . PHP_EOL;
- }
- if ($this->author()) {
- $content .= $page->authors('string') . PHP_EOL;
- }
- $content .= '</li>';
+ public function listhtml(array $pagelist, Page $actualpage, Modelrender $render)
+ {
+ $this->render = $render;
+
+ $li = '';
+
+ foreach ($pagelist as $page) {
+
+ // ================= Class =============
+
+ $classdata = [];
+ if ($page->id() === $actualpage->id()) {
+ $classdata['actual'] = 'current_page';
+ }
+ $classdata['secure'] = $page->secure('string');
+ $class = ' class="' . implode(' ', $classdata) . '" ';
+
+
+ // ================ Content
+
+ $content = '';
+
+ $title = '<span class="title">' . $page->title() . '</span>';
+ if ($this->description()) {
+ $content .= '<span class="description">' . $page->description() . '</span>';
+ }
+ if ($this->date()) {
+ $content .= '<time datetime="' . $page->date('pdate') . '">' . $page->date('pdate') . '</time>' . PHP_EOL;
+ }
+ if ($this->time()) {
+ $content .= '<time datetime="' . $page->date('ptime') . '">' . $page->date('ptime') . '</time>' . PHP_EOL;
+ }
+ if ($this->author()) {
+ $content .= $page->authors('string') . PHP_EOL;
}
- $content .= '</ul>';
+ if ($this->thumbnail) {
+ $content .= '<img class="thumbnail" src="' . Model::thumbnailpath() . $page->thumbnail() . '" alt="' . $page->title() . '">';
+ }
+
+
- return $content;
-
+ switch ($this->style) {
+ case 'card':
+ $li .= $this->li($this->a($title . $content, $class, $page->id()), $page->id());
+ break;
+
+ case 'list':
+ $li .= $this->li($this->a($title, $class, $page->id()) . $content, $page->id());
+ break;
+ }
}
+
+ $html = $this->ul($li);
+
+ return $html;
+ }
+
+ public function ul(string $content)
+ {
+ return '<ul class="pagelist">' . PHP_EOL . $content . PHP_EOL . '</ul>';
}
+ public function li(string $content, string $id)
+ {
+ return '<li id="' . $id . '">' . PHP_EOL . $content . PHP_EOL . '</li>' . PHP_EOL;
+ }
+
+ public function a(string $content, string $class, string $id)
+ {
+ return '<a ' . $class . ' href="' . $this->render->upage($id) . '">' . $content . '</a>' . PHP_EOL;
+ }
+
+ public function spandescription(Page $page)
+ {
+ if ($this->description) {
+ return '<span class="description">' . $page->description() . '</span>';
+ } else {
+ return '';
+ }
+ }
+
+
// _______________________________________ G E T _____________________________________
@@ -137,13 +188,8 @@ class Optlist extends Opt
public function setstyle($style)
{
- $this->style = intval($style);
- }
-
- public function setrender($render)
- {
- if(is_a($render, 'Wcms\Modelrender')) {
- $this->render = $render;
+ if (is_string($style) && key_exists($style, Model::LIST_STYLES)) {
+ $this->style = $style;
}
}
}