Skip to content

Commit 08ee9b5

Browse files
committed
allow multiple user ids in (not_)found_by search; fixes #356
1 parent cb7d222 commit 08ee9b5

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

okapi/services/caches/search/all.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@
125125
</ul>
126126
</opt>
127127
<opt name='found_by'>
128-
<p>User UUID. If given, the response will only include geocaches found by
129-
the given user.</p>
128+
<p>Pipe-separated list of user IDs. If given, the response will only include
129+
geocaches found by one or more of the given users.</p>
130130
</opt>
131131
<opt name='not_found_by'>
132-
<p>User UUID. If given, the response will only include geocaches not found by
133-
the given user.</p>
132+
<p>Pipe-separated list of user IDs. If given, the response will only include
133+
geocaches not found by one or more of the given users.</p>
134134
</opt>
135135
<opt name='watched_only' default='false'>
136136
<p><b>Notice:</b> This parameter may be used only for requests signed with an Access Token

okapi/services/caches/search/searching.inc.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ public function prepare_common_search_params()
380380
throw new InvalidParam('found_status', "'$tmp'");
381381
if ($tmp != 'either')
382382
{
383-
$found_cache_ids = self::get_found_cache_ids($this->request->token->user_id);
383+
$found_cache_ids = self::get_found_cache_ids(array($this->request->token->user_id));
384384
$operator = ($tmp == 'found_only') ? "in" : "not in";
385385
$where_conds[] = "caches.cache_id $operator ('".implode("','", array_map('mysql_real_escape_string', $found_cache_ids))."')";
386386
}
@@ -393,12 +393,13 @@ public function prepare_common_search_params()
393393
if ($tmp = $this->request->get_parameter('found_by'))
394394
{
395395
try {
396-
$user = OkapiServiceRunner::call("services/users/user", new OkapiInternalRequest(
397-
$this->request->consumer, null, array('user_uuid' => $tmp, 'fields' => 'internal_id')));
396+
$users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest(
397+
$this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id')));
398398
} catch (InvalidParam $e) { # invalid uuid
399399
throw new InvalidParam('found_by', $e->whats_wrong_about_it);
400400
}
401-
$found_cache_ids = self::get_found_cache_ids($user['internal_id']);
401+
$internal_user_ids = array_map(create_function('$internalid', 'return $internalid["internal_id"];'), $users);
402+
$found_cache_ids = self::get_found_cache_ids($internal_user_ids);
402403
$where_conds[] = "caches.cache_id in ('".implode("','", array_map('mysql_real_escape_string', $found_cache_ids))."')";
403404
}
404405

@@ -409,12 +410,13 @@ public function prepare_common_search_params()
409410
if ($tmp = $this->request->get_parameter('not_found_by'))
410411
{
411412
try {
412-
$user = OkapiServiceRunner::call("services/users/user", new OkapiInternalRequest(
413-
$this->request->consumer, null, array('user_uuid' => $tmp, 'fields' => 'internal_id')));
413+
$users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest(
414+
$this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id')));
414415
} catch (InvalidParam $e) { # invalid uuid
415416
throw new InvalidParam('not_found_by', $e->whats_wrong_about_it);
416417
}
417-
$found_cache_ids = self::get_found_cache_ids($user['internal_id']);
418+
$internal_user_ids = array_map(create_function('$internalid', 'return $internalid["internal_id"];'), $users);
419+
$found_cache_ids = self::get_found_cache_ids($internal_user_ids);
418420
$where_conds[] = "caches.cache_id not in ('".implode("','", array_map('mysql_real_escape_string', $found_cache_ids))."')";
419421
}
420422

@@ -846,13 +848,13 @@ public function get_latitude_expr()
846848
* Get the list of cache IDs which were found by given user.
847849
* Parameter needs to be *internal* user id, not uuid.
848850
*/
849-
private static function get_found_cache_ids($internal_user_id)
851+
private static function get_found_cache_ids($internal_user_ids)
850852
{
851853
return Db::select_column("
852854
select cache_id
853855
from cache_logs
854856
where
855-
user_id = '".mysql_real_escape_string($internal_user_id)."'
857+
user_id in ('".implode("','", array_map('mysql_real_escape_string', $internal_user_ids))."')
856858
and type in (
857859
'".mysql_real_escape_string(Okapi::logtypename2id("Found it"))."',
858860
'".mysql_real_escape_string(Okapi::logtypename2id("Attended"))."'

0 commit comments

Comments
 (0)