From e75e54d23d262940acd4c7df2a8cc7b7ab1751d5 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 7 Aug 2019 18:10:00 +0200 Subject: media insertion new synthax working --- app/class/medialist.php | 97 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 23 deletions(-) (limited to 'app/class/medialist.php') diff --git a/app/class/medialist.php b/app/class/medialist.php index f3bdac5..156ee2e 100644 --- a/app/class/medialist.php +++ b/app/class/medialist.php @@ -4,18 +4,29 @@ class Medialist { /** @var string full regex match */ protected $fullmatch; + /** @var string options */ protected $options = ''; + /** @var string directory of media */ protected $path = ''; + /** @var string */ protected $sortby = 'id'; - /** @var string */ + + /** @var int */ protected $order = 1; - /** @var string */ - protected $recursive = 'id'; - const SORT_BY_OPTIONS = ['id', 'size']; + /** @var int display media contents*/ + protected $display = 1; + + /** @var int display download links*/ + protected $links = 0; + + /** @var string ouput html code generated*/ + protected $content = ''; + + const SORT_BY_OPTIONS = ['id', 'size', 'type']; @@ -23,22 +34,22 @@ class Medialist - public function __construct(array $datas = []) - { + public function __construct(array $datas = []) + { $this->hydrate($datas); $this->readoptions(); + $this->generatecontent(); + } - } - - public function hydrate($datas) - { - foreach ($datas as $key => $value) { - $method = 'set' . $key; + public function hydrate($datas) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; - if (method_exists($this, $method)) { - $this->$method($value); - } - } + if (method_exists($this, $method)) { + $this->$method($value); + } + } } public function readoptions() @@ -47,6 +58,43 @@ class Medialist $this->hydrate($datas); } + public function generatecontent() + { + $mediamanager = new Modelmedia(); + $medialist = $mediamanager->getlistermedia(Model::MEDIA_DIR . $this->path . '/'); + if (!$medialist) { + $this->content = 'RENDERING ERROR : path : ' . Model::MEDIA_DIR . $this->path . '/ does not exist'; + return false; + } else { + + $mediamanager->medialistsort($medialist, $this->sortby, $this->order); + + $dirid = str_replace('/', '-', $this->path); + + $div = '
' . PHP_EOL; + + foreach ($medialist as $media) { + $div .= '
'; + if ($media->type() == 'image') { + $div .= '' . $media->id() . ''; + } elseif ($media->type() == 'sound') { + $div .= '
' . PHP_EOL; + } + + $div .= '
' . PHP_EOL; + + $this->content = $div; + + return true; + } + } + // __________________________________________________ G E T ____________________________________________________________ @@ -61,6 +109,11 @@ class Medialist return $this->options; } + public function content() + { + return $this->content; + } + // __________________________________________________ S E T ____________________________________________________________ @@ -74,7 +127,7 @@ class Medialist public function setoptions(string $options) { - if(!empty($options)) { + if (!empty($options)) { $this->options = $options; } } @@ -83,20 +136,18 @@ class Medialist { $this->path = $path; } - + public function setsortby(string $sortby) { - if(in_array($sortby, self::SORT_BY_OPTIONS)) { + if (in_array($sortby, self::SORT_BY_OPTIONS)) { $this->sortby = $sortby; } } public function setorder(int $order) { - if($order === -1 || $order === 1) { + if ($order === -1 || $order === 1) { $this->order = $order; } } - - -} \ No newline at end of file +} -- cgit v1.2.3