") * @Serializer\SerializedName("metaFields") * @Serializer\Accessor(getter="getVisibleMetaFields") * * @ORM\OneToMany(targetEntity="App\Entity\ActivityMeta", mappedBy="activity", cascade={"persist"}) */ private $meta; /** * Teams * * If no team is assigned, everyone can access the activity * * @var Team[]|ArrayCollection * * @Serializer\Expose() * @Serializer\Groups({"Activity"}) * @SWG\Property(type="array", @SWG\Items(ref="#/definitions/Team")) * * @ORM\ManyToMany(targetEntity="Team", cascade={"persist"}, inversedBy="activities") * @ORM\JoinTable( * name="kimai2_activities_teams", * joinColumns={ * @ORM\JoinColumn(name="activity_id", referencedColumnName="id", onDelete="CASCADE") * }, * inverseJoinColumns={ * @ORM\JoinColumn(name="team_id", referencedColumnName="id", onDelete="CASCADE") * } * ) */ private $teams; /** * @var string|null * * @ORM\Column(name="invoice_text", type="text", nullable=true) */ private $invoiceText; public function __construct() { $this->meta = new ArrayCollection(); $this->teams = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getProject(): ?Project { return $this->project; } public function setProject(?Project $project): Activity { $this->project = $project; return $this; } public function setName(string $name): Activity { $this->name = $name; return $this; } public function getName(): ?string { return $this->name; } public function setComment(?string $comment): Activity { $this->comment = $comment; return $this; } public function getComment(): ?string { return $this->comment; } public function setVisible(bool $visible): Activity { $this->visible = $visible; return $this; } public function isGlobal(): bool { return $this->project === null; } public function isVisible(): bool { return $this->visible; } public function setBillable(bool $billable): void { $this->billable = $billable; } public function isBillable(): bool { return $this->billable; } /** * @return Collection|MetaTableTypeInterface[] */ public function getMetaFields(): Collection { return $this->meta; } /** * @return MetaTableTypeInterface[] */ public function getVisibleMetaFields(): array { $all = []; foreach ($this->meta as $meta) { if ($meta->isVisible()) { $all[] = $meta; } } return $all; } public function getMetaField(string $name): ?MetaTableTypeInterface { foreach ($this->meta as $field) { if (strtolower($field->getName()) === strtolower($name)) { return $field; } } return null; } /** * @param string $name * @return bool|int|string|null */ public function getMetaFieldValue(string $name) { $field = $this->getMetaField($name); if ($field === null) { return null; } return $field->getValue(); } public function setMetaField(MetaTableTypeInterface $meta): EntityWithMetaFields { if (null === ($current = $this->getMetaField($meta->getName()))) { $meta->setEntity($this); $this->meta->add($meta); return $this; } $current->merge($meta); return $this; } public function addTeam(Team $team) { if ($this->teams->contains($team)) { return; } $this->teams->add($team); $team->addActivity($this); } public function removeTeam(Team $team) { if (!$this->teams->contains($team)) { return; } $this->teams->removeElement($team); $team->removeActivity($this); } /** * @return Collection */ public function getTeams(): Collection { return $this->teams; } public function getInvoiceText(): ?string { return $this->invoiceText; } public function setInvoiceText(?string $invoiceText): void { $this->invoiceText = $invoiceText; } /** * @return string */ public function __toString() { return $this->getName(); } public function __clone() { if ($this->id) { $this->id = null; } $currentTeams = $this->teams; $this->teams = new ArrayCollection(); /** @var Team $team */ foreach ($currentTeams as $team) { $this->addTeam($team); } $currentMeta = $this->meta; $this->meta = new ArrayCollection(); /** @var ActivityMeta $meta */ foreach ($currentMeta as $meta) { $newMeta = clone $meta; $newMeta->setEntity($this); $this->setMetaField($newMeta); } } }