diff --git a/src/CoreBundle/Entity/TrackEAttempt.php b/src/CoreBundle/Entity/TrackEAttempt.php index 1dc6e14dcd..9d220197f7 100644 --- a/src/CoreBundle/Entity/TrackEAttempt.php +++ b/src/CoreBundle/Entity/TrackEAttempt.php @@ -1,9 +1,9 @@ ['track_e_attempt:read']])] +#[ApiResource( + operations: [ + new Get(security: 'is_granted("VIEW", object)'), + new GetCollection(security: 'is_granted("ROLE_USER")'), + ], + normalizationContext: [ + 'groups' => ['track_e_attempt:read'], + ], + security: 'is_granted("ROLE_USER")' +)] #[ORM\Table(name: 'track_e_attempt')] -#[ORM\Index(name: 'exe_id', columns: ['exe_id'])] -#[ORM\Index(name: 'user_id', columns: ['user_id'])] -#[ORM\Index(name: 'question_id', columns: ['question_id'])] -#[ORM\Index(name: 'idx_track_e_attempt_tms', columns: ['tms'])] +#[ORM\Index(columns: ['exe_id'], name: 'exe_id')] +#[ORM\Index(columns: ['user_id'], name: 'user_id')] +#[ORM\Index(columns: ['question_id'], name: 'question_id')] +#[ORM\Index(columns: ['tms'], name: 'idx_track_e_attempt_tms')] #[ORM\Entity] -#[ApiFilter(filterClass: SearchFilter::class, properties: ['user' => 'exact', 'questionId' => 'exact', 'answer' => 'exact', 'marks' => 'exact'])] +#[ApiFilter( + filterClass: SearchFilter::class, + properties: [ + 'user' => 'exact', + 'questionId' => 'exact', + 'answer' => 'exact', + 'marks' => 'exact', + ] +)] class TrackEAttempt { use UserTrait; + #[ORM\Column(name: 'id', type: 'integer')] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] protected ?int $id = null; + #[Assert\NotNull] - #[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\TrackEExercise::class, inversedBy: 'attempts')] + #[ORM\ManyToOne(targetEntity: TrackEExercise::class, inversedBy: 'attempts')] #[ORM\JoinColumn(name: 'exe_id', referencedColumnName: 'exe_id', nullable: false, onDelete: 'CASCADE')] protected TrackEExercise $trackExercise; + #[Assert\NotNull] #[Groups(['track_e_attempt:read'])] - #[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\User::class, inversedBy: 'trackEAttempts')] + #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'trackEAttempts')] #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')] protected User $user; + #[Assert\NotBlank] #[Groups(['track_e_attempt:read'])] #[ORM\Column(name: 'question_id', type: 'integer', nullable: false)] protected ?int $questionId = null; + #[Groups(['track_e_attempt:read'])] #[ORM\Column(name: 'answer', type: 'text', nullable: false)] protected string $answer; + #[ORM\Column(name: 'teacher_comment', type: 'text', nullable: false)] protected string $teacherComment; + #[Groups(['track_e_attempt:read'])] #[ORM\Column(name: 'marks', type: 'float', precision: 6, scale: 2, nullable: false)] protected float $marks; + #[ORM\Column(name: 'position', type: 'integer', nullable: true)] protected ?int $position = null; + #[Assert\NotNull] #[ORM\Column(name: 'tms', type: 'datetime', nullable: false)] protected DateTime $tms; + #[ORM\Column(name: 'filename', type: 'string', length: 255, nullable: true)] protected ?string $filename = null; + #[ORM\Column(name: 'seconds_spent', type: 'integer')] protected int $secondsSpent; + /** - * @var Collection|AttemptFile[] + * @var Collection */ - #[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\AttemptFile::class, mappedBy: 'attempt', cascade: ['persist'], orphanRemoval: true)] + #[ORM\OneToMany( + mappedBy: 'attempt', + targetEntity: AttemptFile::class, + cascade: ['persist'], + orphanRemoval: true + )] protected Collection $attemptFiles; + /** - * @var Collection|AttemptFeedback[] + * @var Collection */ - #[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\AttemptFeedback::class, mappedBy: 'attempt', cascade: ['persist'], orphanRemoval: true)] + #[ORM\OneToMany( + mappedBy: 'attempt', + targetEntity: AttemptFeedback::class, + cascade: ['persist'], + orphanRemoval: true + )] protected Collection $attemptFeedbacks; + public function __construct() { $this->attemptFiles = new ArrayCollection(); @@ -84,187 +125,168 @@ class TrackEAttempt $this->teacherComment = ''; $this->secondsSpent = 0; } + + public function getQuestionId(): ?int + { + return $this->questionId; + } + public function setQuestionId(int $questionId): self { $this->questionId = $questionId; return $this; } - /** - * Get questionId. - * - * @return int - */ - public function getQuestionId() + + public function getAnswer(): string { - return $this->questionId; + return $this->answer; } + public function setAnswer(string $answer): self { $this->answer = $answer; return $this; } - /** - * Get answer. - * - * @return string - */ - public function getAnswer() + + public function getTeacherComment(): string { - return $this->answer; + return $this->teacherComment; } + public function setTeacherComment(string $teacherComment): self { $this->teacherComment = $teacherComment; return $this; } - /** - * Get teacherComment. - * - * @return string - */ - public function getTeacherComment() + + public function getMarks(): float { - return $this->teacherComment; + return $this->marks; } + public function setMarks(float $marks): self { $this->marks = $marks; return $this; } - /** - * Get marks. - * - * @return float - */ - public function getMarks() + + public function getPosition(): ?int { - return $this->marks; + return $this->position; } + public function setPosition(int $position): self { $this->position = $position; return $this; } - /** - * Get position. - * - * @return int - */ - public function getPosition() + + public function getTms(): DateTime { - return $this->position; + return $this->tms; } + public function setTms(DateTime $tms): self { $this->tms = $tms; return $this; } - /** - * Get tms. - * - * @return DateTime - */ - public function getTms() + + public function getFilename(): ?string { - return $this->tms; + return $this->filename; } - /** - * Set filename. - * - * @return TrackEAttempt - */ - public function setFilename(string $filename) + + public function setFilename(string $filename): static { $this->filename = $filename; return $this; } - /** - * Get filename. - * - * @return string - */ - public function getFilename() - { - return $this->filename; - } - /** - * Get id. - * - * @return int - */ - public function getId() + + public function getId(): ?int { return $this->id; } + public function getUser(): User { return $this->user; } + public function setUser(User $user): self { $this->user = $user; return $this; } + public function getTrackEExercise(): TrackEExercise { return $this->trackExercise; } + public function setTrackEExercise(TrackEExercise $trackExercise): self { $this->trackExercise = $trackExercise; return $this; } + public function getSecondsSpent(): int { return $this->secondsSpent; } + public function setSecondsSpent(int $secondsSpent): self { $this->secondsSpent = $secondsSpent; return $this; } + /** - * @return AttemptFile[]|Collection + * @return Collection */ - public function getAttemptFiles(): array|Collection + public function getAttemptFiles(): Collection { return $this->attemptFiles; } + /** - * @param AttemptFile[]|Collection $attemptFiles + * @param Collection $attemptFiles */ - public function setAttemptFiles(array|Collection $attemptFiles): self + public function setAttemptFiles(Collection $attemptFiles): self { $this->attemptFiles = $attemptFiles; return $this; } + /** - * @return AttemptFeedback[]|Collection + * @return Collection */ - public function getAttemptFeedbacks(): array|Collection + public function getAttemptFeedbacks(): Collection { return $this->attemptFeedbacks; } + /** - * @param AttemptFeedback[]|Collection $attemptFeedbacks + * @param Collection $attemptFeedbacks */ - public function setAttemptFeedbacks(array|Collection $attemptFeedbacks): self + public function setAttemptFeedbacks(Collection $attemptFeedbacks): self { $this->attemptFeedbacks = $attemptFeedbacks; return $this; } + public function addAttemptFeedback(AttemptFeedback $attemptFeedback): self { if (!$this->attemptFeedbacks->contains($attemptFeedback)) { @@ -274,6 +296,7 @@ class TrackEAttempt return $this; } + public function addAttemptFile(AttemptFile $attemptFile): self { if (!$this->attemptFiles->contains($attemptFile)) { diff --git a/src/CoreBundle/Entity/TrackEAttemptRecording.php b/src/CoreBundle/Entity/TrackEAttemptRecording.php index 15025b7f1f..2899515101 100644 --- a/src/CoreBundle/Entity/TrackEAttemptRecording.php +++ b/src/CoreBundle/Entity/TrackEAttemptRecording.php @@ -1,22 +1,19 @@ author = 0; } - /** - * Set exeId. - * - * @return TrackEAttemptRecording - */ - public function setExeId(int $exeId) + public function getExeId(): int + { + return $this->exeId; + } + + public function setExeId(int $exeId): static { $this->exeId = $exeId; return $this; } - /** - * Get exeId. - * - * @return int - */ - public function getExeId() + public function getQuestionId(): int { - return $this->exeId; + return $this->questionId; } - /** - * Set questionId. - * - * @return TrackEAttemptRecording - */ - public function setQuestionId(int $questionId) + public function setQuestionId(int $questionId): static { $this->questionId = $questionId; return $this; } - /** - * Get questionId. - * - * @return int - */ - public function getQuestionId() + public function getMarks(): int { - return $this->questionId; + return $this->marks; } public function setMarks(int $marks): self @@ -109,14 +91,9 @@ class TrackEAttemptRecording return $this; } - /** - * Get marks. - * - * @return int - */ - public function getMarks() + public function getInsertDate(): DateTime { - return $this->marks; + return $this->insertDate; } public function setInsertDate(DateTime $insertDate): self @@ -126,36 +103,21 @@ class TrackEAttemptRecording return $this; } - /** - * Get insertDate. - * - * @return DateTime - */ - public function getInsertDate() + public function getAuthor(): int { - return $this->insertDate; + return $this->author; } - /** - * Set author. - * - * @return TrackEAttemptRecording - */ - public function setAuthor(int $author) + public function setAuthor(int $author): static { $this->author = $author; return $this; } - /** - * Get author. - * - * @return int - */ - public function getAuthor() + public function getTeacherComment(): string { - return $this->author; + return $this->teacherComment; } public function setTeacherComment(string $teacherComment): self @@ -165,44 +127,19 @@ class TrackEAttemptRecording return $this; } - /** - * Get teacherComment. - * - * @return string - */ - public function getTeacherComment() + public function getSessionId(): int { - return $this->teacherComment; + return $this->sessionId; } - /** - * Set sessionId. - * - * @return TrackEAttemptRecording - */ - public function setSessionId(int $sessionId) + public function setSessionId(int $sessionId): static { $this->sessionId = $sessionId; return $this; } - /** - * Get sessionId. - * - * @return int - */ - public function getSessionId() - { - return $this->sessionId; - } - - /** - * Get id. - * - * @return int - */ - public function getId() + public function getId(): ?int { return $this->id; }