diff --git a/Web/Models/Repositories/Clubs.php b/Web/Models/Repositories/Clubs.php index de5d9269..c15edfb2 100644 --- a/Web/Models/Repositories/Clubs.php +++ b/Web/Models/Repositories/Clubs.php @@ -62,9 +62,25 @@ class Clubs $order_str = 'id'; switch($order['type']) { + default: case 'id': $order_str = 'id ' . ($order['invert'] ? 'ASC' : 'DESC'); break; + case 'subs': + $sql_query = <<where("name LIKE ? OR about LIKE ?", $query, $query); diff --git a/Web/Models/Repositories/Util/EntityStream.php b/Web/Models/Repositories/Util/EntityStream.php index dd8f317f..cf715fad 100644 --- a/Web/Models/Repositories/Util/EntityStream.php +++ b/Web/Models/Repositories/Util/EntityStream.php @@ -27,7 +27,7 @@ class EntityStream implements \IteratorAggregate return new $this->entityClass($result); } - private function stream(\Traversable $iterator): \Traversable + protected function stream(\Traversable $iterator): \Traversable { foreach($iterator as $result) yield $this->getEntity($result); diff --git a/Web/Models/Repositories/Util/RawEntityStream.php b/Web/Models/Repositories/Util/RawEntityStream.php new file mode 100644 index 00000000..fe075b30 --- /dev/null +++ b/Web/Models/Repositories/Util/RawEntityStream.php @@ -0,0 +1,50 @@ +sqlQuery = $sql; + $this->entityRepo = new ($class[0] === "\\" ? $repo : "openvk\\Web\\Models\\Repositories\\$repo"."s"); + $this->dbParams = $db_params; + } + + private function dbs(int $page = 0, ?int $perPage = NULL): \Traversable + { + if(!$this->dbQuery) { + $this->dbParams[] = $perPage; + $this->dbParams[] = (($page - 1) * $perPage); + + $this->dbQuery = \Chandler\Database\DatabaseConnection::i()->getConnection()->query($this->sqlQuery, ...$this->dbParams); + } + + return $this->dbQuery; + } + + private function getEntity(Row $result) + { + $repo = new $this->entityRepo; + return $repo->get($result->id); + } + + protected function stream(\Traversable $iterator): \Traversable + { + foreach($iterator as $result) + yield $this->getEntity($result); + } + + function page(int $page, ?int $perPage = NULL): \Traversable + { + $fetchedRows = $this->dbs($page, $perPage); + + return $this->stream($fetchedRows); + } + + function size(): int + { + bdump($this->dbs()->getRowCount()); + return $this->dbs()->getRowCount(); + } +} diff --git a/Web/Presenters/templates/Search/Index.xml b/Web/Presenters/templates/Search/Index.xml index 92e8b1d4..3108c96d 100644 --- a/Web/Presenters/templates/Search/Index.xml +++ b/Web/Presenters/templates/Search/Index.xml @@ -330,6 +330,9 @@ {if OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"]} {/if} + {elseif $section == "groups"} + + {elseif $section == "posts"} {elseif $section == "audios"} @@ -344,7 +347,7 @@ {/if} -