Commit c4cec89b authored by Dominik Hebeler's avatar Dominik Hebeler

Added functionality to provide custom date range

parent a0f6e181
<?php
namespace App;
use Carbon;
class DynamicEngineParameters {
......@@ -12,4 +13,14 @@ class DynamicEngineParameters {
$lastYear = \Carbon::now()->subYear()->format("Y-m-d");
return $lastYear . ".." . $now;
}
public static function FreshnessCustomBing(){
// Bings custom date filter uses YYYY-mm-dd..YYYY-mm-dd
// From and two dates are supplied by parameters ff and ft
// They already have been checked if they match above pattern in parseFormData function
$from = \Request::input("ff");
$to = \Request::input("ft");
return $from . ".." . $to;
}
}
\ No newline at end of file
......@@ -717,19 +717,23 @@ class MetaGer
$availableFilter = [];
foreach ($parameterFilter as $filterName => $filter) {
$values = $filter->values;
$values = clone $filter->values;
# Check if any of the enabled search engines provide this filter
foreach ($this->enabledSearchengines as $engineName => $engine) {
if (!empty($filter->sumas->$engineName)) {
if (empty($availableFilter[$filterName])) {
$availableFilter[$filterName] = $filter;
unset($availableFilter[$filterName]->values);
foreach($availableFilter[$filterName]->values as $key => $value){
if($key !== "nofilter"){
unset($availableFilter[$filterName]->values->{$key});
}
}
}
if (empty($availableFilter[$filterName]->values)) {
$availableFilter[$filterName]->values = (object) ["" => $values->{""}];
$availableFilter[$filterName]->values = new \stdClass();
}
foreach ($filter->sumas->{$engineName}->values as $key => $value) {
$availableFilter[$filterName]->values->$key = $values->$key;
$availableFilter[$filterName]->values->{$key} = $values->$key;
}
}
}
......@@ -745,13 +749,17 @@ class MetaGer
}
if (empty($availableFilter[$filterName])) {
$availableFilter[$filterName] = $filter;
unset($availableFilter[$filterName]->values);
foreach($availableFilter[$filterName]->values as $key => $value){
if($key !== "nofilter"){
unset($availableFilter[$filterName]->values->{$key});
}
}
}
if (empty($availableFilter[$filterName]->values)) {
$availableFilter[$filterName]->values = (object) ["" => $values->{""}];
$availableFilter[$filterName]->values = new \stdClass();
}
foreach ($filter->sumas->{$suma}->values as $key => $value) {
$availableFilter[$filterName]->values->$key = $values->$key;
$availableFilter[$filterName]->values->{$key} = $values->$key;
}
}
}
......@@ -1011,6 +1019,51 @@ class MetaGer
// Remove Inputs that are not used
$this->request = $request->replace($request->except(['verification_id', 'uid', 'verification_count']));
// Disable freshness filter if custom freshness filter isset
if($this->request->filled("ff") && $this->request->filled("f")){
$this->request = $this->request->replace($this->request->except(["f"]));
}
// Remove custom time filter if either of the dates isn't set or is not a date
if($this->request->input("fc") === "on"){
if(!$this->request->filled("ff") || !$this->request->filled("ft")){
$this->request = $this->request->replace($this->request->except(["fc", "ff", "ft"]));
}else{
$ff = $this->request->input("ff");
$ft = $this->request->input("ft");
if(!preg_match("/^\d{4}-\d{2}-\d{2}$/", $ff) || !preg_match("/^\d{4}-\d{2}-\d{2}$/", $ft)){
$this->request = $this->request->replace($this->request->except(["fc", "ff", "ft"]));
}else{
// Now Check if there is something wrong with the dates
$from = $this->request->input("ff");
$to = $this->request->input("ft");
$changed = false;
$from = Carbon::createFromFormat("Y-m-d H:i:s", $from . " 00:00:00");
$to = Carbon::createFromFormat("Y-m-d H:i:s", $to . " 00:00:00");
if($from > Carbon::now()){
$from = Carbon::now();
$changed = true;
}
if($to > Carbon::now()){
$to = Carbon::now();
$changed = true;
}
if($from > $to){
$tmp = $to;
$to = $from;
$from = $tmp;
$changed = true;
}
if($changed){
$oldParameters = $this->request->all();
$oldParameters["ff"] = $from->format("Y-m-d");
$oldParameters["ft"] = $to->format("Y-m-d");
$this->request = $this->request->replace($oldParameters);
}
}
}
}
$this->out = $request->input('out', "html");
# Standard output format html
if ($this->out !== "html" && $this->out !== "json" && $this->out !== "results" && $this->out !== "results-with-style" && $this->out !== "result-count" && $this->out !== "rss20" && $this->out !== "atom10" && $this->out !== "rich" && $this->out !== "api") {
......
......@@ -98,7 +98,6 @@ abstract class Searchengine
}
$this->engine->{"get-parameter"}->{$engineParameterKey} = $engineParameterValue;
}
#dd($this->engine->{"get-parameter"});
$this->getString = $this->generateGetString($q);
$this->updateHash();
......
......@@ -82,6 +82,8 @@ return [
"filter.freshness.week" => "Letzte Woche",
"filter.freshness.month" => "Letzter Monat",
"filter.freshness.year" => "Letztes Jahr",
"filter.freshness.custom" => "Benutzerdefiniert",
"filter.customdatetitle" => "Benutzerdefiniertes Datum auswählen",
"filter.market" => "Sprache",
"filter.market.ga" => "Deutsch (Österreich)",
......
......@@ -604,6 +604,21 @@ a {
padding: 3px;
border-radius: 5px;
}
label[for="custom-date"] {
cursor: pointer;
&:hover {
color: red;
}
}
#bing-from-to {
display: none;
}
#custom-date:checked + select {
display: none;
}
#custom-date:checked + select + #bing-from-to {
display: flex;
}
}
.option-selector:nth-child(1){
margin-left: 0;
......
<div id="bing-from-to">
<input type="date" form="searchForm" @if(Request::filled("ff")) value="{{ Request::input("ff", "") }}" @endif name="ff">
<div>&nbsp;-&nbsp;</div>
<input type="date" form="searchForm" @if(Request::filled("ft")) value="{{ Request::input("ft", "") }}" @endif name="ft">
</div>
\ No newline at end of file
......@@ -33,18 +33,37 @@
<div id="options-box">
<div id="options-items">
@foreach($metager->getAvailableParameterFilter() as $filterName => $filter)
@if(empty($filter->hidden) || $filter->hidden === false)
<div class="option-selector">
<label for="{{$filterName}}">@lang($filter->name)</label>
<select name="{{$filter->{'get-parameter'} }}" class="custom-select custom-select-sm" form="searchForm" onchange="this.form.submit()">
<div>
<label for="{{$filterName}}">
@lang($filter->name)
</label>
@if($filter->{'get-parameter'} === "f")
<label for="custom-date" title="@lang('metaGer.filter.customdatetitle')">
<i class="fas fa-cogs"></i>
</label>
</div>
<input id="custom-date" type="checkbox" form="searchForm" @if(Request::input('fc', "off") === "on")checked @endif name="fc" />
@else
</div>
@endif
<select name="{{$filter->{'get-parameter'} }}" class="custom-select custom-select-sm" form="searchForm" onchange="this.form.submit()">
@foreach($filter->values as $value => $text)
@if($value === "" && Cookie::get($metager->getFokus() . "_setting_" . $filter->{"get-parameter"}) !== null)
@if($value === "nofilter" && Cookie::get($metager->getFokus() . "_setting_" . $filter->{"get-parameter"}) !== null)
<option value="off" @if(empty($filter->value) || $filter->value === "off")selected @endif>{{trans($text)}}</option>
@elseif($value === "nofilter")
<option value="" @if(!empty($filter->value) && $filter->value === $value)selected @endif>{{trans($text)}}</option>
@else
<option value="{{$value}}" @if(!empty($filter->value) && $filter->value === $value)selected @endif>{{trans($text)}}</option>
@endif
@endforeach
</select>
@if(!empty($filter->htmlbelow))
@include($filter->htmlbelow)
@endif
</div>
@endif
@endforeach
</div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment