summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2024-11-23 16:54:22 +0300
committerAndrew Dolgov <fox@fakecake.org>2024-11-23 16:54:22 +0300
commit417065b8f56e5d273c80a866a67f9555073c6592 (patch)
treee6f996a482fa45f012ca6dfaafa71b0d25a65a24 /classes
parentc2d0c5a5c934a9472d123742b4b3ea8da000a0d3 (diff)
show cumulative score adjustment (if any) and up to 3 actions total in filter tree
Diffstat (limited to 'classes')
-rw-r--r--classes/Pref_Filters.php30
1 files changed, 22 insertions, 8 deletions
diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php
index 76d5d686e..9b11284b4 100644
--- a/classes/Pref_Filters.php
+++ b/classes/Pref_Filters.php
@@ -10,6 +10,8 @@ class Pref_Filters extends Handler_Protected {
const PARAM_ACTIONS = [self::ACTION_TAG, self::ACTION_SCORE,
self::ACTION_LABEL, self::ACTION_PLUGIN, self::ACTION_REMOVE_TAG];
+ const MAX_ACTIONS_TO_DISPLAY = 3;
+
/** @var array<int,array<mixed>> $action_descriptions */
private $action_descriptions = [];
@@ -746,23 +748,35 @@ class Pref_Filters extends Handler_Protected {
->order_by_asc('id')
->find_many();
- $actions_summary = "";
+ /** @var array<string> $actions_summary */
+ $actions_summary = [];
$cumulative_score = 0;
+ // we're going to show a summary adjustment so we skip individual score action descriptions here
foreach ($actions as $action) {
- if ($action->action_id == self::ACTION_SCORE)
+ if ($action->action_id == self::ACTION_SCORE) {
$cumulative_score += (int) $action->action_param;
+ continue;
+ }
- if ($actions_summary == "")
- $actions_summary = self::_get_action_name($action);
+ array_push($actions_summary, self::_get_action_name($action));
}
- if ($cumulative_score) array_push($title_summary, T_sprintf("sets score: %d", $cumulative_score));
+ // inject a fake action description using cumulative filter score
+ if ($cumulative_score != 0) {
+ array_unshift($actions_summary,
+ self::_get_action_name(["action_id" => self::ACTION_SCORE, "action_param" => $cumulative_score]));
+ }
- if (count($actions) > 1)
- $actions_summary .= " " . sprintf(_ngettext("(+%d action)", "(+%d actions)", count($actions) - 1), count($actions) - 1);
+ if (count($actions_summary) > self::MAX_ACTIONS_TO_DISPLAY) {
+ $actions_not_shown = count($actions_summary) - self::MAX_ACTIONS_TO_DISPLAY;
+ $actions_summary = array_slice($actions_summary, 0, self::MAX_ACTIONS_TO_DISPLAY);
+
+ array_push($actions_summary,
+ sprintf(_ngettext("(+%d action)", "(+%d actions)", $actions_not_shown), $actions_not_shown));
+ }
- return [implode(", ", $title_summary), $actions_summary];
+ return [implode(", ", $title_summary), implode("<br/>", $actions_summary)];
}
return [];