firefly-iii/app/Helpers/Csv/Converter/CategoryName.php

36 lines
840 B
PHP
Raw Normal View History

2015-07-05 08:16:44 -05:00
<?php
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
2015-07-05 08:16:44 -05:00
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Category;
/**
* Class CategoryName
*
* @package FireflyIII\Helpers\Csv\Converter
*/
class CategoryName extends BasicConverter implements ConverterInterface
{
/**
* @return Category
*/
public function convert()
{
// is mapped? Then it's easy!
if (isset($this->mapped[$this->index][$this->value])) {
$category = Auth::user()->categories()->find($this->mapped[$this->index][$this->value]);
} else {
2016-02-11 21:59:14 -06:00
$category = Category::firstOrCreateEncrypted( // See issue #180
2015-07-05 08:16:44 -05:00
[
'name' => $this->value,
2016-01-15 16:12:52 -06:00
'user_id' => Auth::user()->id,
2015-07-05 08:16:44 -05:00
]
);
}
return $category;
}
2015-07-09 14:26:40 -05:00
}