Commit a8dc13d5 authored by Anthony Gautreau's avatar Anthony Gautreau
Browse files

Entités, tables et routes Pegase (/ounits, /programmes, /courses, /instances) au format OCCAPI

parent 5c158fb5
Loading
Loading
Loading
Loading
+148
Changes for api/migrations/Version20261008150816.php: 148 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20261008150816 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Tables de l\'import Pegase (ounit, programme, course, course_instance, pegase_import_log)';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE SEQUENCE pegase_import_log_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql(<<<'SQL'
            CREATE TABLE course (
              code VARCHAR(255) NOT NULL,
              title JSON NOT NULL,
              ects DOUBLE PRECISION DEFAULT NULL,
              language_of_instruction JSON NOT NULL,
              academic_term JSON NOT NULL,
              description JSON DEFAULT NULL,
              deprecated BOOLEAN NOT NULL,
              diploma_code VARCHAR(255) DEFAULT NULL,
              diploma_title JSON DEFAULT NULL,
              last_modified TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
              ounit_id VARCHAR DEFAULT NULL,
              PRIMARY KEY (code)
            )
        SQL);
        $this->addSql('CREATE INDEX IDX_169E6FB9938C20D ON course (ounit_id)');
        $this->addSql(<<<'SQL'
            CREATE TABLE course_programme (
              course_code VARCHAR NOT NULL,
              programme_code VARCHAR NOT NULL,
              PRIMARY KEY (course_code, programme_code)
            )
        SQL);
        $this->addSql('CREATE INDEX IDX_BF7DF953BFB7ED9E ON course_programme (course_code)');
        $this->addSql('CREATE INDEX IDX_BF7DF9536E5502F5 ON course_programme (programme_code)');
        $this->addSql(<<<'SQL'
            CREATE TABLE course_instance (
              id VARCHAR(255) NOT NULL,
              academic_term_id VARCHAR(255) NOT NULL,
              start_date DATE NOT NULL,
              end_date DATE NOT NULL,
              ects DOUBLE PRECISION DEFAULT NULL,
              language_of_instruction JSON NOT NULL,
              engagement_hours DOUBLE PRECISION DEFAULT NULL,
              catalogue_ounit JSON DEFAULT NULL,
              catalogue_group JSON DEFAULT NULL,
              last_modified TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
              course_code VARCHAR NOT NULL,
              PRIMARY KEY (id)
            )
        SQL);
        $this->addSql('CREATE INDEX IDX_EB84DC88BFB7ED9E ON course_instance (course_code)');
        $this->addSql(<<<'SQL'
            CREATE TABLE ounit (
              ounit_id VARCHAR(255) NOT NULL,
              title JSON NOT NULL,
              abbreviation VARCHAR(255) DEFAULT NULL,
              last_modified TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
              PRIMARY KEY (ounit_id)
            )
        SQL);
        $this->addSql(<<<'SQL'
            CREATE TABLE pegase_import_log (
              id INT NOT NULL,
              date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
              status VARCHAR(255) NOT NULL,
              message TEXT DEFAULT NULL,
              nb_ounits INT DEFAULT NULL,
              nb_programmes INT DEFAULT NULL,
              nb_courses INT DEFAULT NULL,
              nb_instances INT DEFAULT NULL,
              PRIMARY KEY (id)
            )
        SQL);
        $this->addSql(<<<'SQL'
            CREATE TABLE programme (
              code VARCHAR(255) NOT NULL,
              title JSON NOT NULL,
              ects DOUBLE PRECISION DEFAULT NULL,
              eqf_level_provided SMALLINT DEFAULT NULL,
              language_of_instruction JSON NOT NULL,
              level_in_diploma VARCHAR(255) DEFAULT NULL,
              diploma_code VARCHAR(255) DEFAULT NULL,
              diploma_title JSON DEFAULT NULL,
              last_modified TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
              ounit_id VARCHAR DEFAULT NULL,
              PRIMARY KEY (code)
            )
        SQL);
        $this->addSql('CREATE INDEX IDX_3DDCB9FF938C20D ON programme (ounit_id)');
        $this->addSql(<<<'SQL'
            ALTER TABLE
              course
            ADD
              CONSTRAINT FK_169E6FB9938C20D FOREIGN KEY (ounit_id) REFERENCES ounit (ounit_id) NOT DEFERRABLE
        SQL);
        $this->addSql(<<<'SQL'
            ALTER TABLE
              course_programme
            ADD
              CONSTRAINT FK_BF7DF953BFB7ED9E FOREIGN KEY (course_code) REFERENCES course (code) ON DELETE CASCADE NOT DEFERRABLE
        SQL);
        $this->addSql(<<<'SQL'
            ALTER TABLE
              course_programme
            ADD
              CONSTRAINT FK_BF7DF9536E5502F5 FOREIGN KEY (programme_code) REFERENCES programme (code) ON DELETE CASCADE NOT DEFERRABLE
        SQL);
        $this->addSql(<<<'SQL'
            ALTER TABLE
              course_instance
            ADD
              CONSTRAINT FK_EB84DC88BFB7ED9E FOREIGN KEY (course_code) REFERENCES course (code) ON DELETE CASCADE NOT DEFERRABLE
        SQL);
        $this->addSql(<<<'SQL'
            ALTER TABLE
              programme
            ADD
              CONSTRAINT FK_3DDCB9FF938C20D FOREIGN KEY (ounit_id) REFERENCES ounit (ounit_id) NOT DEFERRABLE
        SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP SEQUENCE pegase_import_log_id_seq CASCADE');
        $this->addSql('ALTER TABLE course DROP CONSTRAINT FK_169E6FB9938C20D');
        $this->addSql('ALTER TABLE course_programme DROP CONSTRAINT FK_BF7DF953BFB7ED9E');
        $this->addSql('ALTER TABLE course_programme DROP CONSTRAINT FK_BF7DF9536E5502F5');
        $this->addSql('ALTER TABLE course_instance DROP CONSTRAINT FK_EB84DC88BFB7ED9E');
        $this->addSql('ALTER TABLE programme DROP CONSTRAINT FK_3DDCB9FF938C20D');
        $this->addSql('DROP TABLE course');
        $this->addSql('DROP TABLE course_programme');
        $this->addSql('DROP TABLE course_instance');
        $this->addSql('DROP TABLE ounit');
        $this->addSql('DROP TABLE pegase_import_log');
        $this->addSql('DROP TABLE programme');
    }
}
+75
Changes for api/src/Entity/Course.php: 75 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * Cours OCCAPI : cours Pegase ouvert à la mobilité, avec les valeurs de sa période la plus récente.
 */
