@@ -405,29 +405,42 @@ private static function _call(OkapiRequest $request)
405
405
406
406
# Check if already found it (and make sure the user is not the owner).
407
407
#
408
- # OCPL forbids logging 'Found it' or "Didn't find" for an already found cache,
409
- # while OCDE allows all kinds of duplicate logs.
408
+ # OCPL forbids logging 'Found it', 'Attended' and "Didn't find" for an
409
+ # already found/attended cache, while OCDE allows all kinds of duplicate logs.
410
+ #
411
+ # Duplicate 'Will attend' logs are currently allowed by OCPL code, though
412
+ # this may be unintentional and change in the future.
410
413
411
414
if (
412
415
Settings::get ('OC_BRANCH ' ) == 'oc.pl '
413
- && (( $ logtype == 'Found it ' ) || ( $ logtype == "Didn't find it " ) )
416
+ && in_array ( $ logtype, [ 'Found it ' , ' Attended ' , "Didn't find it " ] )
414
417
) {
418
+ $ matching_logtype = ($ logtype == "Didn't find it " ? 'Found it ' : $ logtype );
415
419
$ has_already_found_it = Db::select_value ("
416
420
select 1
417
421
from cache_logs
418
422
where
419
423
user_id = ' " .Db::escape_string ($ user ['internal_id ' ])."'
420
424
and cache_id = ' " .Db::escape_string ($ cache ['internal_id ' ])."'
421
- and type = ' " .Db::escape_string (Okapi::logtypename2id (" Found it " ))."'
425
+ and type = ' " .Db::escape_string (Okapi::logtypename2id ($ matching_logtype ))."'
422
426
and " .((Settings::get ('OC_BRANCH ' ) == 'oc.pl ' ) ? "deleted = 0 " : "true " )."
427
+ limit 1
428
+ /* there should be maximum 1 of these logs, but who knows ... */
423
429
" );
424
430
if ($ has_already_found_it ) {
425
- throw new CannotPublishException (_ (
426
- "You have already submitted a \"Found it \" log entry once. " .
427
- "Now you may submit \"Comments \" only! "
428
- ));
431
+ throw new CannotPublishException (
432
+ $ matching_logtype == 'Found it '
433
+ ? _ ("You have already submitted a \"Found it \" log entry once. " .
434
+ "Now you may submit \"Comments \" only! " )
435
+ : _ ("You have already submitted an \"Attended \" log entry once. " .
436
+ "Now you may submit \"Comments \" only! " )
437
+ );
429
438
}
430
- if ($ user ['uuid ' ] == $ cache ['owner ' ]['uuid ' ]) {
439
+
440
+ # OCPL owners are allowed to attend their own events, but not to
441
+ # search their own caches.
442
+
443
+ if ($ user ['uuid ' ] == $ cache ['owner ' ]['uuid ' ] && $ logtype != 'Attended ' ) {
431
444
throw new CannotPublishException (_ (
432
445
"You are the owner of this cache. You may submit " .
433
446
"\"Comments \" only! "
0 commit comments