src/Entity/User.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Formation\Intervenant;
  5. use App\Entity\Formation\Apayment;
  6. use App\Entity\Formation\Classe;
  7. use App\Entity\Formation\Participant;
  8. use App\Entity\Training\Former;
  9. use App\Entity\Training\Fpayment;
  10. use App\Entity\Training\Groupe;
  11. use App\Entity\Training\Trainee;
  12. use App\Entity\Tutoring\Course;
  13. use App\Entity\Tutoring\Tutor;
  14. use App\Repository\UserRepository;
  15. use App\Traits\Actions;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  20. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  21. use Symfony\Component\Security\Core\User\UserInterface;
  22. #[ORM\Entity(repositoryClassUserRepository::class)]
  23. #[ORM\Table(name'hs_tc_user')]
  24. #[ApiResource]
  25. class User implements UserInterfacePasswordAuthenticatedUserInterfaceUserPasswordHasherInterface\Stringable
  26. {
  27.     final public const ROLE_DEFAULT 'ROLE_USER';
  28.     final public const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  29.     use Actions;
  30.     #[ORM\Column(length180uniquetrue)]
  31.     private ?string $email null;
  32.     #[ORM\Column]
  33.     private array $roles = [];
  34.     /**
  35.      * @var string The hashed password
  36.      */
  37.     #[ORM\Column]
  38.     private ?string $password null;
  39.     #[ORM\Column(name"name"type"string"length255nullabletrue)]
  40.     private ?string $name=null;
  41.     #[ORM\Column(name"first_name"type"string"length255nullabletrue)]
  42.     private ?string $firstName=null;
  43.     #[ORM\Column(name"last_name"type"string"length255nullabletrue)]
  44.     private ?string $lastName=null;
  45.     #[ORM\Column(name"phone"type"string"length255nullabletrue)]
  46.     private ?string $phone=null;
  47.     #[ORM\Column(name"skin"type"string"length255nullabletrue)]
  48.     private ?string $skin 'skin-red';
  49.     #[ORM\OneToOne(mappedBy'user'targetEntityFormer::class, cascade: ['persist''remove'])]
  50.     private $former;
  51.     #[ORM\OneToOne(mappedBy'user'targetEntityTutor::class, cascade: ['persist''remove'])]
  52.     private $tutor;
  53.     
  54.     #[ORM\OneToOne(mappedBy'user'targetEntityIntervenant::class, cascade: ['persist''remove'])]
  55.     private $intervenant;
  56.     
  57.     #[ORM\OneToOne(mappedBy'user'targetEntityTrainee::class, cascade: ['all'])]
  58.     private $trainee;
  59.     #[ORM\OneToOne(mappedBy'user'targetEntityParticipant::class, cascade: ['all'])]
  60.     private $participant;
  61.     #[ORM\OneToMany(mappedBy'user'targetEntityNotification::class, orphanRemovaltrue)]
  62.     private Collection $notifications;
  63.     #[ORM\OneToMany(mappedBy'initie'targetEntityApayment::class, orphanRemovaltrue)]
  64.     private Collection $payments;
  65.     #[ORM\OneToMany(mappedBy'responsable'targetEntityGroupe::class)]
  66.     private Collection $groupes;
  67.     
  68.     #[ORM\OneToMany(mappedBy'responsable'targetEntityCourse::class)]
  69.     private Collection $courses;
  70.     #[ORM\OneToMany(mappedBy'responsable'targetEntityClasse::class)]
  71.     private Collection $classes;
  72.     #[ORM\Column(type'datetime'nullabletrue)]
  73.     private ?\DateTimeInterface $lastLogin;
  74.     public function __construct()
  75.     {
  76.         // date_default_timezone_set('Africa/Casablanca');
  77.         $this->createAt=new \DateTime('now');
  78.         $this->published=false;
  79.         $this->notifications = new ArrayCollection();
  80.     }
  81.     public function getEmail(): ?string
  82.     {
  83.         return $this->email;
  84.     }
  85.     public function setEmail(string $email): self
  86.     {
  87.         $this->email $email;
  88.         return $this;
  89.     }
  90.     /**
  91.      * A visual identifier that represents this user.
  92.      *
  93.      * @see UserInterface
  94.      */
  95.     public function getUserIdentifier(): string
  96.     {
  97.         return (string) $this->email;
  98.     }
  99.     /**
  100.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  101.      */
  102.     public function getUsername(): string
  103.     {
  104.         return (string) $this->email;
  105.     }
  106.     public function setUsername(string $username): self
  107.     {
  108.         $this->email $username;
  109.         return $this;
  110.     }
  111.     public function getRoleHierarchy()
  112.     {
  113.         return  [
  114.             'ROLE_ADMIN' => 'ROLE_USER',
  115.             'ROLE_LEARNER' => 'ROLE_USER',
  116.             'ROLE_STUDENT' => 'ROLE_LEARNER',
  117.             'ROLE_TRAINEE' => 'ROLE_LEARNER',
  118.             'ROLE_PARTICIPANT' => 'ROLE_LEARNER',
  119.             'ROLE_TEACHER' => 'ROLE_USER',
  120.             'ROLE_ASSISTANT' => 'ROLE_ADMIN',
  121.             'ROLE_OPERATOR' => 'ROLE_ASSISTANT',
  122.             'ROLE_SECRETARY' => 'ROLE_OPERATOR',
  123.             'ROLE_RESPONSABLE' => 'ROLE_SECRETARY',
  124.             'ROLE_DIRECTOR' => 'ROLE_RESPONSABLE',
  125.             'ROLE_TEACHER_ACTIVITY' => 'ROLE_TEACHER',
  126.             'ROLE_TEACHER_TUTORING' => 'ROLE_TEACHER',
  127.             'ROLE_TEACHER_TRAINING' => 'ROLE_TEACHER',
  128.             'ROLE_SECRETARY_TRAINING' => 'ROLE_SECRETARY',
  129.             'ROLE_SECRETARY_TUTORING' => 'ROLE_SECRETARY',
  130.             'ROLE_SECRETARY_ACTIVITY' => 'ROLE_SECRETARY',
  131.             'ROLE_RESPONSABLE_TRAINING' => ['ROLE_SECRETARY_TRAINING''ROLE_RESPONSABLE'],
  132.             'ROLE_RESPONSABLE_TUTORING' => ['ROLE_SECRETARY_TUTORING''ROLE_RESPONSABLE'],
  133.             'ROLE_RESPONSABLE_ACTIVITY' => ['ROLE_SECRETARY_ACTIVITY''ROLE_RESPONSABLE'],
  134.             'ROLE_DIRECTOR_TRAINING' => ['ROLE_RESPONSABLE_TRAINING''ROLE_DIRECTOR'],
  135.             'ROLE_DIRECTOR_TUTORING' => ['ROLE_RESPONSABLE_TUTORING''ROLE_DIRECTOR'],
  136.             'ROLE_DIRECTOR_ACTIVITY' => ['ROLE_RESPONSABLE_ACTIVITY''ROLE_DIRECTOR'],
  137.             'ROLE_SUPER_ADMIN' => ['ROLE_DIRECTOR_TRAINING''ROLE_DIRECTOR_TUTORING''ROLE_DIRECTOR_ACTIVITY'],
  138.             'ROLE_MANAGER_GENERAL' => 'ROLE_SUPER_ADMIN',
  139.             'ROLE_WEBMASTER' => 'ROLE_MANAGER_GENERAL',
  140.         ];
  141.     }
  142.     /**
  143.      * @see UserInterface
  144.      */
  145.     public function getRolesFr(): array
  146.     {
  147.         $roles $this->roles;
  148.         // guarantee every user at least has ROLE_USER
  149.         $roles[] = 'ROLE_USER';
  150.         $rolesFrancais = [];
  151.         foreach ($roles as $role) {
  152.             switch ($role) {
  153.                 case 'ROLE_TRAINEE':
  154.                     $rolesFrancais[] = 'Stagiaire';
  155.                     break;
  156.                 case 'ROLE_STUDENT':
  157.                     $rolesFrancais[] = 'Élève';
  158.                     break;
  159.                 case 'ROLE_TEACHER_TUTORING':
  160.                     $rolesFrancais[] = 'Tuteur';
  161.                     break;
  162.                 case 'ROLE_TEACHER_TRAINING':
  163.                     $rolesFrancais[] = 'Formateur';
  164.                     break;
  165.                 case 'ROLE_TEACHER_ACTIVITY':
  166.                     $rolesFrancais[] = 'Intervenant';
  167.                     break;
  168.                 case 'ROLE_ASSISTANT':
  169.                     $rolesFrancais[] = 'Assistant';
  170.                     break;
  171.                 case 'ROLE_OPERATOR':
  172.                     $rolesFrancais[] = 'Opérateur de saisie ';
  173.                     break;
  174.                 case 'ROLE_SECRETARY_TRAINING':
  175.                     $rolesFrancais[] = 'Secrétaire Formation Professionnelle';
  176.                     break;
  177.                 case 'ROLE_SECRETARY_TUTORING':
  178.                     $rolesFrancais[] = 'Secrétaire Soutien Scolaire';
  179.                     break;
  180.                 case 'ROLE_SECRETARY_ACTIVITY':
  181.                     $rolesFrancais[] = 'Secrétaire Activités Parallèles';
  182.                     break;
  183.                 case 'ROLE_DIRECTOR_TRAINING':
  184.                     $rolesFrancais[] = 'Directeur Formation Professionnelle';
  185.                     break;
  186.                 case 'ROLE_DIRECTOR_TUTORING':
  187.                     $rolesFrancais[] = 'Directeur Soutien Scolaire';
  188.                     break;
  189.                 case 'ROLE_DIRECTOR_ACTIVITY':
  190.                     $rolesFrancais[] = 'Directeur Activités Parallèles';
  191.                     break;
  192.                 case 'ROLE_RESPONSABLE_TRAINING':
  193.                     $rolesFrancais[] = 'Responsable Formation Professionnelle';
  194.                     break;
  195.                 case 'ROLE_RESPONSABLE_TUTORING':
  196.                     $rolesFrancais[] = 'Responsable Soutien Scolaire';
  197.                     break;
  198.                 case 'ROLE_RESPONSABLE_ACTIVITY':
  199.                     $rolesFrancais[] = 'Responsable Activités Parallèles';
  200.                     break;
  201.                 case 'ROLE_SUPER_ADMIN':
  202.                     $rolesFrancais[] = 'Vice-Directeur';
  203.                     break;
  204.                 case 'ROLE_MANAGER_GENERAL':
  205.                     $rolesFrancais[] = 'Directeur Général';
  206.                     break;
  207.                 case 'ROLE_WEBMASTER':
  208.                     $rolesFrancais[] = 'Webmaster';
  209.                     break;
  210.             }
  211.         }
  212.         return array_unique($rolesFrancais);
  213.     }
  214.     public function getRoles(): array
  215.     {
  216.         $roles $this->roles;
  217.         // guarantee every user at least has ROLE_USER
  218.         $roles[] = 'ROLE_USER';
  219.         return array_unique($roles);
  220.     }
  221.     public function setRoles(array $roles): self
  222.     {
  223.         $this->roles $roles;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @see PasswordAuthenticatedUserInterface
  228.      */
  229.     public function getPassword(): string
  230.     {
  231.         return $this->password;
  232.     }
  233.     public function setPassword(string $password): self
  234.     {
  235.         $this->password $password;
  236.         return $this;
  237.     }
  238.     /**
  239.      * Returning a salt is only needed, if you are not using a modern
  240.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  241.      *
  242.      * @see UserInterface
  243.      */
  244.     public function getSalt(): ?string
  245.     {
  246.         return null;
  247.     }
  248.     /**
  249.      * @see UserInterface
  250.      */
  251.     public function eraseCredentials()
  252.     {
  253.         // If you store any temporary, sensitive data on the user, clear it here
  254.         // $this->plainPassword = null;
  255.     }
  256.     /**
  257.      * @return string
  258.      */
  259.     public function getName(): ?string
  260.     {
  261.         return $this->name;
  262.     }
  263.     /**
  264.      * @param string $name
  265.      */
  266.     public function setName(?string $name): User
  267.     {
  268.         $this->name $name;
  269.         return $this;
  270.     }
  271.     /**
  272.      * @return string
  273.      */
  274.     public function getFirstName(): ?string
  275.     {
  276.         return $this->firstName;
  277.     }
  278.     /**
  279.      * @param string $firstName
  280.      */
  281.     public function setFirstName(?string $firstName): User
  282.     {
  283.         $this->firstName $firstName;
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return string
  288.      */
  289.     public function getLastName(): ?string
  290.     {
  291.         return $this->lastName;
  292.     }
  293.     /**
  294.      * @param string $lastName
  295.      */
  296.     public function setLastName(?string $lastName): User
  297.     {
  298.         $this->lastName $lastName;
  299.         return $this;
  300.     }
  301.     /**
  302.      * @return string
  303.      */
  304.     public function getPhone(): ?string
  305.     {
  306.         return $this->phone;
  307.     }
  308.     /**
  309.      * @param string $phone
  310.      */
  311.     public function setPhone(?string $phone): User
  312.     {
  313.         $this->phone $phone;
  314.         return $this;
  315.     }
  316.     /**
  317.      * @return mixed
  318.      */
  319.     public function getFormer()
  320.     {
  321.         return $this->former;
  322.     }
  323.     /**
  324.      * @return User
  325.      */
  326.     public function setFormer(mixed $former)
  327.     {
  328.         $this->former $former;
  329.         return $this;
  330.     }
  331.     /**
  332.      * @return mixed
  333.      */
  334.     public function getTrainee()
  335.     {
  336.         return $this->trainee;
  337.     }
  338.     /**
  339.      * @return User
  340.      */
  341.     public function setTrainee(mixed $trainee)
  342.     {
  343.         $this->trainee $trainee;
  344.         return $this;
  345.     }
  346.     /**
  347.      * @return mixed
  348.      */
  349.     public function getParticipant()
  350.     {
  351.         return $this->participant;
  352.     }
  353.     /**
  354.      * @param mixed $participant
  355.      */
  356.     public function setParticipant($participant): void
  357.     {
  358.         $this->participant $participant;
  359.     }
  360.     public function getNameComplet(){
  361.         if($this->firstName=='' && $this->lastName=='' && $this->firstName==null && $this->lastName==null)
  362.             return strstr($this->email'@',true);
  363.         else
  364.             return $this->lastName.' '.$this->firstName;
  365.     }
  366.     public function addRole($role)
  367.     {
  368.         $role strtoupper((string) $role);
  369.         if ($role === "ROLE_USER") {
  370.             return $this;
  371.         }
  372.         if (!in_array($role$this->rolestrue)) {
  373.             $this->roles[] = $role;
  374.         }
  375.         return $this;
  376.     }
  377.     public function hasRole($role)
  378.     {
  379.         return in_array(strtoupper((string) $role), $this->getRoles(), true);
  380.     }
  381.     public function hasRole2(string $role): bool
  382.     {
  383.         $allRoles $this->getAllRoles();
  384.         return in_array($role$allRolestrue);
  385.     }
  386.     public function getAllRoles(array $roles=null): array
  387.     {
  388.         $roles=$roles ?? $this->getRoles();
  389.         $roleHierarchy=$this->getRoleHierarchy();
  390.         $allRoles $roles;
  391.         foreach ($roles as $role) {
  392.             if (isset($roleHierarchy[$role])) {
  393.                 $childRoles = (array) $roleHierarchy[$role];
  394.                 $allRoles array_merge($allRoles$this->getAllRoles($childRoles));
  395.             }
  396.         }
  397.         return array_unique($allRoles);
  398.     }
  399.     function getParentRole($role) {
  400.         foreach ($this->getRoleHierarchy() as $parent => $children) {
  401.             if (is_array($children)) {
  402.                 if (in_array($role$children)) {
  403.                     return $parent;
  404.                 }
  405.             } else {
  406.                 if ($children === $role) {
  407.                     return $parent;
  408.                 }
  409.             }
  410.         }
  411.         return null// Si aucun parent n'est trouvé
  412.     }
  413.     public function getParentsRoles()
  414.     {
  415.         $items=[];
  416.         foreach ($this->getRoles() as $role) {
  417.             $items[]=$this->getParentRole($role);
  418.         }
  419.         return $items;
  420.     }
  421.     public function hasParentRole(User $user)
  422.     {
  423.         foreach ($user->getHighRoles() as $role) {
  424.             if (in_array($this->getParentRole($role), $this->getAllRoles(), true)) {
  425.                 return true;
  426.             }
  427.         }
  428.         return false;
  429.     }
  430.     public function getHighRoles()
  431.     {
  432.         $items=[];
  433.         foreach ($this->getRoles() as $role) {
  434.             if(!in_array($this->getParentRole($role), $this->getAllRoles(), true)) $items[]=$role;
  435.         }
  436.         return $items;
  437.     }
  438.     public function isSuperAdmin()
  439.     {
  440.         return $this->hasRole("ROLE_SUPER_ADMIN");
  441.     }
  442.     public function removeRole($role)
  443.     {
  444.         if (false !== $key array_search(strtoupper((string) $role), $this->rolestrue)) {
  445.             unset($this->roles[$key]);
  446.             $this->roles array_values($this->roles);
  447.         }
  448.         return $this;
  449.     }
  450.     /**
  451.      * @return Collection<int, Notification>
  452.      */
  453.     public function getNotifications(): Collection
  454.     {
  455.         return $this->notifications;
  456.     }
  457.     public function addNotification(Notification $notification): self
  458.     {
  459.         if (!$this->notifications->contains($notification)) {
  460.             $this->notifications->add($notification);
  461.             $notification->setUser($this);
  462.         }
  463.         return $this;
  464.     }
  465.     public function removeNotification(Notification $notification): self
  466.     {
  467.         if ($this->notifications->removeElement($notification)) {
  468.             // set the owning side to null (unless already changed)
  469.             if ($notification->getUser() === $this) {
  470.                 $notification->setUser(null);
  471.             }
  472.         }
  473.         return $this;
  474.     }
  475.     public function setPlainPassword(string $password): self{
  476.         $this->setPassword(
  477.             $this->hashPassword(
  478.                 $this,
  479.                 $password
  480.             )
  481.         );
  482.         return $this;
  483.     }
  484.     public function getLastLogin(): ?\DateTimeInterface
  485.     {
  486.         return $this->lastLogin;
  487.     }
  488.     public function setLastLogin(\DateTimeInterface $lastLogin): self
  489.     {
  490.         $this->lastLogin $lastLogin;
  491.         return $this;
  492.     }
  493.     public function __toString(): string
  494.     {
  495.         return (string) $this->email.' - '$this->getNameComplet();
  496.     }
  497.     public function getActionsS()
  498.     {
  499.         $actions="<div class='btn-group'>" .
  500.             "<button type='button' class='btn btn-default btn-flat dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>" .
  501.             "<span class='fa fa-ellipsis-v'></span>" .
  502.             "<span class='sr-only'>Toggle Dropdown</span>" .
  503.             "</button>" .
  504.             "<ul class='dropdown-menu dropdown-menu-right' role='menu'>";
  505.         $actions.="<li><a title='Modifier' class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('edit')."'>"
  506.             ."<i class='fa text-warning fa-fw fa-edit'></i> Modifier</a></li>";
  507.         $actions.="<li><a title='Afficher' class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('show')."'>"
  508.             ."<i class='fa text-info fa-fw fa-eye'></i> Afficher</a></li>";
  509.         $actions.="<li><a title='Supprimer ?' 
  510.                 data-toggle='confirmation'
  511.                 data-btn-ok-label='Supprimer' 
  512.                 data-btn-ok-icon='glyphicon glyphicon-ok'
  513.                 data-btn-ok-class='btn-success'
  514.                 data-btn-cancel-label='Annuler' 
  515.                 data-btn-cancel-icon='glyphicon glyphicon-remove'
  516.                 data-btn-cancel-class='btn-danger'
  517.                 data-title='Supprimer ?'
  518.                 data-popout='true'
  519.                 data-content='Voulez-vous vraiment supprimer cet élément ?' 
  520.                 class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('remove')."'>"
  521.             ."<i class='fa text-red fa-fw fa-trash-o'></i> Supprimer</a></li>";
  522.         $actions.="<li><a title='Changer le mot de passe' class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='hs_training_center_user_change_password'>"
  523.             ."<i class='fa fa-lock fa-fw text-warning'></i> Changer le mot de passe</a></li>";
  524.         $actions.="</ul></div>";
  525.         return $actions;
  526.     }
  527.     function generateRandomPassword($length 12) {
  528.         //$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+';
  529.         $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  530.         $password '';
  531.         $maxIndex strlen($characters) - 1;
  532.         for ($i 0$i $length$i++) {
  533.             $randomIndex mt_rand(0$maxIndex);
  534.             $password .= $characters[$randomIndex];
  535.         }
  536.         return $password;
  537.     }
  538.     public function getMatricule($title)
  539.     {
  540.         // replace non letter or digits by -
  541.         $text preg_replace('~[^\pL\d]+~u''', (string) $title);
  542.         // transliterate
  543.         $text iconv('utf-8''us-ascii//TRANSLIT'$text);
  544.         // remove unwanted characters
  545.         $text preg_replace('~[^\-\w]+~'''$text);
  546.         // trim
  547.         $text trim($text'-');
  548.         // remove duplicate -
  549.         $text preg_replace('~-+~''-'$text);
  550.         // lowercase
  551.         //$text = strtolower($text);
  552.         if (empty($text)) {
  553.             return 'n-a';
  554.         }
  555.         return $text;
  556.     }
  557.     function validatePassword($password) {
  558.         // Vérifiez la longueur minimale (au moins 6 caractères)
  559.         if (strlen($password) < 6) {
  560.             return false;
  561.         }
  562.         // Vérifiez la présence d'au moins un chiffre
  563.         if (!preg_match('/[0-9]/'$password)) {
  564.             return false;
  565.         }
  566.         // Vérifiez la présence d'au moins une lettre majuscule
  567.         if (!preg_match('/[A-Z]/'$password)) {
  568.             return false;
  569.         }
  570.         // Vérifiez la présence d'au moins une lettre minuscule
  571.         if (!preg_match('/[a-z]/'$password)) {
  572.             return false;
  573.         }
  574.         // Si toutes les conditions sont remplies, le mot de passe est valide
  575.         return true;
  576.     }
  577.     public function getTypeUser()
  578.     {
  579.         $type='all';
  580.         foreach ($this->roles as $role) {
  581.             switch ($role) {
  582.                 case 'ROLE_TRAINEE':
  583.                     $type 'trainees';
  584.                     break;
  585.                 case 'ROLE_STUDENT':
  586.                     $type 'students';
  587.                     break;
  588.                 case 'ROLE_TEACHER_TUTORING':
  589.                     $type 'tutors';
  590.                     break;
  591.                 case 'ROLE_TEACHER_TRAINING':
  592.                     $type 'formers';
  593.                     break;
  594.                 case 'ROLE_TEACHER_ACTIVITY':
  595.                     $type 'intervenants';
  596.                     break;
  597.                 case 'ROLE_ASSISTANT':
  598.                 case 'ROLE_SECRETARY_TRAINING':
  599.                 case 'ROLE_SECRETARY_TUTORING':
  600.                 case 'ROLE_SECRETARY_ACTIVITY':
  601.                 case 'ROLE_DIRECTOR_TRAINING':
  602.                 case 'ROLE_DIRECTOR_TUTORING':
  603.                 case 'ROLE_DIRECTOR_ACTIVITY':
  604.                 case 'ROLE_RESPONSABLE_TRAINING':
  605.                 case 'ROLE_RESPONSABLE_TUTORING':
  606.                 case 'ROLE_RESPONSABLE_ACTIVITY':
  607.                 case 'ROLE_SUPER_ADMIN':
  608.                 case 'ROLE_MANAGER_GENERAL':
  609.                     $type 'administrators';
  610.                     break;
  611.                 case 'ROLE_WEBMASTER':
  612.                     $type 'webmaster';
  613.                     break;
  614.             }
  615.         }
  616.         return $type;
  617.     }
  618.     /**
  619.      * @return mixed
  620.      */
  621.     public function getTutor()
  622.     {
  623.         return $this->tutor;
  624.     }
  625.     /**
  626.      * @param mixed $tutor
  627.      */
  628.     public function setTutor($tutor): void
  629.     {
  630.         $this->tutor $tutor;
  631.     }
  632.     /**
  633.      * @return mixed
  634.      */
  635.     public function getIntervenant()
  636.     {
  637.         return $this->intervenant;
  638.     }
  639.     /**
  640.      * @param mixed $intervenant
  641.      */
  642.     public function setIntervenant($intervenant): void
  643.     {
  644.         $this->intervenant $intervenant;
  645.     }
  646.     /**
  647.      * Add groupe
  648.      *
  649.      *
  650.      * @return User
  651.      */
  652.     public function addGroupe(Classe $groupe)
  653.     {
  654.         $groupe->setResponsable($this);
  655.         $this->groupes[] = $groupe;
  656.         return $this;
  657.     }
  658.     /**
  659.      * Remove groupe
  660.      */
  661.     public function removeGroupe(Classe $groupe)
  662.     {
  663.         $this->groupes->removeElement($groupe);
  664.     }
  665.     /**
  666.      * Get groupes
  667.      *
  668.      * @return Collection
  669.      */
  670.     public function getGroupes()
  671.     {
  672.         return $this->groupes;
  673.     }
  674.     
  675.     /**
  676.      * Add course
  677.      *
  678.      *
  679.      * @return User
  680.      */
  681.     public function addCourse(Course $course)
  682.     {
  683.         $course->setResponsable($this);
  684.         $this->courses[] = $course;
  685.         return $this;
  686.     }
  687.     /**
  688.      * Remove course
  689.      */
  690.     public function removeCourse(Course $course)
  691.     {
  692.         $this->courses->removeElement($course);
  693.     }
  694.     /**
  695.      * Get courses
  696.      *
  697.      * @return Collection
  698.      */
  699.     public function getCourses()
  700.     {
  701.         return $this->courses;
  702.     }
  703.     /**
  704.      * Add activite
  705.      *
  706.      *
  707.      * @return User
  708.      */
  709.     public function addClasse(Classe $classe)
  710.     {
  711.         $classe->setResponsable($this);
  712.         $this->classes[] = $classe;
  713.         return $this;
  714.     }
  715.     /**
  716.      * Remove classe
  717.      */
  718.     public function removeClasse(Classe $classe)
  719.     {
  720.         $this->classes->removeElement($classe);
  721.     }
  722.     /**
  723.      * Get classes
  724.      *
  725.      * @return Collection
  726.      */
  727.     public function getClasses()
  728.     {
  729.         return $this->classes;
  730.     }
  731.     public function getMyCurrentCourses(Schoolyear $schoolyear)
  732.     {
  733.         $items=[];
  734.         foreach ($this->getCourses() as $course) {
  735.             if ($course->getSchoolyear() === $schoolyear) {
  736.                 $items[] = $course;
  737.             }
  738.         }
  739.         return $items;
  740.     }
  741.     public function getCurrentGroupes(Schoolyear $schoolyear)
  742.     {
  743.         $groupes=new ArrayCollection();
  744.         /** @var Groupe $groupe */
  745.         foreach ($this->groupes as $groupe) {
  746.             if(in_array($groupe->getTrainingYearFr($schoolyear), ['1ier année''2ème année''3ème année'])) $groupes->add($groupe);
  747.         }
  748.         return $groupes;
  749.     }
  750.     public function getCurrentClasses(Schoolyear $schoolyear)
  751.     {
  752.         $classes=new ArrayCollection();
  753.         /** @var Classe $classe */
  754.         foreach ($this->classes as $classe) {
  755.             if($classe->getSchoolyear()===$schoolyear$classes->add($classe);
  756.         }
  757.         return $classes;
  758.     }
  759.     public function getNbrStudents(Schoolyear $schoolyear)
  760.     {
  761.         $nbr=0;
  762.         /** @var Course $course */
  763.         foreach ($this->getMyCurrentCourses($schoolyear) as $course) {
  764.             $nbr+=$course->getRowscourses()->count();
  765.         }
  766.         return $nbr;
  767.     }
  768.     public function getNbrStudentsInProgress(Schoolyear $schoolyear)
  769.     {
  770.         $nbr=0;
  771.         /** @var Course $course */
  772.         foreach ($this->getMyCurrentCourses($schoolyear) as $course) {
  773.             $nbr+=count($course->getInProgress());
  774.         }
  775.         return $nbr;
  776.     }
  777.     public function getNbrStudentsAbandons(Schoolyear $schoolyear)
  778.     {
  779.         $nbr=0;
  780.         /** @var Course $course */
  781.         foreach ($this->getMyCurrentCourses($schoolyear) as $course) {
  782.             $nbr+=count($course->getAbandons());
  783.         }
  784.         return $nbr;
  785.     }
  786.     public function getNbrTrainees(Schoolyear $schoolyear)
  787.     {
  788.         $nbr=0;
  789.         /** @var Groupe $groupe */
  790.         foreach ($this->getCurrentGroupes($schoolyear) as $groupe) {
  791.             $nbr+=$groupe->getTrainees()->count();
  792.         }
  793.         return $nbr;
  794.     }
  795.     public function getNbrTraineesInProgress(Schoolyear $schoolyear)
  796.     {
  797.         $nbr=0;
  798.         /** @var Groupe $groupe */
  799.         foreach ($this->getCurrentGroupes($schoolyear) as $groupe) {
  800.             $nbr+=$groupe->getNbrTrainees();
  801.         }
  802.         return $nbr;
  803.     }
  804.     public function getNbrTraineesAbandons(Schoolyear $schoolyear)
  805.     {
  806.         $nbr=0;
  807.         /** @var Groupe $groupe */
  808.         foreach ($this->getCurrentGroupes($schoolyear) as $groupe) {
  809.             $nbr+=$groupe->getNbrAbandonnes();
  810.         }
  811.         return $nbr;
  812.     }
  813.     public function getNbrParticipants(Schoolyear $schoolyear)
  814.     {
  815.         $nbr=0;
  816.         /** @var Classe $classe */
  817.         foreach ($this->getCurrentClasses($schoolyear) as $classe) {
  818.             $nbr+=$classe->getParticipants()->count();
  819.         }
  820.         return $nbr;
  821.     }
  822.     public function getNbrParticipantsInProgress(Schoolyear $schoolyear)
  823.     {
  824.         $nbr=0;
  825.         /** @var Classe $classe */
  826.         foreach ($this->getCurrentClasses($schoolyear) as $classe) {
  827.             $nbr+=$classe->getNbrParticipants();
  828.         }
  829.         return $nbr;
  830.     }
  831.     public function getNbrParticipantsAbandons(Schoolyear $schoolyear)
  832.     {
  833.         $nbr=0;
  834.         /** @var Classe $classe */
  835.         foreach ($this->getCurrentClasses($schoolyear) as $classe) {
  836.             $nbr+=$classe->getNbrAbandonnes();
  837.         }
  838.         return $nbr;
  839.     }
  840.     public function getTotalApprenants(Schoolyear $schoolyear)
  841.     {
  842.         return $this->getNbrTrainees($schoolyear)+$this->getNbrParticipants($schoolyear)+$this->getNbrStudents($schoolyear);
  843.     }
  844.     public function getLatePaid(Schoolyear $schoolyear$service='all'){
  845.         $sum=0;
  846.         if($service=='tutoring'){
  847.             /** @var Course $course */
  848.             foreach ($this->getMyCurrentCourses($schoolyear) as $course){
  849.                 $sum+=$course->getRest();
  850.             }
  851.         }
  852.         elseif($service=='training'){
  853.             foreach ($this->getCurrentGroupes($schoolyear) as $groupe){
  854.                 $sum+=$groupe->getRestPay('all');
  855.             }
  856.         }
  857.         elseif($service=='formation'){
  858.             foreach ($this->getCurrentClasses($schoolyear) as $classe){
  859.                 $sum+=$classe->getRestPay('all');
  860.             }
  861.         }
  862.         elseif ($service=='all'){
  863.             $sum=$this->getLatePaid($schoolyear'tutoring')+$this->getLatePaid($schoolyear'training') + $this->getLatePaid($schoolyear'formation');
  864.         }
  865.         return $sum;
  866.     }
  867.     public function getNbrRetard(Schoolyear $schoolyear$service='all'){
  868.         $sum=0;
  869.         if($service=='tutoring'){
  870.             foreach ($this->getMyCurrentCourses($schoolyear) as $course){
  871.                 $sum+=$course->getNbrRetard();
  872.             }
  873.         }
  874.         elseif($service=='training'){
  875.             foreach ($this->getCurrentGroupes($schoolyear) as $groupe){
  876.                 $sum+=$groupe->getNbrRetard('all');
  877.             }
  878.         }
  879.         elseif($service=='formation'){
  880.             foreach ($this->getCurrentClasses($schoolyear) as $classe){
  881.                 $sum+=$classe->getNbrRetard('all');
  882.             }
  883.         }
  884.         elseif ($service=='all'){
  885.             $sum=$this->getNbrRetard($schoolyear'tutoring')+$this->getNbrRetard($schoolyear'training') + $this->getNbrRetard($schoolyear'formation');
  886.         }
  887.         return $sum;
  888.     }
  889.     public function getAdvance($service){
  890.         $sum=0;
  891.         if($service=='tutoring'){
  892.             foreach ($this->getCourses() as $course){
  893.                 $sum+=$course->getAdvance();
  894.             }
  895.         }
  896.         elseif($service=='training'){
  897.             foreach ($this->getGroupes() as $groupe){
  898.                 $sum+=$groupe->getAdvance('all');
  899.             }
  900.         }
  901.         elseif ($service=='all'){
  902.             $sum=$this->getAdvance('tutoring')+$this->getAdvance('training');
  903.         }
  904.         return $sum;
  905.     }
  906.     public function getButtonEnable($redirect=null)
  907.     {
  908.         $confirm="data-toggle='confirmation'
  909.                 data-btn-ok-label='Oui' 
  910.                 data-btn-ok-icon='glyphicon glyphicon-ok'
  911.                 data-btn-ok-class='btn-success'
  912.                 data-btn-cancel-label='Non' 
  913.                 data-btn-cancel-icon='glyphicon glyphicon-remove'
  914.                 data-btn-cancel-class='btn-danger'
  915.                 data-title='Changer statut ?'
  916.                 data-popout='true'
  917.                 data-content='Voulez-vous vraiment changer le statut de cet élément ?' ";
  918.         if($this->published && ($this->groupes->count()>|| $this->courses->count()>0)){
  919.             $icon"<i class=\"text-green fa fa-toggle-on\"> Oui</i>";
  920.             $btn="<a ".$confirm." href='javascript:void(0)'  class='btn_statut_user' data-id='".$this->id."' data-boledit-route='".$this->getRoute('statut')."'>".$icon."</a>";
  921.         }
  922.         elseif($this->published){
  923.             $icon"<i class=\"text-green fa fa-toggle-on\"> Oui</i>";
  924.             $btn="<a ".$confirm." href='javascript:void(0)' class='boledit' data-boledit-id='".$this->id."' data-boledit-route='".$this->getRoute('statut')."'>".$icon."</a> </td>";
  925.         }
  926.         else{
  927.             $icon"<i class=\"text-red fa fa-toggle-off\"> Non</i>";
  928.             $btn="<a ".$confirm." href='javascript:void(0)' class='boledit' data-boledit-id='".$this->id."' data-boledit-route='".$this->getRoute('statut')."'>".$icon."</a> </td>";
  929.         }
  930.         return $btn;
  931.     }
  932.     function isChildRole($childRole$parentRole$roleHierarchy) {
  933.         if (!isset($roleHierarchy[$parentRole])) {
  934.             return false// Le rôle parent n'existe pas dans la hiérarchie
  935.         }
  936.         $children $roleHierarchy[$parentRole];
  937.         if (is_array($children)) {
  938.             if (in_array($childRole$children)) {
  939.                 return true;
  940.             }
  941.             foreach ($children as $child) {
  942.                 if (isChildRole($childRole$child$roleHierarchy)) {
  943.                     return true;
  944.                 }
  945.             }
  946.         } else {
  947.             if ($children === $childRole) {
  948.                 return true;
  949.             }
  950.             return isChildRole($childRole$children$roleHierarchy);
  951.         }
  952.         return false;
  953.     }
  954.     /**
  955.      * @return string
  956.      */
  957.     public function getSkin(): ?string
  958.     {
  959.         return $this->skin;
  960.     }
  961.     public function setSkin(?string $skin): self
  962.     {
  963.         $this->skin $skin;
  964.         return $this;
  965.     }
  966. }