Internal: Add entity relation between TrackEExercise and TrackEAttemptRecording - refs BT#21114

pull/4932/head
Angel Fernando Quiroz Campos 1 year ago
parent 7c1c1b8cea
commit 05d0f9f64e
  1. 9
      public/main/exercise/exercise_report.php
  2. 3
      public/main/inc/lib/events.lib.php
  3. 13
      src/CoreBundle/Entity/TrackEAttemptRecording.php
  4. 35
      src/CoreBundle/Entity/TrackEExercise.php
  5. 3
      src/CoreBundle/Migrations/Schema/V200/Version20231009124500.php

@ -3,6 +3,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\TrackEAttemptRecording;
use Chamilo\CoreBundle\Entity\TrackEExercise;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CLp;
@ -167,6 +168,10 @@ if (isset($_REQUEST['comments']) &&
api_not_allowed();
}
$em = Database::getManager();
$trackExercise = $em->find(TrackEExercise::class, $id);
$student_id = $track_exercise_info['exe_user_id'];
$session_id = $track_exercise_info['session_id'];
$lp_id = $track_exercise_info['orig_lp_id'];
@ -238,16 +243,14 @@ if (isset($_REQUEST['comments']) &&
$recording = new TrackEAttemptRecording();
$recording
->setExeId($id)
->setTrackExercise($trackExercise)
->setQuestionId($questionId)
->setAuthor(api_get_user_id())
->setTeacherComment($my_comments)
->setExeId($id)
->setMarks($marks)
->setSessionId(api_get_session_id())
;
$em = Database::getManager();
$em->persist($recording);
$em->flush();
}

@ -615,11 +615,12 @@ class Event
$em = Database::getManager();
if (false == $updateResults) {
$attempt_id = Database::insert($TBL_TRACK_ATTEMPT, $attempt);
$trackExercise = $em->find(TrackEExercise::class, $exe_id);
if ($attempt_id) {
$recording = new TrackEAttemptRecording();
$recording
->setExeId($attempt_id)
->setTrackExercise($trackExercise)
->setQuestionId($question_id)
->setAnswer($answer)
->setMarks((int) $score)

@ -22,8 +22,9 @@ class TrackEAttemptRecording
#[ORM\GeneratedValue]
protected ?int $id = null;
#[ORM\Column(name: 'exe_id', type: 'integer', nullable: false)]
protected int $exeId;
#[ORM\ManyToOne(inversedBy: 'revisedAttempts')]
#[ORM\JoinColumn(name: 'exe_id', referencedColumnName: 'exe_id', nullable: false)]
private ?TrackEExercise $trackExercise = null;
#[ORM\Column(name: 'question_id', type: 'integer', nullable: false)]
protected int $questionId;
@ -55,14 +56,14 @@ class TrackEAttemptRecording
$this->author = 0;
}
public function getExeId(): int
public function getTrackExercise(): ?TrackEExercise
{
return $this->exeId;
return $this->trackExercise;
}
public function setExeId(int $exeId): static
public function setTrackExercise(?TrackEExercise $trackExercise): static
{
$this->exeId = $exeId;
$this->trackExercise = $trackExercise;
return $this;
}

@ -173,9 +173,14 @@ class TrackEExercise
#[ORM\OneToMany(mappedBy: 'trackExercise', targetEntity: TrackEAttempt::class, cascade: ['persist'])]
protected Collection $attempts;
#[Groups(['track_e_exercise:read'])]
#[ORM\OneToMany(mappedBy: 'trackExercise', targetEntity: TrackEAttemptRecording::class, orphanRemoval: true)]
private Collection $revisedAttempts;
public function __construct()
{
$this->attempts = new ArrayCollection();
$this->revisedAttempts = new ArrayCollection();
$this->questionsToCheck = '';
$this->blockedCategories = '';
$this->dataTracking = '';
@ -448,4 +453,34 @@ class TrackEExercise
return null;
}
/**
* @return Collection<int, TrackEAttemptRecording>
*/
public function getRevisedAttempts(): Collection
{
return $this->revisedAttempts;
}
public function addRevisedAttempt(TrackEAttemptRecording $revisedAttempt): static
{
if (!$this->revisedAttempts->contains($revisedAttempt)) {
$this->revisedAttempts->add($revisedAttempt);
$revisedAttempt->setTrackExercise($this);
}
return $this;
}
public function removeRevisedAttempt(TrackEAttemptRecording $revisedAttempt): static
{
if ($this->revisedAttempts->removeElement($revisedAttempt)) {
// set the owning side to null (unless already changed)
if ($revisedAttempt->getTrackExercise() === $this) {
$revisedAttempt->setTrackExercise(null);
}
}
return $this;
}
}

@ -22,5 +22,8 @@ class Version20231009124500 extends AbstractMigrationChamilo
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE track_e_attempt_recording CHANGE marks marks DOUBLE PRECISION NOT NULL');
$this->addSql('DELETE FROM track_e_attempt_recording WHERE exe_id NOT IN (SELECT exe_id FROM track_e_exercises)');
$this->addSql('ALTER TABLE track_e_attempt_recording ADD CONSTRAINT FK_369B2007B5A18F57 FOREIGN KEY (exe_id) REFERENCES track_e_exercises (exe_id)');
}
}

Loading…
Cancel
Save