Fix method to add and remove CDocument::gradebookCategories

pull/5766/head
Angel Fernando Quiroz Campos 1 year ago
parent f7d79cbcc1
commit 3c939ba353
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 22
      src/CoreBundle/Entity/GradebookCategory.php
  2. 27
      src/CourseBundle/Entity/CDocument.php

@ -112,10 +112,10 @@ class GradebookCategory
#[ORM\Column(name: 'certif_min_score', type: 'integer', nullable: true)]
protected ?int $certifMinScore = null;
#[ORM\ManyToOne(inversedBy: 'gradebookCategory', targetEntity: CDocument::class)]
#[ORM\JoinColumn(name: 'document_id', referencedColumnName: 'iid', onDelete: 'set null')]
#[Groups(['gradebookCategory:read', 'gradebookCategory:write'])]
protected ?CDocument $document = null;
#[ORM\ManyToOne(targetEntity: CDocument::class, inversedBy: 'gradebookCategories')]
#[ORM\JoinColumn(name: 'document_id', referencedColumnName: 'iid', onDelete: 'set null')]
private ?CDocument $document = null;
#[Assert\NotBlank]
#[ORM\Column(name: 'locked', type: 'integer', nullable: false)]
@ -242,26 +242,14 @@ class GradebookCategory
return $this->certifMinScore;
}
/**
* Set documentId.
*
* @param mixed $document
*
* @return GradebookCategory
*/
public function setDocument($document)
public function setDocument(?CDocument $document): static
{
$this->document = $document;
return $this;
}
/**
* Get documentId.
*
* @return CDocument|null
*/
public function getDocument()
public function getDocument(): ?CDocument
{
return $this->document;
}

@ -29,6 +29,7 @@ use Chamilo\CoreBundle\Filter\CidFilter;
use Chamilo\CoreBundle\Filter\SidFilter;
use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
@ -172,9 +173,9 @@ class CDocument extends AbstractResource implements ResourceInterface, ResourceS
#[ORM\Column(name: 'template', type: 'boolean', nullable: false)]
protected bool $template;
#[ORM\OneToMany(mappedBy: 'document', targetEntity: GradebookCategory::class)]
#[Groups(['document:read'])]
protected Collection $gradebookCategories;
#[ORM\OneToMany(mappedBy: 'document', targetEntity: GradebookCategory::class)]
private Collection $gradebookCategories;
public function __construct()
{
@ -277,4 +278,26 @@ class CDocument extends AbstractResource implements ResourceInterface, ResourceS
{
return $this->gradebookCategories;
}
public function addGradebookCategory(GradebookCategory $gradebookCategory): static
{
if (!$this->gradebookCategories->contains($gradebookCategory)) {
$this->gradebookCategories->add($gradebookCategory);
$gradebookCategory->setDocument($this);
}
return $this;
}
public function removeGradebookCategory(GradebookCategory $gradebookCategory): static
{
if ($this->gradebookCategories->removeElement($gradebookCategory)) {
// set the owning side to null (unless already changed)
if ($gradebookCategory->getDocument() === $this) {
$gradebookCategory->setDocument(null);
}
}
return $this;
}
}

Loading…
Cancel
Save