Skip to content
Permalink
Browse files

always prefer user-supplied cache country; updates #82

  • Loading branch information...
following5 committed Aug 7, 2015
1 parent 61cee6a commit 0e0a4eaa968872f96f63798b53ed845d87dd3a88
Showing with 60 additions and 32 deletions.
  1. +16 −16 htdocs/lib2/logic/getNew.class.php
  2. +8 −8 htdocs/tops.php
  3. +36 −8 htdocs/util2/cron/modules/rating_tops.class.php
@@ -105,15 +105,15 @@ private function cacheRs($args=null)
`caches`.`type`,
`caches`.`longitude` `longitude`,
`caches`.`latitude` `latitude`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`,
`cache_location`.`adm2`,
`cache_location`.`adm3`,
`cache_location`.`adm4`,
IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`,
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,''),
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,''),
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,''),
`ca`.`attrib_id` IS NOT NULL AS `oconly`
FROM `caches`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `countries` ON `countries`.`short`=`cache_location`.`code1`
LEFT JOIN `countries` ON `countries`.`short`=`caches`.`country`
LEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` AND `sys_trans_text`.`lang`='&2'
LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
WHERE `caches`.`country`='&1' AND
@@ -149,15 +149,15 @@ private function eventRs($args=null)
`caches`.`cache_id` `cache_id`,
`caches`.`name` `name`,
`caches`.`date_hidden`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`,
`cache_location`.`adm2`,
`cache_location`.`adm3`,
`cache_location`.`adm4`,
`ca`.`attrib_id` IS NOT NULL AS `oconly`
IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`,
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,''),
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,''),
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,''),
`ca`.`attrib_id` IS NOT NULL AS `oconly`
FROM `caches`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `countries` ON `countries`.`short`=`cache_location`.`code1`
LEFT JOIN `countries` ON `countries`.`short`=`caches`.`country`
LEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` AND `sys_trans_text`.`lang`='&2'
LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
WHERE `caches`.`country`='&1' AND
@@ -223,16 +223,16 @@ private function ratingRs($args=null)
`caches`.`cache_id` AS `cache_id`,
`caches`.`name` AS `name`,
`caches`.`type`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`,
`cache_location`.`adm2`,
`cache_location`.`adm3`,
`cache_location`.`adm4`,
IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`,
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,''),
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,''),
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,''),
`ca`.`attrib_id` IS NOT NULL AS `oconly`
FROM `cache_rating`
INNER JOIN `caches` ON `caches`.`cache_id`=`cache_rating`.`cache_id`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
LEFT JOIN `cache_location` ON `cache_rating`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `countries` ON `countries`.`short`=`cache_location`.`code1`
LEFT JOIN `countries` ON `countries`.`short`=`caches`.`country`
LEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` AND `sys_trans_text`.`lang`='&2'
LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
WHERE `caches`.`country`='&1' AND
@@ -14,24 +14,24 @@
if (!$tpl->is_cached())
{
$rs = sql("SELECT IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`,
`cache_location`.`adm3`,
`cache_location`.`code1`,
$rs = sql("SELECT IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`,
IF(`cache_location`.`code1`=`caches`.`country`,`cache_location`.`adm3`,NULL) AS `adm3`,
`caches`.`country` AS `code1`,
`rating_tops`.`rating` AS `idx`, `stat_caches`.`toprating` AS `ratings`, `stat_caches`.`found` AS `founds`,
`caches`.`name`, `caches`.`wp_oc` AS `wpoc`, `user`.`username`, `user`.`user_id` AS `userid`,
`ca`.`attrib_id` IS NOT NULL AS `oconly`
FROM `rating_tops`
INNER JOIN `caches` ON `rating_tops`.`cache_id`=`caches`.`cache_id`
INNER JOIN `cache_location` ON `rating_tops`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `countries` ON `countries`.`short`=`cache_location`.`code1`
LEFT JOIN `countries` ON `countries`.`short`=`caches`.`country`
LEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` AND `sys_trans_text`.`lang`='&1'
INNER JOIN `stat_caches` ON `rating_tops`.`cache_id`=`stat_caches`.`cache_id`
INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_id`
LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
ORDER BY `cache_location`.`adm1` ASC,
`cache_location`.`adm3` ASC,
`rating_tops`.`rating` DESC,
`caches`.`name` ASC", $opt['template']['locale']);
ORDER BY `adm1` ASC,
`adm3` ASC,
`rating_tops`.`rating` DESC,
`caches`.`name` ASC", $opt['template']['locale']);
$tpl->assign_rs('tops', $rs);
sql_free_result($rs);
}
@@ -26,23 +26,51 @@ function run()
sql("CREATE TEMPORARY TABLE &topRatings (`cache_id` INT(11) PRIMARY KEY, `ratings` INT(11)) ENGINE=MEMORY");
sql("CREATE TEMPORARY TABLE &topResult (`idx` INT(11), `cache_id` INT(11) PRIMARY KEY, `ratings` INT(11), `founds` INT(11)) ENGINE=MEMORY");
$rsAdm1 = sql('SELECT SQL_BUFFER_RESULT SQL_SMALL_RESULT DISTINCT `adm1`, `code1` FROM `cache_location` WHERE NOT ISNULL(`adm1`) ORDER BY `adm1` ASC');
while ($rAdm1 = sql_fetch_assoc($rsAdm1))
$rsCountry = sql('SELECT SQL_BUFFER_RESULT SQL_SMALL_RESULT DISTINCT `country` FROM `caches`');
while ($rCountry = sql_fetch_assoc($rsCountry))
{
$rsAdm3 = sql("SELECT SQL_BUFFER_RESULT SQL_SMALL_RESULT DISTINCT `adm3` FROM `cache_location` WHERE `code1`='&1' ORDER BY `adm3` ASC", $rAdm1['code1']);
$rsAdm3 = sql("
SELECT SQL_BUFFER_RESULT SQL_SMALL_RESULT DISTINCT
IF(`cache_location`.`code1`=`caches`.`country`,`cache_location`.`code3`,NULL) `code3`
FROM `caches`
LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_id`
WHERE `caches`.`country`='&1'",
$rCountry['country']);
while ($rAdm3 = sql_fetch_assoc($rsAdm3))
{
sql("TRUNCATE TABLE &topLocationCaches");
sql("TRUNCATE TABLE &topRatings");
sql("TRUNCATE TABLE &topResult");
// Alle Caches für diese Gruppe finden
if ($rAdm3['adm3'] == null)
sql("INSERT INTO &topLocationCaches (`cache_id`) SELECT `caches`.`cache_id` FROM `cache_location` INNER JOIN `caches` ON `caches`.`cache_id`=`cache_location`.`cache_id` LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id` WHERE IFNULL(`stat_caches`.`toprating`,0)>0 AND `cache_location`.`adm1`='&1' AND ISNULL(`cache_location`.`adm3`) AND `caches`.`status`=1", $rAdm1['adm1']);
if ($rAdm3['code3'] == null)
sql("
INSERT INTO &topLocationCaches (`cache_id`)
SELECT `caches`.`cache_id`
FROM `cache_location`
INNER JOIN `caches` ON `caches`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`
WHERE IFNULL(`stat_caches`.`toprating`,0)>0 AND `cache_location`.`code1`='&1' AND ISNULL(`cache_location`.`code3`) AND `caches`.`status`=1",
$rCountry['country']);
else
sql("INSERT INTO &topLocationCaches (`cache_id`) SELECT `caches`.`cache_id` FROM `cache_location` INNER JOIN `caches` ON `caches`.`cache_id`=`cache_location`.`cache_id` LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id` WHERE IFNULL(`stat_caches`.`toprating`,0)>0 AND `cache_location`.`adm1`='&1' AND `cache_location`.`adm3`='&2' AND `caches`.`status`=1", $rAdm1['adm1'], $rAdm3['adm3']);
sql("
INSERT INTO &topLocationCaches (`cache_id`)
SELECT `caches`.`cache_id`
FROM `cache_location`
INNER JOIN `caches` ON `caches`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`
WHERE IFNULL(`stat_caches`.`toprating`,0)>0 AND `cache_location`.`code1`='&1' AND `cache_location`.`code3`='&2' AND `caches`.`status`=1",
$rCountry['country'], $rAdm3['code3']);
sql("INSERT INTO &topRatings (`cache_id`, `ratings`) SELECT `cache_rating`.`cache_id`, COUNT(`cache_rating`.`cache_id`) AS `ratings` FROM `cache_rating` INNER JOIN &topLocationCaches ON `cache_rating`.`cache_id`=&topLocationCaches.`cache_id` INNER JOIN `caches` ON `cache_rating`.`cache_id`=`caches`.`cache_id` WHERE `cache_rating`.`user_id`!=`caches`.`user_id` GROUP BY `cache_rating`.`cache_id`");
sql("
INSERT INTO &topRatings (`cache_id`, `ratings`)
SELECT `cache_rating`.`cache_id`, COUNT(`cache_rating`.`cache_id`) AS `ratings`
FROM `cache_rating`
INNER JOIN &topLocationCaches ON `cache_rating`.`cache_id`=&topLocationCaches.`cache_id`
INNER JOIN `caches` ON `cache_rating`.`cache_id`=`caches`.`cache_id`
WHERE `cache_rating`.`user_id`!=`caches`.`user_id`
GROUP BY `cache_rating`.`cache_id`");
sql("INSERT INTO &topResult (`idx`, `cache_id`, `ratings`, `founds`)
SELECT SQL_SMALL_RESULT (&topRatings.`ratings`+1)*(&topRatings.`ratings`+1)/(IFNULL(`stat_caches`.`found`, 0)/10+1)*100 AS `idx`,
@@ -68,7 +96,7 @@ function run()
}
sql_free_result($rsAdm3);
}
sql_free_result($rsAdm1);
sql_free_result($rsCountry);
sql_drop_temp_table('topLocationCaches');
sql_drop_temp_table('topRatings');

0 comments on commit 0e0a4ea

Please sign in to comment.
You can’t perform that action at this time.