2015-07-05 15:16:44 +02:00
|
|
|
<?php
|
2016-02-05 12:08:25 +01:00
|
|
|
declare(strict_types = 1);
|
2015-07-05 15:16:44 +02:00
|
|
|
namespace FireflyIII\Helpers\Csv\Converter;
|
|
|
|
|
|
|
|
|
|
use Auth;
|
|
|
|
|
use FireflyIII\Models\Category;
|
2016-04-01 13:23:12 +02:00
|
|
|
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
|
2015-07-05 15:16:44 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class CategoryName
|
|
|
|
|
*
|
|
|
|
|
* @package FireflyIII\Helpers\Csv\Converter
|
|
|
|
|
*/
|
|
|
|
|
class CategoryName extends BasicConverter implements ConverterInterface
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Category
|
|
|
|
|
*/
|
2016-04-06 16:37:28 +02:00
|
|
|
public function convert(): Budget
|
2015-07-05 15:16:44 +02:00
|
|
|
{
|
2016-04-01 13:23:12 +02:00
|
|
|
/** @var SingleCategoryRepositoryInterface $repository */
|
|
|
|
|
$repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
|
|
|
|
|
|
2015-07-05 15:16:44 +02:00
|
|
|
// is mapped? Then it's easy!
|
|
|
|
|
if (isset($this->mapped[$this->index][$this->value])) {
|
2016-04-01 13:23:12 +02:00
|
|
|
$category = $repository->find($this->mapped[$this->index][$this->value]);
|
2015-07-05 15:16:44 +02:00
|
|
|
} else {
|
2016-04-01 13:23:12 +02:00
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'name' => $this->value,
|
|
|
|
|
'user' => Auth::user()->id,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$category = $repository->store($data);
|
2015-07-05 15:16:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $category;
|
|
|
|
|
}
|
2015-07-09 21:26:40 +02:00
|
|
|
}
|