mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-04 05:06:37 +00:00
Reformat various code.
This commit is contained in:
@@ -53,7 +53,7 @@ class EitherConfigKey
|
||||
// triggers and actions:
|
||||
'firefly.rule-actions',
|
||||
'firefly.context-rule-actions',
|
||||
'search.operators'
|
||||
'search.operators',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,7 +42,7 @@ class RecurringCronjob extends AbstractCronjob
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
/** @var Configuration $config */
|
||||
$config = app('fireflyconfig')->get('last_rt_job', 0);
|
||||
$lastTime = (int)$config->data;
|
||||
$lastTime = (int) $config->data;
|
||||
$diff = time() - $lastTime;
|
||||
$diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true);
|
||||
|
||||
@@ -95,8 +95,8 @@ class RecurringCronjob extends AbstractCronjob
|
||||
$this->jobSucceeded = true;
|
||||
$this->message = 'Recurring transactions cron job fired successfully.';
|
||||
|
||||
app('fireflyconfig')->set('last_rt_job', (int)$this->date->format('U'));
|
||||
Log::info(sprintf('Marked the last time this job has run as "%s" (%d)', $this->date->format('Y-m-d H:i:s'), (int)$this->date->format('U')));
|
||||
app('fireflyconfig')->set('last_rt_job', (int) $this->date->format('U'));
|
||||
Log::info(sprintf('Marked the last time this job has run as "%s" (%d)', $this->date->format('Y-m-d H:i:s'), (int) $this->date->format('U')));
|
||||
Log::info('Done with recurring cron job task.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ trait RuleManagement
|
||||
[
|
||||
'oldAction' => $oldAction['type'],
|
||||
'oldValue' => $oldAction['value'],
|
||||
'oldChecked' => 1 === (int)($oldAction['stop_processing'] ?? '0'),
|
||||
'oldChecked' => 1 === (int) ($oldAction['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
]
|
||||
)->render();
|
||||
@@ -84,7 +84,7 @@ trait RuleManagement
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
@@ -100,7 +100,7 @@ trait RuleManagement
|
||||
[
|
||||
'oldTrigger' => OperatorQuerySearch::getRootOperator($oldTrigger['type']),
|
||||
'oldValue' => $oldTrigger['value'],
|
||||
'oldChecked' => 1 === (int)($oldTrigger['stop_processing'] ?? '0'),
|
||||
'oldChecked' => 1 === (int) ($oldTrigger['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
@@ -130,7 +130,7 @@ trait RuleManagement
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
@@ -167,8 +167,8 @@ trait RuleManagement
|
||||
$repository = app(RuleGroupRepositoryInterface::class);
|
||||
if (0 === $repository->count()) {
|
||||
$data = [
|
||||
'title' => (string)trans('firefly.default_rule_group_name'),
|
||||
'description' => (string)trans('firefly.default_rule_group_description'),
|
||||
'title' => (string) trans('firefly.default_rule_group_name'),
|
||||
'description' => (string) trans('firefly.default_rule_group_description'),
|
||||
'active' => true,
|
||||
];
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ trait UserNavigation
|
||||
final protected function getPreviousUri(string $identifier): string
|
||||
{
|
||||
Log::debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier));
|
||||
$url = (string)session($identifier);
|
||||
$url = (string) session($identifier);
|
||||
Log::debug(sprintf('The URL is %s', $url));
|
||||
|
||||
return app('steam')->getSafeUrl($url, route('index'));
|
||||
|
||||
@@ -340,17 +340,17 @@ class Navigation
|
||||
// define period to increment
|
||||
$increment = 'addDay';
|
||||
$format = $this->preferredCarbonFormat($start, $end);
|
||||
$displayFormat = (string)trans('config.month_and_day_js', [], $locale);
|
||||
$displayFormat = (string) trans('config.month_and_day_js', [], $locale);
|
||||
// increment by month (for year)
|
||||
if ($start->diffInMonths($end) > 1) {
|
||||
$increment = 'addMonth';
|
||||
$displayFormat = (string)trans('config.month_js');
|
||||
$displayFormat = (string) trans('config.month_js');
|
||||
}
|
||||
|
||||
// increment by year (for multi year)
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
$increment = 'addYear';
|
||||
$displayFormat = (string)trans('config.year_js');
|
||||
$displayFormat = (string) trans('config.year_js');
|
||||
}
|
||||
$begin = clone $start;
|
||||
$entries = [];
|
||||
@@ -397,23 +397,23 @@ class Navigation
|
||||
{
|
||||
$date = clone $theDate;
|
||||
$formatMap = [
|
||||
'1D' => (string)trans('config.specific_day_js'),
|
||||
'daily' => (string)trans('config.specific_day_js'),
|
||||
'custom' => (string)trans('config.specific_day_js'),
|
||||
'1W' => (string)trans('config.week_in_year_js'),
|
||||
'week' => (string)trans('config.week_in_year_js'),
|
||||
'weekly' => (string)trans('config.week_in_year_js'),
|
||||
'1M' => (string)trans('config.month_js'),
|
||||
'month' => (string)trans('config.month_js'),
|
||||
'monthly' => (string)trans('config.month_js'),
|
||||
'1Y' => (string)trans('config.year_js'),
|
||||
'year' => (string)trans('config.year_js'),
|
||||
'yearly' => (string)trans('config.year_js'),
|
||||
'6M' => (string)trans('config.half_year_js'),
|
||||
'1D' => (string) trans('config.specific_day_js'),
|
||||
'daily' => (string) trans('config.specific_day_js'),
|
||||
'custom' => (string) trans('config.specific_day_js'),
|
||||
'1W' => (string) trans('config.week_in_year_js'),
|
||||
'week' => (string) trans('config.week_in_year_js'),
|
||||
'weekly' => (string) trans('config.week_in_year_js'),
|
||||
'1M' => (string) trans('config.month_js'),
|
||||
'month' => (string) trans('config.month_js'),
|
||||
'monthly' => (string) trans('config.month_js'),
|
||||
'1Y' => (string) trans('config.year_js'),
|
||||
'year' => (string) trans('config.year_js'),
|
||||
'yearly' => (string) trans('config.year_js'),
|
||||
'6M' => (string) trans('config.half_year_js'),
|
||||
];
|
||||
|
||||
if (array_key_exists($repeatFrequency, $formatMap)) {
|
||||
return $date->isoFormat((string)$formatMap[$repeatFrequency]);
|
||||
return $date->isoFormat((string) $formatMap[$repeatFrequency]);
|
||||
}
|
||||
if ('3M' === $repeatFrequency || 'quarter' === $repeatFrequency) {
|
||||
$quarter = ceil($theDate->month / 3);
|
||||
@@ -440,13 +440,13 @@ class Navigation
|
||||
public function preferredCarbonLocalizedFormat(Carbon $start, Carbon $end): string
|
||||
{
|
||||
$locale = app('steam')->getLocale();
|
||||
$format = (string)trans('config.month_and_day_js', [], $locale);
|
||||
$format = (string) trans('config.month_and_day_js', [], $locale);
|
||||
if ($start->diffInMonths($end) > 1) {
|
||||
$format = (string)trans('config.month_js', [], $locale);
|
||||
$format = (string) trans('config.month_js', [], $locale);
|
||||
}
|
||||
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
$format = (string)trans('config.year_js', [], $locale);
|
||||
$format = (string) trans('config.year_js', [], $locale);
|
||||
}
|
||||
|
||||
return $format;
|
||||
|
||||
@@ -77,7 +77,7 @@ trait CalculateXOccurrences
|
||||
$mutator = clone $date;
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$dayOfMonth = (int)$moment;
|
||||
$dayOfMonth = (int) $moment;
|
||||
if ($mutator->day > $dayOfMonth) {
|
||||
// day has passed already, add a month.
|
||||
$mutator->addMonth();
|
||||
@@ -155,7 +155,7 @@ trait CalculateXOccurrences
|
||||
// monday = 1
|
||||
// sunday = 7
|
||||
$mutator->addDay(); // always assume today has passed.
|
||||
$dayOfWeek = (int)$moment;
|
||||
$dayOfWeek = (int) $moment;
|
||||
if ($mutator->dayOfWeekIso > $dayOfWeek) {
|
||||
// day has already passed this week, add one week:
|
||||
$mutator->addWeek();
|
||||
|
||||
@@ -82,7 +82,7 @@ trait CalculateXOccurrencesSince
|
||||
$mutator = clone $date;
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$dayOfMonth = (int)$moment;
|
||||
$dayOfMonth = (int) $moment;
|
||||
$dayOfMonth = 0 === $dayOfMonth ? 1 : $dayOfMonth;
|
||||
if ($mutator->day > $dayOfMonth) {
|
||||
Log::debug(sprintf('%d is after %d, add a month. Mutator is now', $mutator->day, $dayOfMonth));
|
||||
@@ -169,7 +169,7 @@ trait CalculateXOccurrencesSince
|
||||
// sunday = 7
|
||||
// Removed assumption today has passed, see issue https://github.com/firefly-iii/firefly-iii/issues/4798
|
||||
//$mutator->addDay(); // always assume today has passed.
|
||||
$dayOfWeek = (int)$moment;
|
||||
$dayOfWeek = (int) $moment;
|
||||
if ($mutator->dayOfWeekIso > $dayOfWeek) {
|
||||
// day has already passed this week, add one week:
|
||||
$mutator->addWeek();
|
||||
|
||||
@@ -41,7 +41,7 @@ trait ConvertsDataTypes
|
||||
*/
|
||||
public function integer(string $field): int
|
||||
{
|
||||
return (int)$this->get($field);
|
||||
return (int) $this->get($field);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ trait ConvertsDataTypes
|
||||
*/
|
||||
public function string(string $field): string
|
||||
{
|
||||
return $this->clearString((string)($this->get($field) ?? ''), false);
|
||||
return $this->clearString((string) ($this->get($field) ?? ''), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ trait ConvertsDataTypes
|
||||
*/
|
||||
public function stringWithNewlines(string $field): string
|
||||
{
|
||||
return $this->clearString((string)($this->get($field) ?? ''));
|
||||
return $this->clearString((string) ($this->get($field) ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,28 +180,6 @@ trait ConvertsDataTypes
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return date or NULL.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
protected function getCarbonDate(string $field): ?Carbon
|
||||
{
|
||||
$result = null;
|
||||
try {
|
||||
$result = $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||
} catch (InvalidFormatException $e) {
|
||||
// @ignoreException
|
||||
}
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Exception when parsing date "%s".', $this->get($field)));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $string
|
||||
*
|
||||
@@ -245,7 +223,7 @@ trait ConvertsDataTypes
|
||||
return null;
|
||||
}
|
||||
|
||||
return (float)$res;
|
||||
return (float) $res;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,6 +247,28 @@ trait ConvertsDataTypes
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return date or NULL.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
protected function getCarbonDate(string $field): ?Carbon
|
||||
{
|
||||
$result = null;
|
||||
try {
|
||||
$result = $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||
} catch (InvalidFormatException $e) {
|
||||
// @ignoreException
|
||||
}
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Exception when parsing date "%s".', $this->get($field)));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse to integer
|
||||
*
|
||||
@@ -285,7 +285,7 @@ trait ConvertsDataTypes
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int)$string;
|
||||
return (int) $string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,12 +301,12 @@ trait ConvertsDataTypes
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = (string)$this->get($field);
|
||||
$value = (string) $this->get($field);
|
||||
if ('' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int)$value;
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,14 +37,13 @@ class AccountSearch implements GenericSearchInterface
|
||||
/** @var string */
|
||||
public const SEARCH_ALL = 'all';
|
||||
/** @var string */
|
||||
public const SEARCH_NAME = 'name';
|
||||
/** @var string */
|
||||
public const SEARCH_IBAN = 'iban';
|
||||
/** @var string */
|
||||
public const SEARCH_NUMBER = 'number';
|
||||
/** @var string */
|
||||
public const SEARCH_ID = 'id';
|
||||
|
||||
/** @var string */
|
||||
public const SEARCH_NAME = 'name';
|
||||
/** @var string */
|
||||
public const SEARCH_NUMBER = 'number';
|
||||
private string $field;
|
||||
private string $query;
|
||||
private array $types;
|
||||
@@ -62,11 +61,11 @@ class AccountSearch implements GenericSearchInterface
|
||||
public function search(): Collection
|
||||
{
|
||||
|
||||
$searchQuery = $this->user->accounts()
|
||||
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereIn('account_types.type', $this->types);
|
||||
$like = sprintf('%%%s%%', $this->query);
|
||||
$searchQuery = $this->user->accounts()
|
||||
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereIn('account_types.type', $this->types);
|
||||
$like = sprintf('%%%s%%', $this->query);
|
||||
$originalQuery = $this->query;
|
||||
switch ($this->field) {
|
||||
default:
|
||||
@@ -88,7 +87,7 @@ class AccountSearch implements GenericSearchInterface
|
||||
);
|
||||
break;
|
||||
case self::SEARCH_ID:
|
||||
$searchQuery->where('accounts.id', '=', (int)$originalQuery);
|
||||
$searchQuery->where('accounts.id', '=', (int) $originalQuery);
|
||||
break;
|
||||
case self::SEARCH_NAME:
|
||||
$searchQuery->where('accounts.name', 'LIKE', $like);
|
||||
|
||||
@@ -170,73 +170,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$this->collector->setSearchWords($this->words);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function searchTime(): float
|
||||
{
|
||||
return microtime(true) - $this->startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function searchTransactions(): LengthAwarePaginator
|
||||
{
|
||||
if (empty($this->getWords()) && empty($this->getOperators())) {
|
||||
return new LengthAwarePaginator([], 0, 5, 1);
|
||||
}
|
||||
|
||||
return $this->collector->getPaginatedGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function setDate(Carbon $date): void
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
*/
|
||||
public function setLimit(int $limit): void
|
||||
{
|
||||
$this->limit = $limit;
|
||||
$this->collector->setLimit($this->limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setPage(int $page): void
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->collector->setPage($this->page);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->accountRepository->setUser($user);
|
||||
$this->billRepository->setUser($user);
|
||||
$this->categoryRepository->setUser($user);
|
||||
$this->budgetRepository->setUser($user);
|
||||
$this->tagRepository->setUser($user);
|
||||
$this->collector = app(GroupCollectorInterface::class);
|
||||
$this->collector->setUser($user);
|
||||
$this->collector->withAccountInformation()->withCategoryInformation()->withBudgetInformation();
|
||||
|
||||
$this->setLimit((int) app('preferences')->getForUser($user, 'listPageSize', 50)->data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node $searchNode
|
||||
*
|
||||
@@ -1152,14 +1085,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getWords(): array
|
||||
{
|
||||
return $this->words;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $range
|
||||
*
|
||||
@@ -1199,46 +1124,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param array $range
|
||||
* @return void
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function setExactObjectDateParams(string $field,array $range): void
|
||||
{
|
||||
/**
|
||||
* @var string $key
|
||||
* @var Carbon|string $value
|
||||
*/
|
||||
foreach ($range as $key => $value) {
|
||||
switch ($key) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot handle key "%s" in setExactObjectDateParams()', $key));
|
||||
case 'exact':
|
||||
Log::debug(sprintf('Set %s_is_exact value "%s"',$field, $value->format('Y-m-d')));
|
||||
$this->collector->setObjectRange($value, clone $value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d'),]);
|
||||
break;
|
||||
case 'year':
|
||||
Log::debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));
|
||||
$this->collector->objectYearIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'month':
|
||||
Log::debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));
|
||||
$this->collector->objectMonthIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'day':
|
||||
Log::debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));
|
||||
$this->collector->objectDayIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value,]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $range
|
||||
*
|
||||
@@ -1277,6 +1162,85 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $range
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function setDateAfterParams(array $range)
|
||||
{
|
||||
/**
|
||||
* @var string $key
|
||||
* @var Carbon|string $value
|
||||
*/
|
||||
foreach ($range as $key => $value) {
|
||||
switch ($key) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot handle key "%s" in setDateAfterParams()', $key));
|
||||
case 'exact':
|
||||
$this->collector->setAfter($value);
|
||||
$this->operators->push(['type' => 'date_after', 'value' => $value->format('Y-m-d'),]);
|
||||
break;
|
||||
case 'year':
|
||||
Log::debug(sprintf('Set date_is_after YEAR value "%s"', $value));
|
||||
$this->collector->yearAfter($value);
|
||||
$this->operators->push(['type' => 'date_after_year', 'value' => $value,]);
|
||||
break;
|
||||
case 'month':
|
||||
Log::debug(sprintf('Set date_is_after MONTH value "%s"', $value));
|
||||
$this->collector->monthAfter($value);
|
||||
$this->operators->push(['type' => 'date_after_month', 'value' => $value,]);
|
||||
break;
|
||||
case 'day':
|
||||
Log::debug(sprintf('Set date_is_after DAY value "%s"', $value));
|
||||
$this->collector->dayAfter($value);
|
||||
$this->operators->push(['type' => 'date_after_day', 'value' => $value,]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param array $range
|
||||
* @return void
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function setExactMetaDateParams(string $field, array $range): void
|
||||
{
|
||||
Log::debug('Now in setExactMetaDateParams()');
|
||||
/**
|
||||
* @var string $key
|
||||
* @var Carbon|string $value
|
||||
*/
|
||||
foreach ($range as $key => $value) {
|
||||
switch ($key) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot handle key "%s" in setExactMetaDateParams()', $key));
|
||||
case 'exact':
|
||||
Log::debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));
|
||||
$this->collector->setMetaDateRange($value, $value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d'),]);
|
||||
break;
|
||||
case 'year':
|
||||
Log::debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));
|
||||
$this->collector->metaYearIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'month':
|
||||
Log::debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));
|
||||
$this->collector->metaMonthIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'day':
|
||||
Log::debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));
|
||||
$this->collector->metaDayIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value,]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param array $range
|
||||
@@ -1356,11 +1320,12 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $range
|
||||
*
|
||||
* @param string $field
|
||||
* @param array $range
|
||||
* @return void
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function setDateAfterParams(array $range)
|
||||
private function setExactObjectDateParams(string $field, array $range): void
|
||||
{
|
||||
/**
|
||||
* @var string $key
|
||||
@@ -1369,63 +1334,26 @@ class OperatorQuerySearch implements SearchInterface
|
||||
foreach ($range as $key => $value) {
|
||||
switch ($key) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot handle key "%s" in setDateAfterParams()', $key));
|
||||
throw new FireflyException(sprintf('Cannot handle key "%s" in setExactObjectDateParams()', $key));
|
||||
case 'exact':
|
||||
$this->collector->setAfter($value);
|
||||
$this->operators->push(['type' => 'date_after', 'value' => $value->format('Y-m-d'),]);
|
||||
Log::debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));
|
||||
$this->collector->setObjectRange($value, clone $value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d'),]);
|
||||
break;
|
||||
case 'year':
|
||||
Log::debug(sprintf('Set date_is_after YEAR value "%s"', $value));
|
||||
$this->collector->yearAfter($value);
|
||||
$this->operators->push(['type' => 'date_after_year', 'value' => $value,]);
|
||||
Log::debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));
|
||||
$this->collector->objectYearIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'month':
|
||||
Log::debug(sprintf('Set date_is_after MONTH value "%s"', $value));
|
||||
$this->collector->monthAfter($value);
|
||||
$this->operators->push(['type' => 'date_after_month', 'value' => $value,]);
|
||||
Log::debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));
|
||||
$this->collector->objectMonthIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'day':
|
||||
Log::debug(sprintf('Set date_is_after DAY value "%s"', $value));
|
||||
$this->collector->dayAfter($value);
|
||||
$this->operators->push(['type' => 'date_after_day', 'value' => $value,]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $range
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function setObjectDateAfterParams(string $field, array $range)
|
||||
{
|
||||
/**
|
||||
* @var string $key
|
||||
* @var Carbon|string $value
|
||||
*/
|
||||
foreach ($range as $key => $value) {
|
||||
switch ($key) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot handle key "%s" in setDateAfterParams()', $key));
|
||||
case 'exact':
|
||||
$this->collector->setObjectAfter($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_after', $field), 'value' => $value->format('Y-m-d'),]);
|
||||
break;
|
||||
case 'year':
|
||||
Log::debug(sprintf('Set date_is_after YEAR value "%s"', $value));
|
||||
$this->collector->objectYearAfter($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_after_year', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'month':
|
||||
Log::debug(sprintf('Set date_is_after MONTH value "%s"', $value));
|
||||
$this->collector->objectMonthAfter($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_after_month', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'day':
|
||||
Log::debug(sprintf('Set date_is_after DAY value "%s"', $value));
|
||||
$this->collector->objectDayAfter($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_after_day', $field), 'value' => $value,]);
|
||||
Log::debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));
|
||||
$this->collector->objectDayIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value,]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1470,14 +1398,12 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param array $range
|
||||
* @return void
|
||||
* @param array $range
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function setExactMetaDateParams(string $field, array $range): void
|
||||
private function setObjectDateAfterParams(string $field, array $range)
|
||||
{
|
||||
Log::debug('Now in setExactMetaDateParams()');
|
||||
/**
|
||||
* @var string $key
|
||||
* @var Carbon|string $value
|
||||
@@ -1485,28 +1411,102 @@ class OperatorQuerySearch implements SearchInterface
|
||||
foreach ($range as $key => $value) {
|
||||
switch ($key) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot handle key "%s" in setExactMetaDateParams()', $key));
|
||||
throw new FireflyException(sprintf('Cannot handle key "%s" in setDateAfterParams()', $key));
|
||||
case 'exact':
|
||||
Log::debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));
|
||||
$this->collector->setMetaDateRange($value, $value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d'),]);
|
||||
$this->collector->setObjectAfter($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_after', $field), 'value' => $value->format('Y-m-d'),]);
|
||||
break;
|
||||
case 'year':
|
||||
Log::debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));
|
||||
$this->collector->metaYearIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value,]);
|
||||
Log::debug(sprintf('Set date_is_after YEAR value "%s"', $value));
|
||||
$this->collector->objectYearAfter($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_after_year', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'month':
|
||||
Log::debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));
|
||||
$this->collector->metaMonthIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value,]);
|
||||
Log::debug(sprintf('Set date_is_after MONTH value "%s"', $value));
|
||||
$this->collector->objectMonthAfter($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_after_month', $field), 'value' => $value,]);
|
||||
break;
|
||||
case 'day':
|
||||
Log::debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));
|
||||
$this->collector->metaDayIs($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value,]);
|
||||
Log::debug(sprintf('Set date_is_after DAY value "%s"', $value));
|
||||
$this->collector->objectDayAfter($value, $field);
|
||||
$this->operators->push(['type' => sprintf('%s_after_day', $field), 'value' => $value,]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function searchTime(): float
|
||||
{
|
||||
return microtime(true) - $this->startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function searchTransactions(): LengthAwarePaginator
|
||||
{
|
||||
if (empty($this->getWords()) && empty($this->getOperators())) {
|
||||
return new LengthAwarePaginator([], 0, 5, 1);
|
||||
}
|
||||
|
||||
return $this->collector->getPaginatedGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getWords(): array
|
||||
{
|
||||
return $this->words;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function setDate(Carbon $date): void
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setPage(int $page): void
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->collector->setPage($this->page);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->accountRepository->setUser($user);
|
||||
$this->billRepository->setUser($user);
|
||||
$this->categoryRepository->setUser($user);
|
||||
$this->budgetRepository->setUser($user);
|
||||
$this->tagRepository->setUser($user);
|
||||
$this->collector = app(GroupCollectorInterface::class);
|
||||
$this->collector->setUser($user);
|
||||
$this->collector->withAccountInformation()->withCategoryInformation()->withBudgetInformation();
|
||||
|
||||
$this->setLimit((int) app('preferences')->getForUser($user, 'listPageSize', 50)->data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
*/
|
||||
public function setLimit(int $limit): void
|
||||
{
|
||||
$this->limit = $limit;
|
||||
$this->collector->setLimit($this->limit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,53 +43,6 @@ use Str;
|
||||
class Steam
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the previous URL but refuses to send you to specific URLs.
|
||||
*
|
||||
* - outside domain
|
||||
* - to JS files, API or JSON routes
|
||||
*
|
||||
* Uses the session's previousUrl() function as inspired by GitHub user @z1r0-
|
||||
*
|
||||
* session()->previousUrl() uses getSafeUrl() so we can safely return it:
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSafePreviousUrl(): string
|
||||
{
|
||||
//Log::debug(sprintf('getSafePreviousUrl: "%s"', session()->previousUrl()));
|
||||
return session()->previousUrl() ?? route('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure URL is safe.
|
||||
*
|
||||
* @param string $unknownUrl
|
||||
* @param string $safeUrl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSafeUrl(string $unknownUrl, string $safeUrl): string
|
||||
{
|
||||
//Log::debug(sprintf('getSafeUrl(%s, %s)', $unknownUrl, $safeUrl));
|
||||
$returnUrl = $safeUrl;
|
||||
$unknownHost = parse_url($unknownUrl, PHP_URL_HOST);
|
||||
$safeHost = parse_url($safeUrl, PHP_URL_HOST);
|
||||
|
||||
if (null !== $unknownHost && $unknownHost === $safeHost) {
|
||||
$returnUrl = $unknownUrl;
|
||||
}
|
||||
|
||||
// URL must not lead to weird pages
|
||||
$forbiddenWords = ['jscript', 'json', 'debug', 'serviceworker', 'offline', 'delete', '/login', '/attachments/view'];
|
||||
if (Str::contains($returnUrl, $forbiddenWords)) {
|
||||
$returnUrl = $safeUrl;
|
||||
}
|
||||
|
||||
return $returnUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $date
|
||||
@@ -391,6 +344,65 @@ class Steam
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filterSpaces(string $string): string
|
||||
{
|
||||
$search = [
|
||||
"\u{0001}", // start of heading
|
||||
"\u{0002}", // start of text
|
||||
"\u{0003}", // end of text
|
||||
"\u{0004}", // end of transmission
|
||||
"\u{0005}", // enquiry
|
||||
"\u{0006}", // ACK
|
||||
"\u{0007}", // BEL
|
||||
"\u{0008}", // backspace
|
||||
"\u{000E}", // shift out
|
||||
"\u{000F}", // shift in
|
||||
"\u{0010}", // data link escape
|
||||
"\u{0011}", // DC1
|
||||
"\u{0012}", // DC2
|
||||
"\u{0013}", // DC3
|
||||
"\u{0014}", // DC4
|
||||
"\u{0015}", // NAK
|
||||
"\u{0016}", // SYN
|
||||
"\u{0017}", // ETB
|
||||
"\u{0018}", // CAN
|
||||
"\u{0019}", // EM
|
||||
"\u{001A}", // SUB
|
||||
"\u{001B}", // escape
|
||||
"\u{001C}", // file separator
|
||||
"\u{001D}", // group separator
|
||||
"\u{001E}", // record separator
|
||||
"\u{001F}", // unit separator
|
||||
"\u{007F}", // DEL
|
||||
"\u{00A0}", // non-breaking space
|
||||
"\u{1680}", // ogham space mark
|
||||
"\u{180E}", // mongolian vowel separator
|
||||
"\u{2000}", // en quad
|
||||
"\u{2001}", // em quad
|
||||
"\u{2002}", // en space
|
||||
"\u{2003}", // em space
|
||||
"\u{2004}", // three-per-em space
|
||||
"\u{2005}", // four-per-em space
|
||||
"\u{2006}", // six-per-em space
|
||||
"\u{2007}", // figure space
|
||||
"\u{2008}", // punctuation space
|
||||
"\u{2009}", // thin space
|
||||
"\u{200A}", // hair space
|
||||
"\u{200B}", // zero width space
|
||||
"\u{202F}", // narrow no-break space
|
||||
"\u{3000}", // ideographic space
|
||||
"\u{FEFF}", // zero width no -break space
|
||||
"\x20", // plain old normal space
|
||||
];
|
||||
|
||||
return str_replace($search, '', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accounts
|
||||
*
|
||||
@@ -463,6 +475,52 @@ class Steam
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous URL but refuses to send you to specific URLs.
|
||||
*
|
||||
* - outside domain
|
||||
* - to JS files, API or JSON routes
|
||||
*
|
||||
* Uses the session's previousUrl() function as inspired by GitHub user @z1r0-
|
||||
*
|
||||
* session()->previousUrl() uses getSafeUrl() so we can safely return it:
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSafePreviousUrl(): string
|
||||
{
|
||||
//Log::debug(sprintf('getSafePreviousUrl: "%s"', session()->previousUrl()));
|
||||
return session()->previousUrl() ?? route('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure URL is safe.
|
||||
*
|
||||
* @param string $unknownUrl
|
||||
* @param string $safeUrl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSafeUrl(string $unknownUrl, string $safeUrl): string
|
||||
{
|
||||
//Log::debug(sprintf('getSafeUrl(%s, %s)', $unknownUrl, $safeUrl));
|
||||
$returnUrl = $safeUrl;
|
||||
$unknownHost = parse_url($unknownUrl, PHP_URL_HOST);
|
||||
$safeHost = parse_url($safeUrl, PHP_URL_HOST);
|
||||
|
||||
if (null !== $unknownHost && $unknownHost === $safeHost) {
|
||||
$returnUrl = $unknownUrl;
|
||||
}
|
||||
|
||||
// URL must not lead to weird pages
|
||||
$forbiddenWords = ['jscript', 'json', 'debug', 'serviceworker', 'offline', 'delete', '/login', '/attachments/view'];
|
||||
if (Str::contains($returnUrl, $forbiddenWords)) {
|
||||
$returnUrl = $safeUrl;
|
||||
}
|
||||
|
||||
return $returnUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $amount
|
||||
*
|
||||
@@ -505,9 +563,9 @@ class Steam
|
||||
if ($mantis < 0) {
|
||||
$post += abs((int) $mantis);
|
||||
}
|
||||
return number_format((float)$value, $post, '.', '');
|
||||
return number_format((float) $value, $post, '.', '');
|
||||
}
|
||||
return number_format((float)$value, 0, '.', '');
|
||||
return number_format((float) $value, 0, '.', '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -573,63 +631,4 @@ class Steam
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filterSpaces(string $string): string
|
||||
{
|
||||
$search = [
|
||||
"\u{0001}", // start of heading
|
||||
"\u{0002}", // start of text
|
||||
"\u{0003}", // end of text
|
||||
"\u{0004}", // end of transmission
|
||||
"\u{0005}", // enquiry
|
||||
"\u{0006}", // ACK
|
||||
"\u{0007}", // BEL
|
||||
"\u{0008}", // backspace
|
||||
"\u{000E}", // shift out
|
||||
"\u{000F}", // shift in
|
||||
"\u{0010}", // data link escape
|
||||
"\u{0011}", // DC1
|
||||
"\u{0012}", // DC2
|
||||
"\u{0013}", // DC3
|
||||
"\u{0014}", // DC4
|
||||
"\u{0015}", // NAK
|
||||
"\u{0016}", // SYN
|
||||
"\u{0017}", // ETB
|
||||
"\u{0018}", // CAN
|
||||
"\u{0019}", // EM
|
||||
"\u{001A}", // SUB
|
||||
"\u{001B}", // escape
|
||||
"\u{001C}", // file separator
|
||||
"\u{001D}", // group separator
|
||||
"\u{001E}", // record separator
|
||||
"\u{001F}", // unit separator
|
||||
"\u{007F}", // DEL
|
||||
"\u{00A0}", // non-breaking space
|
||||
"\u{1680}", // ogham space mark
|
||||
"\u{180E}", // mongolian vowel separator
|
||||
"\u{2000}", // en quad
|
||||
"\u{2001}", // em quad
|
||||
"\u{2002}", // en space
|
||||
"\u{2003}", // em space
|
||||
"\u{2004}", // three-per-em space
|
||||
"\u{2005}", // four-per-em space
|
||||
"\u{2006}", // six-per-em space
|
||||
"\u{2007}", // figure space
|
||||
"\u{2008}", // punctuation space
|
||||
"\u{2009}", // thin space
|
||||
"\u{200A}", // hair space
|
||||
"\u{200B}", // zero width space
|
||||
"\u{202F}", // narrow no-break space
|
||||
"\u{3000}", // ideographic space
|
||||
"\u{FEFF}", // zero width no -break space
|
||||
"\x20", // plain old normal space
|
||||
];
|
||||
|
||||
return str_replace($search, '', $string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
$colored = false;
|
||||
}
|
||||
|
||||
$result = app('amount')->formatFlat($array['currency_symbol'], (int)$array['currency_decimal_places'], $amount, $colored);
|
||||
$result = app('amount')->formatFlat($array['currency_symbol'], (int) $array['currency_decimal_places'], $amount, $colored);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int)$array['foreign_currency_decimal_places'], $amount, $colored);
|
||||
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int) $array['foreign_currency_decimal_places'], $amount, $colored);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
@@ -203,7 +203,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($currency->symbol, (int)$currency->decimal_places, $amount, $colored);
|
||||
$result = app('amount')->formatFlat($currency->symbol, (int) $currency->decimal_places, $amount, $colored);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
@@ -246,7 +246,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($currency->symbol, (int)$currency->decimal_places, $amount, $colored);
|
||||
$result = app('amount')->formatFlat($currency->symbol, (int) $currency->decimal_places, $amount, $colored);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user