Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 74 additions & 24 deletions WalkingTourPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
Expand All @@ -205,15 +253,15 @@ public function hookAdminDashboard()

for ($i = 0; $i <= 5; $i++) {
if (array_key_exists($i, $results) && is_object($results[$i])) {
$tourItems .= '<div class="recent-row"><p class="recent"><a href="' . html_escape(url('tours/show/')) . $results[$i]->id . '">'
. $results[$i]->title . '</a></p><p class="dash-edit"><a href="' . html_escape(url('tours/edit/')) . $results[$i]->id . '">Edit</a></p></div>';
$tourItems .= '<div class="recent-row"><p class="recent"><a href="' . html_escape(url('walking-tours/show/')) . $results[$i]->id . '">'
. $results[$i]->title . '</a></p><p class="dash-edit"><a href="' . html_escape(url('walking-tours/edit/')) . $results[$i]->id . '">Edit</a></p></div>';
}
}

$html .= '<section class="five columns alpha panel">';
$html .= '<h2>' . __('Recent Tours') . '</h2>';
$html .= '' . $tourItems . '';
$html .= '<p><a class="add-new-item green button" href="' . html_escape(url('tours/add/')) . '">' . __('Add a new tour') . '</a></p>';
$html .= '<p><a class="add-new-item green button" href="' . html_escape(url('walking-tours/add/')) . '">' . __('Add a new tour') . '</a></p>';
$html .= '</section>';

echo $html;
Expand All @@ -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;
}
Expand Down
143 changes: 120 additions & 23 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -57,6 +57,73 @@ public function saveRouteAction() {
}
}

public function previewAction()
{
if (!$this->_request->isXmlHttpRequest()) {
throw new Omeka_Controller_Exception_403;
}

$tourId = (int) $this->_request->getPost('tour_id');
$itemIds = $this->_request->getPost('item_ids', array());

if (is_string($itemIds)) {
$itemIds = array_filter(array_map('trim', explode(',', $itemIds)));
}

$itemIds = array_values(array_filter(array_map('intval', (array) $itemIds)));

$db = $this->_helper->db->getDb();
$tourTable = $db->getTable('WalkingTour');
$tour = $tourTable->find($tourId);

if (!$tour) {
$this->_helper->json(array('error' => 'Tour not found.'));
return;
}

$locations = array();
if (!empty($itemIds)) {
$prefix = $db->prefix;
$placeholders = implode(',', array_fill(0, count($itemIds), '?'));
$sql = "SELECT item_id, latitude, longitude FROM {$prefix}locations WHERE item_id IN ($placeholders)";
$rows = $db->fetchAll($sql, $itemIds);
foreach ($rows as $row) {
$locations[(int) $row['item_id']] = $row;
}
}

$features = array();
foreach ($itemIds as $itemId) {
if (!isset($locations[$itemId])) {
continue;
}

$features[] = array(
'type' => 'Feature',
'geometry' => array(
'type' => 'Point',
'coordinates' => array((float) $locations[$itemId]['longitude'], (float) $locations[$itemId]['latitude']),
),
'properties' => array(
'id' => $itemId,
'marker-color' => $tour->color,
),
);
}

$this->_helper->json(array(
'Data' => array(
'type' => 'FeatureCollection',
'features' => $features,
),
'Color' => $tour->color,
'Tour Name' => $tour->title,
'Description' => $tour->description,
'Credits' => $tour->credits,
'Route' => $tour->route,
));
}

/**
* Display the map.
*/
Expand All @@ -74,12 +141,12 @@ public function indexAction()
->appendFile(src('modernizr.custom.63332', 'javascripts', 'js'))
->appendFile(src('Polyline.encoded', 'javascripts', 'js'))
->appendFile('//cdn.jsdelivr.net/npm/@allmaps/leaflet/dist/bundled/allmaps-leaflet-1.9.umd.js')
->appendFile(src('walking-tour', 'javascripts', 'js'));
->appendFile(src('walking-tour-public', 'javascripts', 'js'));
$this->view->headLink()
->appendStylesheet('//code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css', 'all')
// ->appendStylesheet('//cdn.leafletjs.com/leaflet-0.7/leaflet.css', 'all')
// ->appendStylesheet('//cdn.leafletjs.com/leaflet-0.7/leaflet.ie.css', 'all', 'lte IE 8')
->appendStylesheet(src('walking-tour', 'css', 'css'));
->appendStylesheet(src('walking-tour-public', 'css', 'css'));
// ->appendStylesheet(src('/../../../themes/mall-theme', 'css', 'css'));
}

