Skip to content

Commit

Permalink
Display filterable, sortable list of projects that use specific keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjdann committed Dec 5, 2024
1 parent 0234721 commit b14740c
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 2 deletions.
4 changes: 3 additions & 1 deletion application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
$route['group/(:num)'] = "catalog/group/index/$1";
$route['group/get_results'] = "catalog/group/get_results";

$route['keywords/(:num)'] = "catalog/keywords/index/$1";
$route['keywords/get_results'] = "catalog/keywords/get_results";

$route['sections/readers/(:num)'] = 'catalog/sections/readers/$1';

Expand Down Expand Up @@ -166,4 +168,4 @@
$route['(:any)'] = "catalog/page/index/$1";

/* End of file routes.php */
/* Location: ./application/config/routes.php */
/* Location: ./application/config/routes.php */
108 changes: 108 additions & 0 deletions application/controllers/catalog/Keywords.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Keywords extends Catalog_controller
/**
When passed a keywords_id, display a list of projects that have that keyword
*/

{

public function __construct()
{
parent::__construct();
$this->load->helper('general_functions_helper');
}

public function index($keywords_id)
{
if (empty($keywords_id)) {
show_404();
}
$this->load->model('keyword_model');
$this->data['keywords'] = $this->keyword_model->get($keywords_id);
$this->data['search_category'] = 'keywords';
$this->data['primary_key'] = $keywords_id;
$this->data['search_order'] = $this->input->get('search_order');
$params['keywords_id'] = $keywords_id;
$params['offset'] = 0;
$params['limit'] = 1000000;
$params['search_order'] = $this->input->get('search_order');
$matches = $this->_get_projects_by_keywords_id($params);
$this->data['matches'] = count($matches);
$this->_render('catalog/keywords');
return;
}

function get_results()
{

// collect - search_category, sub_category, page_number, sort_order
// and (sometimes) information about contents of project_type
$input = $this->input->get(null, true);

$params['keywords_id'] = $input['primary_key'];
$params['search_order'] = $input['search_order'];

if (empty($params['keywords_id'])) {
show_error('A primary_key (keywords ID) must be supplied', 400);
}

//format offset
$params['offset'] = ($input['search_page'] - 1) * CATALOG_RESULT_COUNT;

// format limit
$params['limit'] = CATALOG_RESULT_COUNT;



// format project_type_description. Note that values appearing here are not
// necessarily a match to values that appear in the projects.project_type column
// in the database - so we'll need to massage them later (in Project model->get_projects_by_keywords_id()).
if (array_key_exists('project_type', $input))
{
$params['project_type_description'] = $input['project_type'];
} else
{
$params['project_type_description'] = 'either';
}

// go get results
$results = $this->_get_projects_by_keywords_id($params);

// get full set by calling same function with different parameters
$params['offset'] = 0;
$params['limit'] = 1000000;

$full_set = $this->_get_projects_by_keywords_id($params);

// go format results
$retval['results'] = $this->_format_results($results, 'title');

//pagination
$page_count = (count($full_set) > CATALOG_RESULT_COUNT) ? ceil(count($full_set) / CATALOG_RESULT_COUNT) : 0;
$retval['pagination'] = (empty($page_count)) ? '' : $this->_format_pagination($input['search_page'], $page_count);

$retval['status'] = 'SUCCESS';

//return - results, pagination
if ($this->input->is_ajax_request())
{
header('Content-Type: application/json;charset=utf-8');
echo json_encode($retval);
return;
}
}

function _get_projects_by_keywords_id($params)
{
$this->load->model('project_model');
$projects = $this->project_model->get_projects_by_keywords_id($params);

foreach ($projects as $key => $project)
{
$projects[$key]['author_list'] = $this->_author_list($project['id']);
}

return $projects;
}
}
39 changes: 39 additions & 0 deletions application/views/catalog/keywords.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?= $header; ?>

<div class="main-content advanced-search-form">

<div id="sidebar_wrapper" >
<?= $sidebar; ?>
</div>


<div class="browse browse-title">
<div class="browse-header-wrap">
<h4 class="browse-header"></h4>
<h3>Audiobooks tagged with keywords "<?= $keywords->value ?>"</h3>

<div class="sort-menu" id="sort_menu" style="display:none;">
<p>Order by</p>
<select class="js-sort-menu">
<option value="alpha" <?= $search_order === 'alpha' ? 'selected' : '' ?>>Alphabetically</option>
<option value="catalog_date" <?= $search_order === 'catalog_date' ? 'selected' : '' ?>>Release date</option>
</select>
</div><!-- end .sort-menu -->

</div>

<ul class="browse-list"></ul>

<div class="page-number-nav"></div>

</div>


</div><!-- end .main-content -->

<?= $footer; ?>



</body>
</html>
12 changes: 11 additions & 1 deletion application/views/catalog/partials/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function get_search_page_from_url() {
var item = $('.js-menu_item[data-menu_item="'+search_category+'"]');
load_search_data(item, search_category);
}
else if (jQuery.inArray(current_page, ['author', 'reader', 'group']) > -1)
else if (jQuery.inArray(current_page, ['author', 'reader', 'group', 'keywords']) > -1)
{
get_results(current_page, search_page, sub_category, primary_key);
}
Expand Down Expand Up @@ -333,6 +333,15 @@ function get_advanced_results()
}


$('.js-truncated-keywords').on('click', function(e){

e.preventDefault();
$('.secondary_keywords_string').show();
$('.primary_keywords_string').hide();
return false;

});

$('.js-advanced-search').on('click', function(e){

// TODO: make toggle
Expand All @@ -348,6 +357,7 @@ function get_advanced_results()
return false;

});


function advanced_search_actions()
{
Expand Down

0 comments on commit b14740c

Please sign in to comment.