Skip to content

Commit

Permalink
Added the flag if the object is linked to the anr or not to the objec…
Browse files Browse the repository at this point in the history
…ts categories response.
  • Loading branch information
Ruslan Baidan committed Oct 10, 2022
1 parent 34c2ed3 commit f69d456
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
16 changes: 12 additions & 4 deletions src/Model/Entity/ObjectSuperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ class ObjectSuperClass extends AbstractEntity
),
);

public function __construct($obj = null)
{
$this->anrs = new ArrayCollection();

parent::__construct($obj);
}

public function getUuid(): ?string
{
return $this->uuid;
Expand Down Expand Up @@ -315,10 +322,6 @@ public function setAnrs($anrs): self
*/
public function addAnr(AnrSuperClass $anr): self
{
if ($this->anrs === null) {
$this->anrs = new ArrayCollection();
}

if (!$this->anrs->contains($anr)) {
$this->anrs->add($anr);
$anr->addObject($this);
Expand All @@ -327,6 +330,11 @@ public function addAnr(AnrSuperClass $anr): self
return $this;
}

public function isLinkedToAnr(AnrSuperClass $anr): bool
{
return $this->anrs->contains($anr);
}

public function setName(string $nameKey, string $nameValue): self
{
if (in_array($nameKey, ['name1', 'name2', 'name3', 'name4'], true)) {
Expand Down
12 changes: 12 additions & 0 deletions src/Model/Table/ModelTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Monarc\Core\Model\Table;

use Doctrine\ORM\EntityNotFoundException;
use Monarc\Core\Model\Db;
use Monarc\Core\Model\Entity\Model;
use Monarc\Core\Service\ConnectedUserService;
Expand All @@ -22,6 +23,17 @@ public function __construct(Db $dbService, ConnectedUserService $connectedUserSe
parent::__construct($dbService, Model::class, $connectedUserService);
}

public function findById(int $id): Model
{
/** @var Model $model */
$model = $this->getRepository()->find($id);
if ($model === null) {
throw EntityNotFoundException::fromClassNameAndIdentifier(static::class, [$id]);
}

return $model;
}

/**
* Reset Current Default
*/
Expand Down
39 changes: 29 additions & 10 deletions src/Service/ObjectCategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Monarc\Core\Model\Entity\AnrObjectCategory;
use Monarc\Core\Model\Entity\ObjectCategory;
use Monarc\Core\Model\Entity\ObjectCategorySuperClass;
use Monarc\Core\Model\Entity\ObjectSuperClass;
use Monarc\Core\Model\Table\AnrObjectCategoryTable;
use Monarc\Core\Model\Table\ModelTable;
use Monarc\Core\Model\Table\MonarcObjectTable;

/**
Expand All @@ -28,6 +30,8 @@ class ObjectCategoryService extends AbstractService
protected $filterColumns = ['label1', 'label2', 'label3', 'label4'];
protected $dependencies = ['root', 'parent', 'anr'];//required for autopositionning

protected ModelTable $modelTable;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -80,24 +84,39 @@ public function getEntity($id)
/**
* @inheritdoc
*/
public function getListSpecific($page = 1, $limit = 25, $order = null, $filter = null, $filterAnd = [])
{
public function getListSpecific(
$page = 1,
$limit = 25,
$order = null,
$filter = null,
$filterAnd = [],
$modelId = null
) {
$objectCategories = $this->getList($page, $limit, $order, $filter, $filterAnd);
$result = $objectCategories;

$model = null;
if ($modelId !== null) {
$model = $this->modelTable->findById((int)$modelId);
}

$currentObjectCategoriesListId = [];
foreach ($objectCategories as $key => $objectCategory) {
if (\is_object($result[$key]['objects'])) {
$result[$key]['objects'] = [];
}
foreach ($objectCategory['objects'] as $object) {
$result[$key]['objects'][] = [
'uuid' => $object->getUuid(),
'name1' => $object->getName(1),
'name2' => $object->getName(2),
'name3' => $object->getName(3),
'name4' => $object->getName(4),
];
if ($model !== null) {
/** @var ObjectSuperClass $object */
foreach ($objectCategory['objects'] as $object) {
$result[$key]['objects'][] = [
'uuid' => $object->getUuid(),
'name1' => $object->getName(1),
'name2' => $object->getName(2),
'name3' => $object->getName(3),
'name4' => $object->getName(4),
'isLinkedToAnr' => $object->isLinkedToAnr($model->getAnr()),
];
}
}
$currentObjectCategoriesListId[] = $objectCategory['id'];
}
Expand Down
1 change: 1 addition & 0 deletions src/Service/ObjectCategoryServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ class ObjectCategoryServiceFactory extends AbstractServiceFactory
'anrObjectCategoryTable' => Table\AnrObjectCategoryTable::class,
'monarcObjectTable' => Table\MonarcObjectTable::class,
'anrTable' => Table\AnrTable::class,
'modelTable' => Table\ModelTable::class,
];
}

0 comments on commit f69d456

Please sign in to comment.