Skip to content

Commit

Permalink
Portfolio: Add portfolio_show_base_course_post_in_sessions conf setti…
Browse files Browse the repository at this point in the history
…ng - refs BT#22232

Show base course posts in session course. Requires DB changes and edit the Portfolio entity adding the "@" symbol to the beginning of ORM\ManyToOne, ORM\JoinColumn, ORM\OneToMany lines for the Portfolio::$duplicatedFrom and Portfolio::$duplicates properties.

ALTER TABLE portfolio ADD duplicated_from INT DEFAULT NULL;
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062FC4CB679 FOREIGN KEY (duplicated_from) REFERENCES portfolio (id) ON DELETE SET NULL;
CREATE INDEX IDX_A9ED1062FC4CB679 ON portfolio (duplicated_from);
  • Loading branch information
AngelFQC committed Dec 23, 2024
1 parent 34975cd commit e661cbb
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,14 @@
// ALTER TABLE portfolio_comment ADD visibility SMALLINT DEFAULT 1 NOT NULL;
// Then add the "@" symbol to the CPortfolioComment::$visibility property in the ORM\Column() line.
//$_configuration['portfolio_advanced_sharing'] = false;
// Show base course posts in session course. Requires DB changes and edit the Portfolio entity
// adding the "@" symbol to the beginning of ORM\ManyToOne, ORM\JoinColumn, ORM\OneToMany lines for the Portfolio::$duplicatedFrom and Portfolio::$duplicates properties.
/*
ALTER TABLE portfolio ADD duplicated_from INT DEFAULT NULL;
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062FC4CB679 FOREIGN KEY (duplicated_from) REFERENCES portfolio (id) ON DELETE SET NULL;
CREATE INDEX IDX_A9ED1062FC4CB679 ON portfolio (duplicated_from);
*/
//$_configuration['portfolio_show_base_course_post_in_sessions'] = false;

// DEPRECATED: gradebook_enable_best_score is deprecated. Use gradebook_display_extra_stats instead.
// Enable best score column in gradebook. Previously called disable_gradebook_stats
Expand Down
75 changes: 75 additions & 0 deletions src/Chamilo/CoreBundle/Entity/Portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,26 @@ class Portfolio
*/
private bool $isTemplate = false;

/**
* ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Portfolio", inversedBy="duplicates")
* ORM\JoinColumn(name="duplicated_from", onDelete="SET NULL")
*/
private ?Portfolio $duplicatedFrom = null;

/**
* @var Collection<int, Portfolio>
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Portfolio", mappedBy="duplicatedFrom")
*/
private Collection $duplicates;

/**
* Portfolio constructor.
*/
public function __construct()
{
$this->category = null;
$this->comments = new ArrayCollection();
$this->duplicates = new ArrayCollection();
}

public function setUser(User $user): Portfolio
Expand Down Expand Up @@ -332,4 +345,66 @@ public function setIsTemplate(bool $isTemplate): Portfolio

return $this;
}

public function getDuplicatedFrom(): ?Portfolio
{
return $this->duplicatedFrom;
}

public function setDuplicatedFrom(?Portfolio $duplicatedFrom): Portfolio
{
$this->duplicatedFrom = $duplicatedFrom;

return $this;
}

/**
* @return Collection<int, Portfolio>
*/
public function getDuplicates(): Collection
{
return $this->duplicates;
}

public function addDuplicate(Portfolio $duplicate): Portfolio
{
if (!$this->duplicates->contains($duplicate)) {
$this->duplicates->add($duplicate);
$duplicate->setDuplicatedFrom($this);
}

return $this;
}

public function removeDuplicate(Portfolio $duplicate): Portfolio
{
if ($this->duplicates->removeElement($duplicate)) {
// set the owning side to null (unless already changed)
if ($duplicate->getDuplicatedFrom() === $this) {
$duplicate->setDuplicatedFrom(null);
}
}

return $this;
}

public function hasDuplicates(): bool
{
return $this->duplicates->count() > 0;
}

public function isDuplicated(): bool
{
return null !== $this->duplicatedFrom;
}

public function isDuplicatedInSession(Session $session): bool
{
return $this->duplicates->exists(fn($key, Portfolio $duplicated): bool => $duplicated->session === $session);
}

public function isDuplicatedInSessionId(int $sessionId): bool
{
return $this->duplicates->exists(fn($key, Portfolio $duplicated): bool => $duplicated->session && $duplicated->session->getId() === $sessionId);
}
}

0 comments on commit e661cbb

Please sign in to comment.