#[ORM\Entity]
#[ApiResource(
    operations: [new GetCollection(), new Get()],
    order: ['code' => 'ASC'],
)]
class Course
{
    #[ORM\Id, ORM\Column]
    public string $code;

    /** @var list<array{string: string, lang: string}> */
    #[ORM\Column(type: 'json')]
    public array $title;

    #[ORM\Column(nullable: true)]
    public ?float $ects = null;

    /** @var list<string> */
    #[ORM\Column(type: 'json')]
    public array $languageOfInstruction;

    /** @var list<string> */
    #[ORM\Column(type: 'json')]
    public array $academicTerm = [];

    /** @var list<array{multiline: string, lang: string}>|null */
    #[ORM\Column(type: 'json', nullable: true)]
    public ?array $description = null;

    #[ORM\Column]
    public bool $deprecated = false;

    #[ORM\Column(nullable: true)]
    public ?string $diplomaCode = null;

    /** @var list<array{string: string, lang: string}>|null */
    #[ORM\Column(type: 'json', nullable: true)]
    public ?array $diplomaTitle = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(referencedColumnName: 'ounit_id')]
    public ?Ounit $ounit = null;

    /** @var Collection<int, Programme> */
    #[ORM\ManyToMany(targetEntity: Programme::class)]
    #[ORM\JoinTable(name: 'course_programme')]
    #[ORM\JoinColumn(name: 'course_code', referencedColumnName: 'code', onDelete: 'CASCADE')]
    #[ORM\InverseJoinColumn(name: 'programme_code', referencedColumnName: 'code', onDelete: 'CASCADE')]
    public Collection $relatedProgramme;

    #[ORM\Column]
    public \DateTimeImmutable $lastModified;

    /**
     * Initialise la liste des programmes liés.
     */
    public function __construct()
    {
        $this->relatedProgramme = new ArrayCollection();
    }
}
+61
Changes for api/src/Entity/CourseInstance.php: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Context;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;

