src/Entity/Educational/Course.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Educational;
  3. use App\Entity\Users\Child;
  4. use App\Entity\Users\Child as Student;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. /**
  11.  * Define a group of Domain allowed for a user
  12.  * aba\DomainBundle\Entity\Course
  13.  *
  14.  * @ORM\Table(name="Course")
  15.  * @ORM\Entity(repositoryClass="App\Repository\Educational\CourseRepository")
  16.  */
  17. class Course
  18. {
  19.     const ID_TERMINALE = 1;
  20.     const ID_SECONDE = 2;
  21.     const ID_TROISIEME = 3;
  22.     const ID_PREMIERE = 4;
  23.     const ID_QUATRIEME = 5;
  24.     const ID_CINQUIEME = 6;
  25.     const ID_SIXIEME = 7;
  26.     const SLUG_TERMINALE    = 'terminale';
  27.     const SLUG_PREMIERE     = 'premiere';
  28.     const SLUG_SECONDE      = 'seconde';
  29.     const SLUG_TROISIEME    = 'troisieme';
  30.     const SLUG_QUATRIEME    = 'quatrieme';
  31.     const SLUG_CINQUIEME    = 'cinquieme';
  32.     const SLUG_SIXIEME      = 'sixieme';
  33.     /**
  34.      * @var integer $id
  35.      *
  36.      * @ORM\Column(name="id", type="integer")
  37.      * @ORM\Id
  38.      * @ORM\GeneratedValue(strategy="AUTO")
  39.      * @Groups({"api"})
  40.      */
  41.     private $id;
  42.     /**
  43.      * @var string $title
  44.      *
  45.      * @ORM\Column(name="title", type="string", length=255)
  46.      * @Gedmo\Slug(fields={"slug"})
  47.      * @Assert\NotBlank()
  48.      * @Groups({"api"})
  49.      */
  50.     private $title;
  51.     /**
  52.      * @var string $slug
  53.      *
  54.      * @ORM\Column(name="slug", type="string", length=255, unique=true)
  55.      * @Groups({"api"})
  56.      *
  57.      */
  58.     private $slug;
  59.     /**
  60.      * @var
  61.      * @ORM\Column(name="front", type="boolean")
  62.      */
  63.     private $front;
  64.     /**
  65.      * @var integer
  66.      * @ORM\Column(name="order",type="integer")
  67.      */
  68.     private $order;
  69.     /**
  70.      * @var string
  71.      *
  72.      * @ORM\Column(name="description", type="text", nullable=true)
  73.      */
  74.     private $description;
  75.     /**
  76.      * @var string
  77.      *
  78.      * @ORM\Column(name="metadescription", type="text", nullable=true)
  79.      */
  80.     private $metadescription;
  81.     /********************** Association **************/
  82.     /*
  83.      * @ORM\ManyToOne(targetEntity="Serie",inversedBy="discipline")
  84.      * @ORM\JoinColumn(name="serie_id",referencedColumnName="id")
  85.      *
  86.      *
  87.     public $serie;
  88.     */
  89.     /**
  90.      * @ORM\OneToMany(targetEntity="Domain", mappedBy="course")
  91.      * @ORM\OrderBy({"position" = "ASC"})
  92.      */
  93.     private $domains;
  94.     /**
  95.      * @ORM\OneToMany(targetEntity="App\Entity\Users\Child", mappedBy="course")
  96.      */
  97.     private $students;
  98.     /*
  99.      * @ORM\ManyToMany(targetEntity="Bo\MediaBundle\Entity\Slideshow", mappedBy="courses")
  100.      */
  101.     private $slideshows;
  102.     /*********************** FIN ********************/
  103.     public function __construct()
  104.     {
  105.         $this->domains = new ArrayCollection();
  106.         $this->students = new ArrayCollection();
  107.         $this->front = false;
  108.         $this->slideshows = new ArrayCollection();
  109.     }
  110.     /**
  111.      *
  112.      * Return slugs for high school
  113.      * @return array
  114.      */
  115.     public static function getSlugHighSchool()
  116.     {
  117.         return [
  118.             self::SLUG_TERMINALE,
  119.             self::SLUG_PREMIERE,
  120.             self::SLUG_SECONDE,
  121.         ];
  122.     }
  123.     /**
  124.      * Return slugs for middle school
  125.      * @return array
  126.      */
  127.     public static function getSlugMiddleSchool()
  128.     {
  129.         return [
  130.             self::SLUG_SIXIEME,
  131.             self::SLUG_CINQUIEME,
  132.             self::SLUG_QUATRIEME,
  133.             self::SLUG_TROISIEME,
  134.         ];
  135.     }
  136.     /**
  137.      *
  138.      * Return slugs for free video are forbidden
  139.      * @return array
  140.      */
  141.     public static function getSlugFreeVideoForbidden()
  142.     {
  143.         return [
  144.             self::SLUG_TERMINALE,
  145.             self::SLUG_PREMIERE,
  146.             self::SLUG_SECONDE,
  147.             self::SLUG_TROISIEME,
  148.             self::SLUG_QUATRIEME,
  149.             self::SLUG_CINQUIEME,
  150.             self::SLUG_SIXIEME,
  151.         ];
  152.     }
  153.     /**
  154.      *
  155.      * Return slugs for stage are forbidden
  156.      * @return array
  157.      */
  158.     public static function getSlugStageForbidden()
  159.     {
  160.         return [
  161.         ];
  162.     }
  163.     /**
  164.      * Return the slug for pack bac
  165.      *
  166.      * @return array
  167.      */
  168.     public static function getSlugPackBac()
  169.     {
  170.         return [
  171.             self::SLUG_TERMINALE,
  172.             self::SLUG_PREMIERE,
  173.         ];
  174.     }
  175.     /**
  176.      * Return the slug for pack brevet
  177.      *
  178.      * @return array
  179.      */
  180.     public static function getSlugPackBrevet()
  181.     {
  182.         return [
  183.             self::SLUG_TROISIEME,
  184.         ];
  185.     }
  186.     /**
  187.      * Return the slug for pack été
  188.      *
  189.      * @return array
  190.      */
  191.     public static function getSlugPackEte()
  192.     {
  193.         return [
  194.             self::SLUG_TERMINALE,
  195.             self::SLUG_PREMIERE,
  196.             self::SLUG_SECONDE,
  197.         ];
  198.     }
  199.     /**
  200.      * Return all discipline by serie, serie by course
  201.      *
  202.      * @return array
  203.      */
  204.     public static function getAllSerieDiscipline()
  205.     {
  206.         return [
  207.             self::SLUG_TERMINALE => [
  208.                 Serie::SLUG_GENERAL => [
  209.                     Discipline::SLUG_MATHEMATIQUES,
  210.                     Discipline::SLUG_FRANCAIS,
  211.                     Discipline::SLUG_ANGLAIS,
  212.                 ],
  213.                 /*
  214.                 Serie::SLUG_S => [
  215.                     Discipline::SLUG_MATHEMATIQUES,
  216.                     Discipline::SLUG_FRANCAIS,
  217.                     Discipline::SLUG_ANGLAIS,
  218.                 ],
  219.                 Serie::SLUG_L => [
  220.                     Discipline::SLUG_MATHEMATIQUES,
  221.                     Discipline::SLUG_FRANCAIS,
  222.                     Discipline::SLUG_PHILOSOPHIE,
  223.                 ],
  224.                 Serie::SLUG_ES => [
  225.                     Discipline::SLUG_MATHEMATIQUES,
  226.                     Discipline::SLUG_FRANCAIS,
  227.                     Discipline::SLUG_PHILOSOPHIE,
  228.                 ],
  229.                 */
  230.             ],
  231.             self::SLUG_PREMIERE => [
  232.                 Serie::SLUG_GENERAL => [
  233.                     Discipline::SLUG_MATHEMATIQUES,
  234.                     Discipline::SLUG_FRANCAIS,
  235.                     Discipline::SLUG_ANGLAIS,
  236.                 ],
  237.             ],
  238.             self::SLUG_SECONDE => [
  239.                 Serie::SLUG_GENERAL => [
  240.                     Discipline::SLUG_MATHEMATIQUES,
  241.                     Discipline::SLUG_FRANCAIS,
  242.                     Discipline::SLUG_ANGLAIS,
  243.                 ],
  244.             ],
  245.             self::SLUG_TROISIEME => [
  246.                 Serie::SLUG_GENERAL => [
  247.                     Discipline::SLUG_MATHEMATIQUES,
  248.                     Discipline::SLUG_FRANCAIS,
  249.                     Discipline::SLUG_ANGLAIS,
  250.                 ],
  251.             ],
  252.             self::SLUG_QUATRIEME => [
  253.                 Serie::SLUG_GENERAL => [
  254.                     Discipline::SLUG_MATHEMATIQUES,
  255.                     Discipline::SLUG_FRANCAIS,
  256.                     Discipline::SLUG_ANGLAIS,
  257.                 ],
  258.             ],
  259.             self::SLUG_CINQUIEME => [
  260.                 Serie::SLUG_GENERAL => [
  261.                     Discipline::SLUG_MATHEMATIQUES,
  262.                     Discipline::SLUG_FRANCAIS,
  263.                     Discipline::SLUG_ANGLAIS,
  264.                 ],
  265.             ],
  266.             self::SLUG_SIXIEME => [
  267.                 Serie::SLUG_GENERAL => [
  268.                     Discipline::SLUG_MATHEMATIQUES,
  269.                     Discipline::SLUG_FRANCAIS,
  270.                     Discipline::SLUG_ANGLAIS,
  271.                 ],
  272.             ],
  273.         ];
  274.     }
  275.     /**
  276.      *
  277.      * Return html color course slug
  278.      * @return array
  279.      */
  280.     public static function getHtmlColor()
  281.     {
  282.         return [
  283.             self::SLUG_TERMINALE => ['main' => '#FF69ADE9', 'gradient' => '#FF4696E8' ],
  284.             self::SLUG_PREMIERE => ['main' => '#FFF36E88', 'gradient' => '#FFFF9CAF' ],
  285.             self::SLUG_SECONDE => ['main' => '#FFFFA924', 'gradient' => '#FFFFC63B' ],
  286.             self::SLUG_TROISIEME => ['main' => '#FFFF9F61', 'gradient' => '#FFFF854A' ],
  287.             self::SLUG_QUATRIEME => ['main' => '#FF66C36A', 'gradient' => '#FF6AD490' ],
  288.             self::SLUG_CINQUIEME => ['main' => '#FF716AE1', 'gradient' => '#FF8E88FF' ],
  289.             self::SLUG_SIXIEME => ['main' => '#FFEF513A', 'gradient' => '#FFFF8F7E' ],
  290.         ];
  291.     }
  292.     /**
  293.      *
  294.      * Return course code
  295.      * @return array
  296.      */
  297.     public static function getCodeBySlug($courseSlug, Serie $serie = null)
  298.     {
  299.         $courseCode = [
  300.             self::SLUG_PREMIERE => '1',
  301.             self::SLUG_SECONDE => '2',
  302.             self::SLUG_TROISIEME => '3',
  303.             self::SLUG_QUATRIEME => '4',
  304.             self::SLUG_CINQUIEME => '5',
  305.             self::SLUG_SIXIEME => '6',
  306.         ];
  307.         if(array_key_exists($courseSlug, $courseCode) === true) {
  308.             return $courseCode[$courseSlug];
  309.         }
  310.         return $serie->getLabel();
  311.     }
  312.     /**
  313.      * @return int
  314.      */
  315.     public function getId()
  316.     {
  317.         return $this->id;
  318.     }
  319.     /**
  320.      * @param int $id
  321.      */
  322.     public function setId(int $id)
  323.     {
  324.         $this->id = $id;
  325.     }
  326.     /**
  327.      * Set title
  328.      *
  329.      * @param string $title
  330.      */
  331.     public function setTitle($title)
  332.     {
  333.         $this->title = strtoupper($title);
  334.     }
  335.     /**
  336.      * Get title
  337.      *
  338.      * @return string
  339.      */
  340.     public function getTitle()
  341.     {
  342.         return $this->title;
  343.     }
  344.     /**
  345.      * Set slug
  346.      *
  347.      * @param string $slug
  348.      */
  349.     public function setSlug($slug)
  350.     {
  351.         $this->slug = $slug;
  352.     }
  353.     /**
  354.      * Get slug
  355.      *
  356.      * @return string
  357.      */
  358.     public function getSlug()
  359.     {
  360.         return $this->slug;
  361.     }
  362.     /**
  363.      * Add domains
  364.      *
  365.      * @param Domain $domains
  366.      */
  367.     public function addDomains(Domain $domains)
  368.     {
  369.         $this->domains[] = $domains;
  370.     }
  371.     /**
  372.      * Get domains
  373.      *
  374.      * @return ArrayCollection
  375.      */
  376.     public function getDomains()
  377.     {
  378.         return $this->domains;
  379.     }
  380.     /**
  381.      * Add user
  382.      *
  383.      * @param $student
  384.      */
  385.     public function addStudents(Student $student)
  386.     {
  387.         $this->students[] = $student;
  388.     }
  389.     /**
  390.      * Get students
  391.      *
  392.      * @return ArrayCollection
  393.      */
  394.     public function getStudents()
  395.     {
  396.         return $this->students;
  397.     }
  398.     /**
  399.      * @return string
  400.      */
  401.     public function __toString()
  402.     {
  403.         if (!$this) {
  404.             return "N/A";
  405.         }
  406.         return $this->getTitle();
  407.     }
  408.     /**
  409.      * @return mixed
  410.      */
  411.     public function getFront()
  412.     {
  413.         return $this->front;
  414.     }
  415.     /**
  416.      * @param mixed $front
  417.      */
  418.     public function setFront($front)
  419.     {
  420.         $this->front = $front;
  421.     }
  422.     /**
  423.      * @return int
  424.      */
  425.     public function getOrder()
  426.     {
  427.         return $this->order;
  428.     }
  429.     /**
  430.      * @param int $order
  431.      */
  432.     public function setOrder($order)
  433.     {
  434.         $this->order = $order;
  435.     }
  436.     /**
  437.      * Add domains
  438.      *
  439.      * @param Domain $domains
  440.      * @return Course
  441.      */
  442.     public function addDomain(Domain $domains)
  443.     {
  444.         $this->domains[] = $domains;
  445.         return $this;
  446.     }
  447.     /**
  448.      * Remove domains
  449.      *
  450.      * @param Domain $domains
  451.      */
  452.     public function removeDomain(Domain $domains)
  453.     {
  454.         $this->domains->removeElement($domains);
  455.     }
  456.     /**
  457.      * Add students
  458.      *
  459.      * @param Child $students
  460.      * @return Course
  461.      */
  462.     public function addStudent(Child $students)
  463.     {
  464.         $this->students[] = $students;
  465.         return $this;
  466.     }
  467.     /**
  468.      * Remove students
  469.      *
  470.      * @param \Bo\StudentBundle\Entity\Student $students
  471.      */
  472.     public function removeStudent(Child $students)
  473.     {
  474.         $this->students->removeElement($students);
  475.     }
  476.     /**
  477.      * Add slideshows
  478.      *
  479.      * @param \Bo\MediaBundle\Entity\Slideshow $slideshows
  480.      * @return Course
  481.      */
  482.     public function addSlideshow( $slideshows)
  483.     {
  484.         $this->slideshows[] = $slideshows;
  485.         return $this;
  486.     }
  487.     /**
  488.      * Remove slideshows
  489.      *
  490.      * @param \Bo\MediaBundle\Entity\Slideshow $slideshows
  491.      */
  492.     public function removeSlideshow( $slideshows)
  493.     {
  494.         $this->slideshows->removeElement($slideshows);
  495.     }
  496.     /**
  497.      * Get slideshows
  498.      *
  499.      * @return \Doctrine\Common\Collections\Collection
  500.      */
  501.     public function getSlideshows()
  502.     {
  503.         return $this->slideshows;
  504.     }
  505.     /**
  506.      * @return string
  507.      */
  508.     public function getDescription()
  509.     {
  510.         return $this->description;
  511.     }
  512.     /**
  513.      * @param string $description
  514.      */
  515.     public function setDescription($description)
  516.     {
  517.         $this->description = $description;
  518.     }
  519.     /**
  520.      * @return string
  521.      */
  522.     public function getMetadescription()
  523.     {
  524.         return $this->metadescription;
  525.     }
  526.     /**
  527.      * @param string $metadescription
  528.      */
  529.     public function setMetadescription( $metadescription)
  530.     {
  531.         $this->metadescription = $metadescription;
  532.     }
  533. }