From e802d5204b96d645ec3d40b81b4a8bdc6e0ee675 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Mon, 4 Nov 2019 23:31:31 +0100 Subject: refactor: switch to psr-4 autoloading --- app/class/Medialist.php | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 app/class/Medialist.php (limited to 'app/class/Medialist.php') diff --git a/app/class/Medialist.php b/app/class/Medialist.php new file mode 100644 index 0000000..da5ba4f --- /dev/null +++ b/app/class/Medialist.php @@ -0,0 +1,155 @@ +hydrate($datas); + $this->readoptions(); + $this->generatecontent(); + } + + public function hydrate($datas) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function readoptions() + { + parse_str($this->options, $datas); + $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 ____________________________________________________________ + + + public function fullmatch() + { + return $this->fullmatch; + } + + public function options() + { + return $this->options; + } + + public function content() + { + return $this->content; + } + + + + // __________________________________________________ S E T ____________________________________________________________ + + + public function setfullmatch(string $fullmatch) + { + $this->fullmatch = $fullmatch; + } + + + public function setoptions(string $options) + { + if (!empty($options)) { + $this->options = $options; + } + } + + public function setpath(string $path) + { + $this->path = $path; + } + + public function setsortby(string $sortby) + { + if (in_array($sortby, self::SORT_BY_OPTIONS)) { + $this->sortby = $sortby; + } + } + + public function setorder(int $order) + { + if ($order === -1 || $order === 1) { + $this->order = $order; + } + } +} -- cgit v1.2.3