summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2024-11-23 18:13:09 +0300
committerAndrew Dolgov <fox@fakecake.org>2024-11-23 18:13:09 +0300
commit6bc9097b0fef2c47ed8c44ce408fe41eacb6bc92 (patch)
tree80c641f1a9bc984edc251abdc22092db22bc2efb /classes
parentd4636716fb6e1879098823c2f037db5d8d3f24a0 (diff)
getfiltertree: switch to ORM and simplify code
Diffstat (limited to 'classes')
-rw-r--r--classes/Pref_Filters.php85
1 files changed, 34 insertions, 51 deletions
diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php
index 89bc669b6..72574629c 100644
--- a/classes/Pref_Filters.php
+++ b/classes/Pref_Filters.php
@@ -239,66 +239,49 @@ 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_strpos($filter->title, $filter_search) === false &&
+ !ORM::for_table('ttrss_filters2_rules')
+ ->where('filter_id', $filter->id)
+ ->where_raw('LOWER(reg_exp) LIKE ?', ["%$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'];