Add entity relationship TrackEExercise::cQuiz - refs BT#19741

pull/4202/head
Angel Fernando Quiroz Campos 4 years ago
parent bd75ec3a38
commit 52a86dfd8b
  1. 18
      public/main/exercise/exercise.class.php
  2. 2
      public/main/inc/ajax/exercise.ajax.php
  3. 2
      public/main/inc/lib/events.lib.php
  4. 2
      public/main/inc/lib/exercise.lib.php
  5. 17
      src/CoreBundle/Entity/TrackEExercise.php
  6. 11
      src/CoreBundle/Migrations/Schema/V200/Version20180904175500.php
  7. 11
      src/CourseBundle/Entity/CQuiz.php
  8. 6
      tests/CoreBundle/Repository/TrackExerciseRepositoryTest.php

@ -4,9 +4,9 @@
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\CoreBundle\Entity\GradebookLink;
use Chamilo\CoreBundle\Entity\TrackEExercise;
use Chamilo\CoreBundle\Entity\TrackEExerciseConfirmation;
use Chamilo\CoreBundle\Entity\TrackEHotspot;
use Chamilo\CoreBundle\Entity\TrackEExercise;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CExerciseCategory;
use Chamilo\CourseBundle\Entity\CQuiz;
@ -3059,13 +3059,17 @@ class Exercise
/**
* Saves a test attempt.
*
* @param int $clock_expired_time clock_expired_time
* @param int int lp id
* @param int int lp item id
* @param int int lp item_view id
* @param int $clock_expired_time clock_expired_time
* @param int $safe_lp_id lp id
* @param int $safe_lp_item_id lp item id
* @param int $safe_lp_item_view_id lp item_view id
* @param array $questionList
* @param float $weight
*
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
*
* @return int
*/
public function save_stat_track_exercise_info(
@ -3087,6 +3091,8 @@ class Exercise
$questionList = array_map('intval', $questionList);
$em = Database::getManager();
$quiz = $em->find(CQuiz::class, $this->getId());
$trackExercise = (new TrackEExercise())
->setSession(api_get_session_entity())
->setCourse(api_get_course_entity())
@ -3098,7 +3104,7 @@ class Exercise
->setOrigLpItemId($safe_lp_item_id)
->setOrigLpItemViewId($safe_lp_item_view_id)
->setExpiredTimeControl($clock_expired_time)
->setExeExoId($this->getId())
->setQuiz($quiz)
;
$em->persist($trackExercise);
$em->flush();

@ -79,7 +79,7 @@ switch ($action) {
$nowObject = api_get_utc_datetime(null, false, true);
$now = $nowObject->getTimestamp();
$exerciseId = $attempt->getExeExoId();
$exerciseId = $attempt->getQuiz()?->getIid();
$userId = $attempt->getUser()->getId();
if ($userId != $currentUserId) {

@ -1241,7 +1241,7 @@ class Event
self::addEvent(
LOG_EXERCISE_RESULT_DELETE,
LOG_EXERCISE_AND_USER_ID,
$track->getExeExoId().'-'.$track->getUser()->getId(),
($track->getQuiz()?->getIid()).'-'.$track->getUser()->getId(),
null,
null,
$course_id,

@ -5390,7 +5390,7 @@ EOT;
}
if ($trackedExercise->getUser()->getId() != $userId ||
$trackedExercise->getExeExoId() != $exerciseId
$trackedExercise->getQuiz()?->getIid() != $exerciseId
) {
return null;
}

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CourseBundle\Entity\CQuiz;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -59,10 +60,10 @@ class TrackEExercise
protected DateTime $exeDate;
/**
* @ORM\Column(name="exe_exo_id", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CQuiz", inversedBy="attempts")
* @ORM\JoinColumn(name="exe_exo_id", referencedColumnName="iid", nullable=true, onDelete="SET NULL")
*/
#[Assert\NotBlank]
protected int $exeExoId;
protected ?CQuiz $quiz;
/**
* @ORM\Column(name="score", type="float", precision=6, scale=2, nullable=false)
@ -143,7 +144,7 @@ class TrackEExercise
protected ?string $blockedCategories;
/**
* @var Collection|TrackEAttempt[]
* @var Collection<int, TrackEAttempt>
*
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEAttempt", mappedBy="trackExercise", cascade={"persist"})
*/
@ -180,16 +181,16 @@ class TrackEExercise
return $this->exeDate;
}
public function setExeExoId(int $exeExoId): self
public function setQuiz(CQuiz $cQuiz): self
{
$this->exeExoId = $exeExoId;
$this->quiz = $cQuiz;
return $this;
}
public function getExeExoId(): int
public function getQuiz(): ?CQuiz
{
return $this->exeExoId;
return $this->quiz;
}
public function setUserIp(string $userIp): self

@ -132,6 +132,17 @@ class Version20180904175500 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE track_e_exercises ADD blocked_categories LONGTEXT DEFAULT NULL');
}
$this->addSql('ALTER TABLE track_e_exercises CHANGE exe_exo_id exe_exo_id INT DEFAULT NULL');
$this->addSql("UPDATE track_e_exercises SET exe_exo_id = NULL WHERE exe_exo_id NOT IN (SELECT iid FROM c_quiz)");
if (!$table->hasForeignKey('FK_AA0DA082B9773F9E')) {
$this->addSql('ALTER TABLE track_e_exercises ADD CONSTRAINT FK_AA0DA082B9773F9E FOREIGN KEY (exe_exo_id) REFERENCES c_quiz (iid) ON DELETE SET NULL');
}
if (!$table->hasIndex('IDX_AA0DA082B9773F9E')) {
$this->addSql('CREATE INDEX IDX_AA0DA082B9773F9E ON track_e_exercises (exe_exo_id)');
}
$table = $schema->getTable('track_e_hotspot');
$this->addSql('DELETE FROM track_e_hotspot WHERE c_id NOT IN (SELECT id FROM course)');

@ -9,6 +9,7 @@ namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface;
use Chamilo\CoreBundle\Entity\TrackEExercise;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -203,6 +204,13 @@ class CQuiz extends AbstractResource implements ResourceInterface, ResourceShowC
*/
protected Collection $questionsCategories;
/**
* @var Collection<int, TrackEExercise>
*
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEExercise", mappedBy="quiz")
*/
protected Collection $attempts;
public function __construct()
{
$this->questions = new ArrayCollection();
@ -227,6 +235,7 @@ class CQuiz extends AbstractResource implements ResourceInterface, ResourceShowC
$this->randomByCategory = 0;
$this->displayCategoryName = 0;
$this->pageResultConfiguration = [];
$this->attempts = new ArrayCollection();
}
public function __toString(): string
@ -648,7 +657,7 @@ class CQuiz extends AbstractResource implements ResourceInterface, ResourceShowC
/**
* @return int
*/
public function getIid()
public function getIid(): int
{
return $this->iid;
}

@ -65,7 +65,7 @@ class TrackEExerciseRepositoryTest extends AbstractApiTest
->setOrigLpItemViewId(0)
->setExeDuration(10)
->setExpiredTimeControl(new DateTime())
->setExeExoId($exercise->getIid())
->setQuiz($exercise)
;
$em->persist($trackExercise);
$this->assertHasNoEntityViolations($trackExercise);
@ -131,7 +131,7 @@ class TrackEExerciseRepositoryTest extends AbstractApiTest
->setOrigLpItemViewId(0)
->setExeDuration(10)
->setExpiredTimeControl(new DateTime())
->setExeExoId($exercise->getIid())
->setQuiz($exercise)
;
$em->persist($trackExercise);
$this->assertHasNoEntityViolations($trackExercise);
@ -204,7 +204,7 @@ class TrackEExerciseRepositoryTest extends AbstractApiTest
->setOrigLpItemViewId(0)
->setExeDuration(10)
->setExpiredTimeControl(new DateTime())
->setExeExoId($exercise->getIid())
->setQuiz($exercise)
->addAttempt($attempt)
;
$em->persist($attempt);

Loading…
Cancel
Save