Skip to content
Draft
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
22 changes: 10 additions & 12 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 Down Expand Up @@ -122,15 +122,14 @@ 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) {
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 Down Expand Up @@ -185,7 +184,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;
}
Expand All @@ -203,15 +202,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('TourItem');
$tourItemTable = $db->getTable('WalkingTourItem');
$prefix = $db->prefix;


$tourItem = $tourItemTable->fetchObjects("SELECT * FROM " . $prefix . "tour_items
WHERE tour_id = $tour_id AND item_id = $item_id");
$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"];

Expand Down
6 changes: 3 additions & 3 deletions controllers/ToursController.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
require_once 'Tour.php';
require_once 'TourItem.php';
require_once 'WalkingTour.php';
require_once 'WalkingTourItem.php';

class WalkingTour_ToursController extends Omeka_Controller_AbstractActionController
{
public function init()
{
$this->_helper->db->setDefaultModelName( 'Tour' );
$this->_helper->db->setDefaultModelName( 'WalkingTour' );
}

}
26 changes: 13 additions & 13 deletions helpers/TourFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ 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 );
}


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!" );
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
18 changes: 11 additions & 7 deletions models/Tour.php → models/WalkingTour.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

require_once 'TourTable.php';
require_once 'WalkingTourTable.php';

/**
* Tour
* WalkingTour
* @package: Omeka
*/
class Tour extends Omeka_Record_AbstractRecord
class WalkingTour extends Omeka_Record_AbstractRecord
{
public $title;
public $description;
Expand All @@ -17,7 +17,10 @@ class Tour extends Omeka_Record_AbstractRecord
public $color = "#000000";
public $route;

protected $_related = array( 'Items' => 'getItems','Image' => 'getImage' );
protected $_related = array(
'Items' => 'getItems',
'Image' => 'getImage'
);

public function _initializeMixins()
{
Expand All @@ -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 ) );

Expand All @@ -54,15 +57,15 @@ 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) {
$ordinal = $tiTable->fetchOne( $select );
}

# 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;
Expand Down Expand Up @@ -96,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();


Expand Down
Loading