mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup
This commit is contained in:
@@ -51,6 +51,7 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Csv\CannotInsertRecord;
|
||||
use League\Csv\Writer;
|
||||
|
||||
/**
|
||||
@@ -58,19 +59,19 @@ use League\Csv\Writer;
|
||||
*/
|
||||
class ExportDataGenerator
|
||||
{
|
||||
private Collection $accounts;
|
||||
private Carbon $end;
|
||||
private bool $exportTransactions;
|
||||
private Carbon $start;
|
||||
private bool $exportAccounts;
|
||||
private bool $exportBills;
|
||||
private bool $exportBudgets;
|
||||
private bool $exportCategories;
|
||||
private bool $exportTags;
|
||||
private bool $exportPiggies;
|
||||
private bool $exportRecurring;
|
||||
private bool $exportRules;
|
||||
private bool $exportBills;
|
||||
private bool $exportPiggies;
|
||||
private bool $exportTags;
|
||||
private bool $exportTransactions;
|
||||
private Carbon $start;
|
||||
private User $user;
|
||||
private Collection $accounts;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -89,25 +90,9 @@ class ExportDataGenerator
|
||||
$this->exportPiggies = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): void
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \League\Csv\CannotInsertRecord
|
||||
* @throws CannotInsertRecord
|
||||
*/
|
||||
public function export(): array
|
||||
{
|
||||
@@ -143,150 +128,6 @@ class ExportDataGenerator
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportAccounts
|
||||
*/
|
||||
public function setExportAccounts(bool $exportAccounts): void
|
||||
{
|
||||
$this->exportAccounts = $exportAccounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportBudgets
|
||||
*/
|
||||
public function setExportBudgets(bool $exportBudgets): void
|
||||
{
|
||||
$this->exportBudgets = $exportBudgets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportCategories
|
||||
*/
|
||||
public function setExportCategories(bool $exportCategories): void
|
||||
{
|
||||
$this->exportCategories = $exportCategories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportTags
|
||||
*/
|
||||
public function setExportTags(bool $exportTags): void
|
||||
{
|
||||
$this->exportTags = $exportTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportRecurring
|
||||
*/
|
||||
public function setExportRecurring(bool $exportRecurring): void
|
||||
{
|
||||
$this->exportRecurring = $exportRecurring;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportRules
|
||||
*/
|
||||
public function setExportRules(bool $exportRules): void
|
||||
{
|
||||
$this->exportRules = $exportRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportBills
|
||||
*/
|
||||
public function setExportBills(bool $exportBills): void
|
||||
{
|
||||
$this->exportBills = $exportBills;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportPiggies
|
||||
*/
|
||||
public function setExportPiggies(bool $exportPiggies): void
|
||||
{
|
||||
$this->exportPiggies = $exportPiggies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $end
|
||||
*/
|
||||
public function setEnd(Carbon $end): void
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportTransactions
|
||||
*/
|
||||
public function setExportTransactions(bool $exportTransactions): void
|
||||
{
|
||||
$this->exportTransactions = $exportTransactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
*/
|
||||
public function setStart(Carbon $start): void
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function exportRules(): string
|
||||
{
|
||||
$header = ['user_id', 'rule_id', 'row_contains', 'created_at', 'updated_at', 'group_id', 'group_name', 'title', 'description', 'order', 'active',
|
||||
'stop_processing', 'strict', 'trigger_type', 'trigger_value', 'trigger_order', 'trigger_active', 'trigger_stop_processing', 'action_type',
|
||||
'action_value', 'action_order', 'action_active', 'action_stop_processing',];
|
||||
$ruleRepos = app(RuleRepositoryInterface::class);
|
||||
$ruleRepos->setUser($this->user);
|
||||
$rules = $ruleRepos->getAll();
|
||||
$records = [];
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
$records[] = [
|
||||
$this->user->id, $rule->id, 'rule',
|
||||
$rule->created_at->toAtomString(), $rule->updated_at->toAtomString(),
|
||||
$rule->ruleGroup->id, $rule->ruleGroup->name,
|
||||
$rule->title, $rule->description, $rule->order, $rule->active, $rule->stop_processing, $rule->strict,
|
||||
];
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($rule->ruleTriggers as $trigger) {
|
||||
$records[] = [
|
||||
$this->user->id, $rule->id, 'trigger',
|
||||
null, null,
|
||||
null, null,
|
||||
null, null, null, null, null, null,
|
||||
$trigger->trigger_type, $trigger->trigger_value, $trigger->order, $trigger->active, $trigger->stop_processing,
|
||||
];
|
||||
}
|
||||
|
||||
/** @var RuleAction $action */
|
||||
foreach ($rule->ruleActions as $action) {
|
||||
$records[] = [
|
||||
$this->user->id, $rule->id, 'action',
|
||||
null, null,
|
||||
null, null,
|
||||
null, null, null, null, null, null,
|
||||
null, null, null, null, null,
|
||||
$action->action_type, $action->action_value, $action->order, $action->active, $action->stop_processing,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//load the CSV document from a string
|
||||
$csv = Writer::createFromString('');
|
||||
|
||||
//insert the header
|
||||
$csv->insertOne($header);
|
||||
|
||||
//insert all the records
|
||||
$csv->insertAll($records);
|
||||
|
||||
return $csv->getContent(); //returns the CSV document as a string
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -380,7 +221,7 @@ class ExportDataGenerator
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \League\Csv\CannotInsertRecord
|
||||
* @throws CannotInsertRecord
|
||||
*/
|
||||
private function exportBudgets(): string
|
||||
{
|
||||
@@ -610,6 +451,62 @@ class ExportDataGenerator
|
||||
return $csv->getContent(); //returns the CSV document as a string
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function exportRules(): string
|
||||
{
|
||||
$header = ['user_id', 'rule_id', 'row_contains', 'created_at', 'updated_at', 'group_id', 'group_name', 'title', 'description', 'order', 'active',
|
||||
'stop_processing', 'strict', 'trigger_type', 'trigger_value', 'trigger_order', 'trigger_active', 'trigger_stop_processing', 'action_type',
|
||||
'action_value', 'action_order', 'action_active', 'action_stop_processing',];
|
||||
$ruleRepos = app(RuleRepositoryInterface::class);
|
||||
$ruleRepos->setUser($this->user);
|
||||
$rules = $ruleRepos->getAll();
|
||||
$records = [];
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
$records[] = [
|
||||
$this->user->id, $rule->id, 'rule',
|
||||
$rule->created_at->toAtomString(), $rule->updated_at->toAtomString(),
|
||||
$rule->ruleGroup->id, $rule->ruleGroup->name,
|
||||
$rule->title, $rule->description, $rule->order, $rule->active, $rule->stop_processing, $rule->strict,
|
||||
];
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($rule->ruleTriggers as $trigger) {
|
||||
$records[] = [
|
||||
$this->user->id, $rule->id, 'trigger',
|
||||
null, null,
|
||||
null, null,
|
||||
null, null, null, null, null, null,
|
||||
$trigger->trigger_type, $trigger->trigger_value, $trigger->order, $trigger->active, $trigger->stop_processing,
|
||||
];
|
||||
}
|
||||
|
||||
/** @var RuleAction $action */
|
||||
foreach ($rule->ruleActions as $action) {
|
||||
$records[] = [
|
||||
$this->user->id, $rule->id, 'action',
|
||||
null, null,
|
||||
null, null,
|
||||
null, null, null, null, null, null,
|
||||
null, null, null, null, null,
|
||||
$action->action_type, $action->action_value, $action->order, $action->active, $action->stop_processing,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//load the CSV document from a string
|
||||
$csv = Writer::createFromString('');
|
||||
|
||||
//insert the header
|
||||
$csv->insertOne($header);
|
||||
|
||||
//insert all the records
|
||||
$csv->insertAll($records);
|
||||
|
||||
return $csv->getContent(); //returns the CSV document as a string
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -668,7 +565,7 @@ class ExportDataGenerator
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($this->start, $this->end)->withAccountInformation()->withCategoryInformation()->withBillInformation()
|
||||
->withBudgetInformation()->withTagInformation()->withNotes();
|
||||
if(0 !== $this->accounts->count()) {
|
||||
if (0 !== $this->accounts->count()) {
|
||||
$collector->setAccounts($this->accounts);
|
||||
}
|
||||
|
||||
@@ -776,4 +673,108 @@ class ExportDataGenerator
|
||||
return implode(',', $smol);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): void
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $end
|
||||
*/
|
||||
public function setEnd(Carbon $end): void
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportAccounts
|
||||
*/
|
||||
public function setExportAccounts(bool $exportAccounts): void
|
||||
{
|
||||
$this->exportAccounts = $exportAccounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportBills
|
||||
*/
|
||||
public function setExportBills(bool $exportBills): void
|
||||
{
|
||||
$this->exportBills = $exportBills;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportBudgets
|
||||
*/
|
||||
public function setExportBudgets(bool $exportBudgets): void
|
||||
{
|
||||
$this->exportBudgets = $exportBudgets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportCategories
|
||||
*/
|
||||
public function setExportCategories(bool $exportCategories): void
|
||||
{
|
||||
$this->exportCategories = $exportCategories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportPiggies
|
||||
*/
|
||||
public function setExportPiggies(bool $exportPiggies): void
|
||||
{
|
||||
$this->exportPiggies = $exportPiggies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportRecurring
|
||||
*/
|
||||
public function setExportRecurring(bool $exportRecurring): void
|
||||
{
|
||||
$this->exportRecurring = $exportRecurring;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportRules
|
||||
*/
|
||||
public function setExportRules(bool $exportRules): void
|
||||
{
|
||||
$this->exportRules = $exportRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportTags
|
||||
*/
|
||||
public function setExportTags(bool $exportTags): void
|
||||
{
|
||||
$this->exportTags = $exportTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exportTransactions
|
||||
*/
|
||||
public function setExportTransactions(bool $exportTransactions): void
|
||||
{
|
||||
$this->exportTransactions = $exportTransactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
*/
|
||||
public function setStart(Carbon $start): void
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user