- add category management

This commit is contained in:
2023-07-28 15:43:53 +02:00
parent d47c719d13
commit 8974721c9c
9 changed files with 235 additions and 41 deletions

View File

@@ -48,7 +48,7 @@ class CategoryRepository implements CategoryRepositoryInterface
public function update(Category $category, array $data = []): bool
{
$data = $this->parseToArray($data);
if (!$category->default && isset($data['default']) && $data['default'] === true)
if (!$category->default && $data['default'] === true)
$this->unsetDefault();
return $category
@@ -58,7 +58,7 @@ class CategoryRepository implements CategoryRepositoryInterface
public function create(array $data = []): Category
{
$data = $this->parseToArray($data);
if (isset($data['default']) && $data['default'] === true)
if ($data['default'] === true)
$this->unsetDefault();
return $this->category
@@ -85,18 +85,12 @@ class CategoryRepository implements CategoryRepositoryInterface
if (isset($data['priority']) && !is_integer($data['priority']))
$toSave['priority'] = (int)$data['priority'];
if (
isset($data['default']) &&
in_array($data['default'], ['yes', 'on', 1, true])
) $toSave['default'] = true;
else $toSave['default'] = false;
$toSave['default'] = $data['default'];
if (
(isset($toSave['default']) && $toSave['default'] === true) ||
(isset($data['visible']) &&
in_array($data['visible'], ['yes', 'on', 1, true]))
) $toSave['visible'] = true;
else $toSave['visible'] = false;
if ($toSave['default'] === true)
$toSave['visible'] = true;
else
$toSave['visible'] = $data['visible'];
return $toSave;
}