Skip to content

Commit

Permalink
Merge pull request #15 from monarc-project/bugfix/216
Browse files Browse the repository at this point in the history
Fixed the library categories manipulation for Backoffice and Frontoffice
  • Loading branch information
ruslanbaydan authored Dec 18, 2019
2 parents 5f2828c + 988e34c commit 3597c76
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 208 deletions.
1 change: 0 additions & 1 deletion src/Controller/ApiAnrLibraryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,5 @@ public function delete($id)
'status' => 'ok'
)
);

}
}
17 changes: 11 additions & 6 deletions src/Model/Entity/AnrObjectCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,38 +81,42 @@ public function setId($id): self
}

/**
* @return Anr
* @return AnrSuperClass
*/
public function getAnr()
{
return $this->anr;
}

/**
* @param Anr $anr
* @return AnrObjectCategory
* @param AnrSuperClass $anr
*
* @return self
*/
public function setAnr($anr)
{
$this->anr = $anr;

return $this;
}

/**
* @return ObjectCategory
* @return ObjectCategorySuperClass
*/
public function getCategory()
{
return $this->category;
}

/**
* @param ObjectCategory $category
* @return AnrObjectCategory
* @param ObjectCategorySuperClass $category
*
* @return self
*/
public function setCategory($category)
{
$this->category = $category;

return $this;
}

Expand All @@ -121,6 +125,7 @@ public function getInputFilter($partial = false)
if (!$this->inputFilter) {
parent::getInputFilter($partial);
}

return $this->inputFilter;
}

Expand Down
9 changes: 5 additions & 4 deletions src/Model/Entity/AnrSuperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Monarc\Core\Model\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Monarc\Core\Model\Entity\Traits;

Expand All @@ -32,9 +33,9 @@ class AnrSuperClass extends AbstractEntity
protected $id;

/**
* @var \Monarc\Core\Model\Entity\MonarcObject
* @var ArrayCollection|ObjectSuperClass[]
*
* @ORM\ManyToMany(targetEntity="Monarc\Core\Model\Entity\MonarcObject", mappedBy="anrs")
* @ORM\ManyToMany(targetEntity="MonarcObject", mappedBy="anrs")
*/
protected $objects;

Expand Down Expand Up @@ -263,15 +264,15 @@ public function setId(?int $id): self
}

/**
* @return Object
* @return ArrayCollection|ObjectSuperClass[]
*/
public function getObjects()
{
return $this->objects;
}

/**
* @param Object $objects
* @param ObjectSuperClass[] $objects
* @return Anr
*/
public function setObjects($objects): self
Expand Down
117 changes: 66 additions & 51 deletions src/Model/Entity/ObjectCategorySuperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Monarc\Core\Model\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Monarc\Core\Model\Entity\Traits\CreateEntityTrait;
use Monarc\Core\Model\Entity\Traits\UpdateEntityTrait;
Expand Down Expand Up @@ -38,35 +39,59 @@ class ObjectCategorySuperClass extends AbstractEntity
protected $id;

/**
* @var \Monarc\Core\Model\Entity\Anr
* @var AnrSuperClass
*
* @ORM\ManyToOne(targetEntity="Monarc\Core\Model\Entity\Anr", cascade={"persist"})
* @ORM\ManyToOne(targetEntity="Anr", cascade={"persist"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="anr_id", referencedColumnName="id", nullable=true)
* })
*/
protected $anr;

/**
* @var \Monarc\Core\Model\Entity\ObjectCategory
* @var ObjectCategorySuperClass
*
* @ORM\ManyToOne(targetEntity="Monarc\Core\Model\Entity\ObjectCategory", cascade={"persist"})
* @ORM\ManyToOne(targetEntity="ObjectCategory", cascade={"persist"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="root_id", referencedColumnName="id", nullable=true)
* })
*/
protected $root;

/**
* @var \Monarc\Core\Model\Entity\ObjectCategory
* @var ObjectCategorySuperClass
*
* @ORM\ManyToOne(targetEntity="Monarc\Core\Model\Entity\ObjectCategory", cascade={"persist"})
* @ORM\ManyToOne(targetEntity="ObjectCategory", cascade={"persist"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true)
* })
*/
protected $parent;

/**
* @var ObjectCategorySuperClass[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="ObjectCategory", mappedBy="parent")
*/
protected $children;

/**
* @var ArrayCollection|ObjectSuperClass[]
*
* @ORM\OneToMany(targetEntity="MonarcObject", orphanRemoval=true, mappedBy="category",
* cascade={"persist", "remove"}
* )
*/
protected $objects;

/**
* @return ArrayCollection|ObjectCategorySuperClass[]
*/
public function getChildren()
{
return $this->children;
}

/**
* @var string
*
Expand Down Expand Up @@ -102,6 +127,14 @@ class ObjectCategorySuperClass extends AbstractEntity
*/
protected $position = 1;

