Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Merged case type collections
Browse files Browse the repository at this point in the history
  • Loading branch information
brettminnie committed Nov 27, 2014
1 parent 07e8759 commit 08b2f8f
Show file tree
Hide file tree
Showing 18 changed files with 197 additions and 466 deletions.
41 changes: 41 additions & 0 deletions src/Opg/Common/Model/Entity/HasCasesInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace Opg\Common\Model\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Opg\Core\Model\Entity\CaseItem\CaseItem;

/**
* Interface HasCasesInterface
* @package Opg\Core\Model\Entity\CaseActor\Interfaces
*/
interface HasCasesInterface
{
/**
* @return ArrayCollection
*/
public function getCases();

/**
* @param ArrayCollection $caseCollection
*
* @return HasCasesInterface
*/
public function setCases(ArrayCollection $caseCollection);

/**
* @param CaseItem $caseItem
* @return HasCasesInterface
*/
public function addCase(CaseItem $caseItem);

/**
* @param CaseItem $caseItem
* @return HasCasesInterface
*/
public function removeCase(CaseItem $caseItem);

/**
* @return bool
*/
public function hasAttachedCase();
}
99 changes: 99 additions & 0 deletions src/Opg/Common/Model/Entity/Traits/HasCases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php


namespace Opg\Common\Model\Entity\Traits;


use Doctrine\Common\Collections\ArrayCollection;
use Opg\Common\Model\Entity\HasCasesInterface;
use Opg\Core\Model\Entity\CaseItem\CaseItem;

/**
* Class HasCases
* @package Opg\Common\Model\Entity\Traits
*/
trait HasCases
{

/**
* @ORM\ManyToMany(targetEntity="Opg\Core\Model\Entity\CaseItem\CaseItem", cascade={"persist"})
* @ORM\OrderBy({"id"="ASC"})
* @var ArrayCollection
* @Groups({"api-person-get"})
*/
protected $cases;

/**
* @return ArrayCollection
*/
public function getCases()
{
$this->initCases();

return $this->cases;
}

/**
* @param ArrayCollection $caseCollection
*
* @return HasCasesInterface
*/
public function setCases(ArrayCollection $caseCollection)
{
$this->cases = $caseCollection;

return $this;
}

/**
* @param CaseItem $caseItem
* @return HasCasesInterface
*/
public function addCase(CaseItem $caseItem)
{
$this->initCases();

if (false === $this->cases->contains($caseItem)) {
$this->cases->add($caseItem);
}

return $this;
}

/**
* @param CaseItem $caseItem
* @return HasCasesInterface
*/
public function removeCase(CaseItem $caseItem)
{
$this->initCases();

if (true == $this->cases->contains($caseItem)) {
$this->cases->removeElement($caseItem);
}

return $this;
}

/**
* @internal
*/
protected function initCases()
{
if (null === $this->cases) {
$this->cases = new ArrayCollection();
}
}

/**
* Method to validate a person in the input filter, where required
* This is a bitwise or comparison, if either condition is true, it returns true
* @return bool
*
*/
public function hasAttachedCase()
{
return (bool)($this->getCases()->count() > 0);
}

}
160 changes: 5 additions & 155 deletions src/Opg/Core/Model/Entity/Assignable/AssignableComposite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Opg\Core\Model\Entity\Assignable;

