Files
firefly-iii/app/Http/Controllers/Controller.php

98 lines
3.2 KiB
PHP
Raw Normal View History

<?php
2015-02-06 04:39:52 +01:00
namespace FireflyIII\Http\Controllers;
2016-01-08 20:47:35 +01:00
use App;
2016-01-09 07:48:45 +01:00
use Auth;
use Carbon\Carbon;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
2015-06-13 10:02:36 +02:00
use Illuminate\Foundation\Bus\DispatchesJobs;
2015-02-06 04:39:52 +01:00
use Illuminate\Foundation\Validation\ValidatesRequests;
2015-02-11 07:35:10 +01:00
use Illuminate\Routing\Controller as BaseController;
2016-01-10 18:02:24 +01:00
use NumberFormatter;
use Preferences;
2016-01-09 07:48:45 +01:00
use View;
2015-02-06 04:39:52 +01:00
2015-02-11 07:35:10 +01:00
/**
* Class Controller
*
* @package FireflyIII\Http\Controllers
*/
class Controller extends BaseController
2015-02-11 07:35:10 +01:00
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
2015-05-14 13:41:21 +02:00
2016-01-10 18:02:24 +01:00
/** @var string|\Symfony\Component\Translation\TranslatorInterface */
2016-01-09 07:48:45 +01:00
protected $monthAndDayFormat;
2016-01-24 15:58:16 +01:00
/** @var string|\Symfony\Component\Translation\TranslatorInterface */
protected $monthFormat;
2016-01-09 07:48:45 +01:00
2015-04-28 15:26:30 +02:00
/**
* Controller constructor.
2015-04-28 15:26:30 +02:00
*/
public function __construct()
{
View::share('hideBudgets', false);
View::share('hideCategories', false);
View::share('hideBills', false);
View::share('hideTags', false);
2015-05-14 13:41:21 +02:00
if (Auth::check()) {
2015-12-20 08:40:58 +01:00
$pref = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'));
2015-05-14 13:41:21 +02:00
$lang = $pref->data;
2015-12-24 08:35:08 +01:00
$this->monthFormat = trans('config.month');
$this->monthAndDayFormat = trans('config.month_and_day');
2015-05-14 13:41:21 +02:00
2016-01-08 20:47:35 +01:00
App::setLocale($lang);
Carbon::setLocale(substr($lang, 0, 2));
$locale = explode(',', trans('config.locale'));
$locale = array_map('trim', $locale);
setlocale(LC_TIME, $locale);
setlocale(LC_MONETARY, $locale);
2016-01-10 18:02:24 +01:00
// change localeconv to a new array:
$numberFormatter = numfmt_create($lang, NumberFormatter::CURRENCY);
$localeconv = [
'mon_decimal_point' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL)),
'mon_thousands_sep' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL)),
2016-01-15 23:12:52 +01:00
'frac_digits' => $numberFormatter->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS),
2016-01-10 18:02:24 +01:00
];
2015-05-14 13:41:21 +02:00
View::share('monthFormat', $this->monthFormat);
View::share('monthAndDayFormat', $this->monthAndDayFormat);
View::share('language', $lang);
2016-01-10 18:02:24 +01:00
View::share('localeconv', $localeconv);
2015-05-14 13:41:21 +02:00
}
2015-04-28 15:26:30 +02:00
}
2015-12-31 17:20:54 +01: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-06 04:39:52 +01:00
}