mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-02 12:15:55 +00:00
New converters for #180 (Tag and accounts)
This commit is contained in:
@@ -2,9 +2,8 @@
|
|||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
namespace FireflyIII\Helpers\Csv\Converter;
|
namespace FireflyIII\Helpers\Csv\Converter;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use Log;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OpposingAccountIban
|
* Class OpposingAccountIban
|
||||||
@@ -21,15 +20,23 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
|
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
} else {
|
} else {
|
||||||
if (strlen($this->value) > 0) {
|
if (strlen($this->value) > 0) {
|
||||||
$account = $this->findAccount();
|
|
||||||
if (!is_null($account)) {
|
$set = $repository->getAccounts([]);
|
||||||
return $account;
|
/** @var Account $account */
|
||||||
|
foreach ($set as $account) {
|
||||||
|
if ($account->iban == $this->value) {
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,21 +44,4 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Account|null
|
|
||||||
*/
|
|
||||||
protected function findAccount()
|
|
||||||
{
|
|
||||||
$set = Auth::user()->accounts()->get();
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($set as $account) {
|
|
||||||
if ($account->iban == $this->value) {
|
|
||||||
Log::debug('OpposingAccountIban::convert found an Account (#' . $account->id . ': ******) with IBAN ******');
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
namespace FireflyIII\Helpers\Csv\Converter;
|
namespace FireflyIII\Helpers\Csv\Converter;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OpposingAccountId
|
* Class OpposingAccountId
|
||||||
@@ -19,11 +19,14 @@ class OpposingAccountId extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
|
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$account = Auth::user()->accounts()->find($this->value);
|
$account = $repository->find($this->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
namespace FireflyIII\Helpers\Csv\Converter;
|
namespace FireflyIII\Helpers\Csv\Converter;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OpposingAccountName
|
* Class OpposingAccountName
|
||||||
@@ -20,8 +20,11 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
|
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
namespace FireflyIII\Helpers\Csv\Converter;
|
namespace FireflyIII\Helpers\Csv\Converter;
|
||||||
|
|
||||||
use Auth;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
use FireflyIII\Models\Tag;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,17 +18,22 @@ class TagsComma extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
$tags = new Collection;
|
/** @var TagRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Tag\TagRepositoryInterface');
|
||||||
|
$tags = new Collection;
|
||||||
|
|
||||||
$strings = explode(',', $this->value);
|
$strings = explode(',', $this->value);
|
||||||
foreach ($strings as $string) {
|
foreach ($strings as $string) {
|
||||||
$tag = Tag::firstOrCreateEncrypted( // See issue #180
|
$data = [
|
||||||
[
|
'tag' => $string,
|
||||||
'tag' => $string,
|
'date' => null,
|
||||||
'tagMode' => 'nothing',
|
'description' => null,
|
||||||
'user_id' => Auth::user()->id,
|
'latitude' => null,
|
||||||
]
|
'longitude' => null,
|
||||||
);
|
'zoomLevel' => null,
|
||||||
|
'tagMode' => 'nothing',
|
||||||
|
];
|
||||||
|
$tag = $repository->store($data); // should validate first?
|
||||||
$tags->push($tag);
|
$tags->push($tag);
|
||||||
}
|
}
|
||||||
$tags = $tags->merge($this->data['tags']);
|
$tags = $tags->merge($this->data['tags']);
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
namespace FireflyIII\Helpers\Csv\Converter;
|
namespace FireflyIII\Helpers\Csv\Converter;
|
||||||
|
|
||||||
use Auth;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
use FireflyIII\Models\Tag;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,17 +18,23 @@ class TagsSpace extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
|
/** @var TagRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Tag\TagRepositoryInterface');
|
||||||
|
|
||||||
$tags = new Collection;
|
$tags = new Collection;
|
||||||
|
|
||||||
$strings = explode(' ', $this->value);
|
$strings = explode(' ', $this->value);
|
||||||
foreach ($strings as $string) {
|
foreach ($strings as $string) {
|
||||||
$tag = Tag::firstOrCreateEncrypted( // See issue #180
|
$data = [
|
||||||
[
|
'tag' => $string,
|
||||||
'tag' => $string,
|
'date' => null,
|
||||||
'tagMode' => 'nothing',
|
'description' => null,
|
||||||
'user_id' => Auth::user()->id,
|
'latitude' => null,
|
||||||
]
|
'longitude' => null,
|
||||||
);
|
'zoomLevel' => null,
|
||||||
|
'tagMode' => 'nothing',
|
||||||
|
];
|
||||||
|
$tag = $repository->store($data); // should validate first?
|
||||||
$tags->push($tag);
|
$tags->push($tag);
|
||||||
}
|
}
|
||||||
$tags = $tags->merge($this->data['tags']);
|
$tags = $tags->merge($this->data['tags']);
|
||||||
|
|||||||
@@ -112,11 +112,15 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
public function getAccounts(array $types): Collection
|
public function getAccounts(array $types): Collection
|
||||||
{
|
{
|
||||||
/** @var Collection $result */
|
/** @var Collection $result */
|
||||||
$result = $this->user->accounts()->with(
|
$query = $this->user->accounts()->with(
|
||||||
['accountmeta' => function (HasMany $query) {
|
['accountmeta' => function (HasMany $query) {
|
||||||
$query->where('name', 'accountRole');
|
$query->where('name', 'accountRole');
|
||||||
}]
|
}]
|
||||||
)->accountTypeIn($types)->get(['accounts.*']);
|
);
|
||||||
|
if (count($types) > 0) {
|
||||||
|
$query->accountTypeIn($types);
|
||||||
|
}
|
||||||
|
$result = $query->get(['accounts.*']);
|
||||||
|
|
||||||
$result = $result->sortBy(
|
$result = $result->sortBy(
|
||||||
function (Account $account) {
|
function (Account $account) {
|
||||||
|
|||||||
Reference in New Issue
Block a user