-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a62b22
commit 1bab02e
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
class SubjectsBrowsePlugin extends Omeka_Plugin_AbstractPlugin | ||
{ | ||
protected $_hooks = array('define_routes'); | ||
|
||
public function hookDefineRoutes($args) | ||
{ | ||
if (is_admin_theme()) { | ||
return; | ||
} | ||
|
||
$router = $args['router']; | ||
$subjectsRoute = new Zend_Controller_Router_Route( | ||
'items/subjects', | ||
array( | ||
'module' => 'subjects-browse', | ||
'controller' => 'items', | ||
'action' => 'browse', | ||
) | ||
); | ||
$router->addRoute('subjects_browse', $subjectsRoute); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[info] | ||
name="Subjects Browse" | ||
author="Erin Bell" | ||
description="Adds a list of linked Subject terms to items/subjects" | ||
license="GPLv3" | ||
link="https://erinbell.org/" | ||
support_link="https://erinbell.org/" | ||
omeka_minimum_version="3.0" | ||
omeka_target_version="3.0.2" | ||
version="1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
require_once 'functions.php'; | ||
$subjects = sb_get_subjects(); | ||
if(isset($_GET["sort_field"]) && $_GET["sort_field"] == 'name' && isset($_GET["sort_dir"]) && $_GET["sort_dir"] == 'd'){ | ||
arsort($subjects); // z-a | ||
}elseif(isset($_GET["sort_field"]) && $_GET["sort_field"] == 'count' && isset($_GET["sort_dir"]) && $_GET["sort_dir"] == 'a'){ | ||
usort($subjects, 'sb_ascend'); // least | ||
}elseif(isset($_GET["sort_field"]) && $_GET["sort_field"] == 'count' && isset($_GET["sort_dir"]) && $_GET["sort_dir"] == 'd'){ | ||
usort($subjects, 'sb_descend'); // most | ||
}elseif(isset($_GET["sort_field"]) && $_GET["sort_field"] == 'count'){ | ||
usort($subjects, 'sb_ascend'); // least (if no sort_dir is specified) | ||
}else{ | ||
asort($subjects); // a-z | ||
} | ||
$total = count($subjects); | ||
echo head(array('maptype'=>'none', 'title'=>__('Browse by Subject'),'bodyid'=>'items','bodyclass'=>'browse subjects')); | ||
?> | ||
<!-- The following markup is for the Curatescape Echo theme. --> | ||
<!-- If using another theme, you'll need to create a custom template at yourtheme/subjects-browse/items/browse.php --> | ||
<div id="content" role="main"> | ||
<article class="browse subjects"> | ||
<div class="browse-header"> | ||
<h2 class="query-header"><?php echo __('Subjects: %s', $total);?></h2> | ||
<nav class="secondary-nav" id="subject-browse"> | ||
<?php echo function_exists('rl_item_browse_subnav') ? rl_item_browse_subnav() : null; ?> | ||
</nav> | ||
<div id="helper-links"> | ||
<span class="helper-label"><?php echo function_exists('rl_icon') ? rl_icon('funnel').' '.__("Sort by: ") : null; ?> | ||
</span> | ||
<?php echo browse_sort_links(array('Name'=>'name','Count'=>'count')); ?> | ||
</div> | ||
</div> | ||
<div id="primary" class=""> | ||
<section id="subjects" aria-label="<?php echo __('Subjects');?>"> | ||
<?php | ||
if($total > 0){ | ||
sb_subjects_list($subjects); | ||
}else{ | ||
echo '<p>'.__('No subjects are available.').'</p>'; | ||
} | ||
?> | ||
</section> | ||
</div> | ||
</article> | ||
</div> | ||
<?php echo foot(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
function sb_get_subjects(){ | ||
$subjects = []; | ||
if($records = get_records('ElementText',array('element_id'=>'49'),'all')){ | ||
foreach($records as $r){ | ||
$TEXT=trim($r->text); | ||
$subjects[] = array( | ||
'text' => $TEXT, | ||
'letter' => strtolower(substr($r->text, 0, 1)), | ||
'count' => count(array_filter($records, function ($element) use($TEXT){ | ||
return $element['text'] == $TEXT; | ||
})), // @todo | ||
); | ||
} | ||
$subjects = array_unique($subjects, SORT_REGULAR); // unique | ||
} | ||
return $subjects; | ||
} | ||
|
||
function sb_subjects_list($subjects){ | ||
if($subjects){ | ||
echo '<ul>'; | ||
foreach($subjects as $subject){ | ||
$link = WEB_ROOT; | ||
$link .= htmlentities('/items/browse?term='); | ||
$link .= rawurlencode($subject['text']); | ||
$link .= htmlentities('&search=&advanced[0][element_id]=49&advanced[0][type]=contains&advanced[0][terms]='); | ||
$link .= urlencode(str_replace('&', '&', $subject['text'])); | ||
echo '<li data-letter="'.$subject['letter'].'" data-count="'.$subject['count'].'"><a href="'.$link.'">'.$subject['text'].' <span class="count">'.$subject['count'].'</span></a></li>'; | ||
} | ||
echo '</ul>'; | ||
} | ||
} | ||
|
||
function sb_ascend($a, $b){ | ||
return $a['count'] - $b['count']; | ||
} | ||
function sb_descend($a, $b){ | ||
return $b['count'] - $a['count']; | ||
} |