Fixed more of the index.

This commit is contained in:
James Cole
2015-02-07 06:49:24 +01:00
parent de715c14be
commit 37e58ac13a
12 changed files with 220 additions and 70 deletions

View File

@@ -4,7 +4,6 @@ namespace FireflyIII\Support;
use Carbon\Carbon;
use FireflyIII\Exception\FireflyException;
use Session;
/**
* Class Navigation
@@ -15,48 +14,6 @@ class Navigation
{
public function jumpToPrevious($range, Carbon $date)
{
$functionMap = [
'1D' => 'Day',
'1W' => 'Week',
'1M' => 'Month',
'1Y' => 'Year'
];
if (isset($functionMap[$range])) {
$startFunction = 'startOf' . $functionMap[$range];
$subFunction = 'sub' . $functionMap[$range];
$date->$startFunction()->$subFunction();
return $date;
}
if ($range == '3M') {
$date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
return $date;
}
if ($range == '6M') {
$month = intval($date->format('m'));
$date->startOfYear();
if ($month <= 6) {
$date->subMonths(6);
}
return $date;
}
throw new FireflyException('Cannot do _previous() on ' . $range);
}
public function next()
{
$range = Session::get('range');
$start = Session::get('start');
Session::put('start', Navigation::jumpToNext($range, clone $start));
}
public function jumpToNext($range, Carbon $date)
{
switch ($range) {
@@ -90,6 +47,39 @@ class Navigation
return $date;
}
public function jumpToPrevious($range, Carbon $date)
{
$functionMap = [
'1D' => 'Day',
'1W' => 'Week',
'1M' => 'Month',
'1Y' => 'Year'
];
if (isset($functionMap[$range])) {
$startFunction = 'startOf' . $functionMap[$range];
$subFunction = 'sub' . $functionMap[$range];
$date->$startFunction()->$subFunction();
return $date;
}
if ($range == '3M') {
$date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
return $date;
}
if ($range == '6M') {
$month = intval($date->format('m'));
$date->startOfYear();
if ($month <= 6) {
$date->subMonths(6);
}
return $date;
}
throw new FireflyException('Cannot do _previous() on ' . $range);
}
public function periodName($range, Carbon $date)
{
$formatMap = [
@@ -116,15 +106,6 @@ class Navigation
throw new FireflyException('No _periodName() for range "' . $range . '"');
}
public function prev()
{
$range = Session::get('range');
$start = Session::get('start');
Session::put('start', Navigation::jumpToPrevious($range, clone $start));
}
public function updateEndDate($range, Carbon $start)
{
$functionMap = [