Skip to content

Commit

Permalink
misc/minor/formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ebellempire committed Nov 7, 2022
1 parent f4c60ab commit 2bc7a86
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 252 deletions.
86 changes: 42 additions & 44 deletions TourBuilderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ public function hookInstall()
$db = $this->_db;

$tourQuery = "
CREATE TABLE IF NOT EXISTS `$db->Tour` (
`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,
`credits` text collate utf8_unicode_ci,
`postscript_text` text collate utf8_unicode_ci,
`featured` tinyint( 1 ) default '0',
`public` tinyint( 1 ) default '0',
PRiMARY KEY( `id` )
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
CREATE TABLE IF NOT EXISTS `$db->Tour` (
`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,
`credits` text collate utf8_unicode_ci,
`postscript_text` text collate utf8_unicode_ci,
`featured` tinyint( 1 ) default '0',
`public` tinyint( 1 ) default '0',
PRiMARY KEY( `id` )
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";

$tourItemQuery = "
CREATE TABLE IF NOT EXISTS `$db->TourItem` (
`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,
PRIMARY KEY( `id` ),
KEY `tour` ( `tour_id` )
) ENGINE=InnoDB ";
CREATE TABLE IF NOT EXISTS `$db->TourItem` (
`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,
PRIMARY KEY( `id` ),
KEY `tour` ( `tour_id` )
) ENGINE=InnoDB ";

$db->query( $tourQuery );
$db->query( $tourItemQuery );
Expand All @@ -63,31 +63,29 @@ public function hookUninstall()

public function hookUpgrade($args)
{
$oldVersion = $args['old_version'];
$newVersion = $args['new_version'];
$db = $this->_db;
$prefix=$db->prefix;

if ($oldVersion < '1.4') {

$sql = "ALTER TABLE `$db->Tour` ADD COLUMN `postscript_text` text collate utf8_unicode_ci default NULL";
$db->query($sql);

}

if ($oldVersion < '1.5') {
$sql = "ALTER TABLE `$db->Tour` DROP COLUMN `slug`";
$db->query($sql);

$sql = "ALTER TABLE `$db->Tour` DROP COLUMN `tour_image`";
$db->query($sql);

}
$oldVersion = $args['old_version'];
$newVersion = $args['new_version'];
$db = $this->_db;
$prefix=$db->prefix;

if ($oldVersion < '1.4') {
$sql = "ALTER TABLE `$db->Tour` ADD COLUMN `postscript_text` text collate utf8_unicode_ci default NULL";
$db->query($sql);
}

if ($oldVersion < '1.5') {
$sql = "ALTER TABLE `$db->Tour` DROP COLUMN `slug`";
$db->query($sql);

$sql = "ALTER TABLE `$db->Tour` DROP COLUMN `tour_image`";
$db->query($sql);
}

if($oldVersion < '1.6'){
Zend_Registry::get('bootstrap')->getResource('jobs')->sendLongRunning('Job_SearchTextIndex');
}
if($oldVersion < '1.7'){
}

if($oldVersion < '1.7'){
// Get rid of orphan tour_items that weren't being deleted along with their respective tours in previous versions
$sql = "DELETE ".$prefix."tour_items
FROM ".$prefix."tour_items
Expand All @@ -96,7 +94,7 @@ public function hookUpgrade($args)
WHERE ".$prefix."tours.id IS NULL";

$db->query($sql);
}
}
}

public function hookDefineAcl( $args )
Expand Down Expand Up @@ -190,8 +188,8 @@ public function hookAdminHead()


public function filterSearchRecordTypes($recordTypes){
$recordTypes['Tour'] = __('Tour');
return $recordTypes;
$recordTypes['Tour'] = __('Tour');
return $recordTypes;
}


Expand Down
4 changes: 1 addition & 3 deletions helpers/TourFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ function total_tours()

function nls2p($str) {
$str = str_replace('<p></p>', '', '<p>'
. preg_replace('#([
]\s*?[
]){2,}#', '</p><p>', $str)
. preg_replace('#([]\s*?[]){2,}#', '</p><p>', $str)
. '</p>');
return $str;
}
Expand Down
17 changes: 7 additions & 10 deletions models/Tour.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,17 @@ protected function _validate()
if( empty( $this->title ) ) {
$this->addError( 'title', 'Tour must be given a title.' );
}

if( strlen( $this->title ) > 255 ) {
$this->addError( 'title', 'Title for a tour must be 255 characters or fewer.' );
}
if (!$this->fieldIsUnique('title')) {
$this->addError('title', 'The Title is already in use by another tour. Please choose another.');
}

}

protected function beforeDelete(){
$this->removeAllItems();
$this->deleteTaggings();
}

protected function afterSave($args)
Expand All @@ -102,8 +101,6 @@ protected function afterSave($args)
$tour_item_ids=trim( $post['tour_item_ids'] );
$item_ids=explode( ',', $tour_item_ids );
$i=0;


foreach($item_ids as $item_id){
$item_id=intval($item_id);
if($item_id){
Expand All @@ -113,11 +110,11 @@ protected function afterSave($args)
}

// Add tour to search index
if (!$this->public) {
$this->setSearchTextPrivate();
}
$this->setSearchTextTitle($this->title);
$this->addSearchText($this->title);
$this->addSearchText($this->description);
if (!$this->public) {
$this->setSearchTextPrivate();
}
$this->setSearchTextTitle($this->title);
$this->addSearchText($this->title);
$this->addSearchText($this->description);
}
}
27 changes: 10 additions & 17 deletions models/TourTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public function findItemsByTourId( $tour_id )
$select->order( 'ti.ordinal ASC' );

$items = $itemTable->fetchObjects( "SELECT i.*, ti.ordinal
FROM ".$prefix."items i LEFT JOIN ".$prefix."tour_items ti
ON i.id = ti.item_id
WHERE ti.tour_id = ?
ORDER BY ti.ordinal ASC",
array( $tour_id ) );
FROM ".$prefix."items i LEFT JOIN ".$prefix."tour_items ti
ON i.id = ti.item_id
WHERE ti.tour_id = ?
ORDER BY ti.ordinal ASC",
array( $tour_id ) );

//$items = $itemTable->fetchObjects( $select );
return $items;
Expand All @@ -37,11 +37,11 @@ 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
ON i.id = ti.item_id
WHERE ti.tour_id = ?
ORDER BY ti.ordinal ASC",
array( $tour_id ) );
FROM ".$prefix."files f LEFT JOIN ".$prefix."tour_items ti
ON i.id = ti.item_id
WHERE ti.tour_id = ?
ORDER BY ti.ordinal ASC",
array( $tour_id ) );

//$items = $itemTable->fetchObjects( $select );
return $items;
Expand All @@ -54,13 +54,6 @@ public function getSelect()
$permissions = new Omeka_Db_Select_PublicPermissions( 'TourBuilder_Tours' );
$permissions->apply( $select, 'tours', null );
$acl = Zend_Registry::get('bootstrap')->getResource('Acl');
/*
if( $acl && ! is_allowed( 'TourBuilder_Tours', 'show-unpublished' ) )
{
// Determine public level TODO: May be outdated
$select->where( $this->getTableAlias() . '.public = 1' );
}
*/

return $select;
}
Expand Down
65 changes: 33 additions & 32 deletions views/admin/tours/add.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
<?php
echo head( array( 'title' => 'Add Tour', 'content_class' => 'vertical-nav',
'bodyclass' => 'tours primary add-tour-form' ) );
echo head( array( 'title' => 'Add Tour',
'content_class' => 'vertical-nav',
'bodyclass' => 'tours primary add-tour-form'
));
echo flash();
?>

<form method="post" enctype="multipart/form-data" id="tour-form" action="">

