diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2024-11-24 06:37:31 +0000 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2024-11-24 06:37:31 +0000 |
| commit | b089d67e26b9847d14a8e839df051ec035c980de (patch) | |
| tree | 5048fcc308d11ccd5cd1b569daafa2a2e5ddcee5 | |
| parent | 7892b412348c03f2b6733a326776a47d980fd7f6 (diff) | |
| parent | aad69b7ca6b2e5848102836de6c6a65b107a62db (diff) | |
Merge branch 'getfiltertree-eldritch-horrors' into 'master'
getfiltertree: switch to ORM and simplify code
See merge request tt-rss/tt-rss!79
| -rw-r--r-- | classes/Pref_Filters.php | 94 |
1 files changed, 39 insertions, 55 deletions
diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php index 89bc669b6..45b11d345 100644 --- a/classes/Pref_Filters.php +++ b/classes/Pref_Filters.php @@ -239,74 +239,58 @@ class Pref_Filters extends Handler_Protected { } function getfiltertree(): void { - $root = array(); - $root['id'] = 'root'; - $root['name'] = __('Filters'); - $root['enabled'] = true; - $root['items'] = array(); + $root = [ + 'id' => 'root', + 'name' => __('Filters'), + 'enabled' => true, + 'items' => [] + ]; $filter_search = ($_SESSION["prefs_filter_search"] ?? ""); - $sth = $this->pdo->prepare("SELECT *, - (SELECT action_param FROM ttrss_filters2_actions - WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param, - (SELECT action_id FROM ttrss_filters2_actions - WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id, - (SELECT description FROM ttrss_filter_actions - WHERE id = (SELECT action_id FROM ttrss_filters2_actions - WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1)) AS action_name, - (SELECT reg_exp FROM ttrss_filters2_rules - WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp - FROM ttrss_filters2 WHERE - owner_uid = ? ORDER BY order_id, title"); - $sth->execute([$_SESSION['uid']]); - - $folder = array(); - $folder['items'] = array(); - - while ($line = $sth->fetch()) { + $filters = ORM::for_table('ttrss_filters2') + ->where('owner_uid', $_SESSION['uid']) + ->order_by_asc(['order_id', 'title']) + ->find_many(); - $name = $this->_get_name($line["id"]); + $folder = [ + 'items' => [] + ]; - $match_ok = false; - if ($filter_search) { - if (mb_strpos($line['title'], $filter_search) !== false) { - $match_ok = true; - } + foreach ($filters as $filter) { + $name = $this->_get_name($filter->id); - $rules_sth = $this->pdo->prepare("SELECT reg_exp - FROM ttrss_filters2_rules WHERE filter_id = ?"); - $rules_sth->execute([$line['id']]); + if ($filter_search && + mb_stripos($filter->title, $filter_search) === false && + !ORM::for_table('ttrss_filters2_rules') + ->where('filter_id', $filter->id) + ->where_raw('LOWER(reg_exp) LIKE LOWER(?)', ["%$filter_search%"]) + ->find_one()) { - while ($rule_line = $rules_sth->fetch()) { - if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) { - $match_ok = true; - break; - } - } + continue; } - $filter = array(); - $filter['id'] = 'FILTER:' . $line['id']; - $filter['bare_id'] = $line['id']; - $filter['name'] = $name[0]; - $filter['param'] = $name[1]; - $filter['checkbox'] = false; - $filter['last_triggered'] = $line["last_triggered"] ? TimeHelper::make_local_datetime($line["last_triggered"], false) : null; - $filter['enabled'] = sql_bool_to_bool($line["enabled"]); - $filter['rules'] = $this->_get_rules_list($line['id']); - - if (!$filter_search || $match_ok) { - array_push($folder['items'], $filter); - } + $item = [ + 'id' => 'FILTER:' . $filter->id, + 'bare_id' => $filter->id, + 'name' => $name[0], + 'param' => $name[1], + 'checkbox' => false, + 'last_triggered' => $filter->last_triggered ? TimeHelper::make_local_datetime($filter->last_triggered, false) : null, + 'enabled' => sql_bool_to_bool($filter->enabled), + 'rules' => $this->_get_rules_list($filter->id) + ]; + + array_push($folder['items'], $item); } $root['items'] = $folder['items']; - $fl = array(); - $fl['identifier'] = 'id'; - $fl['label'] = 'name'; - $fl['items'] = array($root); + $fl = [ + 'identifier' => 'id', + 'label' => 'name', + 'items' => [$root] + ]; print json_encode($fl); } |