diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2019-08-07 13:18:45 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-08-07 13:18:45 +0200 |
commit | ce8c4c5e7d918d81e09710d7c89a45d36a80c32a (patch) | |
tree | 9ebe2fa7a2d89ebd3da16f229df3802041295b26 /app/class/medialist.php | |
parent | 7ccb591697227fcc77125e6b6fbe33f9fbe13ca4 (diff) | |
download | wcms-ce8c4c5e7d918d81e09710d7c89a45d36a80c32a.tar.gz wcms-ce8c4c5e7d918d81e09710d7c89a45d36a80c32a.zip |
new medialist parse synthax + media file id bugfix
Diffstat (limited to 'app/class/medialist.php')
-rw-r--r-- | app/class/medialist.php | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/app/class/medialist.php b/app/class/medialist.php new file mode 100644 index 0000000..f3bdac5 --- /dev/null +++ b/app/class/medialist.php @@ -0,0 +1,102 @@ +<?php + +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 */ + protected $order = 1; + /** @var string */ + protected $recursive = 'id'; + + const SORT_BY_OPTIONS = ['id', 'size']; + + + + // __________________________________________________ F U N ____________________________________________________________ + + + + public function __construct(array $datas = []) + { + $this->hydrate($datas); + $this->readoptions(); + + } + + 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); + } + + + // __________________________________________________ G E T ____________________________________________________________ + + + public function fullmatch() + { + return $this->fullmatch; + } + + public function options() + { + return $this->options; + } + + + + // __________________________________________________ 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; + } + } + + +}
\ No newline at end of file |