src/Entity/Formation/Activity.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Formation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Image;
  5. use App\Repository\Formation\ActivityRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\Traits\Actions;
  10. use Doctrine\ORM\Mapping\Column;
  11. use Doctrine\ORM\Mapping\OneToMany;
  12. use Doctrine\ORM\Mapping\OrderBy;
  13. #[ORM\Entity(repositoryClassActivityRepository::class)]
  14. #[ORM\Table(name'hs_tc_formation_activity')]
  15. #[ApiResource]
  16. class Activity implements \Stringable
  17. {
  18.     use Actions;
  19.     #[ORM\ManyToOne(targetEntityCategory::class, cascade: ['persist'], inversedBy'activites')]
  20.     private $category;
  21.     #[ORM\ManyToOne(targetEntityDomaine::class, cascade: ['persist'])]
  22.     private $domaine;
  23.     #[ORM\Column(name"title"type"string"length255uniquetrue)]
  24.     private $title;
  25.     #[ORM\Column(name"title_ar"type"string"length255nullabletrue)]
  26.     private ?string $titleAr null;
  27.     #[ORM\Column(name"diploma"type"string"length255nullabletrue)]
  28.     private ?string $diploma;
  29.     #[ORM\Column(name'slug'type'string'length255)]
  30.     private $slug;
  31.     #[ORM\OneToMany(mappedBy"activity"targetEntity"Unite")]
  32.     #[ORM\OrderBy(["ref" => "ASC"])]
  33.     private ?Collection $unites null;
  34.     #[ORM\OneToMany(mappedBy"activity"targetEntity"Classe")]
  35.     private ?Collection $classes null;
  36.     #[ORM\Column(name'forder'type'integer'nullabletrue)]
  37.     private ?int $forder;
  38.     #[ORM\Column(name'featured'type'boolean')]
  39.     private bool $featured false;
  40.     #[ORM\OneToMany(mappedBy'activity'targetEntityImage::class, cascade: ['all'])]
  41.     private ?Collection $images null;
  42.     private $file;
  43.     public function __construct()
  44.     {
  45.         // date_default_timezone_set('Africa/Casablanca');
  46.         $this->createAt=new \DateTime('now');
  47.         $this->published=true;
  48.         $this->featured=false;
  49.         $this->unites = new ArrayCollection();
  50.         $this->images = new ArrayCollection();
  51.     }
  52.     /**
  53.      * Set title
  54.      *
  55.      * @param string $title
  56.      *
  57.      * @return Activity
  58.      */
  59.     public function setTitle($title)
  60.     {
  61.         $this->title $title;
  62.         $this->setSlug($this->slugify($title));
  63.         return $this;
  64.     }
  65.     /**
  66.      * Get title
  67.      *
  68.      * @return string
  69.      */
  70.     public function getTitle()
  71.     {
  72.         return $this->title;
  73.     }
  74.     /**
  75.      * @return string
  76.      */
  77.     public function getTitleAr(): ?string
  78.     {
  79.         return $this->titleAr;
  80.     }
  81.     /**
  82.      * @param string $titleAr
  83.      */
  84.     public function setTitleAr(?string $titleAr): Activity
  85.     {
  86.         $this->titleAr $titleAr;
  87.         return $this;
  88.     }
  89.     /**
  90.      * Set diploma
  91.      *
  92.      * @param string $diploma
  93.      *
  94.      * @return Activity
  95.      */
  96.     public function setDiploma($diploma)
  97.     {
  98.         $this->diploma $diploma;
  99.         return $this;
  100.     }
  101.     /**
  102.      * Get diploma
  103.      *
  104.      * @return string
  105.      */
  106.     public function getDiploma()
  107.     {
  108.         return $this->diploma;
  109.     }
  110.     public function getDiplomaText(): ?string
  111.     {
  112.         $diplomaChoices = [
  113.             'Aucun' => 'Aucun diplôme',
  114.             'FC' => 'Formation Continue',
  115.             'AP Comptabilité' => 'Aptitude Professionnelle : Comptabilité',
  116.             'AP AMPP' => 'Aptitude Professionnelle : Assistant Médicale',
  117.             'QP AC' => 'Qualification Professionnelle : Attestation de Conduite',
  118.             'CEL Fr A1' => 'Certificat de langue : Français Niveau A1',
  119.             'CEL Fr A2' => 'Certificat de langue : Français Niveau A2',
  120.             'CEL Fr B1' => 'Certificat de langue : Français Niveau B1',
  121.             'CEL Fr B2' => 'Certificat de langue : Français Niveau B2',
  122.             'CEL Fr A1+' => 'Certificat de langue : Français Niveau A1+',
  123.             'CEL Fr A2+' => 'Certificat de langue : Français Niveau A2+',
  124.             'CEL Fr B1+' => 'Certificat de langue : Français Niveau B1+',
  125.             'CEL Fr B2+' => 'Certificat de langue : Français Niveau B2+',
  126.             'CEL Fr C1' => 'Certificat de langue : Français Niveau C1',
  127.             'CEL Fr C2' => 'Certificat de langue : Français Niveau C2',
  128.             'CEL En A1' => 'Certificat de langue : Anglais Niveau A1',
  129.             'CEL En A2' => 'Certificat de langue : Anglais Niveau A2',
  130.             'CEL En B1' => 'Certificat de langue : Anglais Niveau B1',
  131.             'CEL En B2' => 'Certificat de langue : Anglais Niveau B2',
  132.             'CEL En A1+' => 'Certificat de langue : Anglais Niveau A1+',
  133.             'CEL En A2+' => 'Certificat de langue : Anglais Niveau A2+',
  134.             'CEL En B1+' => 'Certificat de langue : Anglais Niveau B1+',
  135.             'CEL En B2+' => 'Certificat de langue : Anglais Niveau B2+',
  136.             'CEL En C1' => 'Certificat de langue : Anglais Niveau C1',
  137.             'CEL En C2' => 'Certificat de langue : Anglais Niveau C2',
  138.             'CEL Es A1' => 'Certificat de langue : Espagnole Niveau A1',
  139.             'CEL Es A2' => 'Certificat de langue : Espagnole Niveau A2',
  140.             'CEL Es B1' => 'Certificat de langue : Espagnole Niveau B1',
  141.             'CEL Es B2' => 'Certificat de langue : Espagnole Niveau B2',
  142.             'CEL Es A1+' => 'Certificat de langue : Espagnole Niveau A1+',
  143.             'CEL Es A2+' => 'Certificat de langue : Espagnole Niveau A2+',
  144.             'CEL Es B1+' => 'Certificat de langue : Espagnole Niveau B1+',
  145.             'CEL Es B2+' => 'Certificat de langue : Espagnole Niveau B2+',
  146.             'CEL Es C1' => 'Certificat de langue : Espagnole Niveau C1',
  147.             'CEL Es C2' => 'Certificat de langue : Espagnole Niveau C2',
  148.             'CEL De A1' => 'Certificat de langue : Allemand Niveau A1',
  149.             'CEL De A2' => 'Certificat de langue : Allemand Niveau A2',
  150.             'CEL De B1' => 'Certificat de langue : Allemand Niveau B1',
  151.             'CEL De B2' => 'Certificat de langue : Allemand Niveau B2',
  152.             'CEL De A1+' => 'Certificat de langue : Allemand Niveau A1+',
  153.             'CEL De A2+' => 'Certificat de langue : Allemand Niveau A2+',
  154.             'CEL De B1+' => 'Certificat de langue : Allemand Niveau B1+',
  155.             'CEL De B2+' => 'Certificat de langue : Allemand Niveau B2+',
  156.             'CEL De C1' => 'Certificat de langue : Allemand Niveau C1',
  157.             'CEL De C2' => 'Certificat de langue : Allemand Niveau C2',
  158.         ];
  159.         return $diplomaChoices[$this->diploma] ?? 'Aucun diplôme';
  160.     }
  161.     public function getLevel(): ?string
  162.     {
  163.         // Vérifie si le diplôme est un certificat de langue
  164.         if (strpos($this->diploma'CEL ') === 0) {
  165.             // Utilise une expression régulière pour extraire le niveau (A1, A2, B1, etc.)
  166.             if (preg_match('/CEL \w+ (\w+\+?)/'$this->diploma$matches)) {
  167.                 return $matches[1]; // Retourne le niveau (A1, A2, etc.)
  168.             }
  169.         }
  170.         return null// Retourne null si ce n'est pas un certificat de langue
  171.     }
  172.     public function getLangue(): ?string
  173.     {
  174.         // Vérifie si le diplôme est un certificat de langue
  175.         if (strpos($this->diploma'CEL ') === 0) {
  176.             // Utilise une expression régulière pour extraire le code de langue (Fr, En, Es, De)
  177.             if (preg_match('/CEL (\w+) \w+/'$this->diploma$matches)) {
  178. //                // Convertit le code de langue en nom complet
  179. //                $langueCodes = [
  180. //                    'Fr' => 'Français',
  181. //                    'En' => 'Anglais',
  182. //                    'Es' => 'Espagnole',
  183. //                    'De' => 'Allemand', // Allemand ajouté
  184. //                ];
  185.                 return $matches[1] ?? null// Retourne la langue ou null si non trouvé
  186.             }
  187.         }
  188.         return null// Retourne null si ce n'est pas un certificat de langue
  189.     }
  190.     public function getSlug()
  191.     {
  192.         return $this->slug;
  193.     }
  194.     public function setSlug($slug)
  195.     {
  196.         $this->slug $slug;
  197.     }
  198.     public function __toString(): string
  199.     {
  200.         return (string) $this->title;
  201.     }
  202.     public function getName(){
  203.         return $this->diploma.' en '.$this->title;
  204.     }
  205.     /**
  206.      * Add unite
  207.      *
  208.      *
  209.      * @return Activity
  210.      */
  211.     public function addUnite(Unite $unite)
  212.     {
  213.         $unite->setActivity($this);
  214.         $this->unites[] = $unite;
  215.         return $this;
  216.     }
  217.     /**
  218.      * Remove unite
  219.      */
  220.     public function removeUnite(Unite $unite)
  221.     {
  222.         $this->unites->removeElement($unite);
  223.     }
  224.     /**
  225.      * Get unites
  226.      *
  227.      * @return \Doctrine\Common\Collections\Collection
  228.      */
  229.     public function getUnites()
  230.     {
  231.         return $this->unites;
  232.     }
  233.     /**
  234.      * Add classe
  235.      *
  236.      *
  237.      * @return Activity
  238.      */
  239.     public function addClasse(Classe $classe)
  240.     {
  241.         $classe->setActivity($this);
  242.         $this->classes[] = $classe;
  243.         return $this;
  244.     }
  245.     /**
  246.      * Remove classe
  247.      */
  248.     public function removeClasse(Classe $classe)
  249.     {
  250.         $this->classes->removeElement($classe);
  251.     }
  252.     /**
  253.      * Get classes
  254.      *
  255.      * @return \Doctrine\Common\Collections\Collection
  256.      */
  257.     public function getClasses()
  258.     {
  259.         return $this->classes;
  260.     }
  261.     public function getClasseOpned()
  262.     {
  263.         /** @var Classe $classe */
  264.         foreach($this->classes as $classe){
  265.             if($classe->isOpened()) return $classe;
  266.         }
  267.         return null;
  268.     }
  269.     /**
  270.      * @return mixed
  271.      */
  272.     public function getForder()
  273.     {
  274.         return $this->forder;
  275.     }
  276.     /**
  277.      * @return Activity
  278.      */
  279.     public function setForder(mixed $forder)
  280.     {
  281.         $this->forder $forder;
  282.         return $this;
  283.     }
  284.     /**
  285.      * Add image
  286.      *
  287.      *
  288.      * @return Activity
  289.      */
  290.     public function addImage(Image $image)
  291.     {
  292.         $this->images[] = $image;
  293.         return $this;
  294.     }
  295.     /**
  296.      * Remove image
  297.      */
  298.     public function removeImage(Image $image)
  299.     {
  300.         $this->images->removeElement($image);
  301.     }
  302.     /**
  303.      * Get images
  304.      *
  305.      * @return Collection
  306.      */
  307.     public function getImages()
  308.     {
  309.         if($this->images->isEmpty()){
  310.             $imageVide=new Image();
  311.             $imageVide->setUrl("aucun.jpg");
  312.             $this->images->add($imageVide);
  313.         }
  314.         return $this->images;
  315.     }
  316.     /**
  317.      * @return mixed
  318.      */
  319.     public function getFile()
  320.     {
  321.         return $this->file;
  322.     }
  323.     /**
  324.      * @param mixed $file
  325.      * @return Activity
  326.      */
  327.     public function setFile($file)
  328.     {
  329.         $this->file $file;
  330.         return $this;
  331.     }
  332.     /**
  333.      * @return mixed
  334.      */
  335.     public function getCategory()
  336.     {
  337.         return $this->category;
  338.     }
  339.     /**
  340.      * @param mixed $category
  341.      */
  342.     public function setCategory($category): void
  343.     {
  344.         $this->category $category;
  345.     }
  346.     /**
  347.      * @return mixed
  348.      */
  349.     public function getDomaine()
  350.     {
  351.         return $this->domaine;
  352.     }
  353.     /**
  354.      * @param mixed $domaine
  355.      */
  356.     public function setDomaine($domaine): void
  357.     {
  358.         $this->domaine $domaine;
  359.     }
  360.     public function isFeatured(): bool
  361.     {
  362.         return $this->featured;
  363.     }
  364.     public function setFeatured(bool $featured): void
  365.     {
  366.         $this->featured $featured;
  367.     }
  368.     public function getButtonFeatured()
  369.     {
  370.         $confirm="data-toggle='confirmation'
  371.                 data-btn-ok-label='Oui' 
  372.                 data-btn-ok-icon='glyphicon glyphicon-ok'
  373.                 data-btn-ok-class='btn-success'
  374.                 data-btn-cancel-label='Non' 
  375.                 data-btn-cancel-icon='glyphicon glyphicon-remove'
  376.                 data-btn-cancel-class='btn-danger'
  377.                 data-title='Changer statut ?'
  378.                 data-popout='true'
  379.                 data-content='Voulez-vous vraiment changer le statut de cet élément ?' ";
  380.         if($this->featured)
  381.             $icon"<i class=\"text-green fa fa-toggle-on\"> Oui</i>";
  382.         else
  383.             $icon"<i class=\"text-red fa fa-toggle-off\"> Non</i>";
  384.         $btn="<a ".$confirm." href='javascript:void(0)' class='boledit' data-boledit-id='".$this->id."' data-boledit-route='".$this->getRoute('featured')."'>".$icon."</a> </td>";
  385.         return $btn;
  386.     }
  387.     public function slugify($title)
  388.     {
  389.         // replace non letter or digits by -
  390.         $text preg_replace('~[^\pL\d]+~u''-', (string) $title);
  391.         // transliterate
  392.         $text iconv('utf-8''us-ascii//TRANSLIT'$text);
  393.         // remove unwanted characters
  394.         $text preg_replace('~[^\-\w]+~'''$text);
  395.         // trim
  396.         $text trim($text'-');
  397.         // remove duplicate -
  398.         $text preg_replace('~-+~''-'$text);
  399.         // lowercase
  400.         $text strtolower($text);
  401.         if (empty($text)) {
  402.             return 'n-a';
  403.         }
  404.         return $text;
  405.     }
  406. }