Skip to content

Commit

Permalink
bug 3069: add quick search as filter in batch manager
Browse files Browse the repository at this point in the history
git-svn-id: http://piwigo.org/svn/trunk@28087 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Apr 5, 2014
1 parent 7a84635 commit 1f3f5ff
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 63 deletions.
50 changes: 31 additions & 19 deletions admin/batch_manager.php
Expand Up @@ -85,14 +85,14 @@
if (in_array($_POST['filter_level'], $conf['available_permission_levels']))
{
$_SESSION['bulk_manager_filter']['level'] = $_POST['filter_level'];

if (isset($_POST['filter_level_include_lower']))
{
$_SESSION['bulk_manager_filter']['level_include_lower'] = true;
}
}
}

if (isset($_POST['filter_dimension_use']))
{
foreach (array('min_width','max_width','min_height','max_height') as $type)
Expand All @@ -110,42 +110,47 @@
}
}
}

if (isset($_POST['filter_search_use']))
{
$_SESSION['bulk_manager_filter']['search']['q'] = $_POST['q'];
}
}
// filters from url
else if (isset($_GET['filter']))
elseif (isset($_GET['filter']))
{
if (!is_array($_GET['filter']))
{
$_GET['filter'] = explode(',', $_GET['filter']);
}

$_SESSION['bulk_manager_filter'] = array();

foreach ($_GET['filter'] as $filter)
{
list($type, $value) = explode('-', $filter);

switch ($type)
{
case 'prefilter':
$_SESSION['bulk_manager_filter']['prefilter'] = $value;
break;

case 'album':
if (is_numeric($value))
{
$_SESSION['bulk_manager_filter']['category'] = $value;
}
break;

case 'tag':
if (is_numeric($value))
{
$_SESSION['bulk_manager_filter']['tags'] = array($value);
$_SESSION['bulk_manager_filter']['tag_mode'] = 'AND';
}
break;

case 'level':
if (is_numeric($value) && in_array($value, $conf['available_permission_levels']))
{
Expand Down Expand Up @@ -178,7 +183,7 @@
WHERE user_id = '.$user['id'].'
;';
$filter_sets[] = array_from_query($query, 'element_id');

break;

case 'favorites':
Expand All @@ -188,7 +193,7 @@
WHERE user_id = '.$user['id'].'
;';
$filter_sets[] = array_from_query($query, 'image_id');

break;

case 'last_import':
Expand All @@ -206,7 +211,7 @@
;';
$filter_sets[] = array_from_query($query, 'id');
}

break;

case 'no_virtual_album':
Expand Down Expand Up @@ -234,7 +239,7 @@
}

$filter_sets[] = array_diff($all_elements, $linked_to_virtual);

break;

case 'no_album':
Expand All @@ -246,7 +251,7 @@
WHERE category_id is null
;';
$filter_sets[] = array_from_query($query, 'id');

break;

case 'no_tag':
Expand All @@ -258,7 +263,7 @@
WHERE tag_id is null
;';
$filter_sets[] = array_from_query($query, 'id');

break;


Expand All @@ -280,7 +285,7 @@
WHERE file IN (\''.implode("','", array_map('pwg_db_real_escape_string', $duplicate_files)).'\')
;';
$filter_sets[] = array_from_query($query, 'id');

break;

case 'all_photos':
Expand All @@ -290,7 +295,7 @@
'.$conf['order_by'];

$filter_sets[] = array_from_query($query, 'id');

break;
}

Expand Down Expand Up @@ -325,7 +330,7 @@
{
$operator = '<=';
}

$query = '
SELECT id
FROM '.IMAGES_TABLE.'
Expand Down Expand Up @@ -374,7 +379,7 @@
// max_ratio is a floor value, so must be a bit increased
$where_clause[] = 'width/height < '.($_SESSION['bulk_manager_filter']['dimension']['max_ratio']+0.01);
}

$query = '
SELECT id
FROM '.IMAGES_TABLE.'
Expand All @@ -384,6 +389,13 @@
$filter_sets[] = array_from_query($query, 'id');
}

if (isset($_SESSION['bulk_manager_filter']['search']))
{
include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' );
$res = get_quick_search_results($_SESSION['bulk_manager_filter']['search']['q'], array('permissions'=>false));
$filter_sets[] = $res['items'];
}

$current_set = array_shift($filter_sets);
foreach ($filter_sets as $set)
{
Expand Down
24 changes: 12 additions & 12 deletions admin/batch_manager_global.php
Expand Up @@ -86,7 +86,7 @@
}

$action = $_POST['selectAction'];

