mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Reformat various code.
This commit is contained in:
@@ -93,6 +93,14 @@ class RemoteUserGuard implements Guard
|
|||||||
$this->user = $retrievedUser;
|
$this->user = $retrievedUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function guest(): bool
|
||||||
|
{
|
||||||
|
return !$this->check();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
@@ -104,9 +112,17 @@ class RemoteUserGuard implements Guard
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function guest(): bool
|
public function user(): ?User
|
||||||
{
|
{
|
||||||
return !$this->check();
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function hasUser()
|
||||||
|
{
|
||||||
|
// TODO: Implement hasUser() method.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,14 +141,6 @@ class RemoteUserGuard implements Guard
|
|||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function user(): ?User
|
|
||||||
{
|
|
||||||
return $this->user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
@@ -140,12 +148,4 @@ class RemoteUserGuard implements Guard
|
|||||||
{
|
{
|
||||||
throw new FireflyException('Did not implement RemoteUserGuard::validate()');
|
throw new FireflyException('Did not implement RemoteUserGuard::validate()');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function hasUser()
|
|
||||||
{
|
|
||||||
// TODO: Implement hasUser() method.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,15 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
trait AppendsLocationData
|
trait AppendsLocationData
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Abstract method.
|
||||||
|
*
|
||||||
|
* @param $key
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
abstract public function has($key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the submitted Request data and add new or updated Location data to the array.
|
* Read the submitted Request data and add new or updated Location data to the array.
|
||||||
*
|
*
|
||||||
@@ -148,25 +157,6 @@ trait AppendsLocationData
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract method stolen from "InteractsWithInput".
|
|
||||||
*
|
|
||||||
* @param null $key
|
|
||||||
* @param bool $default
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
abstract public function boolean($key = null, $default = false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract method.
|
|
||||||
*
|
|
||||||
* @param $key
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
abstract public function has($key);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method.
|
* Abstract method.
|
||||||
*
|
*
|
||||||
@@ -183,6 +173,16 @@ trait AppendsLocationData
|
|||||||
*/
|
*/
|
||||||
abstract public function routeIs(...$patterns);
|
abstract public function routeIs(...$patterns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract method stolen from "InteractsWithInput".
|
||||||
|
*
|
||||||
|
* @param null $key
|
||||||
|
* @param bool $default
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
abstract public function boolean($key = null, $default = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $prefix
|
* @param string|null $prefix
|
||||||
*
|
*
|
||||||
|
@@ -45,18 +45,6 @@ class AmountFormat extends AbstractExtension
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getFunctions(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
$this->formatAmountByAccount(),
|
|
||||||
$this->formatAmountBySymbol(),
|
|
||||||
$this->formatAmountByCurrency(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TwigFilter
|
* @return TwigFilter
|
||||||
*/
|
*/
|
||||||
@@ -89,6 +77,18 @@ class AmountFormat extends AbstractExtension
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getFunctions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$this->formatAmountByAccount(),
|
||||||
|
$this->formatAmountBySymbol(),
|
||||||
|
$this->formatAmountByCurrency(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will format the amount by the currency related to the given account.
|
* Will format the amount by the currency related to the given account.
|
||||||
*
|
*
|
||||||
|
@@ -53,25 +53,6 @@ class General extends AbstractExtension
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getFunctions(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
$this->phpdate(),
|
|
||||||
$this->activeRouteStrict(),
|
|
||||||
$this->activeRoutePartial(),
|
|
||||||
$this->activeRoutePartialObjectType(),
|
|
||||||
$this->menuOpenRoutePartial(),
|
|
||||||
$this->formatDate(),
|
|
||||||
$this->getMetaField(),
|
|
||||||
$this->hasRole(),
|
|
||||||
$this->getRootSearchOperator(),
|
|
||||||
$this->carbonize()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show account balance. Only used on the front page of Firefly III.
|
* Show account balance. Only used on the front page of Firefly III.
|
||||||
*
|
*
|
||||||
@@ -93,24 +74,6 @@ class General extends AbstractExtension
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show URL host name
|
|
||||||
*
|
|
||||||
* @return TwigFilter
|
|
||||||
*/
|
|
||||||
protected function phpHostName(): TwigFilter
|
|
||||||
{
|
|
||||||
return new TwigFilter(
|
|
||||||
'phphost',
|
|
||||||
static function (string $string): string {
|
|
||||||
$proto = (string)parse_url($string, PHP_URL_SCHEME);
|
|
||||||
$host = (string)parse_url($string, PHP_URL_HOST);
|
|
||||||
|
|
||||||
return e(sprintf('%s://%s', $proto, $host));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to convert 1024 to 1kb etc.
|
* Used to convert 1024 to 1kb etc.
|
||||||
*
|
*
|
||||||
@@ -250,6 +213,43 @@ class General extends AbstractExtension
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show URL host name
|
||||||
|
*
|
||||||
|
* @return TwigFilter
|
||||||
|
*/
|
||||||
|
protected function phpHostName(): TwigFilter
|
||||||
|
{
|
||||||
|
return new TwigFilter(
|
||||||
|
'phphost',
|
||||||
|
static function (string $string): string {
|
||||||
|
$proto = (string) parse_url($string, PHP_URL_SCHEME);
|
||||||
|
$host = (string) parse_url($string, PHP_URL_HOST);
|
||||||
|
|
||||||
|
return e(sprintf('%s://%s', $proto, $host));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getFunctions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$this->phpdate(),
|
||||||
|
$this->activeRouteStrict(),
|
||||||
|
$this->activeRoutePartial(),
|
||||||
|
$this->activeRoutePartialObjectType(),
|
||||||
|
$this->menuOpenRoutePartial(),
|
||||||
|
$this->formatDate(),
|
||||||
|
$this->getMetaField(),
|
||||||
|
$this->hasRole(),
|
||||||
|
$this->getRootSearchOperator(),
|
||||||
|
$this->carbonize(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic example thing for some views.
|
* Basic example thing for some views.
|
||||||
*
|
*
|
||||||
@@ -396,19 +396,6 @@ class General extends AbstractExtension
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return TwigFunction
|
|
||||||
*/
|
|
||||||
protected function carbonize(): TwigFunction
|
|
||||||
{
|
|
||||||
return new TwigFunction(
|
|
||||||
'carbonize',
|
|
||||||
static function (string $date): Carbon {
|
|
||||||
return new Carbon($date);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will return true if the user is of role X.
|
* Will return true if the user is of role X.
|
||||||
*
|
*
|
||||||
@@ -438,4 +425,17 @@ class General extends AbstractExtension
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TwigFunction
|
||||||
|
*/
|
||||||
|
protected function carbonize(): TwigFunction
|
||||||
|
{
|
||||||
|
return new TwigFunction(
|
||||||
|
'carbonize',
|
||||||
|
static function (string $date): Carbon {
|
||||||
|
return new Carbon($date);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -86,84 +86,6 @@ class SearchRuleEngine implements RuleEngineInterface
|
|||||||
return $collection->unique();
|
return $collection->unique();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
public function fire(): void
|
|
||||||
{
|
|
||||||
$this->resultCount = [];
|
|
||||||
Log::debug('SearchRuleEngine::fire()!');
|
|
||||||
|
|
||||||
// if rules and no rule groups, file each rule separately.
|
|
||||||
if (0 !== $this->rules->count()) {
|
|
||||||
Log::debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
|
|
||||||
foreach ($this->rules as $rule) {
|
|
||||||
$this->fireRule($rule);
|
|
||||||
}
|
|
||||||
Log::debug('SearchRuleEngine:: done processing all rules!');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (0 !== $this->groups->count()) {
|
|
||||||
Log::debug(sprintf('SearchRuleEngine:: found %d rule group(s) to fire.', $this->groups->count()));
|
|
||||||
// fire each group:
|
|
||||||
/** @var RuleGroup $group */
|
|
||||||
foreach ($this->groups as $group) {
|
|
||||||
$this->fireGroup($group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log::debug('SearchRuleEngine:: done processing all rules!');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the number of changed transactions from the previous "fire" action.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getResults(): int
|
|
||||||
{
|
|
||||||
return count($this->resultCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function setRuleGroups(Collection $ruleGroups): void
|
|
||||||
{
|
|
||||||
Log::debug(__METHOD__);
|
|
||||||
foreach ($ruleGroups as $group) {
|
|
||||||
if ($group instanceof RuleGroup) {
|
|
||||||
Log::debug(sprintf('Adding a rule group to the SearchRuleEngine: #%d ("%s")', $group->id, $group->title));
|
|
||||||
$this->groups->push($group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function setRules(Collection $rules): void
|
|
||||||
{
|
|
||||||
|
|
||||||
Log::debug(__METHOD__);
|
|
||||||
foreach ($rules as $rule) {
|
|
||||||
if ($rule instanceof Rule) {
|
|
||||||
Log::debug(sprintf('Adding a rule to the SearchRuleEngine: #%d ("%s")', $rule->id, $rule->title));
|
|
||||||
$this->rules->push($rule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function setUser(User $user): void
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
$this->operators = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the transactions a strict rule will execute on.
|
* Finds the transactions a strict rule will execute on.
|
||||||
*
|
*
|
||||||
@@ -365,6 +287,36 @@ class SearchRuleEngine implements RuleEngineInterface
|
|||||||
return $unique;
|
return $unique;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
public function fire(): void
|
||||||
|
{
|
||||||
|
$this->resultCount = [];
|
||||||
|
Log::debug('SearchRuleEngine::fire()!');
|
||||||
|
|
||||||
|
// if rules and no rule groups, file each rule separately.
|
||||||
|
if (0 !== $this->rules->count()) {
|
||||||
|
Log::debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
|
||||||
|
foreach ($this->rules as $rule) {
|
||||||
|
$this->fireRule($rule);
|
||||||
|
}
|
||||||
|
Log::debug('SearchRuleEngine:: done processing all rules!');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (0 !== $this->groups->count()) {
|
||||||
|
Log::debug(sprintf('SearchRuleEngine:: found %d rule group(s) to fire.', $this->groups->count()));
|
||||||
|
// fire each group:
|
||||||
|
/** @var RuleGroup $group */
|
||||||
|
foreach ($this->groups as $group) {
|
||||||
|
$this->fireGroup($group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log::debug('SearchRuleEngine:: done processing all rules!');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the rule has been triggered.
|
* Returns true if the rule has been triggered.
|
||||||
*
|
*
|
||||||
@@ -553,4 +505,52 @@ class SearchRuleEngine implements RuleEngineInterface
|
|||||||
|
|
||||||
return $all;
|
return $all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of changed transactions from the previous "fire" action.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getResults(): int
|
||||||
|
{
|
||||||
|
return count($this->resultCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function setRuleGroups(Collection $ruleGroups): void
|
||||||
|
{
|
||||||
|
Log::debug(__METHOD__);
|
||||||
|
foreach ($ruleGroups as $group) {
|
||||||
|
if ($group instanceof RuleGroup) {
|
||||||
|
Log::debug(sprintf('Adding a rule group to the SearchRuleEngine: #%d ("%s")', $group->id, $group->title));
|
||||||
|
$this->groups->push($group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function setRules(Collection $rules): void
|
||||||
|
{
|
||||||
|
|
||||||
|
Log::debug(__METHOD__);
|
||||||
|
foreach ($rules as $rule) {
|
||||||
|
if ($rule instanceof Rule) {
|
||||||
|
Log::debug(sprintf('Adding a rule to the SearchRuleEngine: #%d ("%s")', $rule->id, $rule->title));
|
||||||
|
$this->rules->push($rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function setUser(User $user): void
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
$this->operators = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -250,16 +250,6 @@ class TransactionGroupTransformer extends AbstractTransformer
|
|||||||
return $this->groupRepos->getLocation($journalId);
|
return $this->groupRepos->getLocation($journalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $journalId
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function hasAttachments(int $journalId): bool
|
|
||||||
{
|
|
||||||
return $this->groupRepos->countAttachments($journalId) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $array
|
* @param array $array
|
||||||
* @param string $key
|
* @param string $key
|
||||||
@@ -290,6 +280,16 @@ class TransactionGroupTransformer extends AbstractTransformer
|
|||||||
return $object[$key]->toAtomString();
|
return $object[$key]->toAtomString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $journalId
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function hasAttachments(int $journalId): bool
|
||||||
|
{
|
||||||
|
return $this->groupRepos->countAttachments($journalId) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionGroup $group
|
* @param TransactionGroup $group
|
||||||
*
|
*
|
||||||
|
@@ -35,6 +35,7 @@ trait ReconciliationValidation
|
|||||||
{
|
{
|
||||||
public ?Account $destination;
|
public ?Account $destination;
|
||||||
public ?Account $source;
|
public ?Account $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $array
|
* @param array $array
|
||||||
*
|
*
|
||||||
|
@@ -198,6 +198,21 @@ class AccountValidator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountType
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function canCreateType(string $accountType): bool
|
||||||
|
{
|
||||||
|
$canCreate = [AccountType::EXPENSE, AccountType::REVENUE, AccountType::INITIAL_BALANCE, AccountType::LIABILITY_CREDIT];
|
||||||
|
if (in_array($accountType, $canCreate, true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $validTypes
|
* @param array $validTypes
|
||||||
* @param array $data
|
* @param array $data
|
||||||
@@ -244,19 +259,4 @@ class AccountValidator
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $accountType
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function canCreateType(string $accountType): bool
|
|
||||||
{
|
|
||||||
$canCreate = [AccountType::EXPENSE, AccountType::REVENUE, AccountType::INITIAL_BALANCE, AccountType::LIABILITY_CREDIT];
|
|
||||||
if (in_array($accountType, $canCreate, true)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -54,47 +54,6 @@ use function is_string;
|
|||||||
class FireflyValidator extends Validator
|
class FireflyValidator extends Validator
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $attribute
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validateUniqueCurrencyName($attribute, $value): bool
|
|
||||||
{
|
|
||||||
return $this->validateUniqueCurrency('name', (string) $attribute, (string) $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $attribute
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validateUniqueCurrencyCode($attribute, $value): bool
|
|
||||||
{
|
|
||||||
return $this->validateUniqueCurrency('code', (string) $attribute, (string) $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $attribute
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validateUniqueCurrencySymbol($attribute, $value): bool
|
|
||||||
{
|
|
||||||
return $this->validateUniqueCurrency('symbol', (string) $attribute, (string) $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $attribute
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validateUniqueCurrency(string $field, string $attribute, string $value): bool
|
|
||||||
{
|
|
||||||
return 0 === DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
@@ -648,6 +607,46 @@ class FireflyValidator extends Validator
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUniqueCurrencyCode($attribute, $value): bool
|
||||||
|
{
|
||||||
|
return $this->validateUniqueCurrency('code', (string) $attribute, (string) $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUniqueCurrencyName($attribute, $value): bool
|
||||||
|
{
|
||||||
|
return $this->validateUniqueCurrency('name', (string) $attribute, (string) $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUniqueCurrency(string $field, string $attribute, string $value): bool
|
||||||
|
{
|
||||||
|
return 0 === DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUniqueCurrencySymbol($attribute, $value): bool
|
||||||
|
{
|
||||||
|
return $this->validateUniqueCurrency('symbol', (string) $attribute, (string) $value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
|
@@ -43,6 +43,36 @@ trait GroupValidation
|
|||||||
*/
|
*/
|
||||||
abstract protected function getTransactionsArray(Validator $validator): array;
|
abstract protected function getTransactionsArray(Validator $validator): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Validator $validator
|
||||||
|
*/
|
||||||
|
protected function preventNoAccountInfo(Validator $validator): void
|
||||||
|
{
|
||||||
|
$transactions = $this->getTransactionsArray($validator);
|
||||||
|
$keys = ['source_id', 'destination_id', 'source_name', 'destination_name', 'source_iban', 'destination_iban', 'source_number', 'destination_number'];
|
||||||
|
/** @var array $transaction */
|
||||||
|
foreach ($transactions as $index => $transaction) {
|
||||||
|
$hasAccountInfo = false;
|
||||||
|
$hasJournalId = array_key_exists('transaction_journal_id', $transaction);
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if (array_key_exists($key, $transaction) && '' !== (string) $transaction[$key]) {
|
||||||
|
$hasAccountInfo = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// set errors:
|
||||||
|
if (false === $hasAccountInfo && !$hasJournalId) {
|
||||||
|
$validator->errors()->add(
|
||||||
|
sprintf('transactions.%d.source_id', $index), (string) trans('validation.generic_no_source')
|
||||||
|
);
|
||||||
|
$validator->errors()->add(
|
||||||
|
sprintf('transactions.%d.destination_id', $index), (string) trans('validation.generic_no_destination')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// only an issue if there is no transaction_journal_id
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error to the "description" field when the user has submitted no descriptions and no
|
* Adds an error to the "description" field when the user has submitted no descriptions and no
|
||||||
* journal description.
|
* journal description.
|
||||||
@@ -83,36 +113,6 @@ trait GroupValidation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Validator $validator
|
|
||||||
*/
|
|
||||||
protected function preventNoAccountInfo(Validator $validator): void
|
|
||||||
{
|
|
||||||
$transactions = $this->getTransactionsArray($validator);
|
|
||||||
$keys = ['source_id', 'destination_id', 'source_name', 'destination_name', 'source_iban', 'destination_iban', 'source_number', 'destination_number'];
|
|
||||||
/** @var array $transaction */
|
|
||||||
foreach ($transactions as $index => $transaction) {
|
|
||||||
$hasAccountInfo = false;
|
|
||||||
$hasJournalId = array_key_exists('transaction_journal_id', $transaction);
|
|
||||||
foreach ($keys as $key) {
|
|
||||||
if (array_key_exists($key, $transaction) && '' !== (string) $transaction[$key]) {
|
|
||||||
$hasAccountInfo = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// set errors:
|
|
||||||
if (false === $hasAccountInfo && !$hasJournalId) {
|
|
||||||
$validator->errors()->add(
|
|
||||||
sprintf('transactions.%d.source_id', $index), (string) trans('validation.generic_no_source')
|
|
||||||
);
|
|
||||||
$validator->errors()->add(
|
|
||||||
sprintf('transactions.%d.destination_id', $index), (string) trans('validation.generic_no_destination')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// only an issue if there is no transaction_journal_id
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method validates if the user has submitted transaction journal ID's for each array they submit, if they've submitted more than 1 transaction
|
* This method validates if the user has submitted transaction journal ID's for each array they submit, if they've submitted more than 1 transaction
|
||||||
* journal. This check is necessary because Firefly III isn't able to distinguish between journals without the ID.
|
* journal. This check is necessary because Firefly III isn't able to distinguish between journals without the ID.
|
||||||
|
Reference in New Issue
Block a user