Skip to content

Commit

Permalink
Initial commit (...)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebellempire committed Aug 19, 2022
1 parent 3a62b22 commit 1bab02e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
23 changes: 23 additions & 0 deletions SubjectsBrowsePlugin.php
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);
}
}
10 changes: 10 additions & 0 deletions plugin.ini
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"
46 changes: 46 additions & 0 deletions views/public/items/browse.php
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').'&nbsp;'.__("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(); ?>
40 changes: 40 additions & 0 deletions views/public/items/functions.php
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('&amp;', '&', $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'];
}

0 comments on commit 1bab02e

Please sign in to comment.