Skill: Fix entity relations between SkillProfile and SkillRelProfile

pull/5964/head
Angel Fernando Quiroz Campos 12 months ago
parent a1e4b402e2
commit 6f30ab709b
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 37
      src/CoreBundle/Entity/Skill.php
  2. 43
      src/CoreBundle/Entity/SkillProfile.php
  3. 20
      src/CoreBundle/Entity/SkillRelProfile.php

@ -142,6 +142,12 @@ class Skill implements Stringable, Translatable
#[Gedmo\Locale]
private ?string $locale = null;
/**
* @var Collection<int, SkillRelProfile>
*/
#[ORM\OneToMany(mappedBy: 'skill', targetEntity: SkillRelProfile::class, cascade: ['persist'])]
private Collection $profiles;
public function __construct()
{
$this->issuedSkills = new ArrayCollection();
@ -152,6 +158,7 @@ class Skill implements Stringable, Translatable
$this->icon = '';
$this->description = '';
$this->status = self::STATUS_ENABLED;
$this->profiles = new ArrayCollection();
}
public function __toString(): string
@ -441,4 +448,34 @@ class Skill implements Stringable, Translatable
->map(fn(SkillRelSkill $skillRelSkill): Skill => $skillRelSkill->getSkill())
;
}
/**
* @return Collection<int, SkillRelProfile>
*/
public function getProfiles(): Collection
{
return $this->profiles;
}
public function addProfile(SkillRelProfile $profile): static
{
if (!$this->profiles->contains($profile)) {
$this->profiles->add($profile);
$profile->setSkill($this);
}
return $this;
}
public function removeProfile(SkillRelProfile $profile): static
{
if ($this->profiles->removeElement($profile)) {
// set the owning side to null (unless already changed)
if ($profile->getSkill() === $this) {
$profile->setSkill(null);
}
}
return $this;
}
}

@ -6,6 +6,8 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@ -25,6 +27,17 @@ class SkillProfile
#[ORM\Column(name: 'description', type: 'text', nullable: false)]
protected string $description;
/**
* @var Collection<int, SkillRelProfile>
*/
#[ORM\OneToMany(mappedBy: 'profile', targetEntity: SkillRelProfile::class, cascade: ['persist'])]
private Collection $skills;
public function __construct()
{
$this->skills = new ArrayCollection();
}
public function setTitle(string $title): self
{
$this->title = $title;
@ -62,4 +75,34 @@ class SkillProfile
{
return $this->id;
}
/**
* @return Collection<int, SkillRelProfile>
*/
public function getSkills(): Collection
{
return $this->skills;
}
public function addSkill(SkillRelProfile $skill): static
{
if (!$this->skills->contains($skill)) {
$this->skills->add($skill);
$skill->setProfile($this);
}
return $this;
}
public function removeSkill(SkillRelProfile $skill): static
{
if ($this->skills->removeElement($skill)) {
// set the owning side to null (unless already changed)
if ($skill->getProfile() === $this) {
$skill->setProfile(null);
}
}
return $this;
}
}

@ -17,37 +17,37 @@ class SkillRelProfile
#[ORM\GeneratedValue]
protected ?int $id = null;
#[ORM\ManyToOne(targetEntity: Skill::class, cascade: ['persist'])]
#[ORM\JoinColumn(name: 'skill_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected Skill $skill;
#[ORM\ManyToOne(inversedBy: 'profiles')]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
private ?Skill $skill = null;
#[ORM\ManyToOne(targetEntity: SkillProfile::class, cascade: ['persist'])]
#[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected SkillProfile $profile;
#[ORM\ManyToOne(inversedBy: 'skills')]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
private ?SkillProfile $profile = null;
public function getId(): ?int
{
return $this->id;
}
public function getSkill(): Skill
public function getSkill(): ?Skill
{
return $this->skill;
}
public function setSkill(Skill $skill): self
public function setSkill(?Skill $skill): static
{
$this->skill = $skill;
return $this;
}
public function getProfile(): SkillProfile
public function getProfile(): ?SkillProfile
{
return $this->profile;
}
public function setProfile(SkillProfile $profile): self
public function setProfile(?SkillProfile $profile): static
{
$this->profile = $profile;

Loading…
Cancel
Save