2015-02-05 21:52:16 -06:00
|
|
|
<?php namespace FireflyIII\Http\Controllers;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-05-14 06:41:21 -05:00
|
|
|
use Auth;
|
2015-12-31 10:20:54 -06:00
|
|
|
use Carbon\Carbon;
|
2015-06-13 03:02:36 -05:00
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
2015-02-05 21:39:52 -06:00
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
2015-02-11 00:35:10 -06:00
|
|
|
use Illuminate\Routing\Controller as BaseController;
|
2015-05-14 06:41:21 -05:00
|
|
|
use Preferences;
|
2015-04-28 08:26:30 -05:00
|
|
|
use View;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* Class Controller
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
|
|
|
abstract class Controller extends BaseController
|
|
|
|
{
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-06-13 03:02:36 -05:00
|
|
|
use DispatchesJobs, ValidatesRequests;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-05-14 06:41:21 -05:00
|
|
|
/** @var string */
|
|
|
|
protected $monthAndDayFormat;
|
2015-05-16 02:41:14 -05:00
|
|
|
/** @var string */
|
2015-05-14 06:41:21 -05:00
|
|
|
protected $monthFormat;
|
|
|
|
|
2015-04-28 08:26:30 -05:00
|
|
|
/**
|
2015-05-23 13:49:57 -05:00
|
|
|
* @codeCoverageIgnore
|
2015-04-28 08:26:30 -05:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
View::share('hideBudgets', false);
|
|
|
|
View::share('hideCategories', false);
|
|
|
|
View::share('hideBills', false);
|
|
|
|
View::share('hideTags', false);
|
2015-05-14 06:41:21 -05:00
|
|
|
|
|
|
|
if (Auth::check()) {
|
2015-12-20 01:40:58 -06:00
|
|
|
$pref = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'));
|
2015-05-14 06:41:21 -05:00
|
|
|
$lang = $pref->data;
|
2015-12-24 01:35:08 -06:00
|
|
|
$this->monthFormat = trans('config.month');
|
|
|
|
$this->monthAndDayFormat = trans('config.month_and_day');
|
2015-05-14 06:41:21 -05:00
|
|
|
|
|
|
|
View::share('monthFormat', $this->monthFormat);
|
|
|
|
View::share('monthAndDayFormat', $this->monthAndDayFormat);
|
|
|
|
View::share('language', $lang);
|
2015-12-20 01:40:58 -06:00
|
|
|
View::share('localeconv', localeconv());
|
2015-05-14 06:41:21 -05:00
|
|
|
}
|
2015-04-28 08:26:30 -05:00
|
|
|
}
|
2015-12-31 10:20:54 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Take the array as returned by SingleCategoryRepositoryInterface::spentPerDay and SingleCategoryRepositoryInterface::earnedByDay
|
|
|
|
* and sum up everything in the array in the given range.
|
|
|
|
*
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
* @param array $array
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getSumOfRange(Carbon $start, Carbon $end, array $array)
|
|
|
|
{
|
|
|
|
bcscale(2);
|
|
|
|
$sum = '0';
|
|
|
|
$currentStart = clone $start; // to not mess with the original one
|
|
|
|
$currentEnd = clone $end; // to not mess with the original one
|
|
|
|
|
|
|
|
while ($currentStart <= $currentEnd) {
|
|
|
|
$date = $currentStart->format('Y-m-d');
|
|
|
|
if (isset($array[$date])) {
|
|
|
|
$sum = bcadd($sum, $array[$date]);
|
|
|
|
}
|
|
|
|
$currentStart->addDay();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sum;
|
|
|
|
}
|
2015-02-05 21:39:52 -06:00
|
|
|
}
|