Closed (duplicate)
Project:
Image Attach Browse
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Oct 2009 at 22:41 UTC
Updated:
4 Mar 2010 at 22:19 UTC
Since we have a ton of images in our site, I've added a title filter.
It simply filters by the first letter in the title. I think it's a great reason to add a hook or theme of some kind. Rather than hacking the module file, one could add code to the ajax easily with a custom module.
I'll paste my code below. I modified the image_attach_browse.module file with it. Please add it, or provide a hook that would enable adding something similar to it. Your module has been very helpful for us, thanks!
I changed this code:
$result = pager_query(
"SELECT n.nid, n.title FROM {node} n
WHERE n.status=1 AND type='image'
ORDER BY n.sticky DESC, n.title ASC", IMAGE_BROWSER_NUM_PER_ROW * IMAGE_BROWSER_NUM_ROWS);
and this:
if(!empty($rows)) {
echo theme('image_attach_browse_browser', $rows) . theme('pager');
} else {
echo t('No attached images found.');
}
... to this:
$query = "SELECT n.nid, n.title FROM {node} n WHERE n.status=1 AND type='image' ";
if ($_GET['alpha']!='') $query.= "AND UCASE(n.title) like UCASE('".$_GET['alpha']."%')";
$query.="ORDER BY n.sticky DESC, n.title ASC";
$result = pager_query($query, IMAGE_BROWSER_NUM_PER_ROW * IMAGE_BROWSER_NUM_ROWS);
and this
echo _alpha_links();
if(!empty($rows)) {
echo theme('image_attach_browse_browser', $rows) . theme('pager');
} else {
echo t('No attached images found.');
}
Then, I added this function to the end of the file:
function _alpha_links() {
$items = array();
$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
foreach ($alphabet as $letter) {
if ($letter==$_GET['alpha'])
$items[] = array('class'=>'pager-current', 'data'=> $letter);
else $items[] = array('class'=>'pager-item', 'data'=> '<small>' . l($letter,'image_attach/browse',array('query'=>'alpha='.$letter,'class'=>'active')) . '</small>');
}
$items[] = array('class'=>'pager-item', 'data'=> l('[All Images]','image_attach/browse',array('query'=>NULL,'class'=>'active')));
return theme_item_list($items,'Filter','ul',array('class'=>'alpha pager'));
}
Comments
Comment #1
aaronbaumanI'm marking this a duplicate of the more general #370647: Views/Directory/Taxonomy filter suggestion.
I like this idea as a stop-gap between where we're at now and implementation of a robust filter.
The latest dev release has an initial framework for such a filter, but no UI is built out yet.
I'll get to that as soon as I can.
Thanks for the contrib.
Please review the guidelines for creating a patch - it will really help others to use your work!