/**
 * Instance OCCAPI : un cours sur une période et un semestre, avec le regroupement du catalogue.
 */
#[ORM\Entity]
#[ApiResource(
    shortName: 'Instance',
    operations: [new GetCollection(), new Get()],
    order: ['id' => 'ASC'],
)]
class CourseInstance
{
    #[ORM\Id, ORM\Column]
    public string $id;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(name: 'course_code', referencedColumnName: 'code', nullable: false, onDelete: 'CASCADE')]
    public Course $course;

    #[ORM\Column]
    public string $academicTermId;

    #[ORM\Column(type: 'date_immutable')]
    #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
    public \DateTimeImmutable $startDate;

    #[ORM\Column(type: 'date_immutable')]
    #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
    public \DateTimeImmutable $endDate;

    #[ORM\Column(nullable: true)]
    public ?float $ects = null;

    /** @var list<string> */
    #[ORM\Column(type: 'json')]
    public array $languageOfInstruction;

    #[ORM\Column(nullable: true)]
    public ?float $engagementHours = null;

    /** @var list<array{string: string, lang: string}>|null */
    #[ORM\Column(type: 'json', nullable: true)]
    public ?array $catalogueOunit = null;

    /** @var list<array{string: string, lang: string}>|null */
    #[ORM\Column(type: 'json', nullable: true)]
    public ?array $catalogueGroup = null;

    #[ORM\Column]
    public \DateTimeImmutable $lastModified;
}
+40
Changes for api/src/Entity/Ounit.php: 40 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * Unité organisationnelle OCCAPI : structure Pegase portant au moins un cours ou un programme.
 */
#[ORM\Entity]
#[ApiResource(
    operations: [new GetCollection(), new Get()],
    order: ['ounitId' => 'ASC'],
)]
class Ounit
{
    #[ORM\Id, ORM\Column]
    public string $ounitId;

    /** @var list<array{string: string, lang: string}> */
    #[ORM\Column(type: 'json')]
    public array $title;

    #[ORM\Column(nullable: true)]
    public ?string $abbreviation = null;

    #[ORM\Column]
    public \DateTimeImmutable $lastModified;

    /**
     * @return string code de la structure, identique à ounitId
     */
    public function getOunitCode(): string
    {
        return $this->ounitId;
    }
}
+36
Changes for api/src/Entity/PegaseImportLog.php: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Une ligne par exécution de app:import-pegase.
 */
#[ORM\Entity]
class PegaseImportLog
{
    #[ORM\Id, ORM\GeneratedValue('SEQUENCE'), ORM\Column]
    public ?int $id = null;

    #[ORM\Column]
    public \DateTimeImmutable $date;

    #[ORM\Column]
    public string $status;

    #[ORM\Column(type: 'text', nullable: true)]
    public ?string $message = null;

    #[ORM\Column(nullable: true)]
    public ?int $nbOunits = null;

    #[ORM\Column(nullable: true)]
    public ?int $nbProgrammes = null;

    #[ORM\Column(nullable: true)]
    public ?int $nbCourses = null;

    #[ORM\Column(nullable: true)]
    public ?int $nbInstances = null;
}
Loading