forked from opencaching/opencaching-pl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_titled_add.php
158 lines (119 loc) · 4.68 KB
/
cache_titled_add.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
global $titled_cache_nr_found, $titled_cache_period_prefix;
require_once('./lib/common.inc.php');
if ( !isset( $_REQUEST[ 'CRON' ] ) )
exit;
$dbc = new dataBase();
$queryMax = "SELECT max( date_alg ) dataMax FROM cache_titled";
$dbc->simpleQuery($queryMax);
$record = $dbc->dbResultFetch();
$dataMax = $record["dataMax"];
$start_date_alg = date("Y-m-d");
$date_alg = $start_date_alg;
$dStart = new DateTime($dataMax);
$dEnd = new DateTime($date_alg);
$dDiff = $dStart->diff($dEnd);
$securityPeriod = 0;
if ( $titled_cache_period_prefix == "week" )
$securityPeriod = 7;
if ( $titled_cache_period_prefix == "month" )
$securityPeriod = 28;
if ( $dDiff->days < $securityPeriod )
exit;
$queryS ="
select
top.cacheId, top.cacheName, top.cacheRegion, ifnull( nrT.nrTinR, 0) nrTinR,
top.RATE, top.ratio,
top.cRating, top.cFounds, top.cNrDays, top.cDateCrt
from
(
SELECT caches.cache_id cacheId , caches.name cacheName, adm3 cacheRegion,
user.user_id userId, user.username userName,
round((r.rating/f.nr_founds) + DATEDIFF(caches.date_created, :1 )/5000,4) RATE,
round((r.rating/f.nr_founds), 4) ratio,
r.rating cRating, f.nr_founds cFounds, caches.date_created cDateCrt,
DATEDIFF(caches.date_created, :1 ) cNrDays
FROM `caches`
JOIN
(
SELECT lcaches.cache_id cid, count(*) rating
FROM `caches` lcaches
INNER JOIN `cache_logs` ON `cache_logs`.`cache_id` = lcaches .`cache_id`
JOIN cache_rating ON `cache_rating`.`cache_id` = `cache_logs`.`cache_id`
AND `cache_rating`.`user_id` = `cache_logs`.user_id
where
`cache_logs`.`deleted` =0 AND `cache_logs`.`type` =1
and cache_logs.date_created < :1
group by 1
)
as r ON r.cid = caches.cache_id
JOIN
(
SELECT fcaches.cache_id cid, count(*) nr_founds
FROM
caches fcaches
JOIN cache_logs ON cache_logs.cache_id = fcaches.cache_id
where
cache_logs.deleted=0 AND cache_logs.type=1
and cache_logs.date_created < :1
group by 1
)
as f ON f.cid = caches.cache_id
JOIN user ON `caches`.`user_id` = `user`.`user_id`
JOIN `cache_location` ON `caches`.`cache_id` = `cache_location`.`cache_id`
left JOIN cache_titled ON cache_titled.cache_id = caches.cache_id
WHERE
`status` =1
AND `caches`.`type` <>4 AND `caches`.`type` <>5 AND caches.type <>6
and f.nr_founds >= :2 and caches.date_created < :1
and cache_titled.cache_id is NULL
ORDER BY RATE DESC, founds DESC, caches.date_created DESC
LIMIT 30) as top
left join
(
select adm3 cacheRegion, count(*) nrTinR from cache_titled
JOIN cache_location ON cache_titled.cache_id = cache_location.cache_id
group by adm3
) as nrT on top.cacheRegion = nrT.cacheRegion
order by nrTinR, cFounds DESC, cDateCrt, RATE DESC
";
$dbc->multiVariableQuery($queryS, $date_alg, $titled_cache_nr_found );
$rec = $dbc->dbResultFetch();
$queryL = "
SELECT i.id logId
FROM
(select cache_logs.id, cache_logs.cache_id from
cache_logs
where
cache_logs.cache_id = :1 and
cache_logs.id =
(select id from cache_logs cl
JOIN cache_rating ON `cache_rating`.`cache_id` = cl.`cache_id`
AND `cache_rating`.`user_id` = cl.user_id
where cl.cache_id = cache_logs.cache_id
ORDER BY length(cl.text) DESC LIMIT 1 )
) as i";
$dbc->multiVariableQuery($queryL, $rec[ "cacheId" ] );
$recL = $dbc->dbResultFetch();
$queryI = "INSERT INTO cache_titled
(cache_id, rate, ratio, rating, found, days, date_alg, log_id)
VALUES (:1, :2, :3, :4, :5, :6, :7, :8)";
$dbc->multiVariableQuery($queryI, $rec[ "cacheId" ], $rec[ "RATE" ], $rec[ "ratio" ],
$rec[ "cRating" ], $rec[ "cFounds" ], $rec[ "cNrDays" ], $date_alg, $recL["logId"] );
$queryLogI =
"INSERT INTO cache_logs
(cache_id, user_id, type, date,
text, text_html, text_htmledit, last_modified , okapi_syncbase, uuid, picturescount, mp3count,
date_created, owner_notified, node, deleted, encrypt,
del_by_user_id, last_deleted, edit_by_user_id, edit_count )
VALUES ( :1, :2, :3, :4, :5, :6, :7, :8 , :9 , :10, :11, :12, :13, :14, :15, '0', '0', NULL , NULL , NULL , '0' )";
$SystemUser = -1;
$LogType = 12; //OCTeam
$ntitled_cache = $titled_cache_period_prefix.'_titled_cache_congratulations';
$msgText = tr($ntitled_cache);
$LogUuid = create_uuid();
$dbc->multiVariableQuery($queryLogI, $rec[ "cacheId" ], $SystemUser, $LogType, $date_alg,
$msgText, '1', '1', $date_alg, $date_alg, $LogUuid, '0', '0',
$date_alg, '0', $oc_nodeid );
unset($dbc);
?>