protected $parameters = [
'implicitPosition' => [
'field' => 'parent',
'root' => 'root',
'subField' => ['anr']
],
];

/**
* @return int
*/
Expand All @@ -112,106 +145,89 @@ public function getId()

/**
* @param int $id
* @return Model
*
* @return self
*/
public function setId($id)
public function setId($id): self
{
$this->id = $id;

return $this;
}

/**
* @return Anr
* @return AnrSuperClass
*/
public function getAnr()
{
return $this->anr;
}

/**
* @param Anr $anr
* @return ObjectCategory
* @param AnrSuperClass $anr
*
* @return self
*/
public function setAnr($anr)
public function setAnr($anr): self
{
$this->anr = $anr;

return $this;
}

/**
* @return ObjectCategory
* @return ObjectCategorySuperClass|null
*/
public function getParent()
{
return $this->parent;
}

/**
* @param ObjectCategory $parent
* @return ObjectCategory
* @param ObjectCategorySuperClass $parent
*
* @return self
*/
public function setParent($parent)
public function setParent($parent): self
{
$this->parent = $parent;

return $this;
}

/**
* @return ObjectCategory
* @return ObjectCategorySuperClass|null
*/
public function getRoot()
{
return $this->root;
}

/**
* @param ObjectCategory $root
* @return ObjectCategory
* @param ObjectCategorySuperClass $root
*
* @return self
*/
public function setRoot($root)
public function setRoot($root): self
{
$this->root = $root;

return $this;
}

/**
* @return \Doctrine\Common\Collections\Collection
* @return ArrayCollection|ObjectSuperClass[]
*/
public function getAnrs()
public function getObjects()
{
return $this->anrs;
return $this->objects;
}

/**
* Add Anr
*
* @param Anr $anr
* @throws \Exception
*/
public function addAnr(AnrSuperClass $anr)
public function hasObjects(): bool
{
$currentAnrs = $this->anrs;

$alreadyUsed = false;
foreach ($currentAnrs as $currentAnr) {
if ($currentAnr->id == $anr->id) {
$alreadyUsed = true;
}
}

if (!$alreadyUsed) {
$this->anrs[] = $anr;
}
return (bool)\count($this->objects);
}

protected $parameters = array(
'implicitPosition' => array(
'field' => 'parent',
'root' => 'root',
'subField' => ['anr']
),
);

public function getInputFilter($partial = false)
{
if (!$this->inputFilter) {
Expand All @@ -231,4 +247,3 @@ public function getInputFilter($partial = false)
return $this->inputFilter;
}
}

8 changes: 4 additions & 4 deletions src/Model/Entity/ObjectSuperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ObjectSuperClass extends AbstractEntity
/**
* @var ObjectCategorySuperClass
*
* @ORM\ManyToOne(targetEntity="ObjectCategory", cascade={"persist"})
* @ORM\ManyToOne(targetEntity="ObjectCategory", cascade={"persist", "remove"}, inversedBy="objects")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="object_category_id", referencedColumnName="id", nullable=true)
* })
Expand Down Expand Up @@ -217,15 +217,15 @@ public function setUuid($uuid): self
}

/**
* @return AnrSuperClass
* @return AnrSuperClass|null
*/
public function getAnr()
public function getAnr(): ?AnrSuperClass
{
return $this->anr;
}

/**
* @param AnrSuperClass $anr
* @param AnrSuperClass|null $anr
*/
public function setAnr($anr): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Entity/UserSuperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ abstract class UserSuperClass
protected $language = 1;

/**
* @var ArrayCollection
* @var ArrayCollection|UserRoleSuperClass[]
*
* @ORM\OneToMany(targetEntity="UserRole", orphanRemoval=true, mappedBy="user", cascade={"persist", "remove"})
*/
Expand Down
18 changes: 18 additions & 0 deletions src/Model/Table/AnrObjectCategoryTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use Monarc\Core\Model\Db;
use Monarc\Core\Model\Entity\AnrObjectCategory;
use Monarc\Core\Model\Entity\AnrSuperClass;
use Monarc\Core\Model\Entity\ObjectCategorySuperClass;
use Monarc\Core\Service\ConnectedUserService;

/**
Expand All @@ -21,4 +23,20 @@ public function __construct(Db $dbService, ConnectedUserService $connectedUserSe
{
parent::__construct($dbService, AnrObjectCategory::class, $connectedUserService);
}

// TODO: in order to specify return object type we need to create a superclass for AnrObjectCategory.
public function findOneByAnrAndObjectCategory(AnrSuperClass $anr, ObjectCategorySuperClass $objectCategory)
{
$result = $this->getRepository()
->createQueryBuilder('aoc')
->where('aoc.anr = :anr')
->andWhere('aoc.category = :category')
->setParameter('anr', $anr)
->setParameter('category', $objectCategory)
->setMaxResults(1)
->getQuery()
->getResult();

return $result[0] ?? null;
}
}
Loading

0 comments on commit 3597c76

Please sign in to comment.