diff options
| -rw-r--r-- | classes/Pref_Filters.php | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php index 46cf6c30c..065303130 100644 --- a/classes/Pref_Filters.php +++ b/classes/Pref_Filters.php @@ -464,9 +464,9 @@ class Pref_Filters extends Handler_Protected { } /** - * @param array<string, mixed>|null $action + * @param array<string,mixed>|ArrayAccess<string, mixed>|null $action */ - private function _get_action_name(?array $action = null): string { + private function _get_action_name(array|ArrayAccess|null $action = null): string { if (!$action) { return ""; } @@ -723,45 +723,51 @@ class Pref_Filters extends Handler_Protected { */ private function _get_name(int $id): array { - $sth = $this->pdo->prepare( - "SELECT title,match_any_rule,f.inverse AS inverse,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions - FROM ttrss_filters2 AS f LEFT JOIN ttrss_filters2_rules AS r - ON (r.filter_id = f.id) - LEFT JOIN ttrss_filters2_actions AS a - ON (a.filter_id = f.id) WHERE f.id = ? GROUP BY f.title, f.match_any_rule, f.inverse"); - $sth->execute([$id]); - - if ($row = $sth->fetch()) { - - $title = $row["title"]; - $num_rules = $row["num_rules"]; - $num_actions = $row["num_actions"]; - $match_any_rule = $row["match_any_rule"]; - $inverse = $row["inverse"]; - - if (!$title) $title = __("[No caption]"); + $filter = ORM::for_table("ttrss_filters2") + ->table_alias('f') + ->select('f.title') + ->select('f.match_any_rule') + ->select('f.inverse') + ->select_expr('COUNT(DISTINCT r.id)', 'num_rules') + ->select_expr('COUNT(DISTINCT a.id)', 'num_actions') + ->join('ttrss_filters2_rules', ['r.filter_id', '=', 'f.id'], 'r') + ->join('ttrss_filters2_actions', ['a.filter_id', '=', 'f.id'], 'a') + ->where('f.id', $id) + ->group_by_expr('f.title, f.match_any_rule, f.inverse') + ->find_one(); + + if ($filter) { + $title_summary = [ + sprintf( + _ngettext("%s (%d rule)", "%s (%d rules)", (int) $filter->num_rules), + ($filter->title ? $filter->title : __("[No caption]")), + $filter->num_rules)]; + + if ($filter->match_any_rule) array_push($title_summary, __("matches any rule")); + if ($filter->inverse) array_push($title_summary, __("inverse")); + + $actions = ORM::for_table("ttrss_filters2_actions") + ->where("filter_id", $id) + ->order_by_asc('id') + ->find_many(); + + $actions_summary = ""; + $cumulative_score = 0; - $title = sprintf(_ngettext("%s (%d rule)", "%s (%d rules)", (int) $num_rules), $title, $num_rules); - - $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions - WHERE filter_id = ? ORDER BY id LIMIT 1"); - $sth->execute([$id]); - - $actions = ""; - - if ($line = $sth->fetch()) { - $actions = $this->_get_action_name($line); + foreach ($actions as $action) { + if ($action->action_id == self::ACTION_SCORE) + $cumulative_score += (int) $action->action_param; - $num_actions -= 1; + if ($actions_summary == "") + $actions_summary = self::_get_action_name($action); } - if ($match_any_rule) $title .= " (" . __("matches any rule") . ")"; - if ($inverse) $title .= " (" . __("inverse") . ")"; + if ($cumulative_score) array_push($title_summary, T_sprintf("sets score: %d", $cumulative_score)); - if ($num_actions > 0) - $actions = sprintf(_ngettext("%s (+%d action)", "%s (+%d actions)", (int) $num_actions), $actions, $num_actions); + if (count($actions) > 1) + $actions_summary .= " " . sprintf(_ngettext("(+%d action)", "(+%d actions)", count($actions) - 1), count($actions) - 1); - return [$title, $actions]; + return [implode(", ", $title_summary), $actions_summary]; } return []; |