Fix entity properties + add migration for session promotion relation

pull/3844/head
Julio Montoya 5 years ago
parent 290391fb9b
commit 0bdacbb145
  1. 17
      src/CoreBundle/Entity/Promotion.php
  2. 45
      src/CoreBundle/Entity/Session.php
  3. 2
      src/CoreBundle/Entity/SessionRelUser.php
  4. 6
      src/CoreBundle/Migrations/Schema/V200/Version20190210182615.php

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Validator\Constraints as Assert;
@ -47,6 +48,15 @@ class Promotion
*/
protected Career $career;
/**
* @var Collection|Session[]
*
* @ORM\OneToMany(
* targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="promotion", cascade={"persist"}
* )
*/
protected Collection $sessions;
/**
* @ORM\Column(name="status", type="integer", nullable=false)
*/
@ -67,12 +77,7 @@ class Promotion
return $this->id;
}
/**
* Set name.
*
* @return Promotion
*/
public function setName(string $name)
public function setName(string $name): self
{
$this->name = $name;

@ -187,6 +187,15 @@ class Session
*/
protected User $sessionAdmin;
/**
* @Assert\NotBlank
* @Groups({"session:read", "session:write"})
*
* @ORM\ManyToOne(targetEntity="User", inversedBy="sessionsAsGeneralCoach")
* @ORM\JoinColumn(name="id_coach", referencedColumnName="id")
*/
protected User $generalCoach;
/**
* @Groups({"session:read"})
* @ORM\Column(name="visibility", type="integer")
@ -194,9 +203,10 @@ class Session
protected int $visibility;
/**
* @ORM\Column(name="promotion_id", type="integer", nullable=true, unique=false)
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Promotion", inversedBy="sessions", cascade={"persist"})
* @ORM\JoinColumn(name="promotion_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected ?int $promotionId = null;
protected ?Promotion $promotion;
/**
* @Groups({"session:read"})
@ -242,15 +252,6 @@ class Session
*/
protected int $status;
/**
* @Assert\NotBlank
* @Groups({"session:read", "session:write"})
*
* @ORM\ManyToOne(targetEntity="User", inversedBy="sessionsAsGeneralCoach")
* @ORM\JoinColumn(name="id_coach", referencedColumnName="id")
*/
protected User $generalCoach;
/**
* @Groups({"session:read", "session:write"})
* @ORM\ManyToOne(targetEntity="SessionCategory", inversedBy="session")
@ -658,26 +659,16 @@ class Session
return $this->visibility;
}
/**
* Set promotionId.
*
* @return Session
*/
public function setPromotionId(int $promotionId)
public function getPromotion(): ?Promotion
{
$this->promotionId = $promotionId;
return $this;
return $this->promotion;
}
/**
* Get promotionId.
*
* @return int
*/
public function getPromotionId()
public function setPromotion(?Promotion $promotion): self
{
return $this->promotionId;
$this->promotion = $promotion;
return $this;
}
/**

@ -48,7 +48,7 @@ class SessionRelUser
protected Session $session;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="sessions", cascade={"persist"})
* @ORM\ManyToOne(targetEntity="User", inversedBy="sessionsRelUser", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected User $user;

@ -23,6 +23,12 @@ class Version20190210182615 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE session CHANGE position position INT DEFAULT 0 NOT NULL');
}
$this->addSql('UPDATE session SET promotion_id = NULL WHERE promotion_id = 0');
if (false === $table->hasForeignKey('FK_D044D5D4139DF194')) {
$this->addSql('ALTER TABLE session ADD CONSTRAINT FK_D044D5D4139DF194 FOREIGN KEY (promotion_id) REFERENCES promotion (id) ON DELETE CASCADE');
$this->addSql('CREATE INDEX IDX_D044D5D4139DF194 ON session (promotion_id);');
}
if (false === $table->hasColumn('status')) {
$this->addSql('ALTER TABLE session ADD COLUMN status INT NOT NULL');
}

Loading…
Cancel
Save