EducationNotation.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. namespace AppBundle\Entity\Education;
  3. use AppBundle\Entity\Core\Tagg;
  4. use AppBundle\Enum\Education\TypeCriteriaEnum;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Dunglas\ApiBundle\Annotation\Iri;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use AppBundle\Entity\Traits\TimestampableEntity;
  11. use AppBundle\Entity\Traits\CreatorUpdaterEntity;
  12. /**
  13. * Notes d'un élève pour un enseignement suivi EducationStudent
  14. *
  15. * @Iri("http://schema.org/EducationNotation")
  16. */
  17. #[ORM\Entity(repositoryClass: 'AppBundle\Entity\Education\Repository\EducationNotationRepository')]
  18. class EducationNotation
  19. {
  20. use TimestampableEntity;
  21. use CreatorUpdaterEntity;
  22. /**
  23. * @var int
  24. */
  25. #[ORM\Column(type: 'integer')]
  26. #[ORM\Id]
  27. #[ORM\GeneratedValue(strategy: 'AUTO')]
  28. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationnotation_list', 'educationstudent_notation', 'education_input_list'])]
  29. private $id;
  30. /**
  31. * @var EducationStudent
  32. */
  33. #[ORM\ManyToOne(targetEntity: 'EducationStudent', inversedBy: 'educationNotations')]
  34. #[ORM\JoinColumn(nullable: false)]
  35. #[Assert\NotNull]
  36. #[Groups(['educationnotation', 'educationnotation_list'])]
  37. private $educationStudent;
  38. /**
  39. * @var CriteriaNotation
  40. */
  41. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Education\CriteriaNotation', inversedBy: 'educationNotations')]
  42. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  43. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationnotation_list', 'educationstudent_notation_educationnotations', 'education_input_list_educationnotations'])]
  44. private $criteriaNotation;
  45. /**
  46. * @var EducationNotationCriteriaConfig
  47. */
  48. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Education\EducationNotationCriteriaConfig', inversedBy: 'educationNotations')]
  49. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  50. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationnotation_list', 'educationstudent_notation_educationnotations', 'education_input_list_educationnotations'])]
  51. private $criteriaNotationConfig;
  52. /**
  53. * @var string
  54. */
  55. #[ORM\Column(type: 'text', nullable: true)]
  56. #[Assert\Type(type: 'string')]
  57. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationstudent_notation_educationnotations', 'educationnotation_list'])]
  58. private $freeCriterion;
  59. /**
  60. * @var string
  61. */
  62. #[ORM\Column(type: 'string', nullable: true)]
  63. #[Assert\Choice(callback: ['\AppBundle\Enum\Education\PeriodEnum', 'toArray'], multiple: false)]
  64. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationnotation_list', 'educationstudent_notation_educationnotations', 'education_input_list_educationnotations'])]
  65. private $period;
  66. /**
  67. * @var \DateTime
  68. */
  69. #[ORM\Column(type: 'date', nullable: true)]
  70. #[Assert\Date]
  71. #[Groups(['educationnotation', 'educationstudent_notation_educationnotations', 'educationnotation_list'])]
  72. private $date;
  73. /**
  74. * @var float
  75. */
  76. #[ORM\Column(type: 'decimal', nullable: true, precision: 10, scale: 2)]
  77. #[Assert\GreaterThanOrEqual(value: 0)]
  78. #[Assert\LessThanOrEqual(value: 100, message: 'lessThanOrEqual20')]
  79. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationnotation_list', 'educationstudent_notation_educationnotations', 'education_input_list_educationnotations'])]
  80. private $note;
  81. /**
  82. * @var string
  83. */
  84. #[ORM\Column(type: 'string', nullable: true)]
  85. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationnotation_list', 'educationstudent_notation_educationnotations', 'education_input_list_educationnotations'])]
  86. private $mention;
  87. /**
  88. * @var string
  89. */
  90. #[ORM\Column(type: 'text', nullable: true)]
  91. #[Assert\Type(type: 'string')]
  92. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationstudent_notation_educationnotations', 'educationnotation_list'])]
  93. private $appreciation;
  94. /**
  95. * @var bool
  96. */
  97. #[ORM\Column(type: 'boolean', options: ['default' => false])]
  98. #[Assert\Type(type: 'boolean')]
  99. #[Assert\NotNull]
  100. #[Groups(['educationnotation', 'report_card_educationstudent', 'educationstudent_notation_educationnotations', 'educationnotation_list'])]
  101. private $isValid = false;
  102. /**
  103. * @var string
  104. */
  105. #[Groups(['educationnotation', 'educationstudent_notation_educationnotations', 'educationnotation_list'])]
  106. private $noteTemplate;
  107. /**
  108. * @var string
  109. */
  110. #[Groups(['educationnotation', 'educationstudent_notation_educationnotations', 'educationnotation_list'])]
  111. private $noteOriTemplate;
  112. /**
  113. * @var ArrayCollection<Tagg>
  114. */
  115. #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Core\Tagg', cascade: ['persist'], inversedBy: 'educationNotations')]
  116. #[Assert\Valid]
  117. #[ORM\JoinTable(name: 'tag_educationNotation', joinColumns: [], inverseJoinColumns: [])]
  118. #[ORM\JoinColumn(name: 'educationNotation_id', referencedColumnName: 'id')]
  119. #[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  120. #[Groups(['eductionnotation_tags', 'educationstudent_notation_educationnotations', 'manage_tags'])]
  121. private $tags;
  122. public function __construct() {
  123. $this->tags = new ArrayCollection();
  124. }
  125. /**
  126. * Sets id.
  127. *
  128. * @param int $id
  129. *
  130. * @return $this
  131. */
  132. public function setId($id)
  133. {
  134. $this->id = $id;
  135. return $this;
  136. }
  137. /**
  138. * Gets id.
  139. *
  140. * @return int
  141. */
  142. public function getId()
  143. {
  144. return $this->id;
  145. }
  146. /**
  147. * Sets criteriaNotation.
  148. *
  149. * @param CriteriaNotation $criteriaNotation
  150. *
  151. * @return $this
  152. */
  153. public function setCriteriaNotation($criteriaNotation)
  154. {
  155. $this->criteriaNotation = $criteriaNotation;
  156. return $this;
  157. }
  158. /**
  159. * Gets criteriaNotation.
  160. *
  161. * @return CriteriaNotation
  162. */
  163. public function getCriteriaNotation()
  164. {
  165. return $this->criteriaNotation;
  166. }
  167. /**
  168. * Sets freeCriterion.
  169. *
  170. * @param string $freeCriterion
  171. *
  172. * @return $this
  173. */
  174. public function setFreeCriterion($freeCriterion)
  175. {
  176. $this->freeCriterion = $freeCriterion;
  177. return $this;
  178. }
  179. /**
  180. * Gets freeCriterion.
  181. *
  182. * @return string
  183. */
  184. public function getFreeCriterion()
  185. {
  186. return $this->freeCriterion;
  187. }
  188. /**
  189. * Sets period.
  190. *
  191. * @param string $period
  192. *
  193. * @return $this
  194. */
  195. public function setPeriod($period)
  196. {
  197. if(empty($period) || $period=='')
  198. $period = null;
  199. $this->period = $period;
  200. return $this;
  201. }
  202. /**
  203. * Gets period.
  204. *
  205. * @return string
  206. */
  207. public function getPeriod()
  208. {
  209. return $this->period;
  210. }
  211. /**
  212. * Sets date.
  213. *
  214. * @param \DateTime $date
  215. *
  216. * @return $this
  217. */
  218. public function setDate(\DateTime $date = null)
  219. {
  220. $this->date = $date;
  221. return $this;
  222. }
  223. /**
  224. * Gets date.
  225. *
  226. * @return \DateTime
  227. */
  228. public function getDate()
  229. {
  230. return $this->date ? $this->date->format('Y-m-d') : $this->date;
  231. }
  232. /**
  233. * Sets note.
  234. *
  235. * @param float $note
  236. *
  237. * @return $this
  238. */
  239. public function setNote($note)
  240. {
  241. $this->note = (!is_null($note)) ? floatval($note) : $note;
  242. return $this;
  243. }
  244. /**
  245. * Gets note.
  246. *
  247. * @return float
  248. */
  249. public function getNote()
  250. {
  251. if(is_null($this->note)) return $this->note;
  252. return round ( $this->note , 2 );
  253. }
  254. /**
  255. * Sets mention.
  256. *
  257. * @param string $mention
  258. *
  259. * @return $this
  260. */
  261. public function setMention($mention)
  262. {
  263. $this->mention = $mention;
  264. return $this;
  265. }
  266. /**
  267. * Gets mention.
  268. *
  269. * @return string
  270. */
  271. public function getMention()
  272. {
  273. return $this->mention;
  274. }
  275. /**
  276. * Sets appreciation.
  277. *
  278. * @param string $appreciation
  279. *
  280. * @return $this
  281. */
  282. public function setAppreciation($appreciation)
  283. {
  284. $this->appreciation = $appreciation;
  285. return $this;
  286. }
  287. /**
  288. * Gets appreciation.
  289. *
  290. * @return string
  291. */
  292. public function getAppreciation()
  293. {
  294. return $this->appreciation;
  295. }
  296. /**
  297. * Set isValid
  298. *
  299. * @param boolean $isValid
  300. *
  301. * @return EducationNotation
  302. */
  303. public function setIsValid($isValid)
  304. {
  305. $this->isValid = $isValid;
  306. return $this;
  307. }
  308. /**
  309. * Get isValid
  310. *
  311. * @return boolean
  312. */
  313. public function getIsValid()
  314. {
  315. return $this->isValid;
  316. }
  317. /**
  318. * Set educationStudent
  319. *
  320. * @param \AppBundle\Entity\Education\EducationStudent $educationStudent
  321. *
  322. * @return EducationNotation
  323. */
  324. public function setEducationStudent(\AppBundle\Entity\Education\EducationStudent $educationStudent)
  325. {
  326. $this->educationStudent = $educationStudent;
  327. return $this;
  328. }
  329. /**
  330. * Get educationStudent
  331. *
  332. * @return \AppBundle\Entity\Education\EducationStudent
  333. */
  334. public function getEducationStudent()
  335. {
  336. return $this->educationStudent;
  337. }
  338. /**
  339. * Add tag
  340. *
  341. * @param \AppBundle\Entity\Core\Tagg $tag
  342. *
  343. * @return EducationNotation
  344. */
  345. public function addTag(\AppBundle\Entity\Core\Tagg $tag)
  346. {
  347. $this->tags[] = $tag;
  348. return $this;
  349. }
  350. /**
  351. * Remove tag
  352. *
  353. * @param \AppBundle\Entity\Core\Tagg $tag
  354. */
  355. public function removeTag(\AppBundle\Entity\Core\Tagg $tag)
  356. {
  357. $this->tags->removeElement($tag);
  358. }
  359. /**
  360. * Get tags
  361. *
  362. * @return \Doctrine\Common\Collections\Collection
  363. */
  364. public function getTags()
  365. {
  366. return $this->tags;
  367. }
  368. public function getNoteTemplate($withNoteMax = true)
  369. {
  370. if(is_null($this->getNote())) return null;
  371. if(!$this->getCriteriaNotation()) return null;
  372. if($this->getCriteriaNotation()->getType() !== TypeCriteriaEnum::WITH_NOTATION) return null;
  373. $noteMax = $this->getEducationStudent()->getAccess()->getOrganization()->getParameters()->getAverage();
  374. $note = (!is_null($this->getNote())) ? floatval(($this->getNote() * $noteMax) / 100) : $this->getNote();
  375. $note = round ( $note , 2 );
  376. return $withNoteMax ? $note . '/'. $noteMax : $note;
  377. }
  378. public function getNoteOriTemplate($withNoteMax = true)
  379. {
  380. if(is_null($this->getNote())) return null;
  381. if(!$this->getCriteriaNotation()) return null;
  382. if($this->getCriteriaNotation()->getType() !== TypeCriteriaEnum::WITH_NOTATION) return null;
  383. $noteMax = $this->getCriteriaNotation()->getNoteMax();
  384. $note = (!is_null($this->getNote())) ? floatval(($this->getNote() * $noteMax) / 100) : $this->getNote();
  385. $note = round ( $note , 2 );
  386. return $withNoteMax ? $note . '/'. $noteMax : $note;
  387. }
  388. /**
  389. * Sets criteriaNotationConfig.
  390. *
  391. * @param EducationNotationCriteriaConfig $criteriaNotationConfig
  392. *
  393. * @return $this
  394. */
  395. public function setCriteriaNotationConfig($criteriaNotationConfig)
  396. {
  397. $this->criteriaNotationConfig = $criteriaNotationConfig;
  398. return $this;
  399. }
  400. /**
  401. * Gets criteriaNotationConfig.
  402. *
  403. * @return EducationNotationCriteriaConfig
  404. */
  405. public function getCriteriaNotationConfig()
  406. {
  407. return $this->criteriaNotationConfig;
  408. }
  409. /**
  410. * Pour elasticsearch...
  411. */
  412. public function noteOrigine(){
  413. return null;
  414. }
  415. public function noteRecalcul(){
  416. return null;
  417. }
  418. }