From 50d972141e4f3f40a370958c3bb128fc35977153 Mon Sep 17 00:00:00 2001 From: mai-tran-03 Date: Tue, 5 May 2026 21:41:27 -0500 Subject: [PATCH 1/7] Refractor tours and tour_items database names to walking_tours and walking_tour_items, update upgrade hook to copy old tour tables to new walking tour tables ensuring old ones preserved for existing installation and new ones created for new installation --- WalkingTourPlugin.php | 100 +++++++++++++----- controllers/IndexController.php | 12 +-- controllers/ToursController.php | 6 +- helpers/TourFunctions.php | 8 +- models/{Tour.php => WalkingTour.php} | 17 +-- models/{TourItem.php => WalkingTourItem.php} | 2 +- .../{TourTable.php => WalkingTourTable.php} | 8 +- plugin.ini | 2 +- routes.ini | 8 +- views/admin/tours/browse.php | 6 +- views/admin/tours/form.php | 20 ++-- 11 files changed, 121 insertions(+), 68 deletions(-) rename models/{Tour.php => WalkingTour.php} (89%) rename models/{TourItem.php => WalkingTourItem.php} (94%) rename models/{TourTable.php => WalkingTourTable.php} (88%) diff --git a/WalkingTourPlugin.php b/WalkingTourPlugin.php index 388df5a..7a7ba28 100644 --- a/WalkingTourPlugin.php +++ b/WalkingTourPlugin.php @@ -54,7 +54,7 @@ public function hookInstall() $db = $this->_db; $tourQuery = " - CREATE TABLE IF NOT EXISTS `$db->Tour` ( + CREATE TABLE IF NOT EXISTS `$db->WalkingTour` ( `id` int( 10 ) unsigned NOT NULL auto_increment, `title` varchar( 255 ) collate utf8_unicode_ci default NULL, `description` text collate utf8_unicode_ci NOT NULL, @@ -68,7 +68,7 @@ public function hookInstall() ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci "; $tourItemQuery = " - CREATE TABLE IF NOT EXISTS `$db->TourItem` ( + CREATE TABLE IF NOT EXISTS `$db->WalkingTourItem` ( `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT, `tour_id` INT( 10 ) UNSIGNED NOT NULL, `ordinal` INT NOT NULL, @@ -86,27 +86,75 @@ public function hookInstall() public function hookUninstall() { $db = $this->_db; - $db->query("DROP TABLE IF EXISTS `$db->TourItem`"); - $db->query("DROP TABLE IF EXISTS `$db->Tour`"); + $db->query("DROP TABLE IF EXISTS `$db->WalkingTourItem`"); + $db->query("DROP TABLE IF EXISTS `$db->WalkingTour`"); $this->_uninstallOptions(); } public function hookUpgrade($args) { - - $oldVersion = $args['old_version']; - $newVersion = $args['new_version']; $db = $this->_db; + $oldVersion = $args['old_version']; - if (version_compare($oldVersion, '0.1-dev', "<")) { - $sql = "ALTER TABLE `{$db->prefix}tour_items` MODIFY COLUMN `exhibit_id` INT NOT NULL;"; - $db->query($sql); - } + $oldTourTable = "{$db->prefix}tours"; + $newWalkingTourTable = "{$db->prefix}walking_tours"; + + $oldTourItemTable = "{$db->prefix}tour_items"; + $newWalkingTourItemTable = "{$db->prefix}walking_tour_items"; + + $db->query("CREATE TABLE IF NOT EXISTS `$newWalkingTourTable` ( + `id` int( 10 ) unsigned NOT NULL auto_increment, + `title` varchar( 255 ) collate utf8_unicode_ci default NULL, + `description` text collate utf8_unicode_ci NOT NULL, + `route` text collate utf8_unicode_ci, + `credits` text collate utf8_unicode_ci, + `postscript_text` text collate utf8_unicode_ci, + `featured` tinyint( 1 ) default '0', + `public` tinyint( 1 ) default '0', + `color` text collate utf8_unicode_ci, + PRIMARY KEY( `id` ) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" + ); + + $db->query("CREATE TABLE IF NOT EXISTS `$newWalkingTourItemTable` ( + `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT, + `tour_id` INT( 10 ) UNSIGNED NOT NULL, + `ordinal` INT NOT NULL, + `item_id` INT( 10 ) UNSIGNED NOT NULL, + `exhibit_id` INT NOT NULL, + PRIMARY KEY( `id` ), + KEY `tour` ( `tour_id` ) + ) ENGINE=InnoDB" + ); + + if (version_compare($oldVersion, '2.0.0', '<')) { + $checkOldTourTable = $db->query("SHOW TABLES LIKE '$oldTourTable'")->fetchAll(); + + if (!empty($checkOldTourTable)) { + $migrateTourSql = "INSERT INTO `$newWalkingTourTable` ( + id, title, description, route, credits, postscript_text, featured, public, color) + SELECT + id, title, description, route, credits, postscript_text, featured, public, color + FROM `$oldTourTable` + WHERE id NOT IN (SELECT id FROM `$newWalkingTourTable`)"; + $db->query($migrateTourSql); + + // $db->query("DROP TABLE `$oldTourTable` text;"); + } - if (version_compare($oldVersion, '1.0.0', '<=')) { - $sql = "ALTER TABLE `{$db->prefix}tours` ADD COLUMN `route` TEXT;"; - $db->query($sql);} + $checkOldTourItemTable = $db->query("SHOW TABLES LIKE '$oldTourItemTable'")->fetchAll(); + + if (!empty($checkOldTourItemTable)) { + $migrateItemSql = "INSERT INTO `$newWalkingTourItemTable` ( + id, tour_id, ordinal, item_id, exhibit_id) + SELECT id, tour_id, ordinal, item_id, exhibit_id + FROM `$oldTourItemTable` + WHERE id NOT IN (SELECT id FROM `$newWalkingTourItemTable`)"; + $db->query($migrateItemSql); + // $db->query("DROP TABLE `$oldTourItemTable` text;"); + } } + } public function hookDefineAcl($args) { @@ -191,8 +239,8 @@ public function hookAdminDashboard() // Get the database. $db = get_db(); - // Get the Tour table. - $table = $db->getTable('Tour'); + // Get the Walking Tour table. + $table = $db->getTable('WalkingTour'); // Build the select query. $select = $table->getSelect(); @@ -205,15 +253,15 @@ public function hookAdminDashboard() for ($i = 0; $i <= 5; $i++) { if (array_key_exists($i, $results) && is_object($results[$i])) { - $tourItems .= '

' - . $results[$i]->title . '

Edit

'; + $tourItems .= '

' + . $results[$i]->title . '

Edit

'; } } $html .= '
'; $html .= '

' . __('Recent Tours') . '

'; $html .= '' . $tourItems . ''; - $html .= '

' . __('Add a new tour') . '

'; + $html .= '

' . __('Add a new tour') . '

'; $html .= '
'; echo $html; @@ -225,7 +273,7 @@ public function hookAdminHead() $module = $request->getModuleName(); $controller = $request->getControllerName(); - if ($module == 'walking-tour' && $controller == 'tours') { + if ($module == 'walking-tour' && $controller == 'walking-tours') { queue_css_file('tour-1.7'); queue_js_url('//code.jquery.com/jquery-migrate-3.0.0.min.js'); } @@ -233,23 +281,25 @@ public function hookAdminHead() public function filterPublicNavigationMain($nav) { - $nav[] = array('label' => 'Map', 'uri' => url('map')); + $nav[] = array( + 'label' => 'Map', + 'uri' => url('map') + ); return $nav; } public function filterSearchRecordTypes($recordTypes) { - $recordTypes['Tour'] = __('Tour'); + $recordTypes['WalkingTour'] = __('Walking Tour'); return $recordTypes; } public function filterAdminNavigationMain($nav) { - $nav['Tours'] = array( + $nav['WalkingTours'] = array( 'label' => __('Walking Tours'), - 'action' => 'browse', - 'controller' => 'tours' + 'uri' => url('walking-tours/browse') ); return $nav; } diff --git a/controllers/IndexController.php b/controllers/IndexController.php index 5672dbd..d0cb07a 100755 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -21,8 +21,8 @@ public function publicTours() { // Get the database. $db = get_db(); - // Get the Tour table. - $tour_table = $db->getTable('Tour'); + // Get the Walking Tour table. + $tour_table = $db->getTable('WalkingTour'); // Build the select query. $select = $tour_table->getSelect(); // Fetch some items with our select. @@ -46,7 +46,7 @@ public function saveRouteAction() { $tourId = $this->getRequest()->getPost('tour_id'); $route = $this->getRequest()->getPost('route'); $db = get_db(); - $tourTable = $db->getTable('Tour'); + $tourTable = $db->getTable('WalkingTour'); $tour = $tourTable->find($tourId); if ($tour) { $tour->route = $route; @@ -122,7 +122,7 @@ public function queryAction() $request_tour_id = $this->publicTours(); $colorArray = array(); - $tourItemTable = $db->getTable('TourItem'); + $tourItemTable = $db->getTable('WalkingTourItem'); $tourItemsIDs = array(); $returnArray = array(); foreach ($request_tour_id['id'] as $tour_id => $tour_title) { @@ -185,7 +185,7 @@ public function queryAction() $returnArray[$tour_id]["Description"] = $request_tour_id['description'][$tour_id]; $returnArray[$tour_id]["Credits"] = $request_tour_id['credits'][$tour_id]; - $tourTable = $db->getTable('Tour'); + $tourTable = $db->getTable('WalkingTour'); $tour = $tourTable->find($tour_id); $returnArray[$tour_id]["Route"] = $tour ? $tour->route : null; } @@ -206,7 +206,7 @@ public function getItemAction() $tour_id = $this->_request->getParam('tour'); $db = $this->_helper->db->getDb(); - $tourItemTable = $db->getTable('TourItem'); + $tourItemTable = $db->getTable('WalkingTourItem'); $prefix = $db->prefix; diff --git a/controllers/ToursController.php b/controllers/ToursController.php index 696c735..1ec1924 100644 --- a/controllers/ToursController.php +++ b/controllers/ToursController.php @@ -1,12 +1,12 @@ _helper->db->setDefaultModelName( 'Tour' ); + $this->_helper->db->setDefaultModelName( 'WalkingTour' ); } } diff --git a/helpers/TourFunctions.php b/helpers/TourFunctions.php index d51ef56..13187f1 100644 --- a/helpers/TourFunctions.php +++ b/helpers/TourFunctions.php @@ -34,15 +34,15 @@ function availableExhibit() { } } -function has_tours() +function has_walking_tours() { return( total_tours() > 0 ); } -function has_tours_for_loop() +function has_walking_tours_for_loop() { $view = get_view(); - return $view->tours && count( $view->tours ); + return $view->walking_tours && count( $view->walking_tours ); } @@ -116,7 +116,7 @@ function link_to_tour( function total_tours() { $view = get_view(); - return count( $view->tours ); + return count( $view->walking_tours ); } function nls2p($str) { diff --git a/models/Tour.php b/models/WalkingTour.php similarity index 89% rename from models/Tour.php rename to models/WalkingTour.php index cac1f09..b607d01 100644 --- a/models/Tour.php +++ b/models/WalkingTour.php @@ -1,12 +1,12 @@ 'getItems','Image' => 'getImage' ); + protected $_related = array( + 'Items' => 'getItems', + 'Image' => 'getImage' + ); public function _initializeMixins() { @@ -32,7 +35,7 @@ public function getItems() public function removeAllItems( ) { $db = get_db(); - $tiTable = $db->getTable( 'TourItem' ); + $tiTable = $db->getTable( 'WalkingTourItem' ); $select = $tiTable->getSelect(); $select->where( 'tour_id = ?', array( $this->id ) ); @@ -54,7 +57,7 @@ public function addItem( $item_id, $exhibit_id = 0 , $ordinal = null ) # Get the next ordinal $db = get_db(); - $tiTable = $db->getTable( 'TourItem' ); + $tiTable = $db->getTable( 'WalkingTourItem' ); $select = $tiTable->getSelectForCount(); $select->where( 'tour_id = ?', array( $this->id ) ); if($ordinal === null) { @@ -62,7 +65,7 @@ public function addItem( $item_id, $exhibit_id = 0 , $ordinal = null ) } # Create, assign, and save the new tour item connection - $tourItem = new TourItem; + $tourItem = new WalkingTourItem; $tourItem->tour_id = $this->id; $tourItem->item_id = $item_id; $tourItem->ordinal = $ordinal; diff --git a/models/TourItem.php b/models/WalkingTourItem.php similarity index 94% rename from models/TourItem.php rename to models/WalkingTourItem.php index 0553116..e0e54f4 100644 --- a/models/TourItem.php +++ b/models/WalkingTourItem.php @@ -4,7 +4,7 @@ * Tour Item. * @package: Omeka */ -class TourItem extends Omeka_Record_AbstractRecord +class WalkingTourItem extends Omeka_Record_AbstractRecord { public $tour_id; public $item_id; diff --git a/models/TourTable.php b/models/WalkingTourTable.php similarity index 88% rename from models/TourTable.php rename to models/WalkingTourTable.php index 1f5de47..e811706 100644 --- a/models/TourTable.php +++ b/models/WalkingTourTable.php @@ -1,6 +1,6 @@ getTable( 'Item' ); $select = $itemTable->getSelect(); $iAlias = $itemTable->getTableAlias(); - $select->joinInner( array( 'ti' => $db->TourItem ), + $select->joinInner( array( 'ti' => $db->WalkingTourItem ), "ti.item_id = $iAlias.id", array() ); $select->where( 'ti.tour_id = ?', array( $tour_id ) ); $select->order( 'ti.ordinal ASC' ); @@ -31,7 +31,7 @@ public function findImageByTourId( $tour_id ) { $itemTable = $this->getTable( 'File' ); $select = $itemTable->getSelect(); $iAlias = $itemTable->getTableAlias(); - $select->joinInner( array( 'ti' => $db->TourItem ), + $select->joinInner( array( 'ti' => $db->WalkingTourItem ), "ti.item_id = $iAlias.id", array() ); $select->where( 'ti.tour_id = ?', array( $tour_id ) ); $select->order( 'ti.ordinal ASC' ); @@ -49,7 +49,7 @@ public function findImageByTourId( $tour_id ) { public function getSelect() { - $select = parent::getSelect()->order('tours.id'); + $select = parent::getSelect()->order('walking_tours.id'); $permissions = new Omeka_Db_Select_PublicPermissions( 'WalkingTourBuilder_Tours' ); $permissions->apply( $select, 'tours', null ); diff --git a/plugin.ini b/plugin.ini index 6de57f6..5ea789b 100755 --- a/plugin.ini +++ b/plugin.ini @@ -5,7 +5,7 @@ description="Adds the ability to create and display walking tours on a map" license="GPLv3" link="" support_link="https://github.com/DigitalCarleton/WalkingTour" -version="1.0.1" +version="1.0.3" omeka_minimum_version="3.0" omeka_target_version="3.1.2" tags="map, tour" diff --git a/routes.ini b/routes.ini index 0fbe13a..1a3b181 100644 --- a/routes.ini +++ b/routes.ini @@ -1,22 +1,22 @@ [routes] -tours.route = "tours/:action" +tours.route = "walking-tours/:action" tours.defaults.module = walking-tour tours.defaults.controller = tours tours.defaults.action = "browse" -tourAction.route = "tours/:action/:id" +tourAction.route = "walking-tours/:action/:id" tourAction.defaults.module = walking-tour tourAction.defaults.controller = tours tourAction.defaults.action = "show" tourAction.reqs.id = "\d+" -tourItemAction.route = "tours/edit/:id/:action/:item" +tourItemAction.route = "walking-tours/edit/:id/:action/:item" tourItemAction.defaults.module = walking-tour tourItemAction.defaults.controller = tours tourItemAction.reqs.id = "\d+" tourItemAction.reqs.item = "\d+" -oldTour.route = "tour-builder/tours/:action/:id" +oldTour.route = "tour-builder/walking-tours/:action/:id" oldTour.defaults.module = walking-tour oldTour.defaults.controller = tours oldTour.defaults.action = "browse" diff --git a/views/admin/tours/browse.php b/views/admin/tours/browse.php index a34b229..02f9204 100644 --- a/views/admin/tours/browse.php +++ b/views/admin/tours/browse.php @@ -20,10 +20,10 @@
- + @@ -38,7 +38,7 @@ 'show','id' => $tour->id ), 'tourAction' ); $editUrl = url( array( 'action' => 'edit','id' => $tour->id ), 'tourAction' ); diff --git a/views/admin/tours/form.php b/views/admin/tours/form.php index dcab5ab..7874c82 100644 --- a/views/admin/tours/form.php +++ b/views/admin/tours/form.php @@ -4,7 +4,7 @@ ?>
-
+
@@ -13,7 +13,7 @@ formLabel( 'title', __('Title') ); ?>
- formText( 'title', $tour->title ); ?> + formText( 'title', $walkingTour->title ); ?>

@@ -24,7 +24,7 @@ formLabel( 'credits', __('Credits') ); ?>
- formText( 'credits', $tour->credits ); ?> + formText( 'credits', $walkingTour->credits ); ?>

@@ -35,7 +35,7 @@
- formTextarea( 'description', $tour->description,array( 'rows' => 12, 'cols' => '40' ) ); ?> + formTextarea( 'description', $walkingTour->description,array( 'rows' => 12, 'cols' => '40' ) ); ?>

@@ -45,7 +45,7 @@ formLabel( 'postscript_text', __('Postscript Text') ); ?>
- formTextarea( 'postscript_text', $tour->postscript_text,array( 'rows' => 3, 'cols' => '40' ) ); ?> + formTextarea( 'postscript_text', $walkingTour->postscript_text,array( 'rows' => 3, 'cols' => '40' ) ); ?>

@@ -55,7 +55,7 @@ formLabel( 'color', __('Color') ); ?>
- formTextarea( 'color', $tour->color,array( 'rows' => 1, 'cols' => '40' ) ); ?> + formTextarea( 'color', $walkingTour->color,array( 'rows' => 1, 'cols' => '40' ) ); ?>

@@ -68,7 +68,7 @@ @@ -95,10 +95,10 @@
    - id){ - $tourItems = $tour->getItems(); + id){ + $walkingTourItems = $walkingTour->getItems(); $counter = 1; - foreach($tourItems as $ti){ + foreach($walkingTourItems as $ti){ $html = '
  • '; if (plugin_is_active('ExhibitBuilder')){ From 91a0c2000187162186ad0e1eac501588a7e5586c Mon Sep 17 00:00:00 2001 From: mai-tran-03 Date: Tue, 5 May 2026 22:03:46 -0500 Subject: [PATCH 2/7] Fix adding/editing tour form, mostly accessing walking_tours DB table --- helpers/TourFunctions.php | 18 +++++++++--------- views/admin/tours/form.php | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/helpers/TourFunctions.php b/helpers/TourFunctions.php index 13187f1..87e552f 100644 --- a/helpers/TourFunctions.php +++ b/helpers/TourFunctions.php @@ -46,27 +46,27 @@ function has_walking_tours_for_loop() } -function tour( $fieldName, $options=array(), $tour=null ) +function tour( $fieldName, $options=array(), $walking_tour=null ) { - if( ! $tour ) { - $tour = get_current_tour(); + if( ! $walking_tour ) { + $walking_tour = get_current_tour(); } switch( strtolower( $fieldName ) ) { case 'id': - $text = $tour->id; + $text = $walking_tour->id; break; case 'title': - $text = $tour->title; + $text = $walking_tour->title; break; case 'description': - $text = $tour->description; + $text = $walking_tour->description; break; case 'credits': - $text = $tour->credits; + $text = $walking_tour->credits; break; case 'postscript_text': - $text = $tour->postscript_text; + $text = $walking_tour->postscript_text; break; default: throw new Exception( "\"$fieldName\" does not exist for tours!" ); @@ -92,7 +92,7 @@ function tour( $fieldName, $options=array(), $tour=null ) function get_current_tour() { - return get_view()->tour; + return get_view()->walking_tour; } function link_to_tour( diff --git a/views/admin/tours/form.php b/views/admin/tours/form.php index 7874c82..8210152 100644 --- a/views/admin/tours/form.php +++ b/views/admin/tours/form.php @@ -4,7 +4,7 @@ ?>
    -
    +
    @@ -13,7 +13,7 @@ formLabel( 'title', __('Title') ); ?>
    - formText( 'title', $walkingTour->title ); ?> + formText( 'title', $walking_tour->title ); ?>

    @@ -24,7 +24,7 @@ formLabel( 'credits', __('Credits') ); ?>
    - formText( 'credits', $walkingTour->credits ); ?> + formText( 'credits', $walking_tour->credits ); ?>

    @@ -35,7 +35,7 @@
    - formTextarea( 'description', $walkingTour->description,array( 'rows' => 12, 'cols' => '40' ) ); ?> + formTextarea( 'description', $walking_tour->description,array( 'rows' => 12, 'cols' => '40' ) ); ?>

    @@ -45,7 +45,7 @@ formLabel( 'postscript_text', __('Postscript Text') ); ?>
    - formTextarea( 'postscript_text', $walkingTour->postscript_text,array( 'rows' => 3, 'cols' => '40' ) ); ?> + formTextarea( 'postscript_text', $walking_tour->postscript_text,array( 'rows' => 3, 'cols' => '40' ) ); ?>

    @@ -55,7 +55,7 @@ formLabel( 'color', __('Color') ); ?>
    - formTextarea( 'color', $walkingTour->color,array( 'rows' => 1, 'cols' => '40' ) ); ?> + formTextarea( 'color', $walking_tour->color,array( 'rows' => 1, 'cols' => '40' ) ); ?>

    @@ -68,7 +68,7 @@ @@ -84,8 +84,8 @@
    @@ -95,10 +95,10 @@
      - id){ - $walkingTourItems = $walkingTour->getItems(); + id){ + $walking_tour_items = $walking_tour->getItems(); $counter = 1; - foreach($walkingTourItems as $ti){ + foreach($walking_tour_items as $ti){ $html = '
    • '; if (plugin_is_active('ExhibitBuilder')){ From c3e8dfad20b2fc1d33503dfefebf8f5119b31548 Mon Sep 17 00:00:00 2001 From: mai-tran-03 Date: Tue, 12 May 2026 14:34:25 -0500 Subject: [PATCH 3/7] Revert ToursController to get css connection working --- WalkingTourPlugin.php | 2 +- models/WalkingTourItem.php | 6 +- views/admin/javascripts/walking-tour.js | 111 +++++++++++++----------- 3 files changed, 64 insertions(+), 55 deletions(-) diff --git a/WalkingTourPlugin.php b/WalkingTourPlugin.php index 7a7ba28..f53a7ea 100644 --- a/WalkingTourPlugin.php +++ b/WalkingTourPlugin.php @@ -273,7 +273,7 @@ public function hookAdminHead() $module = $request->getModuleName(); $controller = $request->getControllerName(); - if ($module == 'walking-tour' && $controller == 'walking-tours') { + if ($module == 'walking-tour' && $controller == 'tours') { queue_css_file('tour-1.7'); queue_js_url('//code.jquery.com/jquery-migrate-3.0.0.min.js'); } diff --git a/models/WalkingTourItem.php b/models/WalkingTourItem.php index e0e54f4..406144b 100644 --- a/models/WalkingTourItem.php +++ b/models/WalkingTourItem.php @@ -12,7 +12,7 @@ class WalkingTourItem extends Omeka_Record_AbstractRecord public $exhibit_id = -1; protected $_related = array( - 'Tour' => 'getTour', + 'WalkingTour' => 'getWalkingTour', 'Item' => 'getItem', ); @@ -21,9 +21,9 @@ protected function getItem() return $this->getTable( 'Item' )->find( $this->item_id ); } - protected function getTour() + protected function getWalkingTour() { - return $this->getTable( 'Tour' )->find( $this->tour_id ); + return $this->getTable( 'WalkingTour' )->find( $this->tour_id ); } protected function _validate() diff --git a/views/admin/javascripts/walking-tour.js b/views/admin/javascripts/walking-tour.js index aa72e98..f6f2541 100755 --- a/views/admin/javascripts/walking-tour.js +++ b/views/admin/javascripts/walking-tour.js @@ -25,7 +25,7 @@ jQuery(document).ready(function ($) { var IS_AUTO_FIT; var historicMapLayer; - + var jqXhr; var locationMarker; var allItems = {}; @@ -34,7 +34,7 @@ jQuery(document).ready(function ($) { var baseUrl = window.location.origin; var urlpaths = window.location.pathname.split("/"); if (urlpaths[1] != "admin") { baseUrl += "/" + urlpaths[1] }; - + /* * JQuery Setup */ @@ -247,7 +247,7 @@ jQuery(document).ready(function ($) { async function getRoute(points) { const coordinates = points.map(point => [point[1], point[0]]); // Convert to [lng, lat] format const url = "https://api.openrouteservice.org/v2/directions/foot-walking/geojson"; - + try { const response = await fetch(url, { method: "POST", @@ -259,12 +259,12 @@ jQuery(document).ready(function ($) { coordinates: coordinates }) }); - + if (!response.ok) { console.error("OpenRouteService API error:", response.statusText); return null; } - + const data = await response.json(); const route = data.features[0].geometry.coordinates.map(coord => [coord[1], coord[0]]); // Convert back to [lat, lng] saveRoute(data); @@ -275,11 +275,11 @@ jQuery(document).ready(function ($) { return null; } } - + if (markers) { map.removeLayer(markers); } - + // Map the updated order to coordinates const reorderedPoints = updatedOrder.map((id, index) => { const feature = markerData[currentTour].Data.features.find(f => f.properties.id === id); @@ -289,15 +289,15 @@ jQuery(document).ready(function ($) { } return feature ? [feature.geometry.coordinates[1], feature.geometry.coordinates[0]] : null; }).filter(point => point !== null); - + if (reorderedPoints.length < 2) { console.error("At least two points are required to calculate a route."); return; } - + // Query OpenRouteService for the new route const route = await getRoute(reorderedPoints); - + const reorderedPath = L.polyline(route, { color: markerData[currentTour].Color || '#000000', weight: 3, @@ -321,7 +321,7 @@ jQuery(document).ready(function ($) { const marker = L.marker(latlng, { icon: numberIcon }); markers.addLayer(marker); }); - + markers.addLayer(reorderedPath); map.addLayer(markers); }); @@ -330,7 +330,7 @@ jQuery(document).ready(function ($) { * Query backend */ - + jqXhr = $.post(baseUrl + '/walking-tour/index/map-config', function (response) { mapSetUp(response); doQuery(); @@ -339,7 +339,7 @@ jQuery(document).ready(function ($) { // Retain previous form state, if needed. retainFormState(); - function mapLocateCenter(map){ + function mapLocateCenter(map) { map.flyTo(MAP_CENTER, MAP_ZOOM); } @@ -446,10 +446,10 @@ jQuery(document).ready(function ($) { tour_id: currentTour, route: JSON.stringify(route) }, - success: function(response) { + success: function (response) { console.log('Route saved to database'); }, - error: function(xhr, status, error) { + error: function (xhr, status, error) { console.error('Failed to save route:', error); } }) @@ -528,7 +528,7 @@ jQuery(document).ready(function ($) { onEachFeature: function (feature, layer) { layer.on('click', function (e) { // center click location - map.flyTo(e.latlng,MAP_ZOOM + MAP_MAX_ZOOM_STOP); + map.flyTo(e.latlng, MAP_ZOOM + MAP_MAX_ZOOM_STOP); // Close the filtering var filterButton = $('filter-button'); filterButton.removeClass('on'). @@ -563,36 +563,45 @@ jQuery(document).ready(function ($) { pointList[i] = point; } getOverallPath(pointList, key).then((data) => { - saveRoute(data); - - var path = data["features"][0]["geometry"]["coordinates"]; - path = orderCoords(path); - for (var p of path) { - walkingPath.push(p); + if (data && data.features && data.features.length) { + saveRoute(data); + + var path = data.features[0].geometry.coordinates; + path = orderCoords(path); + for (var p of path) { + walkingPath.push(p); + } + var tourPolyline = new L.Polyline(walkingPath, { + color: value["Color"], + weight: 3, + opacity: 1, + smoothFactor: 1 + }); + + markerData[tourId].walkingPath = tourPolyline; + } else { + console.error('OpenRouteService returned no features for tour', tourId, data); + markerData[tourId].walkingPath = new L.Polyline([], { color: value["Color"] || '#000000', weight: 3 }); } - var tourPolyline = new L.Polyline(walkingPath, { - color: value["Color"], - weight: 3, - opacity: 1, - smoothFactor: 1 - }); - - markerData[tourId].walkingPath = tourPolyline; - resolve() + resolve(); + }).catch(function (err) { + console.error('Error fetching route for tour', tourId, err); + markerData[tourId].walkingPath = new L.Polyline([], { color: value["Color"] || '#000000', weight: 3 }); + resolve(); }); }); }) Promise.all(requests).then(() => { createCustomCSS(); - if (IS_AUTO_FIT){ - map.fitBounds(markerBounds, {padding: [10, 10]}) - mapLocateCenter = function(map) { - map.fitBounds(markerBounds, {padding: [10, 10]}) - } + if (IS_AUTO_FIT) { + map.fitBounds(markerBounds, { padding: [10, 10] }) + mapLocateCenter = function (map) { + map.fitBounds(markerBounds, { padding: [10, 10] }) + } var curZoom = map._zoom; - map.setMaxZoom( curZoom + MAP_MAX_ZOOM_STOP); - map.setMinZoom( curZoom - MAP_MIN_ZOOM_STOP); - // map["options"]["minZoom"] = curZoom - MAP_MIN_ZOOM_STOP + map.setMaxZoom(curZoom + MAP_MAX_ZOOM_STOP); + map.setMinZoom(curZoom - MAP_MIN_ZOOM_STOP); + // map["options"]["minZoom"] = curZoom - MAP_MIN_ZOOM_STOP } doFilters(); }); @@ -662,10 +671,10 @@ jQuery(document).ready(function ($) { for (const tour_id in markerData) { var color = markerData[tour_id]['Color'] - if (color.length == 0){ + if (color.length == 0) { color = "#000000" } - + var rgb = hexToRgb(color) css += `#filters div label.label${tour_id}:before { background-color: ${color} !important; @@ -809,9 +818,9 @@ jQuery(document).ready(function ($) { rightContent += '

      No descriptions available.

      '; } rightContent += '
      ' - rightContent += ''+ DETAIL_BUTTON_TEXT +''; - if (response.exhibitUrl != ""){ - rightContent += ''+ EXHIBIT_BUTTON_TEXT +''; + rightContent += '' + DETAIL_BUTTON_TEXT + ''; + if (response.exhibitUrl != "") { + rightContent += '' + EXHIBIT_BUTTON_TEXT + ''; } rightContent += '
      ' infoContent += '
      ' + rightContent + '
      '; @@ -915,9 +924,9 @@ jQuery(document).ready(function ($) { return b_new } - /* - * Revert to default (original) form state. - */ + /* + * Revert to default (original) form state. + */ function revertFormState() { if (historicMapLayer) { removeHistoricMapLayer(); @@ -1020,10 +1029,10 @@ jQuery(document).ready(function ($) { function hexToRgb(hex) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) } : null; - } + } }); From 0badea34d39d09c93414def2648162e71f8b9a3e Mon Sep 17 00:00:00 2001 From: mai-tran-03 Date: Wed, 13 May 2026 19:45:45 -0500 Subject: [PATCH 4/7] Fix walking tour naming convention in metadata of show view --- controllers/IndexController.php | 8 ++++---- views/admin/tours/show.php | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/controllers/IndexController.php b/controllers/IndexController.php index d0cb07a..8b60417 100755 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -127,10 +127,10 @@ public function queryAction() $returnArray = array(); foreach ($request_tour_id['id'] as $tour_id => $tour_title) { if ($tour_id != 0) { - $tourItemsDat = $tourItemTable->fetchObjects("SELECT item_id FROM " . $prefix . "tour_items + $tourItemsDat = $tourItemTable->fetchObjects("SELECT item_id FROM " . $prefix . "walking_tour_items WHERE tour_id = $tour_id"); } else { - $tourItemsDat = $tourItemTable->fetchObjects("SELECT item_id FROM " . $prefix . "tour_items"); + $tourItemsDat = $tourItemTable->fetchObjects("SELECT item_id FROM " . $prefix . "walking_tour_items"); } $tourItemsIDs[$tour_id] = array(); foreach ($tourItemsDat as $dat) { @@ -203,14 +203,14 @@ public function getItemAction() throw new Omeka_Controller_Exception_403; } $item_id = $this->_request->getParam('id'); - $tour_id = $this->_request->getParam('tour'); + $tour_id = $this->_request->getParam('tour_id'); $db = $this->_helper->db->getDb(); $tourItemTable = $db->getTable('WalkingTourItem'); $prefix = $db->prefix; - $tourItem = $tourItemTable->fetchObjects("SELECT * FROM " . $prefix . "tour_items + $tourItem = $tourItemTable->fetchObjects("SELECT * FROM " . $prefix . "walking_tour_items WHERE tour_id = $tour_id AND item_id = $item_id"); $exhibit_id = $tourItem[0]["exhibit_id"]; diff --git a/views/admin/tours/show.php b/views/admin/tours/show.php index 2661846..e7768ea 100644 --- a/views/admin/tours/show.php +++ b/views/admin/tours/show.php @@ -14,46 +14,46 @@
      - +

      Title

      - +
      - +

      Credits

      - +
      - +

      Description

      - +
      - +

      Postscript Text

      - '.htmlspecialchars_decode(metadata( 'tour', 'postscript_text' )).''; ?> + '.htmlspecialchars_decode(metadata( 'walking_tour', 'postscript_text' )).''; ?>
      getItems(); -if( $tour->getItems() ): ?> +$items = $walking_tour->getItems(); +if( $walking_tour->getItems() ): ?>

      Items

      @@ -75,7 +75,7 @@
      - @@ -98,13 +98,13 @@ class="big blue button" target="_blank"> : - public) ? __('Yes') : __('No'); ?> + public) ? __('Yes') : __('No'); ?>

      : - featured) ? __('Yes') : __('No'); ?> + featured) ? __('Yes') : __('No'); ?>

      From 260a8e248a1dbf2ff3461e6b99b26dfb2706e4d2 Mon Sep 17 00:00:00 2001 From: mai-tran-03 Date: Wed, 13 May 2026 20:05:12 -0500 Subject: [PATCH 5/7] Record type is WalkingTour for total_records --- views/admin/tours/browse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/admin/tours/browse.php b/views/admin/tours/browse.php index 02f9204..06a0407 100644 --- a/views/admin/tours/browse.php +++ b/views/admin/tours/browse.php @@ -72,7 +72,7 @@ - +

      From 674199ecdd173dcd857b1737a01815d3d908b68b Mon Sep 17 00:00:00 2001 From: mai-tran-03 Date: Wed, 13 May 2026 21:03:53 -0500 Subject: [PATCH 6/7] Change a few more naming --- models/WalkingTour.php | 1 + models/WalkingTourItem.php | 2 +- models/WalkingTourTable.php | 4 ++-- views/admin/tours/add.php | 4 ++-- views/admin/tours/edit.php | 6 +++--- views/admin/tours/form.php | 4 ++-- views/public/index/index.php | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/models/WalkingTour.php b/models/WalkingTour.php index b607d01..5a6d4e3 100644 --- a/models/WalkingTour.php +++ b/models/WalkingTour.php @@ -99,6 +99,7 @@ protected function afterSave($args) { $post=$args['post']; if($post && isset($post['tour_item_ids']) && !$args['insert']){ + // if($post && isset($post['tour_item_ids'])){ $this->removeAllItems(); diff --git a/models/WalkingTourItem.php b/models/WalkingTourItem.php index 406144b..c3d3186 100644 --- a/models/WalkingTourItem.php +++ b/models/WalkingTourItem.php @@ -18,7 +18,7 @@ class WalkingTourItem extends Omeka_Record_AbstractRecord protected function getItem() { - return $this->getTable( 'Item' )->find( $this->item_id ); + return $this->getTable( 'WalkingTourItem' )->find( $this->item_id ); } protected function getWalkingTour() diff --git a/models/WalkingTourTable.php b/models/WalkingTourTable.php index e811706..20a312b 100644 --- a/models/WalkingTourTable.php +++ b/models/WalkingTourTable.php @@ -15,7 +15,7 @@ public function findItemsByTourId( $tour_id ) $select->order( 'ti.ordinal ASC' ); $items = $itemTable->fetchObjects( "SELECT i.*, ti.ordinal, ti.exhibit_id - FROM ".$prefix."items i LEFT JOIN ".$prefix."tour_items ti + FROM ".$prefix."items i LEFT JOIN ".$prefix."walking_tour_items ti ON i.id = ti.item_id WHERE ti.tour_id = ? ORDER BY ti.ordinal ASC", @@ -37,7 +37,7 @@ public function findImageByTourId( $tour_id ) { $select->order( 'ti.ordinal ASC' ); $items = $itemTable->fetchObjects( "SELECT f.*, ti.ordinal - FROM ".$prefix."files f LEFT JOIN ".$prefix."tour_items ti + FROM ".$prefix."files f LEFT JOIN ".$prefix."walking_tour_items ti ON i.id = ti.item_id WHERE ti.tour_id = ? ORDER BY ti.ordinal ASC", diff --git a/views/admin/tours/add.php b/views/admin/tours/add.php index ed96d43..10f26a4 100644 --- a/views/admin/tours/add.php +++ b/views/admin/tours/add.php @@ -22,7 +22,7 @@ :
      - formCheckbox( 'public', $tour->public, + formCheckbox( 'public', $walking_tour->public, array(), array( '1', '0' ) ); ?>
      @@ -34,7 +34,7 @@ :
      - formCheckbox( 'featured', $tour->featured, + formCheckbox( 'featured', $walking_tour->featured, array(), array( '1', '0' ) ); ?>
      diff --git a/views/admin/tours/edit.php b/views/admin/tours/edit.php index 9e7363a..22adc80 100644 --- a/views/admin/tours/edit.php +++ b/views/admin/tours/edit.php @@ -20,7 +20,7 @@ formSubmit( 'submit', __('Save Changes'), array( 'id' => 'save-changes', 'class' => 'submit big green button' ) ); ?> - id ) ); ?>" + id ) ); ?>" class="big blue button" target="_blank"> @@ -40,7 +40,7 @@ class="big blue button" target="_blank">
      formCheckbox( - 'public', $tour->public, + 'public', $walking_tour->public, array(), array( '1', '0' ) ); ?>
      @@ -53,7 +53,7 @@ class="big blue button" target="_blank">
      formCheckbox( - 'featured', $tour->featured, + 'featured', $walking_tour->featured, array(), array( '1', '0' ) ); ?>
      diff --git a/views/admin/tours/form.php b/views/admin/tours/form.php index 8210152..b0e0147 100644 --- a/views/admin/tours/form.php +++ b/views/admin/tours/form.php @@ -84,8 +84,8 @@
      diff --git a/views/public/index/index.php b/views/public/index/index.php index 4bb7c51..f1730ef 100755 --- a/views/public/index/index.php +++ b/views/public/index/index.php @@ -11,7 +11,7 @@
      -

      Tours

      +

      Walking Tours

      Choose tour