From 744a68f195a7430fa942995c90b8ff89ef9c7367 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 1 Oct 2015 16:35:10 +0200 Subject: [PATCH] Category unactive implies all the reasons with this category as unactive - refs #622 --- Entity/ActivityReasonCategory.php | 25 +++++++++++++++---- .../doctrine/ActivityReasonCategory.orm.yml | 4 +++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Entity/ActivityReasonCategory.php b/Entity/ActivityReasonCategory.php index 22da06d74..0106ab881 100644 --- a/Entity/ActivityReasonCategory.php +++ b/Entity/ActivityReasonCategory.php @@ -20,6 +20,8 @@ namespace Chill\ActivityBundle\Entity; +use Doctrine\Common\Collections\ArrayCollection; + /** * ActivityReasonCategory */ @@ -40,13 +42,19 @@ class ActivityReasonCategory */ private $active; + /** @var ArrayCollection array of ActivityReason */ + private $reasons; + + public function __construct() + { + $this->reasons = new ArrayCollection(); + } public function __toString() { - return 'blop'; + return 'ActivityReasonCategory('.$this->getName('x').')'; } - /** * Get id * @@ -95,16 +103,23 @@ class ActivityReasonCategory } /** - * Set active + * Declare a category as active (or not). When a category is set + * as unactive, all the reason have this entity as category is also + * set as unactive * * @param boolean $active - * * @return ActivityReasonCategory */ public function setActive($active) { + if($this->active !== $active && !$active) { + foreach ($this->reasons as $reason) { + $reason->setActive($active); + } + } + $this->active = $active; - + return $this; } diff --git a/Resources/config/doctrine/ActivityReasonCategory.orm.yml b/Resources/config/doctrine/ActivityReasonCategory.orm.yml index 830129740..33487eb7b 100644 --- a/Resources/config/doctrine/ActivityReasonCategory.orm.yml +++ b/Resources/config/doctrine/ActivityReasonCategory.orm.yml @@ -12,4 +12,8 @@ Chill\ActivityBundle\Entity\ActivityReasonCategory: type: json_array active: type: boolean + oneToMany: + reasons: + targetEntity: Chill\ActivityBundle\Entity\ActivityReason + mappedBy: category lifecycleCallbacks: { }