mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up filters, extend index and small fix for title.
This commit is contained in:
@@ -3,29 +3,35 @@
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Class Toolkit
|
||||
*
|
||||
* @package Firefly\Helper\Toolkit
|
||||
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||
*/
|
||||
class Toolkit implements ToolkitInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* Lots of code in Firefly III still depends on session['start'], session['end'] and
|
||||
* session['range'] to be available, even though this feature has been removed from Firefly
|
||||
* in favor of a new reporting feature. This reporting feature can show the user past and future
|
||||
* date ranges instead of the dashboard (the dashboard always shows "right now").
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed|null
|
||||
* The only actual choice the user is left with is the range, which can be changed using the Preferences pane.
|
||||
*
|
||||
* The start/end dates are set here, regardless of what the user might want to see.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function getDateRange(Request $request)
|
||||
public function getDateRange()
|
||||
{
|
||||
$range = $this->_getRange();
|
||||
$start = $this->_getStartDate();
|
||||
$end = $this->_getEndDate();
|
||||
// start and end are always "now", and get edited later.
|
||||
$start = new Carbon;
|
||||
$end = new Carbon;
|
||||
|
||||
// update start only:
|
||||
$start = $this->_updateStartDate($range, $start);
|
||||
@@ -33,110 +39,33 @@ class Toolkit implements ToolkitInterface
|
||||
// update end only:
|
||||
$end = $this->_updateEndDate($range, $start, $end);
|
||||
|
||||
if (\Input::get('action') == 'prev') {
|
||||
$start = $this->_moveStartPrevious($range, $start);
|
||||
$end = $this->_moveEndPrevious($range, $end);
|
||||
}
|
||||
if (\Input::get('action') == 'next') {
|
||||
$start = $this->_moveStartNext($range, $start);
|
||||
$end = $this->_moveEndNext($range, $end);
|
||||
}
|
||||
|
||||
// save in session:
|
||||
\Session::put('start', $start);
|
||||
\Session::put('end', $end);
|
||||
\Session::put('range', $range);
|
||||
if (!is_null(\Input::get('action'))) {
|
||||
return \Redirect::to($request->url());
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDateRangeDates()
|
||||
{
|
||||
return [\Session::get('start'), \Session::get('end')];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReminders()
|
||||
protected function _getRange()
|
||||
{
|
||||
// get reminders, for menu, mumble mumble:
|
||||
$today = new Carbon;
|
||||
$reminders = \Auth::user()->reminders()->where('class', 'PiggybankReminder')->validOn($today)->get();
|
||||
|
||||
/** @var \Reminder $reminder */
|
||||
foreach ($reminders as $index => $reminder) {
|
||||
if (\Session::has('dismissal-' . $reminder->id)) {
|
||||
$time = \Session::get('dismissal-' . $reminder->id);
|
||||
if ($time >= $today) {
|
||||
unset($reminders[$index]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
\Session::put('reminderCount', count($reminders));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _getrange()
|
||||
{
|
||||
if (!is_null(\Input::get('range'))) {
|
||||
$range = \Input::get('range');
|
||||
if (!is_null(\Session::get('range'))) {
|
||||
$range = \Session::get('range');
|
||||
} else {
|
||||
if (!is_null(\Session::get('range'))) {
|
||||
$range = \Session::get('range');
|
||||
} else {
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
$preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$viewRange = $preferences->get('viewRange', '1M');
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
$preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$viewRange = $preferences->get('viewRange', '1M');
|
||||
|
||||
// default range:
|
||||
$range = $viewRange->data;
|
||||
}
|
||||
// default range:
|
||||
$range = $viewRange->data;
|
||||
}
|
||||
|
||||
return $range;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon|mixed
|
||||
*/
|
||||
protected function _getStartDate()
|
||||
{
|
||||
$start = \Session::has('start') ? \Session::get('start') : new Carbon;
|
||||
if (\Input::get('start') && \Input::get('end')) {
|
||||
$start = new Carbon(\Input::get('start'));
|
||||
}
|
||||
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon|mixed
|
||||
*/
|
||||
protected function _getEndDate()
|
||||
{
|
||||
$end = \Session::has('end') ? \Session::get('end') : new Carbon;
|
||||
if (\Input::get('start') && \Input::get('end')) {
|
||||
$end = new Carbon(\Input::get('end'));
|
||||
}
|
||||
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $start
|
||||
@@ -211,118 +140,4 @@ class Toolkit implements ToolkitInterface
|
||||
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function _moveStartPrevious($range, Carbon $start)
|
||||
{
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$start->subDay();
|
||||
break;
|
||||
case '1W':
|
||||
$start->subWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$start->subMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$start->subMonths(3)->firstOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
$start->subMonths(6);
|
||||
break;
|
||||
}
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function _moveEndPrevious($range, Carbon $end)
|
||||
{
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$end->subDay();
|
||||
break;
|
||||
case '1W':
|
||||
$end->subWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$end->startOfMonth()->subMonth()->endOfMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$end->subMonths(3)->lastOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
$end->subMonths(6);
|
||||
break;
|
||||
}
|
||||
return $end;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function _moveStartNext($range, Carbon $start)
|
||||
{
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$start->addDay();
|
||||
break;
|
||||
case '1W':
|
||||
$start->addWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$start->addMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$start->addMonths(3)->firstOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
$start->addMonths(6);
|
||||
break;
|
||||
}
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function _moveEndNext($range, Carbon $end)
|
||||
{
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$end->addDay();
|
||||
break;
|
||||
case '1W':
|
||||
$end->addWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$end->addMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$end->addMonths(6)->lastOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
$end->addMonths(6);
|
||||
break;
|
||||
}
|
||||
return $end;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -12,20 +12,9 @@ use Illuminate\Http\Request;
|
||||
interface ToolkitInterface
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return mixed
|
||||
* @return null
|
||||
*/
|
||||
public function getDateRange(Request $request);
|
||||
public function getDateRange();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDateRangeDates();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReminders();
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user