Activity Form : display field according to the parameters

This commit is contained in:
Jean-Francois Monfort
2021-04-29 16:35:39 +02:00
parent 45671bda52
commit 82d8556f24
8 changed files with 354 additions and 209 deletions

View File

@@ -76,7 +76,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
/**
* @ORM\Column(type="time", nullable=true)
*/
private ?\DateTime $travelTime;
private ?\DateTime $travelTime = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence")
@@ -96,7 +96,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope")
*/
private Scope $scope;
private ?Scope $scope = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person")
@@ -217,7 +217,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
return $this;
}
public function getTravelTime(): \DateTime
public function getTravelTime(): ?\DateTime
{
return $this->travelTime;
}
@@ -288,7 +288,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
/**
* Get scope
*/
public function getScope(): Scope
public function getScope(): ?Scope
{
return $this->scope;
}

View File

@@ -632,4 +632,37 @@ class ActivityType
{
$this->socialDataLabel = $socialDataLabel;
}
public function isVisible(string $field): bool
{
$property = $field.'Visible';
if (!property_exists($this, $property)) {
throw new \InvalidArgumentException('Field "'.$field.'" not found');
}
return self::FIELD_INVISIBLE !== $this->$property;
}
public function isRequired(string $field): bool
{
$property = $field.'Visible';
if (!property_exists($this, $property)) {
throw new \InvalidArgumentException('Field "'.$field.'" not found');
}
return self::FIELD_REQUIRED === $this->$property;
}
public function getLabel(string $field): ?string
{
$property = $field.'Label';
if (!property_exists($this, $property)) {
throw new \InvalidArgumentException('Field "'.$field.'" not found');
}
return $this->$property;
}
}