From 9f98c4e7e6de0e9eddb97965f7eee4ffc96d7dbd Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 30 Sep 2015 13:31:09 +0200 Subject: [PATCH] Adding method getActiveCustomFields --- Entity/CustomFieldsGroup.php | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/Entity/CustomFieldsGroup.php b/Entity/CustomFieldsGroup.php index cbcd43575..4b076a8ff 100644 --- a/Entity/CustomFieldsGroup.php +++ b/Entity/CustomFieldsGroup.php @@ -21,6 +21,8 @@ namespace Chill\CustomFieldsBundle\Entity; +use \Doctrine\Common\Collections\Collection; + /** * CustomFieldGroup */ @@ -42,9 +44,18 @@ class CustomFieldsGroup private $entity; /** - * @var \Doctrine\Common\Collections\Collection + * @var \Doctrine\Common\Collections\Collection $customFields: The custom + * fields of the group. The custom fields are asc-ordered regarding to their + * property "ordering". */ private $customFields; + + /** + * @var array(customField) | null $activeCustomFields: The custom fields + * of the group that are active. This variable if null, if this + * informations has not been computed. + */ + private $activeCustomFields = null; /** * @@ -52,7 +63,7 @@ class CustomFieldsGroup */ private $options = array(); - /** + /** * Constructor */ public function __construct() @@ -93,6 +104,25 @@ class CustomFieldsGroup return $this->customFields; } + /** + * Get all the custom + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getActiveCustomFields() + { + if($this->activeCustomFields === null) { + $this->activeCustomFields = array(); + foreach ($this->customFields as $cf) { + if($cf->isActive()) { + array_push($this->activeCustomFields, $cf); + } + } + } + + return $this->activeCustomFields; + } + /** * Get id @@ -189,7 +219,4 @@ class CustomFieldsGroup $this->options = $options; return $this; } - - - }