From 38fca6d7d8e320ead86e568a2bc59ffffeea0fc8 Mon Sep 17 00:00:00 2001 From: sreeshanth-soma1 Date: Wed, 18 Feb 2026 19:29:18 +0530 Subject: [PATCH 1/2] feat: add date filters for created and updated fields in advanced search --- core/models/media_model.php | 35 +++++++++++++++++++++++- public/html/sidebar/advanced_search.html | 10 +++++++ public/js/sidebar.js | 6 ++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/core/models/media_model.php b/core/models/media_model.php index ad873823..e8112a76 100644 --- a/core/models/media_model.php +++ b/core/models/media_model.php @@ -954,7 +954,7 @@ public function search_filters_validate($args = []) OBFHelpers::require_args($args, ['filters']); $filters = $args['filters']; - $allowed_filters = ['comments','artist','title','album','year','type','category','country','language','genre','duration','is_copyright_owner','status','dynamic_select']; + $allowed_filters = ['comments','artist','title','album','year','type','category','country','language','genre','duration','created','updated','is_copyright_owner','status','dynamic_select']; $allowed_operators = [ // deprecated 'like', @@ -1034,6 +1034,8 @@ public function search_filters_where_array($args = []) $column_array['language'] = 'media.language'; $column_array['genre'] = 'media.genre_id'; $column_array['duration'] = 'media.duration'; + $column_array['created'] = 'media.created'; + $column_array['updated'] = 'media.updated'; $column_array['comments'] = 'media.comments'; $column_array['is_copyright_owner'] = 'media.is_copyright_owner'; $column_array['dynamic_select'] = 'media.dynamic_select'; @@ -1110,6 +1112,37 @@ public function search_filters_where_array($args = []) $tmp_sql = $column_array[$filter['filter']]; } + $is_date_filter = in_array($filter['filter'], ['created', 'updated'], true); + $date_value = null; + if ($is_date_filter && preg_match('/^\d{4}-\d{2}-\d{2}$/', (string) $filter['val'])) { + $date_value = strtotime($filter['val'] . ' 00:00:00'); + } + + if ($is_date_filter && $date_value !== false && $date_value !== null) { + $day_start = (int) $date_value; + $day_end = $day_start + 86399; + $column = $tmp_sql; + + if (in_array($filter['op'], ['is', 'eq'], true)) { + $tmp_sql = '(' . $column . ' >= "' . $day_start . '" AND ' . $column . ' <= "' . $day_end . '")'; + } elseif (in_array($filter['op'], ['not', 'neq'], true)) { + $tmp_sql = '(' . $column . ' < "' . $day_start . '" OR ' . $column . ' > "' . $day_end . '")'; + } elseif (in_array($filter['op'], ['gte', 'gt'], true)) { + $compare_value = $filter['op'] == 'gt' ? $day_end : $day_start; + $operator = $filter['op'] == 'gt' ? '>' : '>='; + $tmp_sql = $column . ' ' . $operator . ' "' . $compare_value . '"'; + } elseif (in_array($filter['op'], ['lte', 'lt'], true)) { + $compare_value = $filter['op'] == 'lt' ? $day_start : $day_end; + $operator = $filter['op'] == 'lt' ? '<' : '<='; + $tmp_sql = $column . ' ' . $operator . ' "' . $compare_value . '"'; + } else { + $tmp_sql = $column . ' ' . $op_array[$filter['op']] . ' "' . $day_start . '"'; + } + + $where_array[] = $tmp_sql; + continue; + } + $tmp_sql .= ' ' . $op_array[$filter['op']] . ' "'; // TODO like, not_like deprecated diff --git a/public/html/sidebar/advanced_search.html b/public/html/sidebar/advanced_search.html index cffcba45..2c3e52af 100644 --- a/public/html/sidebar/advanced_search.html +++ b/public/html/sidebar/advanced_search.html @@ -18,6 +18,8 @@ + + @@ -49,6 +51,13 @@ + + + diff --git a/public/js/sidebar.js b/public/js/sidebar.js index 7565691b..88754094 100644 --- a/public/js/sidebar.js +++ b/public/js/sidebar.js @@ -1473,6 +1473,11 @@ OB.Sidebar.advancedSearchAdd = function (filter_data) { return false; } + if ((filter == "created" || filter == "updated") && val.match(/^\d{4}-\d{2}-\d{2}$/) === null) { + $("#advanced_search_message").obWidget("error", ["A valid %1 is required", filter_name.toLowerCase()]); + return false; + } + $("#advanced_search_no_criteria").hide(); OB.Sidebar.advanced_search_filter_id++; @@ -1480,6 +1485,7 @@ OB.Sidebar.advancedSearchAdd = function (filter_data) { if (compare_field == "select") filter_description += " " + op_name + " " + val_name; else if (compare_field == "number") filter_description += " " + op_name + " " + val; + else if (compare_field == "date") filter_description += " " + op_name + " " + val; //T seconds else if (compare_field == "duration") filter_description += " " + op_name + " " + val + " " + OB.t("seconds"); else filter_description += " " + op_name + ' "' + val + '"'; From 0afac64380f358733964673b6a53a5e0253022ca Mon Sep 17 00:00:00 2001 From: sreeshanth-soma1 Date: Sun, 22 Feb 2026 09:12:49 +0530 Subject: [PATCH 2/2] fix(search): replace native date picker with smart date input Updates advanced search to use `` for natural language date parsing, matching the scheduling UI. --- public/html/sidebar/advanced_search.html | 2 +- public/js/sidebar.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/public/html/sidebar/advanced_search.html b/public/html/sidebar/advanced_search.html index 2c3e52af..f3f5dfd9 100644 --- a/public/html/sidebar/advanced_search.html +++ b/public/html/sidebar/advanced_search.html @@ -107,7 +107,7 @@ - + diff --git a/public/js/sidebar.js b/public/js/sidebar.js index 88754094..524b4edb 100644 --- a/public/js/sidebar.js +++ b/public/js/sidebar.js @@ -1454,13 +1454,17 @@ OB.Sidebar.advancedSearchAdd = function (filter_data) { var op_name = $op.text(); var $val = $(".advanced_search [data-type=value][data-name=" + value_field + "]"); - var val = $val.val(); + if ($val.prop("nodeName") == "OB-DATE-INPUT") { + var val = OB.UI.dateInputVal($val[0]); + } else { + var val = $val.val(); + } if ($val.prop("nodeName") == "SELECT") var val_name = $val.find("option:selected").text(); else if ($val.prop("nodeName") == "OB-FIELD-LANGUAGE") var val_name = $val[0].currentLanguageName(); else if ($val.prop("nodeName") == "OB-FIELD-COUNTRY") var val_name = $val[0].currentCountryName(); // trim val - val = val.trim(); + if (typeof val === "string") val = val.trim(); // some basic validation if ((filter == "artist" || filter == "album" || filter == "title") && val == "") { @@ -1473,7 +1477,7 @@ OB.Sidebar.advancedSearchAdd = function (filter_data) { return false; } - if ((filter == "created" || filter == "updated") && val.match(/^\d{4}-\d{2}-\d{2}$/) === null) { + if ((filter == "created" || filter == "updated") && (!val || val === "")) { $("#advanced_search_message").obWidget("error", ["A valid %1 is required", filter_name.toLowerCase()]); return false; }