if ('remove_from_caddie' == $action)
{
$query = '
Expand Down Expand Up @@ -147,7 +147,7 @@
$_SESSION['page_infos'] = array(
l10n('Information data registered in database')
);

// let's refresh the page because we the current set might be modified
if ('no_album' == $page['prefilter'])
{
Expand All @@ -171,7 +171,7 @@
$_SESSION['page_infos'] = array(
l10n('Information data registered in database')
);

// let's refresh the page because we the current set might be modified
if ('no_album' == $page['prefilter'])
{
Expand Down Expand Up @@ -224,7 +224,7 @@
$_SESSION['page_infos'] = array(
l10n('Information data registered in database')
);

// let's refresh the page because the current set might be modified
redirect($redirect_url);
}
Expand All @@ -237,7 +237,7 @@
{
$_POST['author'] = null;
}

$datas = array();
foreach ($collection as $image_id)
{
Expand All @@ -261,7 +261,7 @@
{
$_POST['title'] = null;
}

$datas = array();
foreach ($collection as $image_id)
{
Expand All @@ -277,7 +277,7 @@
$datas
);
}

// date_creation
if ('date_creation' == $action)
{
Expand Down Expand Up @@ -308,7 +308,7 @@
$datas
);
}

// privacy_level
if ('level' == $action)
{
Expand All @@ -335,13 +335,13 @@
}
}
}

// add_to_caddie
if ('add_to_caddie' == $action)
{
fill_caddie($collection);
}

// delete
if ('delete' == $action)
{
Expand Down Expand Up @@ -664,11 +664,11 @@
$query = '
SELECT id,path,representative_ext,file,filesize,level,name,width,height,rotation
FROM '.IMAGES_TABLE;

if ($is_category)
{
$category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']);

$conf['order_by'] = $conf['order_by_inside_category'];
if (!empty($category_info['image_order']))
{
Expand Down
10 changes: 10 additions & 0 deletions admin/themes/default/template/batch_manager_global.tpl
Expand Up @@ -665,6 +665,15 @@ $(document).ready(function() {
<input type="hidden" name="filter_dimension_min_ratio" value="{$dimensions.selected.min_ratio}">
<input type="hidden" name="filter_dimension_max_ratio" value="{$dimensions.selected.max_ratio}">
</li>

<li id="filter_search"{if !isset($filter.search)} style="display:none"{/if}>
<a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a>
<input type="checkbox" name="filter_search_use" class="useFilterCheckbox"{if isset($filter.search)} checked="checked"{/if}>
{'Search'|@translate}
<input name="q" size=40 value="{$filter.search.q|stripslashes|htmlspecialchars}">
{combine_script id='core.scripts' load='async' path='themes/default/js/scripts.js'}
<a href="admin/popuphelp.php?page=quick_search"onclick="popuphelp(this.href);return false;" title="{'Help'|@translate}"><span class="icon-help-circled"></span></a>
</li>
</ul>

<p class="actionButtons">
Expand All @@ -676,6 +685,7 @@ $(document).ready(function() {
<option value="filter_tags" {if isset($filter.tags)}disabled="disabled"{/if}>{'Tags'|@translate}</option>
<option value="filter_level" {if isset($filter.level)}disabled="disabled"{/if}>{'Privacy level'|@translate}</option>
<option value="filter_dimension" {if isset($filter.dimension)}disabled="disabled"{/if}>{'Dimensions'|@translate}</option>
<option value="filter_search"{if isset($filter.search)} disabled="disabled"{/if}>{'Search'|@translate}</option>
</select>
<a id="removeFilters" href="">{'Remove all filters'|@translate}</a>
</p>
Expand Down
39 changes: 24 additions & 15 deletions include/functions_search.inc.php
Expand Up @@ -1193,7 +1193,7 @@ function qsearch_eval(QMultiToken $expr, QResults $qsr, &$qualifies, &$ignored_t
* @param string $images_where optional additional restriction on images table
* @return array
*/
function get_quick_search_results($q, $super_order_by, $images_where='')
function get_quick_search_results($q, $options)
{
global $conf;
//@TODO: maybe cache for 10 minutes the result set to avoid many expensive sql calls when navigating the pictures
Expand Down Expand Up @@ -1254,26 +1254,35 @@ function get_quick_search_results($q, $super_order_by, $images_where='')
return $search_results;
}

$permissions = !isset($options['permissions']) ? true : $options['permissions'];

$where_clauses = array();
$where_clauses[]='i.id IN ('. implode(',', $ids) . ')';
if (!empty($images_where))
if (!empty($options['images_where'))
{
$where_clauses[]='('.$images_where.')';
}
$where_clauses[] = get_sql_condition_FandF(
array
(
'forbidden_categories' => 'category_id',
'visible_categories' => 'category_id',
'visible_images' => 'i.id'
),
null,true
);
if ($permissions)
{
$where_clauses[] = get_sql_condition_FandF(
array
(
'forbidden_categories' => 'category_id',
'visible_categories' => 'category_id',
'visible_images' => 'i.id'
),
null,true
);
}

$query = '
SELECT DISTINCT(id)
FROM '.IMAGES_TABLE.' i
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' i';
if ($permissions)
{
$query .= '
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id';
}
$query .= '
WHERE '.implode("\n AND ", $where_clauses)."\n".
$conf['order_by'];

Expand Down Expand Up @@ -1305,7 +1314,7 @@ function get_search_results($search_id, $super_order_by, $images_where='')
}
else
{
return get_quick_search_results($search['q'], $super_order_by, $images_where);
return get_quick_search_results($search['q'], array('super_order_by'=>$super_order_by, 'images_where'=>$images_where) );
}
}

Expand Down

0 comments on commit 1f3f5ff

Please sign in to comment.