type = Model::mediatypes(); $this->hydrate($datas); } public function readfilter() { parse_str($this->filter, $datas); $this->hydrate($datas); } public function generatecontent() { $mediamanager = new Modelmedia(); $medialist = $mediamanager->getlistermedia($this->dir(), $this->type); 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; return $div; } } /** * Generate link adress for table header * * @param string $sortby * @return string link adress */ public function getsortbyadress(string $sortby) : string { if(!in_array($sortby, self::SORT_BY_FILTER)) { $sortby = 'id'; } if ($this->sortby === $sortby) { $order = $this->order * -1; } else { $order = $this->order; } $query = ['path' => $this->path, 'sortby' => $sortby, 'order' => $order]; if(array_diff( self::TYPES, $this->type) != []) { $query['type'] = $this->type; } return '?' . urldecode(http_build_query($query)); } public function getpathadress(string $path) : string { $query = ['path' => '/' . $path, 'sortby' => $this->sortby, 'order' => $this->order]; if(array_diff( self::TYPES, $this->type) != []) { $query['type'] = $this->type; } return '?' . urldecode(http_build_query($query)); } public function getquery() { $query = ['path' => $this->path, 'sortby' => $this->sortby, 'order' => $this->order]; if(array_diff( self::TYPES, $this->type) != []) { $query['type'] = $this->type; } return '%MEDIA?' . urldecode(http_build_query($query)). '%'; } // __________________________________________________ G E T ____________________________________________________________ public function fullmatch() { return $this->fullmatch; } public function filter() { return $this->filter; } /** * @return string formated like `/media/` */ public function path() { return $this->path; } /** * @return string formated like `media//` */ public function dir() { return ltrim($this->path, '/') . '/'; } public function sortby() { return $this->sortby; } public function order() { return $this->order; } public function type() { return $this->type; } // __________________________________________________ S E T ____________________________________________________________ public function setfullmatch(string $fullmatch) { $this->fullmatch = $fullmatch; } public function setfilter(string $filter) { if (!empty($filter)) { $this->filter = $filter; } } public function setpath(string $path) { if(preg_match('%^\/' . rtrim(Model::MEDIA_DIR, DIRECTORY_SEPARATOR) . '%', $path)) { $this->path = rtrim($path, DIRECTORY_SEPARATOR); } elseif (!preg_match('%^\/%', $path)) { $this->path = '/' . Model::MEDIA_DIR . rtrim($path, DIRECTORY_SEPARATOR); } } public function setsortby(string $sortby) { if (in_array($sortby, self::SORT_BY_FILTER)) { $this->sortby = $sortby; } } public function setorder(int $order) { if ($order === -1 || $order === 1) { $this->order = $order; } } public function settype($type) { if(is_array($type)) { $this->type = array_intersect(Model::mediatypes(), array_unique($type)); } } }