From a579ec14ddf19ce61fe7ea3b63d37d91c968f5bc Mon Sep 17 00:00:00 2001 From: kojoty Date: Thu, 11 Nov 2021 17:22:58 +0100 Subject: [PATCH 1/4] #877: Removing usage of waypoints_type Db table from OCPl code There is still need the fix in OKAPI code. After that this table will be able to be removed. --- editcache.php | 20 +++-- editwp.php | 6 +- lib/search.gpx.inc.php | 98 ++++++++++++------------- lib/search.gpxgc.inc.php | 37 ++++------ myroutes_search.php | 8 +- src/Controllers/ViewCacheController.php | 2 +- src/Models/GeoCache/Waypoint.php | 38 +++++----- src/Models/GeoCache/WaypointCommons.php | 39 +++++----- src/Utils/Database/Updates/100_init.php | 4 +- src/Utils/I18n/I18n.php | 3 +- 10 files changed, 121 insertions(+), 134 deletions(-) diff --git a/editcache.php b/editcache.php index 45d0e2c046..c528edc26f 100644 --- a/editcache.php +++ b/editcache.php @@ -18,6 +18,7 @@ use src\Models\GeoCache\GeoCacheCommons; use src\Models\Pictures\OcPicture; use src\Models\ApplicationContainer; +use src\Models\GeoCache\WaypointCommons; require_once(__DIR__.'/lib/common.inc.php'); @@ -946,17 +947,14 @@ function build_drop_seq($item_row, $selected_seq, $max_drop, $thisid, $drop_type } //Add Waypoint - $lang_db = I18n::getLangForDbTranslations('waypoint_type'); $cache_type = $cache_record['type']; if ($cache_type != GeoCache::TYPE_MOVING) { tpl_set_var('waypoints_start', ''); tpl_set_var('waypoints_end', ''); - $eLang = XDb::xEscape($lang_db); $wp_rs = XDb::xSql( - "SELECT `wp_id`, `type`, `longitude`, `latitude`, `desc`, `status`, `stage`, - `waypoint_type`.`$eLang` wp_type, waypoint_type.icon wp_icon - FROM `waypoints` INNER JOIN waypoint_type ON (waypoints.type = waypoint_type.id) + "SELECT `wp_id`, `type`, `longitude`, `latitude`, `desc`, `status`, `stage` + FROM `waypoints` WHERE `cache_id`=? ORDER BY `stage`,`wp_id`", $cache_id); if (XDb::xNumRows($wp_rs) != 0) { @@ -968,7 +966,13 @@ function build_drop_seq($item_row, $selected_seq, $max_drop, $thisid, $drop_type $waypoints .= '' . tr('stage_wp') . ''; } - $waypoints .= '' . tr('symbol_wp') . '' . tr('type_wp') . '' . tr('coordinates_wp') . '' . tr('describe_wp') . '' . tr('status_wp') . '' . tr('edit') . '' . tr('delete') . ''; + $waypoints .= '' . tr('symbol_wp') . ''. + '' . tr('type_wp') . ''. + '' . tr('coordinates_wp') . ''. + '' . tr('describe_wp') . ''. + '' . tr('status_wp') . ''. + '' . tr('edit') . ''. + '' . tr('delete') . ''; while($wp_record = XDb::xFetchArray($wp_rs)){ $tmpline1 = $wpline; @@ -976,8 +980,8 @@ function build_drop_seq($item_row, $selected_seq, $max_drop, $thisid, $drop_type $coords_lat = mb_ereg_replace(" ", " ", htmlspecialchars(Coordinates::donNotUse_latToDegreeStr($wp_record['latitude']), ENT_COMPAT, 'UTF-8')); $coords_lon = mb_ereg_replace(" ", " ", htmlspecialchars(Coordinates::donNotUse_lonToDegreeStr($wp_record['longitude']), ENT_COMPAT, 'UTF-8')); - $tmpline1 = mb_ereg_replace('{wp_icon}', htmlspecialchars($wp_record['wp_icon'], ENT_COMPAT, 'UTF-8'), $tmpline1); - $tmpline1 = mb_ereg_replace('{type}', htmlspecialchars($wp_record['wp_type'], ENT_COMPAT, 'UTF-8'), $tmpline1); + $tmpline1 = mb_ereg_replace('{wp_icon}',WaypointCommons::getIcon($wp_record['type']), $tmpline1); + $tmpline1 = mb_ereg_replace('{type}', tr(WaypointCommons::typeTranslationKey($wp_record['type'])), $tmpline1); $tmpline1 = mb_ereg_replace('{lon}', $coords_lon, $tmpline1); $tmpline1 = mb_ereg_replace('{lat}', $coords_lat, $tmpline1); $tmpline1 = mb_ereg_replace('{desc}', nl2br($wp_record['desc']), $tmpline1); diff --git a/editwp.php b/editwp.php index c8a9c781ea..c04205e4d1 100644 --- a/editwp.php +++ b/editwp.php @@ -29,9 +29,9 @@ $remove = 1; } -$wp_rs = XDb::xSql("SELECT `wp_id`, `cache_id`, `type`, `longitude`, `latitude`, `desc`, `status`, `stage`, - `opensprawdzacz`, `waypoint_type`.`pl` `wp_type`, `waypoint_type`.`icon` `wp_icon` - FROM `waypoints` INNER JOIN waypoint_type ON (waypoints.type = waypoint_type.id) WHERE `wp_id`= ? ", $wp_id); +$wp_rs = XDb::xSql("SELECT `wp_id`, `cache_id`, `type`, `longitude`, `latitude`, + `desc`, `status`, `stage`, `opensprawdzacz` + FROM `waypoints` WHERE `wp_id`= ? ", $wp_id); if ($wp_record = XDb::xFetchArray($wp_rs)) { $cache_id = $wp_record['cache_id']; diff --git a/lib/search.gpx.inc.php b/lib/search.gpx.inc.php index fa2daec5f3..5dcea8c1e7 100644 --- a/lib/search.gpx.inc.php +++ b/lib/search.gpx.inc.php @@ -12,6 +12,7 @@ use src\Utils\I18n\I18n; use src\Models\OcConfig\OcConfig; use src\Models\ApplicationContainer; +use src\Models\GeoCache\Waypoint; global $content, $bUseZip, $dbcSearch, $queryFilter; require_once (__DIR__.'/common.inc.php'); @@ -98,23 +99,7 @@ function getPictures($cacheid, $picturescount) {text} '; -$gpxWaypoints = ' - - {waypoint} {wp_stage} - {desc} - {wp_type_name} - ' . $absolute_server_URI . 'viewcache.php?wp={waypoint} - {waypoint} {wp_stage} - {wp_type} - Waypoint|{wp_type} - - {waypoint} - false - false - {waypoint} {wp_stage} - - -'; + $gpxFoot = ''; @@ -690,45 +675,58 @@ function getPictures($cacheid, $picturescount) // Waypoints $waypoints = ''; - $rswp = XDb::xSql("SELECT `longitude`, `cache_id`, `latitude`,`desc`,`stage`, `type`, `status`,`waypoint_type`.`pl` `wp_type_name` - FROM `waypoints` INNER JOIN waypoint_type ON (waypoints.type = waypoint_type.id) - WHERE `waypoints`.`cache_id`= ? - ORDER BY `waypoints`.`stage`", $r['cacheid']); - - while ($rwp = XDb::xFetchArray($rswp)) { - if ($rwp['status'] == 1) { + $gpxWaypoints = ' '. PHP_EOL . + ' '. PHP_EOL . + ' {waypoint} {wp_stage}'. PHP_EOL . + ' {desc}'. PHP_EOL . + ' {wp_type_name}'. PHP_EOL . + ' ' . $absolute_server_URI . 'viewcache.php?wp={waypoint}'. PHP_EOL . + ' {waypoint} {wp_stage}'. PHP_EOL . + ' {wp_type}'. PHP_EOL . + ' Waypoint|{wp_type}'. PHP_EOL . + ' '. PHP_EOL . + ' {waypoint}'. PHP_EOL . + ' false'. PHP_EOL . + ' false'. PHP_EOL . + ' {waypoint} {wp_stage}'. PHP_EOL . + ' '. PHP_EOL . + ' '. PHP_EOL; + $cacheWps = Waypoint::GetWaypointsForCacheId($r['cacheid']); + foreach ($cacheWps as $wp) { + if ($wp->getStatus() == Waypoint::STATUS_VISIBLE) { $thiswp = $gpxWaypoints; - $lat = sprintf('%01.5f', $rwp['latitude']); + $lat = sprintf('%01.5f', $wp->getCoordinates()->getLatitude()); $thiswp = str_replace('{wp_lat}', $lat, $thiswp); - $lon = sprintf('%01.5f', $rwp['longitude']); + $lon = sprintf('%01.5f', $wp->getCoordinates()->getLongitude()); $thiswp = str_replace('{wp_lon}', $lon, $thiswp); - $thiswp = str_replace('{waypoint}', $waypoint, $thiswp); - $thiswp = str_replace('{cacheid}', $rwp['cache_id'], $thiswp); + + $thiswp = str_replace('{waypoint}', $r['waypoint'], $thiswp); + $thiswp = str_replace('{cacheid}', $r['cacheid'], $thiswp); $thiswp = str_replace('{time}', $time, $thiswp); - $thiswp = str_replace('{wp_type_name}', $rwp['wp_type_name'], $thiswp); - if ($rwp['stage'] != 0) { - $thiswp = str_replace('{wp_stage}', " " . tr('stage_wp') . ": " . $rwp['stage'], $thiswp); + $thiswp = str_replace('{wp_type_name}', tr($wp->getTypeTranslationKey()), $thiswp); + if ($wp->getStage() != 0) { + $thiswp = str_replace('{wp_stage}', " " . tr('stage_wp') . ": " . $wp->getStage(), $thiswp); } else { - $thiswp = str_replace('{wp_stage}', $rwp['wp_type_name'], $thiswp); - } - $thiswp = str_replace('{desc}', cleanup_text($rwp['desc']), $thiswp); - if ($rwp['type'] == 5) { - $thiswp = str_replace('{wp_type}', "Parking Area", $thiswp); - } - if ($rwp['type'] == 1) { - $thiswp = str_replace('{wp_type}', "Flag, Green", $thiswp); - } - if ($rwp['type'] == 2) { - $thiswp = str_replace('{wp_type}', "Flag, Green", $thiswp); - } - if ($rwp['type'] == 3) { - $thiswp = str_replace('{wp_type}', "Flag, Red", $thiswp); - } - if ($rwp['type'] == 4) { - $thiswp = str_replace('{wp_type}', "Circle with X", $thiswp); + $thiswp = str_replace('{wp_stage}', tr($wp->getTypeTranslationKey()), $thiswp); } - if ($rwp['type'] == 6) { - $thiswp = str_replace('{wp_type}', "Trailhead", $thiswp); + $thiswp = str_replace('{desc}', cleanup_text($wp->getDescription()), $thiswp); + switch ($wp->getType()) { + case Waypoint::TYPE_PARKING: + $thiswp = str_replace('{wp_type}', "Parking Area", $thiswp); + break; + case Waypoint::TYPE_PHYSICAL: + case Waypoint::TYPE_VIRTUAL: + $thiswp = str_replace('{wp_type}', "Flag, Green", $thiswp); + break; + case Waypoint::TYPE_FINAL: + $thiswp = str_replace('{wp_type}', "Flag, Red", $thiswp); + break; + case Waypoint::TYPE_INTERESTING: + $thiswp = str_replace('{wp_type}', "Circle with X", $thiswp); + break; + case Waypoint::TYPE_TRAILHEAD: + $thiswp = str_replace('{wp_type}', "Trailhead", $thiswp); + break; } $waypoints .= $thiswp; } diff --git a/lib/search.gpxgc.inc.php b/lib/search.gpxgc.inc.php index 709e14ecf7..2de355cf3c 100644 --- a/lib/search.gpxgc.inc.php +++ b/lib/search.gpxgc.inc.php @@ -5,6 +5,7 @@ use src\Models\GeoCache\CacheNote; use src\Models\GeoCache\GeoCacheCommons; use src\Models\GeoCache\GeoCacheLog; +use src\Models\GeoCache\Waypoint; use src\Utils\I18n\I18n; use src\Utils\Text\Validator; use src\Models\OcConfig\OcConfig; @@ -520,34 +521,26 @@ // Waypoints $waypoints = ''; - - $rswp = XDb::xSql( - "SELECT `longitude`, `cache_id`, `latitude`,`desc`,`stage`, `type`, `status`,`waypoint_type`." . $language . " `wp_type_name` - FROM `waypoints` - INNER JOIN waypoint_type ON (waypoints.type = waypoint_type.id) - WHERE `waypoints`.`cache_id`=? - ORDER BY `waypoints`.`stage`", - $r['cacheid']); - - while ($rwp = XDb::xFetchArray($rswp)) { - if ($rwp['status'] == 1) { + $cacheWps = Waypoint::GetWaypointsForCacheId($r['cacheid']); + foreach ($cacheWps as $wp) { + if ($wp->getStatus() == Waypoint::STATUS_VISIBLE) { $thiswp = $gpxWaypoints; - $lat = sprintf('%01.5f', $rwp['latitude']); + $lat = sprintf('%01.5f', $wp->getCoordinates()->getLatitude()); $thiswp = str_replace('{wp_lat}', $lat, $thiswp); - $lon = sprintf('%01.5f', $rwp['longitude']); + $lon = sprintf('%01.5f', $wp->getCoordinates()->getLongitude()); $thiswp = str_replace('{wp_lon}', $lon, $thiswp); - $thiswp = str_replace('{waypoint}', $waypoint, $thiswp); - $thiswp = str_replace('{cacheid}', $rwp['cache_id'], $thiswp); + $thiswp = str_replace('{waypoint}', $r['waypoint'], $thiswp); + $thiswp = str_replace('{cacheid}', $r['cacheid'], $thiswp); $thiswp = str_replace('{time}', $time, $thiswp); - $thiswp = str_replace('{wp_type_name}', cleanup_text($rwp['wp_type_name']), $thiswp); - if ($rwp['stage'] != 0) { - $thiswp = str_replace('{wp_stage}', " " . cleanup_text(tr('stage_wp')) . ": " . $rwp['stage'], $thiswp); + $thiswp = str_replace('{wp_type_name}', cleanup_text(tr($wp->getTypeTranslationKey())), $thiswp); + if ($wp->getStage() != 0) { + $thiswp = str_replace('{wp_stage}', " " . cleanup_text(tr('stage_wp')) . ": " . $wp->getStage(), $thiswp); } else { - $thiswp = str_replace('{wp_stage}', $rwp['wp_type_name'], $thiswp); + $thiswp = str_replace('{wp_stage}', tr($wp->getTypeTranslationKey()), $thiswp); } - $thiswp = str_replace('{desc}', xmlentities(cleanup_text($rwp['desc'])), $thiswp); - if (isset($wptType[$rwp['type']])) - $thiswp = str_replace('{wp_type}', $wptType[$rwp['type']], $thiswp); + $thiswp = str_replace('{desc}', xmlentities(cleanup_text($wp->getDescription())), $thiswp); + if (isset($wptType[$wp->getType()])) + $thiswp = str_replace('{wp_type}', $wptType[$wp->getType()], $thiswp); else $thiswp = str_replace('{wp_type}', $wptType[0], $thiswp); $waypoints .= $thiswp; diff --git a/myroutes_search.php b/myroutes_search.php index efd4f694d2..0baac90064 100644 --- a/myroutes_search.php +++ b/myroutes_search.php @@ -11,6 +11,7 @@ use src\Utils\I18n\I18n; use src\Models\ApplicationContainer; use src\Models\OcConfig\OcConfig; +use src\Models\GeoCache\WaypointCommons; require_once (__DIR__.'/lib/common.inc.php'); require_once (__DIR__.'/lib/export.inc.php'); @@ -1109,12 +1110,9 @@ // Waypoints $waypoints = ''; - - $langCode = XDb::xEscape(I18n::getCurrentLang()); $rswp = XDb::xSql( - "SELECT `longitude`, `cache_id`, `latitude`,`desc`,`stage`, `type`, `status`,`waypoint_type`." . $langCode . " `wp_type_name` + "SELECT `longitude`, `cache_id`, `latitude`,`desc`,`stage`, `type`, `status` FROM `waypoints` - INNER JOIN waypoint_type ON (waypoints.type = waypoint_type.id) WHERE `waypoints`.`cache_id`=? ORDER BY `waypoints`.`stage`", $r['cacheid']); @@ -1129,7 +1127,7 @@ $thiswp = str_replace('{waypoint}', $waypoint, $thiswp); $thiswp = str_replace('{cacheid}', $rwp['cache_id'], $thiswp); $thiswp = str_replace('{time}', $time, $thiswp); - $thiswp = str_replace('{wp_type_name}', cleanup_text($rwp['wp_type_name']), $thiswp); + $thiswp = str_replace('{wp_type_name}', cleanup_text(tr(WaypointCommons::getTypesArray($rwp['type']))), $thiswp); if ($rwp['stage'] != 0) { $thiswp = str_replace('{wp_stage}', " " . cleanup_text(tr('stage_wp')) . ": " . $rwp['stage'], $thiswp); } else { diff --git a/src/Controllers/ViewCacheController.php b/src/Controllers/ViewCacheController.php index e3ceb09174..4b1fd94a45 100644 --- a/src/Controllers/ViewCacheController.php +++ b/src/Controllers/ViewCacheController.php @@ -425,7 +425,7 @@ private function processPics() private function processWayPoints() { - $waypointsList = Waypoint::GetWaypointsForCacheId($this->geocache); + $waypointsList = Waypoint::GetWaypointsForCache($this->geocache); $this->view->setVar('waypointsList', $waypointsList); $this->view->setVar('cacheWithStages', $this->geocache->getCacheType() == GeoCache::TYPE_OTHERTYPE || diff --git a/src/Models/GeoCache/Waypoint.php b/src/Models/GeoCache/Waypoint.php index 4860e2f7af..e3ecc38c36 100644 --- a/src/Models/GeoCache/Waypoint.php +++ b/src/Models/GeoCache/Waypoint.php @@ -27,17 +27,6 @@ class Waypoint extends WaypointCommons private $cacheId; private $openChecker; - - private $iconNames = array( - self::TYPE_PHYSICAL => 'images/waypoints/wp_physical.png', - self::TYPE_VIRTUAL => 'images/waypoints/wp_virtual.png', - self::TYPE_FINAL => 'images/waypoints/wp_final.png', - self::TYPE_INTERESTING => 'images/waypoints/wp_reference.png', - self::TYPE_PARKING => 'images/waypoints/wp_parking.png', - self::TYPE_TRAILHEAD => 'images/waypoints/wp_trailhead.png' - ); - - private static function FromDbRow($row) { $waypoint = new Waypoint(); @@ -140,7 +129,7 @@ public function setGeocache($geocache) public function getIconName() { - return $this->iconNames[$this->type]; + return $this->getIcon($this->type); } @@ -162,20 +151,29 @@ public function getDesc4Html() return nl2br($this->description); } - public static function GetWaypointsForCacheId(GeoCache $geoCache, $skipHiddenWps=true){ - - + /** + * Returns array of waypoints for given geocache + */ + public static function GetWaypointsForCache(GeoCache $geoCache, $skipHiddenWps=true): array + { if($geoCache->getCacheType() == GeoCache::TYPE_MOVING){ // mobiles can't have waypoints... return []; } + return self::GetWaypointsForCacheId($geoCache->getCacheId(), $skipHiddenWps); + } + + /** + * Returns array of waypoints for given geocache + */ + public static function GetWaypointsForCacheId(int $cacheId, $skipHiddenWps=true): array + { $s = XDb::xSql( - "SELECT wp_id, type, longitude, latitude, `desc`, status, stage, opensprawdzacz, cache_id, - waypoint_type.en wp_type, waypoint_type.icon wp_icon - FROM waypoints INNER JOIN waypoint_type ON (waypoints.type = waypoint_type.id) + "SELECT wp_id, type, longitude, latitude, `desc`, status, stage, opensprawdzacz, cache_id + FROM waypoints WHERE cache_id = ? ORDER BY stage, wp_id", - $geoCache->getCacheId()); + $cacheId); $results = []; while($row = XDb::xFetchArray($s)){ @@ -184,8 +182,6 @@ public static function GetWaypointsForCacheId(GeoCache $geoCache, $skipHiddenWps $results[] = $wp; } } - return $results; } - } diff --git a/src/Models/GeoCache/WaypointCommons.php b/src/Models/GeoCache/WaypointCommons.php index e587fbe2a5..c35d4cc845 100644 --- a/src/Models/GeoCache/WaypointCommons.php +++ b/src/Models/GeoCache/WaypointCommons.php @@ -3,27 +3,26 @@ use src\Models\BaseObject; - class WaypointCommons extends BaseObject { - const TYPE_PHYSICAL = 1; - const TYPE_VIRTUAL = 2; - const TYPE_FINAL = 3; - const TYPE_INTERESTING = 4; - const TYPE_PARKING = 5; - const TYPE_TRAILHEAD = 6; - - const STATUS_VISIBLE = 1; - const STATUS_VISIBLE_HIDDEN_COORDS = 2; - const STATUS_HIDDEN = 3; - - const ICONS = array( - self::TYPE_PHYSICAL => 'images/waypoints/wp_physical.png', - self::TYPE_VIRTUAL => 'images/waypoints/wp_virtual.png', - self::TYPE_FINAL => 'images/waypoints/wp_final.png', - self::TYPE_INTERESTING => 'images/waypoints/wp_reference.png', - self::TYPE_PARKING => 'images/waypoints/wp_parking.png', - self::TYPE_TRAILHEAD => 'images/waypoints/wp_trailhead.png' + public const TYPE_PHYSICAL = 1; + public const TYPE_VIRTUAL = 2; + public const TYPE_FINAL = 3; + public const TYPE_INTERESTING = 4; + public const TYPE_PARKING = 5; + public const TYPE_TRAILHEAD = 6; + + public const STATUS_VISIBLE = 1; + public const STATUS_VISIBLE_HIDDEN_COORDS = 2; + public const STATUS_HIDDEN = 3; + + private const ICONS = array( + self::TYPE_PHYSICAL => '/images/waypoints/wp_physical.png', + self::TYPE_VIRTUAL => '/images/waypoints/wp_virtual.png', + self::TYPE_FINAL => '/images/waypoints/wp_final.png', + self::TYPE_INTERESTING => '/images/waypoints/wp_reference.png', + self::TYPE_PARKING => '/images/waypoints/wp_parking.png', + self::TYPE_TRAILHEAD => '/images/waypoints/wp_trailhead.png' ); public static function typeTranslationKey($type) @@ -58,7 +57,7 @@ public static function getTypesArray($forCacheType=null) } public static function getIcon($type){ - self::ICONS[$type]; + return self::ICONS[$type]; } } diff --git a/src/Utils/Database/Updates/100_init.php b/src/Utils/Database/Updates/100_init.php index 72210e8cd4..26321b133d 100644 --- a/src/Utils/Database/Updates/100_init.php +++ b/src/Utils/Database/Updates/100_init.php @@ -113,8 +113,8 @@ private function adjustTables() $this->db->addIndexIfNotExists('waypoints', 'opensprawdzacz'); // all but PL $this->updateTranslations('de'); // adds columns to all translation tables at PL, RO, UK - $this->updateTranslations('fr'); // adds column to waypoint_type table at PL, RO, UK - $this->updateTranslations('ro'); // adds columns to all translation tables at PL, UK + $this->updateTranslations('fr'); // adds columns to all translation tables at PL, UK + $this->updateTranslations('ro'); $this->updateTranslations('pl'); $this->updateTranslations('en'); diff --git a/src/Utils/I18n/I18n.php b/src/Utils/I18n/I18n.php index f6514af8bc..8c8f90036b 100644 --- a/src/Utils/I18n/I18n.php +++ b/src/Utils/I18n/I18n.php @@ -349,7 +349,7 @@ protected function makePrefixedTranslationsWithFallback(string $prefix): array */ public static function getTranslationTables() { - return ['cache_size', 'cache_status', 'cache_type', 'log_types', 'waypoint_type', 'languages']; + return ['cache_size', 'cache_status', 'cache_type', 'log_types', 'languages']; } /** @@ -383,7 +383,6 @@ public static function getTranslationKey($table, $id) 'cache_type' => 'cacheType_', 'languages' => 'language_', 'log_types' => 'logType', - 'waypoint_type' => 'wayPointType', ]; if (! isset($prefixes[$table])) { From fe7e1c9d733a5a6f665417cfd3ba46fa5e59b8d5 Mon Sep 17 00:00:00 2001 From: kojoty Date: Thu, 11 Nov 2021 23:49:25 +0100 Subject: [PATCH 2/4] #2085: remove any access to cache_size DB table in OCPL code --- lib/search.kml.inc.php | 5 ++--- src/Utils/I18n/I18n.php | 13 +------------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/lib/search.kml.inc.php b/lib/search.kml.inc.php index e2b693a608..7a3da5bd4a 100644 --- a/lib/search.kml.inc.php +++ b/lib/search.kml.inc.php @@ -150,12 +150,11 @@ 'SELECT `kmlcontent`.`cache_id` `cacheid`, `kmlcontent`.`status` `status`, `kmlcontent`.`longitude` `longitude`, `kmlcontent`.`latitude` `latitude`, `kmlcontent`.cache_mod_cords_id, `kmlcontent`.`type` `type`, `kmlcontent`.`size`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`, `caches`.`wp_oc` - `cache_wp`, `cache_type`.`' . $language . '` `typedesc`, `cache_size`.`' . $language . '` `sizedesc`, + `cache_wp`, `cache_type`.`' . $language . '` `typedesc`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `user`.`username` `username` - FROM `kmlcontent`, `caches`, `cache_type`, `cache_size`, `user` + FROM `kmlcontent`, `caches`, `cache_type`, `user` WHERE `kmlcontent`.`cache_id`=`caches`.`cache_id` AND `kmlcontent`.`type`=`cache_type`.`id` - AND `kmlcontent`.`size`=`cache_size`.`id` AND `kmlcontent`.`user_id`=`user`.`user_id`'); while ($r = $dbcSearch->dbResultFetch($s)) { diff --git a/src/Utils/I18n/I18n.php b/src/Utils/I18n/I18n.php index 8c8f90036b..ebc57f710b 100644 --- a/src/Utils/I18n/I18n.php +++ b/src/Utils/I18n/I18n.php @@ -349,7 +349,7 @@ protected function makePrefixedTranslationsWithFallback(string $prefix): array */ public static function getTranslationTables() { - return ['cache_size', 'cache_status', 'cache_type', 'log_types', 'languages']; + return ['cache_status', 'cache_type', 'log_types', 'languages']; } /** @@ -378,7 +378,6 @@ public static function getTranslationIdColumnName($table) public static function getTranslationKey($table, $id) { $prefixes = [ - 'cache_size' => 'cacheSize_', 'cache_status' => 'cacheStatus_', 'cache_type' => 'cacheType_', 'languages' => 'language_', @@ -389,16 +388,6 @@ public static function getTranslationKey($table, $id) throw new Exception("Unknown table: '{$table}'"); } - if ($table === 'cache_size') { - $sizeIds = ['other', 'micro', 'small', 'regular', 'large', 'xLarge', 'none', 'nano']; - - if (! array_key_exists($id - 1, $sizeIds)) { - throw new Exception("Invalid size ID passed to getTranslationId(): {$id}"); - } - - $id = $sizeIds[$id - 1]; - } - return $prefixes[$table] . $id; } } From b87c06ab017ff54159c9b7e8daab9a1aefe8dbf2 Mon Sep 17 00:00:00 2001 From: kojoty Date: Fri, 12 Nov 2021 00:44:33 +0100 Subject: [PATCH 3/4] #880: removing usage of cache_status DB table in OCPL code --- lib/search.xml.inc.php | 9 ++++----- mobile/geo.php | 4 +--- mobile/viewcache.php | 6 ++---- mycaches.php | 12 +++--------- src/Utils/I18n/I18n.php | 3 +-- viewpendings.php | 16 +++++++--------- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/lib/search.xml.inc.php b/lib/search.xml.inc.php index c1f37d02b0..22dc7b3bda 100644 --- a/lib/search.xml.inc.php +++ b/lib/search.xml.inc.php @@ -159,14 +159,13 @@ `xmlcontent`.cache_mod_cords_id, `caches`.`wp_oc` `waypoint`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`, `caches`.`country` `country`, `caches`.`type` `type_id`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `caches`.`desc_languages` `desc_languages`, - `caches`.`size`, `cache_type`.`'.$language.'` `type`, `cache_status`.`'.$language.'` `status`, + `caches`.`size`, `cache_type`.`'.$language.'` `type`, `caches`.`status`.` `status`, `user`.`username` `username`, `cache_desc`.`desc` `desc`, `cache_desc`.`short_desc` `short_desc`, `cache_desc`.`hint` `hint`, `cache_desc`.`desc_html` `html`, `xmlcontent`.`distance` `distance` - FROM `xmlcontent`, `caches`, `user`, `cache_desc`, `cache_type`, `cache_status` + FROM `xmlcontent`, `caches`, `user`, `cache_desc`, `cache_type` WHERE `xmlcontent`.`cache_id`=`caches`.`cache_id` AND `caches`.`cache_id`=`cache_desc`.`cache_id` AND `caches`.`default_desclang`=`cache_desc`.`language` - AND `xmlcontent`.`user_id`=`user`.`user_id` AND `caches`.`type`=`cache_type`.`id` - AND `caches`.`status`=`cache_status`.`id`'); + AND `xmlcontent`.`user_id`=`user`.`user_id` AND `caches`.`type`=`cache_type`.`id`'); while($r = XDb::xFetchArray($stmt) ) { if (OcConfig::isSiteCacheAccessLogEnabled()) { @@ -235,7 +234,7 @@ $thisline = str_replace('{type}', $r['type'], $thisline); $thisline = str_replace('{container}', tr(GeoCacheCommons::CacheSizeTranslationKey($r['size'])), $thisline); - $thisline = str_replace('{status}', $r['status'], $thisline); + $thisline = str_replace('{status}', tr(GeoCacheCommons::CacheStatusTranslationKey($r['status'])), $thisline); $difficulty = sprintf('%01.1f', $r['difficulty'] / 2); $thisline = str_replace('{difficulty}', $difficulty, $thisline); diff --git a/mobile/geo.php b/mobile/geo.php index d934763311..46f5937160 100644 --- a/mobile/geo.php +++ b/mobile/geo.php @@ -48,9 +48,7 @@ function check_wp($wpts) $wynik = XDb::xSql($query); $wiersz3 = XDb::xFetchArray($wynik); - $query = "select en from cache_status where id=" . $wiersz['status']; - $wynik = XDb::xSql($query); - $wiersz4 = XDb::xFetchArray($wynik); + $wiersz4 = tr(GeoCacheCommons::CacheStatusTranslationKey($wiersz['status'])); $wiersz5 = tr(GeoCacheCommons::CacheSizeTranslationKey($wiersz['size'])); diff --git a/mobile/viewcache.php b/mobile/viewcache.php index 7f7663ddc4..0e82d88ee8 100644 --- a/mobile/viewcache.php +++ b/mobile/viewcache.php @@ -87,10 +87,8 @@ $cache_type = XDb::xFetchArray($wynik); $cache_size = tr(GeoCacheCommons::CacheSizeTranslationKey($caches['size'])); + $cache_status = tr(GeoCacheCommons::CacheStatusTranslationKey($caches['status'])); - $query = "select " . I18n::getCurrentLang() . " from cache_status where id =" . $caches['status'] . ';'; - $wynik = XDb::xSql($query); - $cache_status = XDb::xFetchArray($wynik); if (isset($_SESSION['user_id'])) { $query2 = "select 1 from cache_logs where user_id = '" . $_SESSION['user_id'] . "' and type = '1' and deleted='0' and cache_id ='" . $caches['cache_id'] . "';"; @@ -136,7 +134,7 @@ $cache_info['type'] = $cache_type[0]; $cache_info['size'] = $cache_size; $cache_info['status2'] = $caches['status']; - $cache_info['status'] = $cache_status[0]; + $cache_info['status'] = $cache_status; $cache_info['hidden_date'] = date('j.m.Y', strtotime($caches['date_hidden'])); $cache_info['wp_oc'] = $caches['wp_oc']; $cache_info['owner'] = $user[0]; diff --git a/mycaches.php b/mycaches.php index 6db7b30934..acdae95963 100644 --- a/mycaches.php +++ b/mycaches.php @@ -6,6 +6,7 @@ use src\Utils\Text\Formatter; use src\Utils\I18n\I18n; use src\Models\ApplicationContainer; +use src\Models\GeoCache\GeoCache; //include template handling require_once(__DIR__.'/lib/common.inc.php'); @@ -30,11 +31,7 @@ $tplname = 'mycaches'; require(__DIR__.'/src/Views/newlogs.inc.php'); - $eLang = I18n::getLangForDbTranslations('cache_status'); - - $rs_stat = XDb::xMultiVariableQueryValue( - "SELECT cache_status.$eLang FROM cache_status WHERE `cache_status`.`id` = :1 ", 0, $stat_cache); - tpl_set_var('cache_stat', $rs_stat); + tpl_set_var('cache_stat', tr(GeoCache::CacheStatusTranslationKey($stat_cache))); $ran = XDb::xMultiVariableQueryValue( "SELECT count(cache_id) FROM caches WHERE `caches`.`status` = '1' AND `caches`.`user_id`= :1 ", 0, $user_id); @@ -152,7 +149,6 @@ `caches`.`name`, `date_hidden`, `status`,cache_type.icon_small AS cache_icon_small, - `cache_status`.`id` AS `cache_status_id`, `caches`.`founds` AS `founds`, `caches`.`topratings` AS `topratings`, datediff(now(),`caches`.`last_found` ) as `ilosc_dni`, @@ -169,11 +165,9 @@ AND `gk_item`.`stateid` <>5 LEFT JOIN ( SELECT `count`,`cache_id` FROM `cache_visits2` WHERE type = 'C' ) `cv` ON `caches`.`cache_id` = `cv`.`cache_id` - INNER JOIN `cache_type` ON (`caches`.`type` = `cache_type`.`id`), - `cache_status` + INNER JOIN `cache_type` ON (`caches`.`type` = `cache_type`.`id`) WHERE `user_id`=:user_id - AND `cache_status`.`id`=`caches`.`status` AND `caches`.`status` = :stat_cache GROUP BY `caches`.`cache_id` ORDER BY `$sort_warunek` $sort_txt diff --git a/src/Utils/I18n/I18n.php b/src/Utils/I18n/I18n.php index ebc57f710b..8555c3b8dc 100644 --- a/src/Utils/I18n/I18n.php +++ b/src/Utils/I18n/I18n.php @@ -349,7 +349,7 @@ protected function makePrefixedTranslationsWithFallback(string $prefix): array */ public static function getTranslationTables() { - return ['cache_status', 'cache_type', 'log_types', 'languages']; + return ['cache_type', 'log_types', 'languages']; } /** @@ -378,7 +378,6 @@ public static function getTranslationIdColumnName($table) public static function getTranslationKey($table, $id) { $prefixes = [ - 'cache_status' => 'cacheStatus_', 'cache_type' => 'cacheType_', 'languages' => 'language_', 'log_types' => 'logType', diff --git a/viewpendings.php b/viewpendings.php index 5160c7d3c0..7a13a0a0bc 100644 --- a/viewpendings.php +++ b/viewpendings.php @@ -256,14 +256,13 @@ function notifyOwner($cacheid, $msgType) } $stmt = XDb::xSql( - "SELECT cache_status.id AS cs_id, cache_status.pl AS cache_status, - cache_owner.username AS username, cache_owner.user_id AS user_id, - caches.cache_id AS cache_id, caches.name AS cachename, - IFNULL(`cache_location`.`adm3`, '') AS `adm3`, caches.date_created AS date_created, - last_log.id AS last_log_id, last_log.date AS last_log_date, - last_log.user_id AS last_log_author, log_author.username AS last_log_username, - last_log.text AS last_log_text - FROM cache_status, `caches` + "SELECT cache_owner.username AS username, cache_owner.user_id AS user_id, + caches.cache_id AS cache_id, caches.name AS cachename, + IFNULL(`cache_location`.`adm3`, '') AS `adm3`, caches.date_created AS date_created, + last_log.id AS last_log_id, last_log.date AS last_log_date, + last_log.user_id AS last_log_author, log_author.username AS last_log_username, + last_log.text AS last_log_text + FROM `caches` LEFT JOIN `cache_location` ON `caches`.`cache_id` = `cache_location`.`cache_id` LEFT JOIN ( SELECT id, cache_id, text, user_id, date @@ -274,7 +273,6 @@ function notifyOwner($cacheid, $msgType) ON caches.user_id = cache_owner.user_id LEFT JOIN user AS log_author ON last_log.user_id = log_author.user_id - WHERE cache_status.id = caches.status AND caches.status = 4 GROUP BY caches.cache_id ORDER BY caches.date_created DESC"); From 97b530c7b48b15b0d04ec41f1b733ded58e39f88 Mon Sep 17 00:00:00 2001 From: kojoty Date: Fri, 12 Nov 2021 01:24:01 +0100 Subject: [PATCH 4/4] #875: removing usage of cache_types DB table by OCPL code - part1 --- graphs/PieGraphustat.php | 18 +++--- lib/search.html.inc.php | 62 ++++----------------- modules/openchecker/openchecker_classes.php | 6 +- src/Views/search.result.caches.row.tpl.php | 2 +- 4 files changed, 22 insertions(+), 66 deletions(-) diff --git a/graphs/PieGraphustat.php b/graphs/PieGraphustat.php index 6d0de8235f..a3d0502c69 100644 --- a/graphs/PieGraphustat.php +++ b/graphs/PieGraphustat.php @@ -3,6 +3,7 @@ use src\Libs\JpGraph\JpGraphLoader; use src\Utils\Database\XDb; use src\Utils\I18n\I18n; +use src\Models\GeoCache\GeoCache; require(__DIR__ . '/../lib/common.inc.php'); @@ -23,22 +24,18 @@ $y = array(); $x = array(); -$lang_db = I18n::getLangForDbTranslations('cache_type'); - if ($tit == "cc") { - // Ustawic sprawdzanie jezyka w cache_type.pl !!!! $rsCreateCachesYear = XDb::xSql( - "SELECT COUNT(`caches`.`type`) `count`, `cache_type`.`$lang_db` `type` - FROM `caches` INNER JOIN `cache_type` ON (`caches`.`type`=`cache_type`.`id`) + "SELECT COUNT(`caches`.`type`) `count`, `caches`.`type` + FROM `caches` WHERE `user_id`= ? AND status <> 4 AND status <>5 GROUP BY `caches`.`type` ORDER BY `count` DESC", $user_id); if ($rsCreateCachesYear !== false) { - $xtitle = ""; while ($ry = XDb::xFetchArray($rsCreateCachesYear)) { $y[] = $ry['count']; - $x[] = $ry['type']; + $x[] = tr(GeoCache::CacheTypeTranslationKey($ry['type'])); } } XDb::xFreeResults($rsCreateCachesYear); @@ -46,17 +43,16 @@ if ($tit == "cf") { $rsCachesFindYear = XDb::xSql( - "SELECT COUNT(`caches`.`type`) `count`, `cache_type`.`$lang_db` AS `type` - FROM `cache_logs`, caches INNER JOIN `cache_type` ON (`caches`.`type`=`cache_type`.`id`) + "SELECT COUNT(`caches`.`type`) `count`, `caches`.`type` + FROM `cache_logs`, caches WHERE cache_logs.`deleted`=0 AND cache_logs.user_id=? AND cache_logs.`type`='1' AND cache_logs.`cache_id` = caches.cache_id GROUP BY `caches`.`type` ORDER BY `count` DESC", $user_id); if ($rsCachesFindYear !== false) { - $xtitle = ""; while ($rfy = XDb::xFetchArray($rsCachesFindYear)) { $y[] = $rfy['count']; - $x[] = $rfy['type']; + $x[] = tr(GeoCache::CacheTypeTranslationKey($rfy['type'])); } } XDb::xFreeResults($rsCachesFindYear); diff --git a/lib/search.html.inc.php b/lib/search.html.inc.php index d0a3990f41..e76af011a6 100644 --- a/lib/search.html.inc.php +++ b/lib/search.html.inc.php @@ -10,6 +10,9 @@ use src\Models\GeoCache\GeoCacheCommons; use src\Models\ApplicationContainer; use src\Models\OcConfig\OcConfig; +use src\Models\GeoCache\GeoCache; +use src\Models\GeoCache\GeoCacheLog; +use src\Models\GeoCache\GeoCacheLogCommons; /** * This script is used (can be loaded) by /search.php @@ -299,7 +302,6 @@ function fHideColumn($nr, $set) `caches`.`difficulty` `difficulty`, `caches`.`terrain` `terrain`, `caches`.`desc_languages` `desc_languages`, `caches`.`date_created` `date_created`, `caches`.`type` `cache_type`, `caches`.`cache_id` `cache_id`, `user`.`username` `username`, `user`.`user_id` `user_id`, - `cache_type`.`icon_large` `icon_large`, `caches`.`founds` `founds`, `caches`.`topratings` `toprating`, cache_desc.short_desc short_desc '; if (!$loggedUser) { if ($CalcCoordinates) @@ -320,10 +322,10 @@ function fHideColumn($nr, $set) } } $query .= ' LEFT JOIN cache_desc ON cache_desc.cache_id=caches.cache_id AND cache_desc.language=\'' . I18n::getCurrentLang() . '\', - `user`, cache_type + `user` WHERE `caches`.`user_id`=`user`.`user_id` AND `caches`.`cache_id` IN (' . $queryFilter . ') - AND `cache_type`.`id`=`caches`.`type` '; + '; $sortby = $options['sort']; if (! $SearchWithSort) // without interactive sort @@ -371,10 +373,9 @@ function fHideColumn($nr, $set) $tmpline = $cache_line; list ($iconname, $inactive) = getCacheIcon($loggedUser->getUserId(), $caches_record['cache_id'], - $caches_record['status'], $caches_record['user_id'], $caches_record['icon_large']); + $caches_record['status'], $caches_record['cache_type'], $caches_record['user_id']); $tmpline = str_replace('{icon_large}', $iconname, $tmpline); - // sp2ong $tmpline = str_replace('{date_created}', Formatter::date($caches_record['date_created']), $tmpline); $tmpline = str_replace('{date_created_sort}', date($logdateformat_ymd, strtotime($caches_record['date_created'])), $tmpline); @@ -689,17 +690,15 @@ function icon_difficulty($what, $difficulty) return "$text"; } -function getCacheIcon($user_id, $cache_id, $cache_status, $cache_userid, $iconname) +function getCacheIcon($user_id, $cache_id, $cache_status, $cache_type, $cache_userid) { - $cacheicon_searchable = false; - $cacheicon_type = ""; $inactive = false; - - $iconname = str_replace("mystery", "quiz", $iconname); + $logStatus = null; // mark if found if (isset($user_id)) { + $db = OcDb::instance(); $found = 0; $respSql = "SELECT `type` FROM `cache_logs` WHERE `cache_id`=:1 AND `user_id`=:2 AND `deleted`=0 ORDER BY `type`"; @@ -710,55 +709,18 @@ function getCacheIcon($user_id, $cache_id, $cache_status, $cache_userid, $iconna switch ($row['type']) { case 1: case 7: $found = $row['type']; - $cacheicon_type = "-found"; + $logStatus = GeoCacheLogCommons::LOGTYPE_FOUNDIT; $inactive = true; break; case 2: $found = $row['type']; - $cacheicon_type = "-dnf"; + $logStatus = GeoCacheLogCommons::LOGTYPE_DIDNOTFIND; break; } } } } - if ($cache_userid == $user_id) { - $cacheicon_type = "-owner"; - $inactive = true; - switch ($cache_status) { - case 1: $cacheicon_searchable = "-s"; - break; - case 2: $cacheicon_searchable = "-n"; - break; - case 3: $cacheicon_searchable = "-a"; - break; - case 4: $cacheicon_searchable = "-a"; - break; - case 6: $cacheicon_searchable = "-d"; - break; - default: $cacheicon_searchable = "-s"; - break; - } - } else { - switch ($cache_status) { - case 1: $cacheicon_searchable = "-s"; - break; - case 2: $inactive = true; - $cacheicon_searchable = "-n"; - break; - case 3: $inactive = true; - $cacheicon_searchable = "-a"; - break; - case 4: $inactive = true; - $cacheicon_searchable = "-a"; - break; - case 6: $cacheicon_searchable = "-d"; - break; - } - } - - // cacheicon - $iconname = mb_eregi_replace("\..*", "", $iconname); - $iconname .= $cacheicon_searchable . $cacheicon_type . ".png"; + $iconname = GeoCache::CacheIconByType($cache_type, $cache_status, $logStatus, false, $cache_userid == $user_id); return array($iconname, $inactive); } diff --git a/modules/openchecker/openchecker_classes.php b/modules/openchecker/openchecker_classes.php index 521f7d5ffd..b5246d5e01 100644 --- a/modules/openchecker/openchecker_classes.php +++ b/modules/openchecker/openchecker_classes.php @@ -8,6 +8,7 @@ use src\Models\GeoCache\GeoCache; use src\Models\GeoCache\Waypoint; use src\Models\Coordinates\Coordinates; +use src\Models\GeoCache\GeoCacheCommons; class OpenCheckerSetup { @@ -329,8 +330,6 @@ public function DisplayAllOpenCheckerCaches($OpenCheckerSetup) { `caches`.`type`, `caches`.`status`, `user`.`username`, - `cache_type`.`sort`, - `cache_type`.`icon_small`, `opensprawdzacz`.`proby`, `opensprawdzacz`.`sukcesy` FROM @@ -338,7 +337,6 @@ public function DisplayAllOpenCheckerCaches($OpenCheckerSetup) { LEFT JOIN `waypoints` ON (`caches`.`cache_id` = `waypoints`.`cache_id`) LEFT JOIN `opensprawdzacz` ON (`waypoints`.`cache_id` = `opensprawdzacz`.`cache_id`) LEFT JOIN `user` ON (`user`.`user_id` = `caches`.`user_id`) - LEFT JOIN `cache_type` ON (`cache_type`.`id` = `caches`.`type`) WHERE `waypoints`.`opensprawdzacz` = 1 AND `waypoints`.`type` = " . Waypoint::TYPE_FINAL . " @@ -403,7 +401,7 @@ public function DisplayAllOpenCheckerCaches($OpenCheckerSetup) { $caches_table .= ' ' . $cache_data['wp_oc'] . ' - + ' . $cache_data['name'] . ' ' . $status[$cache_data['status']] . ' ' . htmlspecialchars($cache_data['username']) . ' diff --git a/src/Views/search.result.caches.row.tpl.php b/src/Views/search.result.caches.row.tpl.php index 821e42e792..1a240cbd51 100644 --- a/src/Views/search.result.caches.row.tpl.php +++ b/src/Views/search.result.caches.row.tpl.php @@ -1,6 +1,6 @@ gct.addEmptyRow(); gct.addToLastRow( 0, "{CacheID}" ); -gct.addToLastRow( 1, "{cachetype}" ); +gct.addToLastRow( 1, "{cachetype}" ); gct.addToLastRow( 2, "{cachename}" ); gct.addToLastRow( 3, "{short_desc}" ); gct.addToLastRow( 4, "{username}" );