mirror of
https://github.com/openvk/openvk
synced 2025-04-23 16:43:02 +03:00
Compare commits
3 commits
e49f927186
...
66a4d94feb
Author | SHA1 | Date | |
---|---|---|---|
|
66a4d94feb | ||
|
228f14e384 | ||
|
c6f3d767fc |
8 changed files with 87 additions and 2 deletions
|
@ -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 = <<<EOF
|
||||
SELECT `groups`.`id`, `subs`
|
||||
FROM `groups`
|
||||
LEFT JOIN
|
||||
(SELECT `target`, COUNT(`follower`) as `subs`
|
||||
FROM `subscriptions`
|
||||
WHERE `model` = "openvk\\\\Web\\\\Models\\\\Entities\\\\Club"
|
||||
GROUP BY `target`) `subscriptions` ON `subscriptions`.`target` = `groups`.`id`
|
||||
WHERE `groups`.`name` LIKE ? OR `groups`.`about` LIKE ?
|
||||
ORDER BY `subs` DESC
|
||||
LIMIT ? OFFSET ?;
|
||||
EOF;
|
||||
|
||||
return new Util\RawEntityStream("Club", $sql_query, $query, $query);
|
||||
}
|
||||
|
||||
$result = $result->where("name LIKE ? OR about LIKE ?", $query, $query);
|
||||
|
|
|
@ -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);
|
||||
|
|
50
Web/Models/Repositories/Util/RawEntityStream.php
Normal file
50
Web/Models/Repositories/Util/RawEntityStream.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Models\Repositories\Util;
|
||||
use Nette\Database\Row;
|
||||
|
||||
class RawEntityStream extends EntityStream
|
||||
{
|
||||
function __construct(string $repo, string $sql, ...$db_params)
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
|
@ -343,6 +343,9 @@
|
|||
{if OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"]}
|
||||
<option value="rating" n:attr="selected => $order == 'rating'">{_s_order_by_rating}</option>
|
||||
{/if}
|
||||
{elseif $section == "groups"}
|
||||
<option value="id" n:attr="selected => $order == 'id'">{_s_order_by_creation_date}</option>
|
||||
<option value="subs" n:attr="selected => $order == 'subs'">{_s_order_by_subs}</option>
|
||||
{elseif $section == "posts"}
|
||||
<option value="id" n:attr="selected => $order == 'id'">{_s_order_by_publishing_date}</option>
|
||||
{elseif $section == "audios"}
|
||||
|
@ -357,7 +360,7 @@
|
|||
{/if}
|
||||
</select>
|
||||
|
||||
<label n:if="$order != 'rating'">
|
||||
<label n:if="$order != 'rating' && $order != 'subs'">
|
||||
<input type="checkbox" name="invert" value="1" form="search_form" n:attr="checked => $_REQUEST['invert'] == '1'">
|
||||
{_s_order_invert}
|
||||
</label>
|
||||
|
|
|
@ -4173,6 +4173,16 @@ hr {
|
|||
color: #6b6b6b;
|
||||
}
|
||||
|
||||
.doc_icon.no_image span::before {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAKCAYAAABmBXS+AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAABYSURBVChTY2RAAvNnzmwBUtVA3JqYnl4DFgQCJigNAyAFyDQYoCvCCohSxAh0x38oGydANwmmAUUjE9AXKD5EByB5uAIka0E0WBxmAHo4wa3BawOmRxgYAOA2GQMa5cgCAAAAAElFTkSuQmCC");
|
||||
transform: translateY(2px) translateX(-3px);
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.docListViewItem .doc_icon img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
|
|
@ -2141,6 +2141,7 @@
|
|||
"s_order_by_creation_date" = "By creation date";
|
||||
"s_order_by_publishing_date" = "By publication date";
|
||||
"s_order_by_upload_date" = "By upload date";
|
||||
"s_order_by_subs" = "By followers";
|
||||
|
||||
"s_by_date" = "By date";
|
||||
"s_registered_before" = "Registered before";
|
||||
|
|
|
@ -2036,6 +2036,7 @@
|
|||
"s_order_by_creation_date" = "По дате создания";
|
||||
"s_order_by_publishing_date" = "По дате публикации";
|
||||
"s_order_by_upload_date" = "По дате загрузки";
|
||||
"s_order_by_subs" = "По подписчикам";
|
||||
|
||||
"s_by_date" = "По дате";
|
||||
"s_registered_before" = "Зарегистрирован до";
|
||||
|
|
|
@ -656,3 +656,7 @@ ul {
|
|||
.docListViewItem .doc_content b {
|
||||
color: #7c94c5;
|
||||
}
|
||||
|
||||
.doc_icon.no_image span::before {
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAKCAYAAABmBXS+AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsAAAA7AAWrWiQkAAABXSURBVChTY2RAAoFe9ZuEBOR93314uHn9tkY/qDADE5QGA5ACZBoGUBThAkQpYkyOmvcfysYJiDMJROAzbe6yJEZ4EGBTCFIAolHCCVkhTAFWgGkiAwMAzxkZ3qVQ7YEAAAAASUVORK5CYII=");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue