From d04ddd3d185acccb13373220aa8af9c6c5e8e56c Mon Sep 17 00:00:00 2001 From: Ned Henry Date: Tue, 20 Oct 2015 13:41:41 -0700 Subject: [PATCH 1/5] Adds link to exhibits containing each item in the item browse detail --- functions.php | 16 ++++++++++++++++ plugin.ini | 2 +- plugin.php | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 309d9b7b..fbed14d4 100644 --- a/functions.php +++ b/functions.php @@ -605,6 +605,22 @@ function exhibit_builder_search_record_types($recordTypes) return $recordTypes; } +/** + * Show the Exhibits that each item is included in on the Item Browse page + * + * @param array $args An array of parameters passed by the hook + * @return void + */ +function exhibit_builder_item_detail($args) +{ + $item = $args['item']; + $exhibits = get_db()->getTable('Exhibit')->findAll(); + foreach($exhibits as $exhibit){ + if($exhibit->hasItem($item)) + echo('

Appears in Exhibit: '.$exhibit->title.'

'); + } +} + /** * Add exhibit title to item search filters. */ diff --git a/plugin.ini b/plugin.ini index 038ead05..c2bfde82 100644 --- a/plugin.ini +++ b/plugin.ini @@ -7,5 +7,5 @@ link="http://omeka.org/codex/Plugins/ExhibitBuilder_3.0" support_link="http://omeka.org/forums/forum/plugins" omeka_minimum_version="2.3" omeka_target_version="2.3" -version="3.2.1" +version="3.2.2" tags="exhibit, pages, presentation" diff --git a/plugin.php b/plugin.php index 1a9db50e..a1443360 100644 --- a/plugin.php +++ b/plugin.php @@ -23,6 +23,7 @@ add_plugin_hook('admin_items_search', 'exhibit_builder_items_search'); add_plugin_hook('public_items_search', 'exhibit_builder_items_search'); add_plugin_hook('html_purifier_form_submission', 'exhibit_builder_purify_html'); +add_plugin_hook('admin_items_browse_detailed_each', 'exhibit_builder_item_detail'); add_filter('public_navigation_main', 'exhibit_builder_public_main_nav'); add_filter('admin_navigation_main', 'exhibit_builder_admin_nav'); From 440d65570c2121e8dac80dafaeff054e15416e26 Mon Sep 17 00:00:00 2001 From: Ned Henry Date: Tue, 27 Oct 2015 08:51:10 -0700 Subject: [PATCH 2/5] Performance improvement - single db query --- functions.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/functions.php b/functions.php index fbed14d4..c89b1857 100644 --- a/functions.php +++ b/functions.php @@ -613,11 +613,22 @@ function exhibit_builder_search_record_types($recordTypes) */ function exhibit_builder_item_detail($args) { + global $exhibitItems; + if(!isset($exhibitItems)){ + $db = get_db(); + $sql = "SELECT i.id as item, e.id as exhibit FROM $db->Item i + INNER JOIN $db->ExhibitBlockAttachment eba ON eba.item_id = i.id + INNER JOIN $db->ExhibitPageBlock epb ON epb.id = eba.block_id + INNER JOIN $db->ExhibitPage ep ON ep.id = epb.page_id + INNER JOIN $db->Exhibit e ON e.id = ep.exhibit_id"; + $results = $db->query($sql); + while ($row = $results->fetch()) + $exhibitItems[$row['item']][]=$row['exhibit']; + } $item = $args['item']; - $exhibits = get_db()->getTable('Exhibit')->findAll(); - foreach($exhibits as $exhibit){ - if($exhibit->hasItem($item)) - echo('

Appears in Exhibit: '.$exhibit->title.'

'); + foreach($exhibitItems[$item->id] as $exhibitId){ + $exhibit = get_record_by_id('Exhibit',$exhibitId); + echo('

Appears in Exhibit: '.$exhibit->title.'

'); } } From cba76cb35d5f395298595563953514a3a810013e Mon Sep 17 00:00:00 2001 From: Ned Henry Date: Tue, 27 Oct 2015 08:56:04 -0700 Subject: [PATCH 3/5] corrected variable scope --- functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.php b/functions.php index c89b1857..1ba1db2f 100644 --- a/functions.php +++ b/functions.php @@ -613,7 +613,7 @@ function exhibit_builder_search_record_types($recordTypes) */ function exhibit_builder_item_detail($args) { - global $exhibitItems; + static $exhibitItems; if(!isset($exhibitItems)){ $db = get_db(); $sql = "SELECT i.id as item, e.id as exhibit FROM $db->Item i From 1bcb7dd2b3284cd4b89ab04b031b5bcca1b4f9c3 Mon Sep 17 00:00:00 2001 From: Ned Henry Date: Tue, 27 Oct 2015 09:03:15 -0700 Subject: [PATCH 4/5] eliminated remaining exhibit lookup query --- functions.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index 1ba1db2f..e9d58b14 100644 --- a/functions.php +++ b/functions.php @@ -616,19 +616,18 @@ function exhibit_builder_item_detail($args) static $exhibitItems; if(!isset($exhibitItems)){ $db = get_db(); - $sql = "SELECT i.id as item, e.id as exhibit FROM $db->Item i + $sql = "SELECT i.id as item, e.id as exhibit_id, e.title as exhibit_title FROM $db->Item i INNER JOIN $db->ExhibitBlockAttachment eba ON eba.item_id = i.id INNER JOIN $db->ExhibitPageBlock epb ON epb.id = eba.block_id INNER JOIN $db->ExhibitPage ep ON ep.id = epb.page_id INNER JOIN $db->Exhibit e ON e.id = ep.exhibit_id"; $results = $db->query($sql); while ($row = $results->fetch()) - $exhibitItems[$row['item']][]=$row['exhibit']; + $exhibitItems[$row['item']][]=array('id'=>$row['exhibit_id'],'title'=>$row['exhibit_title']); } $item = $args['item']; - foreach($exhibitItems[$item->id] as $exhibitId){ - $exhibit = get_record_by_id('Exhibit',$exhibitId); - echo('

Appears in Exhibit: '.$exhibit->title.'

'); + foreach($exhibitItems[$item->id] as $exhibit){ + echo('

Appears in Exhibit: '.$exhibit['title'].'

'); } } From 36ef432440003f3c257e521a8234ea6ec010dcb4 Mon Sep 17 00:00:00 2001 From: Ned Henry Date: Tue, 27 Oct 2015 16:59:38 -0700 Subject: [PATCH 5/5] Now retrieves exhibits on an item-by-item basis --- functions.php | 20 +++++--------------- models/Table/Exhibit.php | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/functions.php b/functions.php index e9d58b14..2aecb46c 100644 --- a/functions.php +++ b/functions.php @@ -613,22 +613,12 @@ function exhibit_builder_search_record_types($recordTypes) */ function exhibit_builder_item_detail($args) { - static $exhibitItems; - if(!isset($exhibitItems)){ - $db = get_db(); - $sql = "SELECT i.id as item, e.id as exhibit_id, e.title as exhibit_title FROM $db->Item i - INNER JOIN $db->ExhibitBlockAttachment eba ON eba.item_id = i.id - INNER JOIN $db->ExhibitPageBlock epb ON epb.id = eba.block_id - INNER JOIN $db->ExhibitPage ep ON ep.id = epb.page_id - INNER JOIN $db->Exhibit e ON e.id = ep.exhibit_id"; - $results = $db->query($sql); - while ($row = $results->fetch()) - $exhibitItems[$row['item']][]=array('id'=>$row['exhibit_id'],'title'=>$row['exhibit_title']); - } $item = $args['item']; - foreach($exhibitItems[$item->id] as $exhibit){ - echo('

Appears in Exhibit: '.$exhibit['title'].'

'); - } + $exhibits = get_db()->getTable('Exhibit')->findByItem($item->id); + foreach($exhibits as $exhibit) + echo('

Appears in Exhibit: '.$exhibit['title'].'

'); } /** diff --git a/models/Table/Exhibit.php b/models/Table/Exhibit.php index 3de0333e..11e8a2fa 100644 --- a/models/Table/Exhibit.php +++ b/models/Table/Exhibit.php @@ -120,6 +120,30 @@ public function findBySlug($slug) return $this->fetchObject($select, array($slug)); } + /** + * Find all exhibits containing an item. + * + * @param string $slug + */ + public function findByItem($item_id) + { + if(is_object($item_id)) + $item_id = $item_id->id; + $db=$this->getDb(); + $select = $this->getSelect() + ->join(array('ep' => $db->ExhibitPage), + '`exhibits`.id = ep.exhibit_id', + array()) + ->join(array('epb' => $db->ExhibitPageBlock), + 'ep.id = epb.page_id', + array()) + ->join(array('eba' => $db->ExhibitBlockAttachment), + 'epb.id = eba.block_id', + array()) + ->where('eba.item_id = ?'); + return $this->fetchObjects($select,array($item_id)); + } + /** * Find whether an exhibit has a specific item. *