|
1
|
|
|
<?php |
|
2
|
|
|
/*************************************************************************** |
|
3
|
|
|
* for license information see LICENSE.md |
|
4
|
|
|
***************************************************************************/ |
|
5
|
|
|
|
|
6
|
|
|
namespace OcLegacy\GeoCache; |
|
7
|
|
|
|
|
8
|
|
|
class Recommendation |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @param $logId |
|
12
|
|
|
*/ |
|
13
|
|
|
public static function discardRecommendation($logId) |
|
14
|
|
|
{ |
|
15
|
|
|
$rsLog = sql( |
|
16
|
|
|
"SELECT `cache_logs`.`cache_id`, |
|
17
|
|
|
`cache_logs`.`user_id`, |
|
18
|
|
|
`cache_rating`.`rating_date` IS NOT NULL AS `is_rating_log` |
|
19
|
|
|
FROM `cache_logs` |
|
20
|
|
|
LEFT JOIN `cache_rating` |
|
21
|
|
|
ON `cache_rating`.`cache_id`=`cache_logs`.`cache_id` |
|
22
|
|
|
AND `cache_rating`.`user_id`=`cache_logs`.`user_id` |
|
23
|
|
|
AND `cache_rating`.`rating_date`=`cache_logs`.`date` |
|
24
|
|
|
WHERE `cache_logs`.`id`='&1' |
|
25
|
|
|
AND `cache_logs`.`type` IN (1,7)", |
|
26
|
|
|
$logId |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
if ($rLog = sql_fetch_assoc($rsLog)) { |
|
30
|
|
|
$rsFirstOtherFound = sql( |
|
31
|
|
|
"SELECT `date` |
|
32
|
|
|
FROM `cache_logs` |
|
33
|
|
|
WHERE `cache_id`='&1' |
|
34
|
|
|
AND `user_id`='&2' |
|
35
|
|
|
AND `id`<>'&3' |
|
36
|
|
|
AND `type` IN (1,7) |
|
37
|
|
|
ORDER BY `date` |
|
38
|
|
|
LIMIT 1", |
|
39
|
|
|
$rLog['cache_id'], |
|
40
|
|
|
$rLog['user_id'], |
|
41
|
|
|
$logId |
|
42
|
|
|
); |
|
43
|
|
|
$rFirstOtherFound = sql_fetch_assoc($rsFirstOtherFound); |
|
44
|
|
|
sql_free_result($rsFirstOtherFound); |
|
45
|
|
|
|
|
46
|
|
|
if ($rFirstOtherFound && $rLog['is_rating_log']) { |
|
|
|
|
|
|
47
|
|
|
sql( |
|
48
|
|
|
"UPDATE `cache_rating` |
|
49
|
|
|
SET `rating_date`='&3' |
|
50
|
|
|
WHERE `cache_id`='&1' |
|
51
|
|
|
AND `user_id`='&2'", |
|
52
|
|
|
$rLog['cache_id'], |
|
53
|
|
|
$rLog['user_id'], |
|
54
|
|
|
$rFirstOtherFound['date'] |
|
55
|
|
|
); |
|
56
|
|
|
// This will trigger an cache_logs.last_modified update of the corresponding |
|
57
|
|
|
// log, so that XML interface will resend it with the updated |
|
58
|
|
|
// "recommendation" flag. |
|
59
|
|
|
} elseif (!$rFirstOtherFound) { |
|
|
|
|
|
|
60
|
|
|
// This is also called for $rLog['is_rating_log'] == false, so that |
|
61
|
|
|
// even a rating record with inconsistent date gets deleted. |
|
62
|
|
|
sql( |
|
63
|
|
|
"DELETE FROM `cache_rating` WHERE `cache_id` = '&1' AND `user_id` = '&2'", |
|
64
|
|
|
$rLog['cache_id'], |
|
65
|
|
|
$rLog['user_id'] |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
sql_free_result($rsLog); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.