src/Entity/Compagne.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CompagneRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\Persistence\ObjectManagerAware;
  8. use Doctrine\Persistence\Mapping\ClassMetadata;
  9. /**
  10. * @ORM\Entity(repositoryClass=CompagneRepository::class)
  11. */
  12. class Compagne implements ObjectManagerAware
  13. {
  14. /**
  15. * @ORM\Id()
  16. * @ORM\GeneratedValue()
  17. * @ORM\Column(type="integer")
  18. */
  19. private $id;
  20. /**
  21. * @ORM\OneToMany(targetEntity=CampagneCouche::class, mappedBy="compagne")
  22. */
  23. private $campagneCouches;
  24. /**
  25. * @ORM\Column(type="integer")
  26. */
  27. private $Type;
  28. /**
  29. * @ORM\Column(type="string", length=255)
  30. */
  31. private $Nom;
  32. /**
  33. * @ORM\Column(type="string", length=255, nullable=true)
  34. */
  35. private $Description;
  36. /**
  37. * @ORM\Column(name="DateDebut",type="datetime")
  38. */
  39. private $DateDebut;
  40. /**
  41. * @ORM\Column(name="DateFin",type="datetime")
  42. */
  43. private $DateFin;
  44. /**
  45. * @ORM\Column(type="integer",nullable=true,options={"default" : 0})
  46. */
  47. private $Progression;
  48. /**
  49. * @ORM\Column(type="integer", nullable=true)
  50. */
  51. private $Objectif;
  52. /**
  53. * @ORM\ManyToOne(targetEntity=Projet::class, inversedBy="compagnes")
  54. * @ORM\JoinColumn(name="id_projet", referencedColumnName="id")
  55. */
  56. private $projet;
  57. /**
  58. * @ORM\Column(type="integer",nullable=true,options={"default" : 0 , "comment":"Nbr des apprenants appelés au moins une seule fois"})
  59. */
  60. private $Tentative = 0;
  61. /**
  62. * @ORM\Column(type="integer",nullable=true,options={"default" : 0})
  63. */
  64. private $archive = 0;
  65. /**
  66. * @ORM\Column(name="DateFinReelle",type="datetime", nullable=true)
  67. */
  68. private $DateFinReelle;
  69. /**
  70. * @ORM\ManyToOne(targetEntity=Utilisateur::class, inversedBy="compagnes")
  71. * @ORM\JoinColumn(name="createur", referencedColumnName="id")
  72. */
  73. private $createur;
  74. /**
  75. * @ORM\Column(name="DateCreation",type="string", length=255, nullable=true)
  76. */
  77. private $DateCreation;
  78. /**
  79. * @ORM\Column(type="integer", nullable=true , options={"default":0, "comment":"(1=CampagnePause) (2=CampagnePlay) (3=CampagneEnd)"})
  80. */
  81. private $state = 0;
  82. /**
  83. * @ORM\Column(type="integer",nullable=true,options={"default" : 0})
  84. */
  85. private $couche = 0;
  86. /**
  87. * @ORM\Column(type="string", length=255, nullable=true)
  88. */
  89. private $statut;
  90. /**
  91. * @ORM\OneToMany(targetEntity=Priorite::class, mappedBy="campagne")
  92. */
  93. private $priorites;
  94. /**
  95. * @ORM\OneToMany(targetEntity=Tache::class, mappedBy="compagne")
  96. */
  97. private $taches;
  98. /**
  99. * @ORM\ManyToMany(targetEntity=Utilisateur::class, inversedBy="campagnes")
  100. */
  101. private $collaborateurs;
  102. /**
  103. * @ORM\ManyToOne(targetEntity=Cours::class, inversedBy="campagnes")
  104. * @ORM\JoinColumn(name="id_cours", referencedColumnName="id")
  105. */
  106. private $cours;
  107. /**
  108. * Init Object Manager
  109. */
  110. private $em;
  111. /**
  112. * @ORM\Column(type="boolean", nullable=true)
  113. */
  114. private $forceVip;
  115. /**
  116. * Initialiser ObjectManager pour qu'on puisse utiliser Reporistory dans l'entity
  117. *
  118. * @param ObjectManager $objectManager
  119. * @param ClassMetadata $classMetadata
  120. * @return void
  121. */
  122. public function injectObjectManager(\Doctrine\Persistence\ObjectManager $objectManager, ClassMetadata $classMetadata = null)
  123. {
  124. $this->em = $objectManager;
  125. }
  126. public function __construct()
  127. {
  128. $this->campagneCouches = new ArrayCollection();
  129. $this->priorites = new ArrayCollection();
  130. $this->taches = new ArrayCollection();
  131. $this->collaborateurs = new ArrayCollection();
  132. }
  133. public function getId(): ?int
  134. {
  135. return $this->id;
  136. }
  137. /**
  138. * @return Collection|CampagneCouche[]
  139. */
  140. public function getCampagneCouches(): Collection
  141. {
  142. return $this->campagneCouches;
  143. }
  144. public function addCampagneCouch(CampagneCouche $campagneCouch): self
  145. {
  146. if (!$this->campagneCouches->contains($campagneCouch)) {
  147. $this->campagneCouches[] = $campagneCouch;
  148. $campagneCouch->setCompagne($this);
  149. }
  150. return $this;
  151. }
  152. public function removeCampagneCouch(CampagneCouche $campagneCouch): self
  153. {
  154. if ($this->campagneCouches->contains($campagneCouch)) {
  155. $this->campagneCouches->removeElement($campagneCouch);
  156. // set the owning side to null (unless already changed)
  157. if ($campagneCouch->getCompagne() === $this) {
  158. $campagneCouch->setCompagne(null);
  159. }
  160. }
  161. return $this;
  162. }
  163. public function getType(): ?int
  164. {
  165. return $this->Type;
  166. }
  167. public function setType(int $Type): self
  168. {
  169. $this->Type = $Type;
  170. return $this;
  171. }
  172. public function getNom(): ?string
  173. {
  174. return $this->Nom;
  175. }
  176. public function setNom(string $Nom): self
  177. {
  178. $this->Nom = $Nom;
  179. return $this;
  180. }
  181. public function getDescription(): ?string
  182. {
  183. return $this->Description;
  184. }
  185. public function setDescription(?string $Description): self
  186. {
  187. $this->Description = $Description;
  188. return $this;
  189. }
  190. public function getDateDebut(): ?\DateTimeInterface
  191. {
  192. return $this->DateDebut;
  193. }
  194. public function setDateDebut(\DateTimeInterface $DateDebut): self
  195. {
  196. $this->DateDebut = $DateDebut;
  197. return $this;
  198. }
  199. public function getDateFin(): ?\DateTimeInterface
  200. {
  201. return $this->DateFin;
  202. }
  203. public function setDateFin(\DateTimeInterface $DateFin): self
  204. {
  205. $this->DateFin = $DateFin;
  206. return $this;
  207. }
  208. public function getProgression(): ?int
  209. {
  210. return $this->Progression;
  211. }
  212. public function setProgression(int $Progression): self
  213. {
  214. $this->Progression = $Progression;
  215. return $this;
  216. }
  217. public function getObjectif(): ?int
  218. {
  219. return $this->Objectif;
  220. }
  221. public function setObjectif(?int $Objectif): self
  222. {
  223. $this->Objectif = $Objectif;
  224. return $this;
  225. }
  226. public function getProjet(): ?Projet
  227. {
  228. return $this->projet;
  229. }
  230. public function setProjet(?Projet $projet): self
  231. {
  232. $this->projet = $projet;
  233. return $this;
  234. }
  235. public function getTentative(): ?int
  236. {
  237. return $this->Tentative;
  238. }
  239. public function setTentative(int $Tentative): self
  240. {
  241. $this->Tentative = $Tentative;
  242. return $this;
  243. }
  244. public function getArchive(): ?int
  245. {
  246. return $this->archive;
  247. }
  248. public function setArchive(int $archive): self
  249. {
  250. $this->archive = $archive;
  251. return $this;
  252. }
  253. public function getDateFinReelle(): ?\DateTimeInterface
  254. {
  255. return $this->DateFinReelle;
  256. }
  257. public function setDateFinReelle(?\DateTimeInterface $DateFinReelle): self
  258. {
  259. $this->DateFinReelle = $DateFinReelle;
  260. return $this;
  261. }
  262. public function getCreateur(): ?Utilisateur
  263. {
  264. return $this->createur;
  265. }
  266. public function setCreateur(?Utilisateur $createur): self
  267. {
  268. $this->createur = $createur;
  269. return $this;
  270. }
  271. public function getDateCreation(): ?string
  272. {
  273. return $this->DateCreation;
  274. }
  275. public function setDateCreation(?string $DateCreation): self
  276. {
  277. $this->DateCreation = $DateCreation;
  278. return $this;
  279. }
  280. public function getState(): ?int
  281. {
  282. return $this->state;
  283. }
  284. public function setState(?int $state): self
  285. {
  286. $this->state = $state;
  287. return $this;
  288. }
  289. public function getCouche(): ?int
  290. {
  291. return $this->couche;
  292. }
  293. public function setCouche(int $couche): self
  294. {
  295. $this->couche = $couche;
  296. return $this;
  297. }
  298. public function getStatut(): ?string
  299. {
  300. return $this->statut;
  301. }
  302. public function setStatut(?string $statut): self
  303. {
  304. $this->statut = $statut;
  305. return $this;
  306. }
  307. /**
  308. * @return Collection|Priorite[]
  309. */
  310. public function getPriorites(): Collection
  311. {
  312. return $this->priorites;
  313. }
  314. public function addPriorite(Priorite $priorite): self
  315. {
  316. if (!$this->priorites->contains($priorite)) {
  317. $this->priorites[] = $priorite;
  318. $priorite->setCampagne($this);
  319. }
  320. return $this;
  321. }
  322. public function removePriorite(Priorite $priorite): self
  323. {
  324. if ($this->priorites->contains($priorite)) {
  325. $this->priorites->removeElement($priorite);
  326. // set the owning side to null (unless already changed)
  327. if ($priorite->getCampagne() === $this) {
  328. $priorite->setCampagne(null);
  329. }
  330. }
  331. return $this;
  332. }
  333. /**
  334. * @return Collection|Tache[]
  335. */
  336. public function getTaches(): Collection
  337. {
  338. return $this->taches;
  339. }
  340. public function addTach(Tache $tach): self
  341. {
  342. if (!$this->taches->contains($tach)) {
  343. $this->taches[] = $tach;
  344. $tach->setCompagne($this);
  345. }
  346. return $this;
  347. }
  348. public function removeTach(Tache $tach): self
  349. {
  350. if ($this->taches->contains($tach)) {
  351. $this->taches->removeElement($tach);
  352. // set the owning side to null (unless already changed)
  353. if ($tach->getCompagne() === $this) {
  354. $tach->setCompagne(null);
  355. }
  356. }
  357. return $this;
  358. }
  359. /**
  360. * @return Collection|Utilisateur[]
  361. */
  362. public function getCollaborateurs(): Collection
  363. {
  364. return $this->collaborateurs;
  365. }
  366. public function addCollaborateur(Utilisateur $collaborateur): self
  367. {
  368. if (!$this->collaborateurs->contains($collaborateur)) {
  369. $this->collaborateurs[] = $collaborateur;
  370. }
  371. return $this;
  372. }
  373. public function removeCollaborateur(Utilisateur $collaborateur): self
  374. {
  375. if ($this->collaborateurs->contains($collaborateur)) {
  376. $this->collaborateurs->removeElement($collaborateur);
  377. }
  378. return $this;
  379. }
  380. public function getCours(): ?Cours
  381. {
  382. return $this->cours;
  383. }
  384. public function setCours(?Cours $cours): self
  385. {
  386. $this->cours = $cours;
  387. return $this;
  388. }
  389. //Recuperer la derniere couche de la campagne
  390. public function getLastCouche()
  391. {
  392. if (count($this->campagneCouches) > 0) {
  393. $campagneCoucheObj = $this->em->getRepository(CampagneCouche::class)->findOneByCompagne($this, ['id' => 'DESC']);
  394. return $campagneCoucheObj;
  395. } else {
  396. return null;
  397. }
  398. }
  399. /**
  400. * (La somme de la progression des couches par campagne) == (progression de la campagne)
  401. *
  402. * @return void
  403. */
  404. public function sumProgressionCouches()
  405. {
  406. $sumProgression = 0;
  407. $campagneCouches = $this->campagneCouches;
  408. if (count($campagneCouches) > 0) {
  409. foreach ($campagneCouches as $compagneCouche) {
  410. $sumProgression += (int)$compagneCouche->getProgression();
  411. }
  412. return $sumProgression;
  413. } else {
  414. return $sumProgression;
  415. }
  416. }
  417. /**
  418. * Recuper un seul apprenant valide et non abouti par compagne
  419. */
  420. public function getTotalAppels()
  421. {
  422. $appels = $this->em->getRepository(Appel::class)->findAppelByCompagne($this);
  423. return $appels;
  424. }
  425. /**
  426. * Recuper un seul apprenant valide et non abouti par compagne
  427. */
  428. public function getApprenantByAgent($agent)
  429. {
  430. $apprenant = ($this->getForceVip()) ? $this->em->getRepository(Apprenant::class)->findApprenantIncludeVipDisponibleByCampagneByAgent($this, $agent) : $this->em->getRepository(Apprenant::class)->findApprenantDisponibleByCampagneByAgent($this, $agent);
  431. return $apprenant;
  432. }
  433. public function getCurrentCouche()
  434. {
  435. $currentCouche = new CampagneCouche();
  436. $campagneLastCoucheObj = $this->getLastCouche();
  437. if (is_object($campagneLastCoucheObj)) {
  438. $currentCouche->setProgression((int)$this->getProgression() - (int)$campagneLastCoucheObj->getProgression());
  439. $currentCouche->setTentative((int)$this->getTentative() - (int)$campagneLastCoucheObj->getTentative());
  440. $currentCouche->setObjectif((int)$campagneLastCoucheObj->getObjectif() - (int)$campagneLastCoucheObj->getProgression());
  441. } else {
  442. $currentCouche->setProgression((int)$this->getProgression());
  443. $currentCouche->setTentative((int)$this->getTentative());
  444. $currentCouche->setObjectif((int)$this->getObjectif());
  445. }
  446. $currentCouche->setCompagne($this);
  447. $currentCouche->setCouche($this->getNom() . "__C" . $this->getCouche());
  448. $currentCouche->setDateDebut($this->getDateDebut());
  449. $currentCouche->setDateFin($this->getDateFin());
  450. return $currentCouche;
  451. }
  452. /**
  453. * Ajouter une nou_velle couche de la campagne
  454. *
  455. * @return void
  456. */
  457. public function newCouche()
  458. {
  459. $campagneCouche = $this->getCurrentCouche();
  460. $this->em->persist($campagneCouche);
  461. $this->em->flush();
  462. return $campagneCouche;
  463. }
  464. /**
  465. * Recuper les apprenants valides par campagne => pour calculer l'objectif de la campagne
  466. *
  467. * @return array
  468. */
  469. public function getValideNumbers()
  470. {
  471. $apprenants = $this->em->getRepository(Apprenant::class)->findApprenantsValidesByCampagneTwo($this);
  472. return $apprenants;
  473. }
  474. public function getForceVip(): ?bool
  475. {
  476. return $this->forceVip;
  477. }
  478. public function setForceVip(?bool $forceVip): self
  479. {
  480. $this->forceVip = $forceVip;
  481. return $this;
  482. }
  483. }