mirror of
https://github.com/openvk/openvk
synced 2024-11-15 03:31:18 +03:00
move $query var and optimize users/groups.search
го рофлить
This commit is contained in:
parent
3d2036345b
commit
3aafae1af3
10 changed files with 45 additions and 28 deletions
|
@ -254,17 +254,28 @@ final class Groups extends VKAPIRequestHandler
|
||||||
|
|
||||||
function search(string $q, int $offset = 0, int $count = 100, string $fields = "screen_name,is_admin,is_member,is_advertiser,photo_50,photo_100,photo_200")
|
function search(string $q, int $offset = 0, int $count = 100, string $fields = "screen_name,is_admin,is_member,is_advertiser,photo_50,photo_100,photo_200")
|
||||||
{
|
{
|
||||||
|
if($count > 100) {
|
||||||
|
$this->fail(100, "One of the parameters specified was missing or invalid: count should be less or equal to 100");
|
||||||
|
}
|
||||||
|
|
||||||
$clubs = new ClubsRepo;
|
$clubs = new ClubsRepo;
|
||||||
|
|
||||||
$array = [];
|
$array = [];
|
||||||
$find = $clubs->find($q);
|
$find = $clubs->find($q);
|
||||||
|
|
||||||
foreach ($find as $group)
|
foreach ($find->offsetLimit($offset, $count) as $group)
|
||||||
$array[] = $group->getId();
|
$array[] = $group->getId();
|
||||||
|
|
||||||
|
if(!$array || sizeof($array) < 1) {
|
||||||
|
return (object) [
|
||||||
|
"count" => 0,
|
||||||
|
"items" => [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return (object) [
|
return (object) [
|
||||||
"count" => $find->size(),
|
"count" => $find->size(),
|
||||||
"items" => $this->getById(implode(',', $array), "", $fields, $offset, $count)
|
"items" => $this->getById(implode(',', $array), "", $fields)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -329,6 +329,10 @@ final class Users extends VKAPIRequestHandler
|
||||||
string $fav_books = ""
|
string $fav_books = ""
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if($count > 100) {
|
||||||
|
$this->fail(100, "One of the parameters specified was missing or invalid: count should be less or equal to 100");
|
||||||
|
}
|
||||||
|
|
||||||
$users = new UsersRepo;
|
$users = new UsersRepo;
|
||||||
$output_sort = ['type' => 'id', 'invert' => false];
|
$output_sort = ['type' => 'id', 'invert' => false];
|
||||||
$output_params = [
|
$output_params = [
|
||||||
|
@ -384,12 +388,19 @@ final class Users extends VKAPIRequestHandler
|
||||||
$array = [];
|
$array = [];
|
||||||
$find = $users->find($q, $output_params, $output_sort);
|
$find = $users->find($q, $output_params, $output_sort);
|
||||||
|
|
||||||
foreach ($find as $user)
|
foreach ($find->offsetLimit($offset, $count) as $user)
|
||||||
$array[] = $user->getId();
|
$array[] = $user->getId();
|
||||||
|
|
||||||
|
if(!$array || sizeof($array) < 1) {
|
||||||
|
return (object) [
|
||||||
|
"count" => 0,
|
||||||
|
"items" => [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return (object) [
|
return (object) [
|
||||||
"count" => $find->size(),
|
"count" => $find->size(),
|
||||||
"items" => $this->get(implode(',', $array), $fields, $offset, $count)
|
"items" => $this->get(implode(',', $array), $fields)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,8 @@ class Applications
|
||||||
|
|
||||||
function find(string $query = "", array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
function find(string $query = "", array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
||||||
{
|
{
|
||||||
$result = $this->apps->where("CONCAT_WS(' ', name, description) LIKE ?", "%$query%")->where("enabled", 1);
|
$query = "%$query%";
|
||||||
|
$result = $this->apps->where("CONCAT_WS(' ', name, description) LIKE ?", $query)->where("enabled", 1);
|
||||||
$order_str = 'id';
|
$order_str = 'id';
|
||||||
|
|
||||||
switch($order['type']) {
|
switch($order['type']) {
|
||||||
|
|
|
@ -246,6 +246,7 @@ class Audios
|
||||||
|
|
||||||
function find(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false], int $page = 1, ?int $perPage = NULL): \Traversable
|
function find(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false], int $page = 1, ?int $perPage = NULL): \Traversable
|
||||||
{
|
{
|
||||||
|
$query = "%$query%";
|
||||||
$result = $this->audios->where([
|
$result = $this->audios->where([
|
||||||
"unlisted" => 0,
|
"unlisted" => 0,
|
||||||
"deleted" => 0,
|
"deleted" => 0,
|
||||||
|
@ -265,9 +266,9 @@ class Audios
|
||||||
}
|
}
|
||||||
|
|
||||||
if($params["only_performers"] == "1") {
|
if($params["only_performers"] == "1") {
|
||||||
$result->where("performer LIKE ?", "%$query%");
|
$result->where("performer LIKE ?", $query);
|
||||||
} else {
|
} else {
|
||||||
$result->where("name LIKE ? OR performer LIKE ?", "%$query%", "%$query%");
|
$result->where("name LIKE ? OR performer LIKE ?", $query, $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($params as $paramName => $paramValue) {
|
foreach($params as $paramName => $paramValue) {
|
||||||
|
@ -299,26 +300,15 @@ class Audios
|
||||||
|
|
||||||
function findPlaylists(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false]): \Traversable
|
function findPlaylists(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false]): \Traversable
|
||||||
{
|
{
|
||||||
|
$query = "%$query%";
|
||||||
$result = $this->playlists->where([
|
$result = $this->playlists->where([
|
||||||
"deleted" => 0,
|
"deleted" => 0,
|
||||||
])->where("CONCAT_WS(' ', name, description) LIKE ?", "%$query%");
|
])->where("CONCAT_WS(' ', name, description) LIKE ?", $query);
|
||||||
$order_str = 'id';
|
$order_str = (['id', 'length', 'listens'][$order['type']] ?? 'id') . ' ' . ($order['invert'] ? 'ASC' : 'DESC');
|
||||||
|
|
||||||
if(is_null($params['from_me']) || empty($params['from_me']))
|
if(is_null($params['from_me']) || empty($params['from_me']))
|
||||||
$result->where(["unlisted" => 0]);
|
$result->where(["unlisted" => 0]);
|
||||||
|
|
||||||
switch($order['type']) {
|
|
||||||
case 'id':
|
|
||||||
$order_str = 'id ' . ($order['invert'] ? 'ASC' : 'DESC');
|
|
||||||
break;
|
|
||||||
case 'length':
|
|
||||||
$order_str = 'length ' . ($order['invert'] ? 'ASC' : 'DESC');
|
|
||||||
break;
|
|
||||||
case 'listens':
|
|
||||||
$order_str = 'listens ' . ($order['invert'] ? 'ASC' : 'DESC');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($params as $paramName => $paramValue) {
|
foreach($params as $paramName => $paramValue) {
|
||||||
if(is_null($paramValue) || $paramValue == '') continue;
|
if(is_null($paramValue) || $paramValue == '') continue;
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Clubs
|
||||||
|
|
||||||
function find(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false], int $page = 1, ?int $perPage = NULL): \Traversable
|
function find(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false], int $page = 1, ?int $perPage = NULL): \Traversable
|
||||||
{
|
{
|
||||||
|
$query = "%$query%";
|
||||||
$result = $this->clubs;
|
$result = $this->clubs;
|
||||||
$order_str = 'id';
|
$order_str = 'id';
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ class Clubs
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $result->where("name LIKE ? OR about LIKE ?", "%$query%", "%$query%");
|
$result = $result->where("name LIKE ? OR about LIKE ?", $query, $query);
|
||||||
|
|
||||||
if($order_str)
|
if($order_str)
|
||||||
$result->order($order_str);
|
$result->order($order_str);
|
||||||
|
|
|
@ -156,7 +156,8 @@ class Posts
|
||||||
|
|
||||||
function find(string $query = "", array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
function find(string $query = "", array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
||||||
{
|
{
|
||||||
$result = $this->posts->where("content LIKE ?", "%$query%")->where("deleted", 0)->where("suggested", 0);
|
$query = "%$query%";
|
||||||
|
$result = $this->posts->where("content LIKE ?", $query)->where("deleted", 0)->where("suggested", 0);
|
||||||
$order_str = 'id';
|
$order_str = 'id';
|
||||||
|
|
||||||
switch($order['type']) {
|
switch($order['type']) {
|
||||||
|
|
|
@ -56,7 +56,8 @@ class Users
|
||||||
|
|
||||||
function find(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
function find(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
||||||
{
|
{
|
||||||
$result = $this->users->where("CONCAT_WS(' ', first_name, last_name, pseudo, shortcode) LIKE ?", "%$query%")->where("deleted", 0);
|
$query = "%$query%";
|
||||||
|
$result = $this->users->where("CONCAT_WS(' ', first_name, last_name, pseudo, shortcode) LIKE ?", $query)->where("deleted", 0);
|
||||||
$order_str = 'id';
|
$order_str = 'id';
|
||||||
|
|
||||||
switch($order['type']) {
|
switch($order['type']) {
|
||||||
|
|
|
@ -48,7 +48,8 @@ class Videos
|
||||||
|
|
||||||
function find(string $query = "", array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
function find(string $query = "", array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
||||||
{
|
{
|
||||||
$result = $this->videos->where("CONCAT_WS(' ', name, description) LIKE ?", "%$query%")->where("deleted", 0);
|
$query = "%$query%";
|
||||||
|
$result = $this->videos->where("CONCAT_WS(' ', name, description) LIKE ?", $query)->where("deleted", 0);
|
||||||
$order_str = 'id';
|
$order_str = 'id';
|
||||||
|
|
||||||
switch($order['type']) {
|
switch($order['type']) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<div class="playlistInfo">
|
<div class="playlistInfo">
|
||||||
<div class="playlistInfoTopPart">
|
<div class="playlistInfoTopPart">
|
||||||
<span class="playlistName noOverflow">
|
<span class="playlistName noOverflow">
|
||||||
{$playlist->getName(), 15}
|
{$playlist->getName()}
|
||||||
</span>
|
</span>
|
||||||
<span n:if='!empty($playlist->getDescription())' class="playlistDesc noOverflow">
|
<span n:if='!empty($playlist->getDescription())' class="playlistDesc noOverflow">
|
||||||
{$playlist->getDescription()}
|
{$playlist->getDescription()}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='page_wrap_content' id='search_page'>
|
<div class='page_wrap_content' id='search_page'>
|
||||||
<div n:class='page_wrap_content_main, $section == "audios" ? audios_padding'>
|
<div n:class='page_wrap_content_main, $section == "audios" && $count > 0 ? audios_padding'>
|
||||||
{if $count > 0}
|
{if $count > 0}
|
||||||
{if $section === 'users'}
|
{if $section === 'users'}
|
||||||
<div class='search_content def_row_content' n:foreach="$data as $dat">
|
<div class='search_content def_row_content' n:foreach="$data as $dat">
|
||||||
|
|
Loading…
Reference in a new issue