use Opg\Common\Model\Entity\HasCasesInterface;
use Opg\Common\Model\Entity\HasIdInterface;
use Opg\Common\Model\Entity\HasTasksInterface;
use Opg\Common\Model\Entity\Traits\HasCases;
use Opg\Common\Model\Entity\Traits\HasId;
use Opg\Common\Model\Entity\Traits\HasTasks;
use Opg\Common\Model\Entity\Traits\ToArray;
Expand Down Expand Up @@ -35,39 +37,12 @@
* Class Composite
* @package Opg\Core\Model\Entity\Composite
*/
abstract class AssignableComposite implements IsAssignee, \IteratorAggregate, HasTasksInterface, HasIdInterface
abstract class AssignableComposite implements IsAssignee, \IteratorAggregate, HasTasksInterface, HasIdInterface, HasCasesInterface
{
use ToArray;
use HasTasks;
use HasId;

/**
* @ORM\ManyToMany(cascade={"all"}, targetEntity="Opg\Core\Model\Entity\CaseItem\PowerOfAttorney\PowerOfAttorney")
* @ORM\JoinTable(
* name="assigned_powerofattorneys",
* joinColumns={@ORM\JoinColumn(name="assignee_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="poa_id", referencedColumnName="id", unique=true)}
* )
*
* @var ArrayCollection
* @Exclude
* @ReadOnly
*/
protected $powerOfAttorneys;

/**
* @ORM\ManyToMany(cascade={"all"}, targetEntity="Opg\Core\Model\Entity\CaseItem\Deputyship\Deputyship")
* @ORM\JoinTable(
* name="assigned_deputyships",
* joinColumns={@ORM\JoinColumn(name="assignee_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="deputyship_id", referencedColumnName="id", unique=true)}
* )
*
* @var ArrayCollection
* @Exclude
* @ReadOnly
*/
protected $deputyships;
use HasCases;

/**
* @ORM\Column(type = "string")
Expand Down Expand Up @@ -96,136 +71,11 @@ abstract class AssignableComposite implements IsAssignee, \IteratorAggregate, Ha

public function __construct()
{
$this->deputyships = new ArrayCollection();
$this->powerOfAttorneys = new ArrayCollection();
$this->cases = new ArrayCollection();
$this->tasks = new ArrayCollection();
$this->teams = new ArrayCollection();
}

/**
* @param CaseEntity $case
*
* @return $this
*/
public function addCase( CaseEntity $case )
{
if ($case instanceof PowerOfAttorneyEntity) {
return $this->addPowerOfAttorney( $case );
} else {
return $this->addDeputyship( $case );
}
}

/**
* @return ArrayCollection
*/
public function getCases()
{
$cases = new ArrayCollection();
foreach ($this->getPowerOfAttorneys() as $case) {
$cases->add( $case );
}
foreach ($this->getDeputyships() as $case) {
$cases->add( $case );
}

return $cases;
}

/**
* @param PowerOfAttorneyEntity $poa
*
* @return AssignableComposite
*/
public function addPowerOfAttorney( PowerOfAttorneyEntity $poa )
{
if (null === $this->powerOfAttorneys) {
$this->powerOfAttorneys = new ArrayCollection();
}

$this->powerOfAttorneys->add( $poa );

return $this;
}

/**
* @return ArrayCollection
*/
public function getPowerOfAttorneys()
{
if (null === $this->powerOfAttorneys) {
$this->powerOfAttorneys = new ArrayCollection();
}

return $this->powerOfAttorneys;
}

/**
* @param DeputyshipEntity $poa
*
* @return AssignableComposite
*/
public function addDeputyship( DeputyshipEntity $poa )
{
if (null === $this->deputyships) {
$this->deputyships = new ArrayCollection();
}

$this->deputyships->add( $poa );

return $this;
}

/**
* @return ArrayCollection
*/
public function getDeputyships()
{
if (null === $this->deputyships) {
$this->deputyships = new ArrayCollection();
}

return $this->deputyships;
}

/**
* @param ArrayCollection $cases
*
* @return AssignableComposite
*/
public function setCases( ArrayCollection $cases )
{
foreach ($cases as $case) {
$this->addCase( $case );
}

return $this;
}

/**
* Alias function
*
* @param ArrayCollection $cases
*
* @return AssignableComposite
*/
public function setPowerOfAttorneys( ArrayCollection $cases )
{
return $this->setCases( $cases );
}

/**
* Alias function
*
* @param ArrayCollection $cases
*
* @return AssignableComposite
*/
public function setDeputyships( ArrayCollection $cases )
{
return $this->setCases( $cases );
}

/**
* @param string $name
*
Expand Down
58 changes: 2 additions & 56 deletions src/Opg/Core/Model/Entity/Assignable/IsAssignee.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,61 +26,7 @@ public function getName();
public function setName( $name );

/**
* @param CaseEntity $case
*
* @return IsAssignee
*/
public function addCase( CaseEntity $case );

/**
* @return ArrayCollection
*/
public function getCases();

/**
* @param PowerOfAttorneyEntity $poa
*
* @return IsAssignee
*/
public function addPowerOfAttorney( PowerOfAttorneyEntity $poa );

/**
* @return ArrayCollection
*/
public function getPowerOfAttorneys();

/**
* @param DeputyshipEntity $poa
*
* @return IsAssignee
*/
public function addDeputyship( DeputyshipEntity $poa );

/**
* @return ArrayCollection
*/
public function getDeputyships();

/**
* @param ArrayCollection $cases
*
* @return IsAssignee
*/
public function setCases( ArrayCollection $cases );

/**
* @param ArrayCollection $cases
*
* @return IsAssignee
* Alias function
*/
public function setPowerOfAttorneys( ArrayCollection $cases );

/**
* @param ArrayCollection $cases
*
* @return IsAssignee
* Alias function
* @return string
*/
public function setDeputyships( ArrayCollection $cases );
public function getDisplayName();
}

0 comments on commit 08b2f8f

Please sign in to comment.