Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion core/models/media_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions public/html/sidebar/advanced_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<option value="genre" data-compare="select" data-value="genre" data-t>Genre</option>
<option value="comments" data-compare="text" data-value="text" data-t>Comments</option>
<option value="duration" data-compare="duration" data-value="text" data-t>Duration</option>
<option value="created" data-compare="date" data-value="date" data-t>Created Date</option>
<option value="updated" data-compare="date" data-value="date" data-t>Last Updated Date</option>
<option value="is_copyright_owner" data-compare="select" data-value="bool" data-t>
Is Copyright Owner
</option>
Expand Down Expand Up @@ -49,6 +51,13 @@
<option value="lte">is less than or equal to (seconds)</option>
</select>

<select id="advanced_search_date_compare" data-type="compare" data-name="date" class="hidden">
<option value="is">is on</option>
<option value="not">is not on</option>
<option value="gte">is on or after</option>
<option value="lte">is on or before</option>
</select>

<select id="advanced_search_select_compare" data-type="compare" data-name="select" class="hidden">
<option value="is">is</option>
<option value="not">is not</option>
Expand Down Expand Up @@ -98,6 +107,7 @@
</select>

<input type="text" id="advanced_search_value" data-type="value" data-name="text" />
<ob-date-input id="advanced_search_date_value" data-type="value" data-name="date" class="hidden"></ob-date-input>

<div id="advanced_search_metadata" style="display: none; align-items: flex-start; gap: 10px"></div>

Expand Down
14 changes: 12 additions & 2 deletions public/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "") {
Expand All @@ -1473,13 +1477,19 @@ OB.Sidebar.advancedSearchAdd = function (filter_data) {
return false;
}

if ((filter == "created" || filter == "updated") && (!val || val === "")) {
$("#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++;

var filter_description = filter_name;

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 + '"';
Expand Down
Loading