Skip to content

Commit 1e3a880

Browse files
committed
added geocache fields 'is_rated' and 'is_recommended'
1 parent 1da1bec commit 1e3a880

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

okapi/services/caches/geocache/docs.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,22 @@
280280
cache location <em>and</em> go back (from/to a parking spot, etc.);
281281
<b>null</b> if unknown,</p>
282282
</li>
283+
<li>
284+
<p>%OKAPI:infotag:ocpl-specific% <b>is_rated</b> - boolean, <b>true</b>
285+
if the user rated this cache.</p>
286+
<p>This is private data. You will need Level 3 Authentication to access
287+
this field.</p>
288+
289+
<p><b>Notice:</b> Only OCPL-based Opencaching installations implement
290+
ratings for their geocaches. On OCDE-based installations, this field
291+
will always contain <b>false</b>.</p>
292+
</li>
293+
<li>
294+
<p><b>is_recommended</b> - boolean, <b>true</b> if the user recommended this
295+
cache.</p>
296+
<p>This field requires you to use the <b>user_uuid</b> parameter
297+
(or Level 3 Authentication).</p>
298+
</li>
283299
<li>
284300
<p>%OKAPI:infotag:ocpl-specific% <b>rating</b> - float (between 1 and 5), an
285301
overall rating of the cache, or <b>null</b> when the geocache does not have a

okapi/services/caches/geocaches/WebService.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function options()
3434
'is_ignored', 'willattends', 'country', 'state', 'preview_image',
3535
'trip_time', 'trip_distance', 'attribution_note','gc_code', 'hint2', 'hints2',
3636
'protection_areas', 'short_description', 'short_descriptions', 'needs_maintenance',
37-
'watchers');
37+
'watchers', 'is_rated', 'is_recommended');
3838

3939
public static function call(OkapiRequest $request)
4040
{
@@ -273,6 +273,8 @@ public static function call(OkapiRequest $request)
273273
case 'is_not_found': /* handled separately */ break;
274274
case 'is_watched': /* handled separately */ break;
275275
case 'is_ignored': /* handled separately */ break;
276+
case 'is_rated': /* handled separately */ break;
277+
case 'is_recommended': /* handled separately */ break;
276278
case 'founds': $entry['founds'] = $row['founds'] + 0; break;
277279
case 'notfounds':
278280
if ($row['type'] != 6) { # non-event
@@ -501,6 +503,53 @@ public static function call(OkapiRequest $request)
501503
$result_ref['is_ignored'] = isset($tmp2[$cache_code]);
502504
}
503505

506+
# is_rated
507+
508+
if (in_array('is_rated', $fields))
509+
{
510+
if ($request->token == null)
511+
throw new BadRequest("Level 3 Authentication is required to access 'is_rated' field.");
512+
$tmp2 = array();
513+
if (Settings::get('OC_BRANCH') == 'oc.pl')
514+
{
515+
$tmp = Db::select_column("
516+
select c.wp_oc
517+
from
518+
caches c,
519+
scores s
520+
where
521+
c.cache_id = s.cache_id
522+
and s.user_id = '".Db::escape_string($request->token->user_id)."'
523+
");
524+
foreach ($tmp as $cache_code)
525+
$tmp2[$cache_code] = true;
526+
}
527+
foreach ($results as $cache_code => &$result_ref)
528+
$result_ref['is_rated'] = isset($tmp2[$cache_code]);
529+
}
530+
531+
# is_recommended
532+
533+
if (in_array('is_recommended', $fields))
534+
{
535+
if ($user_id == null)
536+
throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_recommended' field.");
537+
$tmp = Db::select_column("
538+
select c.wp_oc
539+
from
540+
caches c,
541+
cache_rating cr
542+
where
543+
c.cache_id = cr.cache_id
544+
and cr.user_id = '".Db::escape_string($user_id)."'
545+
");
546+
$tmp2 = array();
547+
foreach ($tmp as $cache_code)
548+
$tmp2[$cache_code] = true;
549+
foreach ($results as $cache_code => &$result_ref)
550+
$result_ref['is_recommended'] = isset($tmp2[$cache_code]);
551+
}
552+
504553
# Descriptions and hints.
505554

506555
if (in_array('description', $fields) || in_array('descriptions', $fields)

0 commit comments

Comments
 (0)