Expand Down Expand Up @@ -117,20 +184,36 @@ public function queryAction()
$joins = array("$db->Item AS items ON items.id = locations.item_id");
$wheres = array("items.public = 1");
$prefix = $db->prefix;
$previewTourId = (int) $this->_request->getParam('tour_id');
$previewItemIds = array();
$postedItemIds = trim((string) $this->_request->getParam('item_ids'));

if ($postedItemIds !== '') {
foreach (explode(',', $postedItemIds) as $postedItemId) {
$postedItemId = (int) trim($postedItemId);
if ($postedItemId) {
$previewItemIds[] = $postedItemId;
}
}
}

// Filter public tours' items
$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) {
if ($previewTourId && $tour_id == $previewTourId) {
$tourItemsIDs[$tour_id] = $previewItemIds;
continue;
}

if ($tour_id != 0) {
$tourItemsDat = $tourItemTable->fetchObjects("SELECT item_id FROM " . $prefix . "tour_items
WHERE tour_id = $tour_id");
$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) {
Expand All @@ -140,6 +223,20 @@ public function queryAction()

foreach ($tourItemsIDs as $tour_id => $item_array) {

$returnArray[$tour_id]["Data"] = array('type' => 'FeatureCollection', 'features' => array());
$returnArray[$tour_id]["Color"] = $request_tour_id['color'][$tour_id];
$returnArray[$tour_id]["Tour Name"] = $request_tour_id['id'][$tour_id];
$returnArray[$tour_id]["Description"] = $request_tour_id['description'][$tour_id];
$returnArray[$tour_id]["Credits"] = $request_tour_id['credits'][$tour_id];

$tourTable = $db->getTable('WalkingTour');
$tour = $tourTable->find($tour_id);
$returnArray[$tour_id]["Route"] = $tour ? $tour->route : null;

if (empty($item_array)) {
continue;
}

$tourItemsID = implode(", ", $item_array);
$wheres = array("items.public = 1");
$wheres[] = $db->quoteInto("items.id IN ($tourItemsID)", Zend_Db::INT_TYPE);
Expand All @@ -154,6 +251,7 @@ public function queryAction()
}
$sql .= "\nGROUP BY items.id";

// TODO ERROR
Comment thread
mai-tran-03 marked this conversation as resolved.
$dbItems = $db->query($sql)->fetchAll();
$orderedItems = array();

Expand All @@ -166,7 +264,6 @@ public function queryAction()
}
}
// Build geoJSON: http://www.geojson.org/geojson-spec.html
$returnArray[$tour_id]["Data"] = array('type' => 'FeatureCollection', 'features' => array());
foreach ($orderedItems as $row) {
$returnArray[$tour_id]["Data"]['features'][] = array(
'type' => 'Feature',
Expand All @@ -180,14 +277,6 @@ public function queryAction()
),
);
}
$returnArray[$tour_id]["Color"] = $request_tour_id['color'][$tour_id];
$returnArray[$tour_id]["Tour Name"] = $request_tour_id['id'][$tour_id];
$returnArray[$tour_id]["Description"] = $request_tour_id['description'][$tour_id];
$returnArray[$tour_id]["Credits"] = $request_tour_id['credits'][$tour_id];

$tourTable = $db->getTable('Tour');
$tour = $tourTable->find($tour_id);
$returnArray[$tour_id]["Route"] = $tour ? $tour->route : null;
}
$this->_helper->json($returnArray);

Expand All @@ -202,16 +291,24 @@ public function getItemAction()
if (!$this->_request->isXmlHttpRequest()) {
throw new Omeka_Controller_Exception_403;
}
$item_id = $this->_request->getParam('id');
$tour_id = $this->_request->getParam('tour');
$item_id = (int) $this->_request->getParam('id');
$tour_id = (int) $this->_request->getParam('tour_id', $this->_request->getParam('tour'));

if (!$item_id || !$tour_id) {
$this->_helper->json(array('error' => 'Missing tour or item id.'));
return;
}

$db = $this->_helper->db->getDb();
$tourItemTable = $db->getTable('TourItem');
$tourItemTable = $db->getTable('WalkingTourItem');
$prefix = $db->prefix;

$tourItem = $tourItemTable->fetchObjects("SELECT * FROM " . $prefix . "walking_tour_items WHERE tour_id = $tour_id AND item_id = $item_id");

$tourItem = $tourItemTable->fetchObjects("SELECT * FROM " . $prefix . "tour_items
WHERE tour_id = $tour_id AND item_id = $item_id");
if (empty($tourItem)) {
$this->_helper->json(array('error' => 'Tour item not found.'));
return;
}

$exhibit_id = $tourItem[0]["exhibit_id"];

Expand Down
Loading