Skip to content

Commit

Permalink
always prefer user-supplied cache country; updates #82
Browse files Browse the repository at this point in the history
  • Loading branch information
following5 committed Aug 7, 2015
1 parent 61cee6a commit 0e0a4ea
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 32 deletions.
32 changes: 16 additions & 16 deletions htdocs/lib2/logic/getNew.class.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ private function cacheRs($args=null)
`caches`.`type`, `caches`.`type`,
`caches`.`longitude` `longitude`, `caches`.`longitude` `longitude`,
`caches`.`latitude` `latitude`, `caches`.`latitude` `latitude`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`, IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`,
`cache_location`.`adm2`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,''),
`cache_location`.`adm3`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,''),
`cache_location`.`adm4`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,''),
`ca`.`attrib_id` IS NOT NULL AS `oconly` `ca`.`attrib_id` IS NOT NULL AS `oconly`
FROM `caches` FROM `caches`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id` INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_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 `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 LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
WHERE `caches`.`country`='&1' AND WHERE `caches`.`country`='&1' AND
Expand Down Expand Up @@ -149,15 +149,15 @@ private function eventRs($args=null)
`caches`.`cache_id` `cache_id`, `caches`.`cache_id` `cache_id`,
`caches`.`name` `name`, `caches`.`name` `name`,
`caches`.`date_hidden`, `caches`.`date_hidden`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`, IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`,
`cache_location`.`adm2`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,''),
`cache_location`.`adm3`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,''),
`cache_location`.`adm4`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,''),
`ca`.`attrib_id` IS NOT NULL AS `oconly` `ca`.`attrib_id` IS NOT NULL AS `oconly`
FROM `caches` FROM `caches`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id` INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_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 `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 LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
WHERE `caches`.`country`='&1' AND WHERE `caches`.`country`='&1' AND
Expand Down Expand Up @@ -223,16 +223,16 @@ private function ratingRs($args=null)
`caches`.`cache_id` AS `cache_id`, `caches`.`cache_id` AS `cache_id`,
`caches`.`name` AS `name`, `caches`.`name` AS `name`,
`caches`.`type`, `caches`.`type`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`, IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`,
`cache_location`.`adm2`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,''),
`cache_location`.`adm3`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,''),
`cache_location`.`adm4`, IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,''),
`ca`.`attrib_id` IS NOT NULL AS `oconly` `ca`.`attrib_id` IS NOT NULL AS `oconly`
FROM `cache_rating` FROM `cache_rating`
INNER JOIN `caches` ON `caches`.`cache_id`=`cache_rating`.`cache_id` INNER JOIN `caches` ON `caches`.`cache_id`=`cache_rating`.`cache_id`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_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 `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 `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 LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
WHERE `caches`.`country`='&1' AND WHERE `caches`.`country`='&1' AND
Expand Down
16 changes: 8 additions & 8 deletions htdocs/tops.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@


if (!$tpl->is_cached()) if (!$tpl->is_cached())
{ {
$rs = sql("SELECT IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`, $rs = sql("SELECT IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`,
`cache_location`.`adm3`, IF(`cache_location`.`code1`=`caches`.`country`,`cache_location`.`adm3`,NULL) AS `adm3`,
`cache_location`.`code1`, `caches`.`country` AS `code1`,
`rating_tops`.`rating` AS `idx`, `stat_caches`.`toprating` AS `ratings`, `stat_caches`.`found` AS `founds`, `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`, `caches`.`name`, `caches`.`wp_oc` AS `wpoc`, `user`.`username`, `user`.`user_id` AS `userid`,
`ca`.`attrib_id` IS NOT NULL AS `oconly` `ca`.`attrib_id` IS NOT NULL AS `oconly`
FROM `rating_tops` FROM `rating_tops`
INNER JOIN `caches` ON `rating_tops`.`cache_id`=`caches`.`cache_id` INNER JOIN `caches` ON `rating_tops`.`cache_id`=`caches`.`cache_id`
INNER JOIN `cache_location` ON `rating_tops`.`cache_id`=`cache_location`.`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' 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 `stat_caches` ON `rating_tops`.`cache_id`=`stat_caches`.`cache_id`
INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_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 LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
ORDER BY `cache_location`.`adm1` ASC, ORDER BY `adm1` ASC,
`cache_location`.`adm3` ASC, `adm3` ASC,
`rating_tops`.`rating` DESC, `rating_tops`.`rating` DESC,
`caches`.`name` ASC", $opt['template']['locale']); `caches`.`name` ASC", $opt['template']['locale']);
$tpl->assign_rs('tops', $rs); $tpl->assign_rs('tops', $rs);
sql_free_result($rs); sql_free_result($rs);
} }
Expand Down
44 changes: 36 additions & 8 deletions htdocs/util2/cron/modules/rating_tops.class.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 &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"); 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'); $rsCountry = sql('SELECT SQL_BUFFER_RESULT SQL_SMALL_RESULT DISTINCT `country` FROM `caches`');
while ($rAdm1 = sql_fetch_assoc($rsAdm1)) 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)) while ($rAdm3 = sql_fetch_assoc($rsAdm3))
{ {
sql("TRUNCATE TABLE &topLocationCaches"); sql("TRUNCATE TABLE &topLocationCaches");
sql("TRUNCATE TABLE &topRatings"); sql("TRUNCATE TABLE &topRatings");
sql("TRUNCATE TABLE &topResult"); sql("TRUNCATE TABLE &topResult");


// Alle Caches für diese Gruppe finden // Alle Caches für diese Gruppe finden
if ($rAdm3['adm3'] == null) 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`.`adm1`='&1' AND ISNULL(`cache_location`.`adm3`) AND `caches`.`status`=1", $rAdm1['adm1']); 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 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`) 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`, SELECT SQL_SMALL_RESULT (&topRatings.`ratings`+1)*(&topRatings.`ratings`+1)/(IFNULL(`stat_caches`.`found`, 0)/10+1)*100 AS `idx`,
Expand All @@ -68,7 +96,7 @@ function run()
} }
sql_free_result($rsAdm3); sql_free_result($rsAdm3);
} }
sql_free_result($rsAdm1); sql_free_result($rsCountry);


sql_drop_temp_table('topLocationCaches'); sql_drop_temp_table('topLocationCaches');
sql_drop_temp_table('topRatings'); sql_drop_temp_table('topRatings');
Expand Down

0 comments on commit 0e0a4ea

Please sign in to comment.