<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Formation\Intervenant;
use App\Entity\Formation\Apayment;
use App\Entity\Formation\Classe;
use App\Entity\Formation\Participant;
use App\Entity\Training\Former;
use App\Entity\Training\Fpayment;
use App\Entity\Training\Groupe;
use App\Entity\Training\Trainee;
use App\Entity\Tutoring\Course;
use App\Entity\Tutoring\Tutor;
use App\Repository\UserRepository;
use App\Traits\Actions;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'hs_tc_user')]
#[ApiResource]
class User implements UserInterface, PasswordAuthenticatedUserInterface, UserPasswordHasherInterface, \Stringable
{
final public const ROLE_DEFAULT = 'ROLE_USER';
final public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
use Actions;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(name: "name", type: "string", length: 255, nullable: true)]
private ?string $name=null;
#[ORM\Column(name: "first_name", type: "string", length: 255, nullable: true)]
private ?string $firstName=null;
#[ORM\Column(name: "last_name", type: "string", length: 255, nullable: true)]
private ?string $lastName=null;
#[ORM\Column(name: "phone", type: "string", length: 255, nullable: true)]
private ?string $phone=null;
#[ORM\Column(name: "skin", type: "string", length: 255, nullable: true)]
private ?string $skin = 'skin-red';
#[ORM\OneToOne(mappedBy: 'user', targetEntity: Former::class, cascade: ['persist', 'remove'])]
private $former;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: Tutor::class, cascade: ['persist', 'remove'])]
private $tutor;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: Intervenant::class, cascade: ['persist', 'remove'])]
private $intervenant;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: Trainee::class, cascade: ['all'])]
private $trainee;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: Participant::class, cascade: ['all'])]
private $participant;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Notification::class, orphanRemoval: true)]
private Collection $notifications;
#[ORM\OneToMany(mappedBy: 'initie', targetEntity: Apayment::class, orphanRemoval: true)]
private Collection $payments;
#[ORM\OneToMany(mappedBy: 'responsable', targetEntity: Groupe::class)]
private Collection $groupes;
#[ORM\OneToMany(mappedBy: 'responsable', targetEntity: Course::class)]
private Collection $courses;
#[ORM\OneToMany(mappedBy: 'responsable', targetEntity: Classe::class)]
private Collection $classes;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $lastLogin;
public function __construct()
{
// date_default_timezone_set('Africa/Casablanca');
$this->createAt=new \DateTime('now');
$this->published=false;
$this->notifications = new ArrayCollection();
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
public function setUsername(string $username): self
{
$this->email = $username;
return $this;
}
public function getRoleHierarchy()
{
return [
'ROLE_ADMIN' => 'ROLE_USER',
'ROLE_LEARNER' => 'ROLE_USER',
'ROLE_STUDENT' => 'ROLE_LEARNER',
'ROLE_TRAINEE' => 'ROLE_LEARNER',
'ROLE_PARTICIPANT' => 'ROLE_LEARNER',
'ROLE_TEACHER' => 'ROLE_USER',
'ROLE_ASSISTANT' => 'ROLE_ADMIN',
'ROLE_OPERATOR' => 'ROLE_ASSISTANT',
'ROLE_SECRETARY' => 'ROLE_OPERATOR',
'ROLE_RESPONSABLE' => 'ROLE_SECRETARY',
'ROLE_DIRECTOR' => 'ROLE_RESPONSABLE',
'ROLE_TEACHER_ACTIVITY' => 'ROLE_TEACHER',
'ROLE_TEACHER_TUTORING' => 'ROLE_TEACHER',
'ROLE_TEACHER_TRAINING' => 'ROLE_TEACHER',
'ROLE_SECRETARY_TRAINING' => 'ROLE_SECRETARY',
'ROLE_SECRETARY_TUTORING' => 'ROLE_SECRETARY',
'ROLE_SECRETARY_ACTIVITY' => 'ROLE_SECRETARY',
'ROLE_RESPONSABLE_TRAINING' => ['ROLE_SECRETARY_TRAINING', 'ROLE_RESPONSABLE'],
'ROLE_RESPONSABLE_TUTORING' => ['ROLE_SECRETARY_TUTORING', 'ROLE_RESPONSABLE'],
'ROLE_RESPONSABLE_ACTIVITY' => ['ROLE_SECRETARY_ACTIVITY', 'ROLE_RESPONSABLE'],
'ROLE_DIRECTOR_TRAINING' => ['ROLE_RESPONSABLE_TRAINING', 'ROLE_DIRECTOR'],
'ROLE_DIRECTOR_TUTORING' => ['ROLE_RESPONSABLE_TUTORING', 'ROLE_DIRECTOR'],
'ROLE_DIRECTOR_ACTIVITY' => ['ROLE_RESPONSABLE_ACTIVITY', 'ROLE_DIRECTOR'],
'ROLE_SUPER_ADMIN' => ['ROLE_DIRECTOR_TRAINING', 'ROLE_DIRECTOR_TUTORING', 'ROLE_DIRECTOR_ACTIVITY'],
'ROLE_MANAGER_GENERAL' => 'ROLE_SUPER_ADMIN',
'ROLE_WEBMASTER' => 'ROLE_MANAGER_GENERAL',
];
}
/**
* @see UserInterface
*/
public function getRolesFr(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
$rolesFrancais = [];
foreach ($roles as $role) {
switch ($role) {
case 'ROLE_TRAINEE':
$rolesFrancais[] = 'Stagiaire';
break;
case 'ROLE_STUDENT':
$rolesFrancais[] = 'Élève';
break;
case 'ROLE_TEACHER_TUTORING':
$rolesFrancais[] = 'Tuteur';
break;
case 'ROLE_TEACHER_TRAINING':
$rolesFrancais[] = 'Formateur';
break;
case 'ROLE_TEACHER_ACTIVITY':
$rolesFrancais[] = 'Intervenant';
break;
case 'ROLE_ASSISTANT':
$rolesFrancais[] = 'Assistant';
break;
case 'ROLE_OPERATOR':
$rolesFrancais[] = 'Opérateur de saisie ';
break;
case 'ROLE_SECRETARY_TRAINING':
$rolesFrancais[] = 'Secrétaire Formation Professionnelle';
break;
case 'ROLE_SECRETARY_TUTORING':
$rolesFrancais[] = 'Secrétaire Soutien Scolaire';
break;
case 'ROLE_SECRETARY_ACTIVITY':
$rolesFrancais[] = 'Secrétaire Activités Parallèles';
break;
case 'ROLE_DIRECTOR_TRAINING':
$rolesFrancais[] = 'Directeur Formation Professionnelle';
break;
case 'ROLE_DIRECTOR_TUTORING':
$rolesFrancais[] = 'Directeur Soutien Scolaire';
break;
case 'ROLE_DIRECTOR_ACTIVITY':
$rolesFrancais[] = 'Directeur Activités Parallèles';
break;
case 'ROLE_RESPONSABLE_TRAINING':
$rolesFrancais[] = 'Responsable Formation Professionnelle';
break;
case 'ROLE_RESPONSABLE_TUTORING':
$rolesFrancais[] = 'Responsable Soutien Scolaire';
break;
case 'ROLE_RESPONSABLE_ACTIVITY':
$rolesFrancais[] = 'Responsable Activités Parallèles';
break;
case 'ROLE_SUPER_ADMIN':
$rolesFrancais[] = 'Vice-Directeur';
break;
case 'ROLE_MANAGER_GENERAL':
$rolesFrancais[] = 'Directeur Général';
break;
case 'ROLE_WEBMASTER':
$rolesFrancais[] = 'Webmaster';
break;
}
}
return array_unique($rolesFrancais);
}
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return string
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(?string $name): User
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getFirstName(): ?string
{
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName(?string $firstName): User
{
$this->firstName = $firstName;
return $this;
}
/**
* @return string
*/
public function getLastName(): ?string
{
return $this->lastName;
}
/**
* @param string $lastName
*/
public function setLastName(?string $lastName): User
{
$this->lastName = $lastName;
return $this;
}
/**
* @return string
*/
public function getPhone(): ?string
{
return $this->phone;
}
/**
* @param string $phone
*/
public function setPhone(?string $phone): User
{
$this->phone = $phone;
return $this;
}
/**
* @return mixed
*/
public function getFormer()
{
return $this->former;
}
/**
* @return User
*/
public function setFormer(mixed $former)
{
$this->former = $former;
return $this;
}
/**
* @return mixed
*/
public function getTrainee()
{
return $this->trainee;
}
/**
* @return User
*/
public function setTrainee(mixed $trainee)
{
$this->trainee = $trainee;
return $this;
}
/**
* @return mixed
*/
public function getParticipant()
{
return $this->participant;
}
/**
* @param mixed $participant
*/
public function setParticipant($participant): void
{
$this->participant = $participant;
}
public function getNameComplet(){
if($this->firstName=='' && $this->lastName=='' && $this->firstName==null && $this->lastName==null)
return strstr($this->email, '@',true);
else
return $this->lastName.' '.$this->firstName;
}
public function addRole($role)
{
$role = strtoupper((string) $role);
if ($role === "ROLE_USER") {
return $this;
}
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
public function hasRole($role)
{
return in_array(strtoupper((string) $role), $this->getRoles(), true);
}
public function hasRole2(string $role): bool
{
$allRoles = $this->getAllRoles();
return in_array($role, $allRoles, true);
}
public function getAllRoles(array $roles=null): array
{
$roles=$roles ?? $this->getRoles();
$roleHierarchy=$this->getRoleHierarchy();
$allRoles = $roles;
foreach ($roles as $role) {
if (isset($roleHierarchy[$role])) {
$childRoles = (array) $roleHierarchy[$role];
$allRoles = array_merge($allRoles, $this->getAllRoles($childRoles));
}
}
return array_unique($allRoles);
}
function getParentRole($role) {
foreach ($this->getRoleHierarchy() as $parent => $children) {
if (is_array($children)) {
if (in_array($role, $children)) {
return $parent;
}
} else {
if ($children === $role) {
return $parent;
}
}
}
return null; // Si aucun parent n'est trouvé
}
public function getParentsRoles()
{
$items=[];
foreach ($this->getRoles() as $role) {
$items[]=$this->getParentRole($role);
}
return $items;
}
public function hasParentRole(User $user)
{
foreach ($user->getHighRoles() as $role) {
if (in_array($this->getParentRole($role), $this->getAllRoles(), true)) {
return true;
}
}
return false;
}
public function getHighRoles()
{
$items=[];
foreach ($this->getRoles() as $role) {
if(!in_array($this->getParentRole($role), $this->getAllRoles(), true)) $items[]=$role;
}
return $items;
}
public function isSuperAdmin()
{
return $this->hasRole("ROLE_SUPER_ADMIN");
}
public function removeRole($role)
{
if (false !== $key = array_search(strtoupper((string) $role), $this->roles, true)) {
unset($this->roles[$key]);
$this->roles = array_values($this->roles);
}
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications->add($notification);
$notification->setUser($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getUser() === $this) {
$notification->setUser(null);
}
}
return $this;
}
public function setPlainPassword(string $password): self{
$this->setPassword(
$this->hashPassword(
$this,
$password
)
);
return $this;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->lastLogin;
}
public function setLastLogin(\DateTimeInterface $lastLogin): self
{
$this->lastLogin = $lastLogin;
return $this;
}
public function __toString(): string
{
return (string) $this->email.' - '. $this->getNameComplet();
}
public function getActionsS()
{
$actions="<div class='btn-group'>" .
"<button type='button' class='btn btn-default btn-flat dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>" .
"<span class='fa fa-ellipsis-v'></span>" .
"<span class='sr-only'>Toggle Dropdown</span>" .
"</button>" .
"<ul class='dropdown-menu dropdown-menu-right' role='menu'>";
$actions.="<li><a title='Modifier' class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('edit')."'>"
."<i class='fa text-warning fa-fw fa-edit'></i> Modifier</a></li>";
$actions.="<li><a title='Afficher' class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('show')."'>"
."<i class='fa text-info fa-fw fa-eye'></i> Afficher</a></li>";
$actions.="<li><a title='Supprimer ?'
data-toggle='confirmation'
data-btn-ok-label='Supprimer'
data-btn-ok-icon='glyphicon glyphicon-ok'
data-btn-ok-class='btn-success'
data-btn-cancel-label='Annuler'
data-btn-cancel-icon='glyphicon glyphicon-remove'
data-btn-cancel-class='btn-danger'
data-title='Supprimer ?'
data-popout='true'
data-content='Voulez-vous vraiment supprimer cet élément ?'
class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('remove')."'>"
."<i class='fa text-red fa-fw fa-trash-o'></i> Supprimer</a></li>";
$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'>"
."<i class='fa fa-lock fa-fw text-warning'></i> Changer le mot de passe</a></li>";
$actions.="</ul></div>";
return $actions;
}
function generateRandomPassword($length = 12) {
//$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+';
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$password = '';
$maxIndex = strlen($characters) - 1;
for ($i = 0; $i < $length; $i++) {
$randomIndex = mt_rand(0, $maxIndex);
$password .= $characters[$randomIndex];
}
return $password;
}
public function getMatricule($title)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '', (string) $title);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^\-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
//$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
function validatePassword($password) {
// Vérifiez la longueur minimale (au moins 6 caractères)
if (strlen($password) < 6) {
return false;
}
// Vérifiez la présence d'au moins un chiffre
if (!preg_match('/[0-9]/', $password)) {
return false;
}
// Vérifiez la présence d'au moins une lettre majuscule
if (!preg_match('/[A-Z]/', $password)) {
return false;
}
// Vérifiez la présence d'au moins une lettre minuscule
if (!preg_match('/[a-z]/', $password)) {
return false;
}
// Si toutes les conditions sont remplies, le mot de passe est valide
return true;
}
public function getTypeUser()
{
$type='all';
foreach ($this->roles as $role) {
switch ($role) {
case 'ROLE_TRAINEE':
$type = 'trainees';
break;
case 'ROLE_STUDENT':
$type = 'students';
break;
case 'ROLE_TEACHER_TUTORING':
$type = 'tutors';
break;
case 'ROLE_TEACHER_TRAINING':
$type = 'formers';
break;
case 'ROLE_TEACHER_ACTIVITY':
$type = 'intervenants';
break;
case 'ROLE_ASSISTANT':
case 'ROLE_SECRETARY_TRAINING':
case 'ROLE_SECRETARY_TUTORING':
case 'ROLE_SECRETARY_ACTIVITY':
case 'ROLE_DIRECTOR_TRAINING':
case 'ROLE_DIRECTOR_TUTORING':
case 'ROLE_DIRECTOR_ACTIVITY':
case 'ROLE_RESPONSABLE_TRAINING':
case 'ROLE_RESPONSABLE_TUTORING':
case 'ROLE_RESPONSABLE_ACTIVITY':
case 'ROLE_SUPER_ADMIN':
case 'ROLE_MANAGER_GENERAL':
$type = 'administrators';
break;
case 'ROLE_WEBMASTER':
$type = 'webmaster';
break;
}
}
return $type;
}
/**
* @return mixed
*/
public function getTutor()
{
return $this->tutor;
}
/**
* @param mixed $tutor
*/
public function setTutor($tutor): void
{
$this->tutor = $tutor;
}
/**
* @return mixed
*/
public function getIntervenant()
{
return $this->intervenant;
}
/**
* @param mixed $intervenant
*/
public function setIntervenant($intervenant): void
{
$this->intervenant = $intervenant;
}
/**
* Add groupe
*
*
* @return User
*/
public function addGroupe(Classe $groupe)
{
$groupe->setResponsable($this);
$this->groupes[] = $groupe;
return $this;
}
/**
* Remove groupe
*/
public function removeGroupe(Classe $groupe)
{
$this->groupes->removeElement($groupe);
}
/**
* Get groupes
*
* @return Collection
*/
public function getGroupes()
{
return $this->groupes;
}
/**
* Add course
*
*
* @return User
*/
public function addCourse(Course $course)
{
$course->setResponsable($this);
$this->courses[] = $course;
return $this;
}
/**
* Remove course
*/
public function removeCourse(Course $course)
{
$this->courses->removeElement($course);
}
/**
* Get courses
*
* @return Collection
*/
public function getCourses()
{
return $this->courses;
}
/**
* Add activite
*
*
* @return User
*/
public function addClasse(Classe $classe)
{
$classe->setResponsable($this);
$this->classes[] = $classe;
return $this;
}
/**
* Remove classe
*/
public function removeClasse(Classe $classe)
{
$this->classes->removeElement($classe);
}
/**
* Get classes
*
* @return Collection
*/
public function getClasses()
{
return $this->classes;
}
public function getMyCurrentCourses(Schoolyear $schoolyear)
{
$items=[];
foreach ($this->getCourses() as $course) {
if ($course->getSchoolyear() === $schoolyear) {
$items[] = $course;
}
}
return $items;
}
public function getCurrentGroupes(Schoolyear $schoolyear)
{
$groupes=new ArrayCollection();
/** @var Groupe $groupe */
foreach ($this->groupes as $groupe) {
if(in_array($groupe->getTrainingYearFr($schoolyear), ['1ier année', '2ème année', '3ème année'])) $groupes->add($groupe);
}
return $groupes;
}
public function getCurrentClasses(Schoolyear $schoolyear)
{
$classes=new ArrayCollection();
/** @var Classe $classe */
foreach ($this->classes as $classe) {
if($classe->getSchoolyear()===$schoolyear) $classes->add($classe);
}
return $classes;
}
public function getNbrStudents(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Course $course */
foreach ($this->getMyCurrentCourses($schoolyear) as $course) {
$nbr+=$course->getRowscourses()->count();
}
return $nbr;
}
public function getNbrStudentsInProgress(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Course $course */
foreach ($this->getMyCurrentCourses($schoolyear) as $course) {
$nbr+=count($course->getInProgress());
}
return $nbr;
}
public function getNbrStudentsAbandons(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Course $course */
foreach ($this->getMyCurrentCourses($schoolyear) as $course) {
$nbr+=count($course->getAbandons());
}
return $nbr;
}
public function getNbrTrainees(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Groupe $groupe */
foreach ($this->getCurrentGroupes($schoolyear) as $groupe) {
$nbr+=$groupe->getTrainees()->count();
}
return $nbr;
}
public function getNbrTraineesInProgress(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Groupe $groupe */
foreach ($this->getCurrentGroupes($schoolyear) as $groupe) {
$nbr+=$groupe->getNbrTrainees();
}
return $nbr;
}
public function getNbrTraineesAbandons(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Groupe $groupe */
foreach ($this->getCurrentGroupes($schoolyear) as $groupe) {
$nbr+=$groupe->getNbrAbandonnes();
}
return $nbr;
}
public function getNbrParticipants(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Classe $classe */
foreach ($this->getCurrentClasses($schoolyear) as $classe) {
$nbr+=$classe->getParticipants()->count();
}
return $nbr;
}
public function getNbrParticipantsInProgress(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Classe $classe */
foreach ($this->getCurrentClasses($schoolyear) as $classe) {
$nbr+=$classe->getNbrParticipants();
}
return $nbr;
}
public function getNbrParticipantsAbandons(Schoolyear $schoolyear)
{
$nbr=0;
/** @var Classe $classe */
foreach ($this->getCurrentClasses($schoolyear) as $classe) {
$nbr+=$classe->getNbrAbandonnes();
}
return $nbr;
}
public function getTotalApprenants(Schoolyear $schoolyear)
{
return $this->getNbrTrainees($schoolyear)+$this->getNbrParticipants($schoolyear)+$this->getNbrStudents($schoolyear);
}
public function getLatePaid(Schoolyear $schoolyear, $service='all'){
$sum=0;
if($service=='tutoring'){
/** @var Course $course */
foreach ($this->getMyCurrentCourses($schoolyear) as $course){
$sum+=$course->getRest();
}
}
elseif($service=='training'){
foreach ($this->getCurrentGroupes($schoolyear) as $groupe){
$sum+=$groupe->getRestPay('all');
}
}
elseif($service=='formation'){
foreach ($this->getCurrentClasses($schoolyear) as $classe){
$sum+=$classe->getRestPay('all');
}
}
elseif ($service=='all'){
$sum=$this->getLatePaid($schoolyear, 'tutoring')+$this->getLatePaid($schoolyear, 'training') + $this->getLatePaid($schoolyear, 'formation');
}
return $sum;
}
public function getNbrRetard(Schoolyear $schoolyear, $service='all'){
$sum=0;
if($service=='tutoring'){
foreach ($this->getMyCurrentCourses($schoolyear) as $course){
$sum+=$course->getNbrRetard();
}
}
elseif($service=='training'){
foreach ($this->getCurrentGroupes($schoolyear) as $groupe){
$sum+=$groupe->getNbrRetard('all');
}
}
elseif($service=='formation'){
foreach ($this->getCurrentClasses($schoolyear) as $classe){
$sum+=$classe->getNbrRetard('all');
}
}
elseif ($service=='all'){
$sum=$this->getNbrRetard($schoolyear, 'tutoring')+$this->getNbrRetard($schoolyear, 'training') + $this->getNbrRetard($schoolyear, 'formation');
}
return $sum;
}
public function getAdvance($service){
$sum=0;
if($service=='tutoring'){
foreach ($this->getCourses() as $course){
$sum+=$course->getAdvance();
}
}
elseif($service=='training'){
foreach ($this->getGroupes() as $groupe){
$sum+=$groupe->getAdvance('all');
}
}
elseif ($service=='all'){
$sum=$this->getAdvance('tutoring')+$this->getAdvance('training');
}
return $sum;
}
public function getButtonEnable($redirect=null)
{
$confirm="data-toggle='confirmation'
data-btn-ok-label='Oui'
data-btn-ok-icon='glyphicon glyphicon-ok'
data-btn-ok-class='btn-success'
data-btn-cancel-label='Non'
data-btn-cancel-icon='glyphicon glyphicon-remove'
data-btn-cancel-class='btn-danger'
data-title='Changer statut ?'
data-popout='true'
data-content='Voulez-vous vraiment changer le statut de cet élément ?' ";
if($this->published && ($this->groupes->count()>0 || $this->courses->count()>0)){
$icon= "<i class=\"text-green fa fa-toggle-on\"> Oui</i>";
$btn="<a ".$confirm." href='javascript:void(0)' class='btn_statut_user' data-id='".$this->id."' data-boledit-route='".$this->getRoute('statut')."'>".$icon."</a>";
}
elseif($this->published){
$icon= "<i class=\"text-green fa fa-toggle-on\"> Oui</i>";
$btn="<a ".$confirm." href='javascript:void(0)' class='boledit' data-boledit-id='".$this->id."' data-boledit-route='".$this->getRoute('statut')."'>".$icon."</a> </td>";
}
else{
$icon= "<i class=\"text-red fa fa-toggle-off\"> Non</i>";
$btn="<a ".$confirm." href='javascript:void(0)' class='boledit' data-boledit-id='".$this->id."' data-boledit-route='".$this->getRoute('statut')."'>".$icon."</a> </td>";
}
return $btn;
}
function isChildRole($childRole, $parentRole, $roleHierarchy) {
if (!isset($roleHierarchy[$parentRole])) {
return false; // Le rôle parent n'existe pas dans la hiérarchie
}
$children = $roleHierarchy[$parentRole];
if (is_array($children)) {
if (in_array($childRole, $children)) {
return true;
}
foreach ($children as $child) {
if (isChildRole($childRole, $child, $roleHierarchy)) {
return true;
}
}
} else {
if ($children === $childRole) {
return true;
}
return isChildRole($childRole, $children, $roleHierarchy);
}
return false;
}
/**
* @return string
*/
public function getSkin(): ?string
{
return $this->skin;
}
public function setSkin(?string $skin): self
{
$this->skin = $skin;
return $this;
}
}