-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mthinon
committed
Oct 11, 2024
1 parent
9a722a0
commit 19580e5
Showing
5 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20241011100716 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE user_history (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, question_id INT NOT NULL, answer_correctly TINYINT(1) NOT NULL, date DATE NOT NULL, INDEX IDX_7FB76E41A76ED395 (user_id), INDEX IDX_7FB76E411E27F6BF (question_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE user_history ADD CONSTRAINT FK_7FB76E41A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); | ||
$this->addSql('ALTER TABLE user_history ADD CONSTRAINT FK_7FB76E411E27F6BF FOREIGN KEY (question_id) REFERENCES question (id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE user_history DROP FOREIGN KEY FK_7FB76E41A76ED395'); | ||
$this->addSql('ALTER TABLE user_history DROP FOREIGN KEY FK_7FB76E411E27F6BF'); | ||
$this->addSql('DROP TABLE user_history'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use App\Repository\UserHistoryRepository; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity(repositoryClass: UserHistoryRepository::class)] | ||
class UserHistory | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private ?int $id = null; | ||
|
||
#[ORM\ManyToOne] | ||
#[ORM\JoinColumn(nullable: false)] | ||
private ?User $user = null; | ||
|
||
#[ORM\ManyToOne(inversedBy: 'userHistories')] | ||
#[ORM\JoinColumn(nullable: false)] | ||
private ?Question $question = null; | ||
|
||
#[ORM\Column] | ||
private ?bool $answerCorrectly = null; | ||
|
||
#[ORM\Column(type: Types::DATE_MUTABLE)] | ||
private ?\DateTimeInterface $date = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getUser(): ?User | ||
{ | ||
return $this->user; | ||
} | ||
|
||
public function setUser(?User $user): static | ||
{ | ||
$this->user = $user; | ||
|
||
return $this; | ||
} | ||
|
||
public function getQuestion(): ?Question | ||
{ | ||
return $this->question; | ||
} | ||
|
||
public function setQuestion(?Question $question): static | ||
{ | ||
$this->question = $question; | ||
|
||
return $this; | ||
} | ||
|
||
public function isAnswerCorrectly(): ?bool | ||
{ | ||
return $this->answerCorrectly; | ||
} | ||
|
||
public function setAnswerCorrectly(bool $answerCorrectly): static | ||
{ | ||
$this->answerCorrectly = $answerCorrectly; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDate(): ?\DateTimeInterface | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function setDate(\DateTimeInterface $date): static | ||
{ | ||
$this->date = $date; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\UserHistory; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @extends ServiceEntityRepository<UserHistory> | ||
*/ | ||
class UserHistoryRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, UserHistory::class); | ||
} | ||
|
||
// /** | ||
// * @return UserHistory[] Returns an array of UserHistory objects | ||
// */ | ||
// public function findByExampleField($value): array | ||
// { | ||
// return $this->createQueryBuilder('u') | ||
// ->andWhere('u.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->orderBy('u.id', 'ASC') | ||
// ->setMaxResults(10) | ||
// ->getQuery() | ||
// ->getResult() | ||
// ; | ||
// } | ||
|
||
// public function findOneBySomeField($value): ?UserHistory | ||
// { | ||
// return $this->createQueryBuilder('u') | ||
// ->andWhere('u.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->getQuery() | ||
// ->getOneOrNullResult() | ||
// ; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters