mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 20:38:57 +00:00
Code clean up and reformat.
This commit is contained in:
@@ -12,39 +12,6 @@ use Firefly\Exception\FireflyException;
|
||||
*/
|
||||
class Date
|
||||
{
|
||||
/**
|
||||
* @param Carbon $currentEnd
|
||||
* @param $repeatFreq
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function endOfPeriod(Carbon $currentEnd, $repeatFreq)
|
||||
{
|
||||
switch ($repeatFreq) {
|
||||
default:
|
||||
throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
|
||||
break;
|
||||
case 'daily':
|
||||
$currentEnd->addDay();
|
||||
break;
|
||||
case 'weekly':
|
||||
$currentEnd->addWeek()->subDay();
|
||||
break;
|
||||
case 'monthly':
|
||||
$currentEnd->addMonth()->subDay();
|
||||
break;
|
||||
case 'quarterly':
|
||||
$currentEnd->addMonths(3)->subDay();
|
||||
break;
|
||||
case 'half-year':
|
||||
$currentEnd->addMonths(6)->subDay();
|
||||
break;
|
||||
case 'yearly':
|
||||
$currentEnd->addYear()->subDay();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param $repeatFreq
|
||||
@@ -81,6 +48,40 @@ class Date
|
||||
$date->addYears($add);
|
||||
break;
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $currentEnd
|
||||
* @param $repeatFreq
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function endOfPeriod(Carbon $currentEnd, $repeatFreq)
|
||||
{
|
||||
switch ($repeatFreq) {
|
||||
default:
|
||||
throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
|
||||
break;
|
||||
case 'daily':
|
||||
$currentEnd->addDay();
|
||||
break;
|
||||
case 'weekly':
|
||||
$currentEnd->addWeek()->subDay();
|
||||
break;
|
||||
case 'monthly':
|
||||
$currentEnd->addMonth()->subDay();
|
||||
break;
|
||||
case 'quarterly':
|
||||
$currentEnd->addMonths(3)->subDay();
|
||||
break;
|
||||
case 'half-year':
|
||||
$currentEnd->addMonths(6)->subDay();
|
||||
break;
|
||||
case 'yearly':
|
||||
$currentEnd->addYear()->subDay();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,29 +18,6 @@ use Firefly\Exception\FireflyException;
|
||||
*/
|
||||
class Filter
|
||||
{
|
||||
/**
|
||||
* Checks and sets the currently set 'range' or defaults to a session
|
||||
* and if that fails, defaults to 1M. Always returns the final value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setSessionRangeValue()
|
||||
{
|
||||
if (!is_null(\Session::get('range'))) {
|
||||
$range = \Session::get('range');
|
||||
} else {
|
||||
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
||||
$preferences = \App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
||||
$viewRange = $preferences->get('viewRange', '1M');
|
||||
|
||||
// default range:
|
||||
$range = $viewRange->data;
|
||||
\Session::put('range', $range);
|
||||
}
|
||||
return $range;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Session::get('start') and Session::get('end') for other methods to use.
|
||||
*/
|
||||
@@ -87,10 +64,35 @@ class Filter
|
||||
\Session::put('period', $period);
|
||||
\Session::put('prev', $this->periodName($range, $prev));
|
||||
\Session::put('next', $this->periodName($range, $next));
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks and sets the currently set 'range' or defaults to a session
|
||||
* and if that fails, defaults to 1M. Always returns the final value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setSessionRangeValue()
|
||||
{
|
||||
if (!is_null(\Session::get('range'))) {
|
||||
$range = \Session::get('range');
|
||||
} else {
|
||||
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
||||
$preferences = \App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
||||
$viewRange = $preferences->get('viewRange', '1M');
|
||||
|
||||
// default range:
|
||||
$range = $viewRange->data;
|
||||
\Session::put('range', $range);
|
||||
}
|
||||
|
||||
return $range;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $start
|
||||
@@ -198,12 +200,14 @@ class Filter
|
||||
break;
|
||||
case '3M':
|
||||
$month = intval($date->format('m'));
|
||||
|
||||
return 'Q' . ceil(($month / 12) * 4) . ' ' . $date->format('Y');
|
||||
break;
|
||||
case '6M':
|
||||
$month = intval($date->format('m'));
|
||||
$half = ceil(($month / 12) * 2);
|
||||
$halfName = $half == 1 ? 'first' : 'second';
|
||||
|
||||
return $halfName . ' half of ' . $date->format('d-m-Y');
|
||||
break;
|
||||
case '1Y':
|
||||
@@ -252,6 +256,7 @@ class Filter
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
@@ -291,6 +296,7 @@ class Filter
|
||||
throw new FireflyException('Cannot do _next() on ' . $range);
|
||||
break;
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,13 @@ use Illuminate\Support\Collection;
|
||||
*
|
||||
* @package FireflyIII\Shared\Toolkit
|
||||
*/
|
||||
class Form {
|
||||
class Form
|
||||
{
|
||||
/**
|
||||
* Takes any collection and tries to make a sensible select list compatible array of it.
|
||||
*
|
||||
* @param Collection $set
|
||||
* @param null $titleField
|
||||
* @param null $titleField
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -44,6 +45,7 @@ class Form {
|
||||
}
|
||||
$selectList[$id] = $title;
|
||||
}
|
||||
|
||||
return $selectList;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ class Navigation
|
||||
* Save in session:
|
||||
*/
|
||||
\Session::put('start', $next);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -59,6 +60,7 @@ class Navigation
|
||||
* Save in session:
|
||||
*/
|
||||
\Session::put('start', $prev);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user