diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index 0b59f838..f8706191 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -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") { + 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; $array = []; $find = $clubs->find($q); - foreach ($find as $group) + foreach ($find->offsetLimit($offset, $count) as $group) $array[] = $group->getId(); + + if(!$array || sizeof($array) < 1) { + return (object) [ + "count" => 0, + "items" => [], + ]; + } return (object) [ "count" => $find->size(), - "items" => $this->getById(implode(',', $array), "", $fields, $offset, $count) + "items" => $this->getById(implode(',', $array), "", $fields) ]; } diff --git a/VKAPI/Handlers/Users.php b/VKAPI/Handlers/Users.php index d85053bb..704823be 100644 --- a/VKAPI/Handlers/Users.php +++ b/VKAPI/Handlers/Users.php @@ -329,6 +329,10 @@ final class Users extends VKAPIRequestHandler 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; $output_sort = ['type' => 'id', 'invert' => false]; $output_params = [ @@ -384,12 +388,19 @@ final class Users extends VKAPIRequestHandler $array = []; $find = $users->find($q, $output_params, $output_sort); - foreach ($find as $user) + foreach ($find->offsetLimit($offset, $count) as $user) $array[] = $user->getId(); + if(!$array || sizeof($array) < 1) { + return (object) [ + "count" => 0, + "items" => [], + ]; + } + return (object) [ - "count" => $find->size(), - "items" => $this->get(implode(',', $array), $fields, $offset, $count) + "count" => $find->size(), + "items" => $this->get(implode(',', $array), $fields) ]; } diff --git a/Web/Models/Repositories/Applications.php b/Web/Models/Repositories/Applications.php index d889a5a4..c0906067 100644 --- a/Web/Models/Repositories/Applications.php +++ b/Web/Models/Repositories/Applications.php @@ -69,7 +69,8 @@ class Applications 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'; switch($order['type']) { diff --git a/Web/Models/Repositories/Audios.php b/Web/Models/Repositories/Audios.php index 1ec45dd2..7ff00a1d 100644 --- a/Web/Models/Repositories/Audios.php +++ b/Web/Models/Repositories/Audios.php @@ -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 { + $query = "%$query%"; $result = $this->audios->where([ "unlisted" => 0, "deleted" => 0, @@ -265,9 +266,9 @@ class Audios } if($params["only_performers"] == "1") { - $result->where("performer LIKE ?", "%$query%"); + $result->where("performer LIKE ?", $query); } else { - $result->where("name LIKE ? OR performer LIKE ?", "%$query%", "%$query%"); + $result->where("name LIKE ? OR performer LIKE ?", $query, $query); } foreach($params as $paramName => $paramValue) { @@ -299,26 +300,15 @@ class Audios function findPlaylists(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false]): \Traversable { + $query = "%$query%"; $result = $this->playlists->where([ "deleted" => 0, - ])->where("CONCAT_WS(' ', name, description) LIKE ?", "%$query%"); - $order_str = 'id'; + ])->where("CONCAT_WS(' ', name, description) LIKE ?", $query); + $order_str = (['id', 'length', 'listens'][$order['type']] ?? 'id') . ' ' . ($order['invert'] ? 'ASC' : 'DESC'); if(is_null($params['from_me']) || empty($params['from_me'])) $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) { if(is_null($paramValue) || $paramValue == '') continue; diff --git a/Web/Models/Repositories/Clubs.php b/Web/Models/Repositories/Clubs.php index 2b303ff4..b393952f 100644 --- a/Web/Models/Repositories/Clubs.php +++ b/Web/Models/Repositories/Clubs.php @@ -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 { + $query = "%$query%"; $result = $this->clubs; $order_str = 'id'; @@ -54,7 +55,7 @@ class Clubs break; } - $result = $result->where("name LIKE ? OR about LIKE ?", "%$query%", "%$query%"); + $result = $result->where("name LIKE ? OR about LIKE ?", $query, $query); if($order_str) $result->order($order_str); diff --git a/Web/Models/Repositories/Posts.php b/Web/Models/Repositories/Posts.php index 0c9a78f9..36082f24 100644 --- a/Web/Models/Repositories/Posts.php +++ b/Web/Models/Repositories/Posts.php @@ -156,7 +156,8 @@ class Posts 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'; switch($order['type']) { diff --git a/Web/Models/Repositories/Users.php b/Web/Models/Repositories/Users.php index a2f298b1..cc75b50f 100644 --- a/Web/Models/Repositories/Users.php +++ b/Web/Models/Repositories/Users.php @@ -56,7 +56,8 @@ class Users 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'; switch($order['type']) { diff --git a/Web/Models/Repositories/Videos.php b/Web/Models/Repositories/Videos.php index 0204e2ff..e91c226d 100644 --- a/Web/Models/Repositories/Videos.php +++ b/Web/Models/Repositories/Videos.php @@ -48,7 +48,8 @@ class Videos 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'; switch($order['type']) { diff --git a/Web/Presenters/templates/Audio/playlistListView.xml b/Web/Presenters/templates/Audio/playlistListView.xml index 6a1e9c96..e7daa9fb 100644 --- a/Web/Presenters/templates/Audio/playlistListView.xml +++ b/Web/Presenters/templates/Audio/playlistListView.xml @@ -6,7 +6,7 @@