<?php include( 'form.php' ); ?>

<section class="three columns omega">
<div id="save" class="panel">
<?php echo $this->formSubmit( 'submit', __('Add Tour'),
array( 'id' => 'save-changes',
'class' => 'submit big green button' ) ); ?>
</div>
<?php include( 'form.php' ); ?>

<div id="public-featured">
<section class="three columns omega">
<div id="save" class="panel">
<?php echo $this->formSubmit( 'submit', __('Add Tour'),
array( 'id' => 'save-changes',
'class' => 'submit big green button' ) ); ?>
</div>

<div id="public-featured">
<?php if( is_allowed( 'TourBuilder_Tours', 'makePublic' ) ): ?>
<div class="checkbox">
<label for="public">
<?php echo __('Public'); ?>:
</label>
<div class="checkbox">
<?php echo $this->formCheckbox( 'public', $tour->public,
array(), array( '1', '0' ) ); ?>
<label for="public">
<?php echo __('Public'); ?>:
</label>
<div class="checkbox">
<?php echo $this->formCheckbox( 'public',
$tour->public,
array(), array( '1', '0' ) ); ?>
</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>

<?php if( is_allowed( 'TourBuilder_Tours', 'makeFeatured' ) ): ?>
<div class="checkbox">
<label for="featured">
<?php echo __('Featured'); ?>:
</label>
<?php if( is_allowed( 'TourBuilder_Tours', 'makeFeatured' ) ): ?>
<div class="checkbox">
<?php echo $this->formCheckbox( 'featured', $tour->featured,
array(), array( '1', '0' ) ); ?>
<label for="featured">
<?php echo __('Featured'); ?>:
</label>
<div class="checkbox">
<?php echo $this->formCheckbox( 'featured',
$tour->featured,
array(), array( '1', '0' ) ); ?>
</div>
</div>
</div>
<?php endif; ?>

</div>

</section>
</div>
</section>

</form>

Expand Down
47 changes: 22 additions & 25 deletions views/admin/tours/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,32 @@

<?php if( $total_results ): ?>

<div class="table-actions">
<div class="tour-actions">
<?php if( is_allowed( 'TourBuilder_Tours', 'add' ) ): ?>
<a class="add button small green" href="<?php echo $addUrl; ?>">
<a class="add button small green" href="<?php echo $addUrl; ?>">
<?php echo __('Add a Tour'); ?>
</a>
</a>
<?php endif; ?>
</div>

<div id="primary">
<?php
echo flash();
if( has_tours() ):
?>
<div class="pagination"><?php echo pagination_links(); ?></div>
<?php echo flash();
if( has_tours() ):?>
<?php if( has_tours_for_loop() ): ?>
<table id="tours" class="simple" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<?php if( $editable ): ?>
<th scope="col">Edit?</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<table id="tours" class="simple" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<?php if( $editable ): ?>
<th scope="col">Actions</th>
<?php endif; ?>
</tr>
</thead>
<tbody>

<?php $key = 0;

<?php
$key = 0;
foreach( $tours as $tour ):
$oddness = ((++$key % 2) == 1) ? 'odd' : 'even';
$showUrl = url( array( 'action' => 'show','id' => $tour->id ), 'tourAction' );
Expand Down Expand Up @@ -92,10 +89,10 @@
</a>
<?php endif; ?>
<?php else: ?>
<p><?php echo __('The query searched %s tours and returned no results.',
total_records( 'Tour' ));
echo __('Would you like to %s?',
link_to_tour_search( __('refine your search') ) ); ?></p>
<p>
<?php echo __('The query searched %s tours and returned no results.',total_records( 'Tour' ));
echo __('Would you like to %s?', link_to_tour_search( __('refine your search') ) ); ?>
</p>
<?php endif; ?>

<?php endif; ?>
Expand Down
Loading

0 comments on commit 2bc7a86

Please sign in to comment.