fixes ##2195 if conf['rate'] show rating filter

only allow rating filter if gallery uses rating
update api, mcs.js and tpl to check if rating
search_filters.inc.php update indentation due to extra if
This commit is contained in:
HWFord
2024-09-16 10:21:49 +02:00
parent e66de5a513
commit 921f679bca
5 changed files with 72 additions and 46 deletions
+1 -1
View File
@@ -510,7 +510,7 @@ SELECT
//
// ratings
//
if (!empty($search['fields']['ratings']))
if ($conf['rate'] and !empty($search['fields']['ratings']))
{
$has_filters_filled = true;
+43 -35
View File
@@ -367,17 +367,21 @@ SELECT
}
// For rating
if (isset($my_search['fields']['ratings']))
if ($conf['rate'])
{
$filter_clause = get_clause_for_filter('ratings');
$cache_key = $persistent_cache->make_key('filter_ratings'.$user['id'].$user['cache_update_time']);
$set_persistent_cache = !preg_match('/^image_id IN/', $filter_clause) and !$persistent_cache->get($cache_key, $ratings);
if (!isset($ratings))
$template->assign('SHOW_FILTER_RATINGS', true);
if (isset($my_search['fields']['ratings']))
{
$query = '
$filter_clause = get_clause_for_filter('ratings');
$cache_key = $persistent_cache->make_key('filter_ratings'.$user['id'].$user['cache_update_time']);
$set_persistent_cache = !preg_match('/^image_id IN/', $filter_clause) and !$persistent_cache->get($cache_key, $ratings);
if (!isset($ratings))
{
$query = '
SELECT
DISTINCT id,
rating_score
@@ -385,43 +389,47 @@ SELECT
JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
WHERE '.$filter_clause;
$filter_rows = query2array($query);
$filter_rows = query2array($query);
$ratings = array_fill(0, 6, 0);
$ratings = array_fill(0, 6, 0);
foreach ($filter_rows as $row)
{
$r = 5;
if (!isset($row['rating_score']))
foreach ($filter_rows as $row)
{
$r = 0;
}
else
{
for ($i=1; $i<=4; $i++)
$r = 5;
if (!isset($row['rating_score']))
{
if ($row['rating_score'] < $i)
$r = 0;
}
else
{
for ($i=1; $i<=4; $i++)
{
$r = $i;
break;
if ($row['rating_score'] < $i)
{
$r = $i;
break;
}
}
}
$ratings[$r]++;
}
$ratings[$r]++;
}
if ($set_persistent_cache)
{
// for this filter, we do not store in cache the $filter_rows : for a big gallery it may
// take more than 10MB. It is smarter to store in cache the result of the computation,
// which is just around 100 bytes.
$persistent_cache->set($cache_key, $ratings);
if ($set_persistent_cache)
{
// for this filter, we do not store in cache the $filter_rows : for a big gallery it may
// take more than 10MB. It is smarter to store in cache the result of the computation,
// which is just around 100 bytes.
$persistent_cache->set($cache_key, $ratings);
}
}
$template->assign('RATING', $ratings);
}
$template->assign('RATING', $ratings);
}
else
{
$template->assign('SHOW_FILTER_RATINGS', false);
}
// For filesize
+2 -2
View File
@@ -724,7 +724,7 @@ SELECT *
*/
function ws_images_filteredSearch_create($params, $service)
{
global $user;
global $user, $conf;
include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php');
@@ -938,7 +938,7 @@ function ws_images_filteredSearch_create($params, $service)
$search['fields']['ratios'] = $params['ratios'];
}
if (isset($params['ratings']))
if ($conf['rate'] and isset($params['ratings']))
{
$search['fields']['ratings'] = $params['ratings'];
}
+17 -5
View File
@@ -443,21 +443,29 @@ $(document).ready(function () {
}
// Setup rating filter
if (global_params.fields.ratings) {
if (global_params.fields.ratings && show_filter_ratings) {
$(".filter-ratings").css("display", "flex");
$(".filter-manager-controller.ratings").prop("checked", true);
ratings_search_str = "";
global_params.fields.ratings.forEach(function(ft){
global_params.fields.ratings.forEach(function(ft, i){
if(0 == ft )
{
ratings_search_str = str_no_rating + ", ";
ratings_search_str += str_no_rating
if(global_params.fields.ratings.length > 1)
{
ratings_search_str += ", ";
}
}
else
{
ratings_search_str = str_between_rating.split("%d");
ratings_search_str = ratings_search_str[0] + (ft-1) + ratings_search_str[1] + ft + ratings_search_str[2];
str_between = str_between_rating.split("%d");
ratings_search_str += str_between[0] + (ft-1) + str_between[1] + ft + str_between[2];
if(global_params.fields.ratings.length-1 != i)
{
ratings_search_str += ", ";
}
}
});
@@ -482,6 +490,10 @@ $(document).ready(function () {
empty_filters_list.push(PS_params.ratings);
}
else if (!show_filter_ratings)
{
updateFilters('ratings', 'add');
}
// Setup filesize filter
if (global_params.fields.filesize_min != null && global_params.fields.filesize_max != null) {
@@ -85,6 +85,11 @@ const prefix_icon = 'gallery-icon-';
{/if}
};
{if $SHOW_FILTER_RATINGS and isset($RATING)}
var show_filter_ratings = true;
{else}
var show_filter_ratings = false;
{/if}
{/footer_script}
@@ -129,10 +134,12 @@ const prefix_icon = 'gallery-icon-';
<input data-wid='ratios' class="filter-manager-controller ratios" type="checkbox"/>
<span class="mcs-icon gallery-icon-crop">{'Ratio'|@translate}</span>
</label>
{if $SHOW_FILTER_RATINGS and isset($SHOW_FILTER_RATINGS)}
<label>
<input data-wid='ratings' class="filter-manager-controller ratings" type="checkbox"/>
<span class="mcs-icon gallery-icon-star-1">{'Rating'|@translate}</span>
</label>
{/if}
<label>
<input data-wid='filesize' class="filter-manager-controller filesize" type="checkbox"/>
<span class="mcs-icon gallery-icon-hdd">{'Filesize'|@translate}</span>
@@ -519,9 +526,8 @@ const prefix_icon = 'gallery-icon-';
</div>
{/if}
{* Add filter for rating *}
{if isset($RATING)}
{* Add filter for rating *}
{if $SHOW_FILTER_RATINGS and isset($RATING)}
<div class="filter filter-ratings">
<span class="mcs-icon mcs-icon gallery-icon-star-1 filter-icon"></span>
</span><span class="search-words"></span>