src/Entity/Feedback.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\FeedbackRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation as JMS;
  10. /**
  11. * @ORM\Table(name="feedback")
  12. * @ORM\Entity(repositoryClass=FeedbackRepository::class)
  13. * @ORM\HasLifecycleCallbacks()
  14. * @JMS\ExclusionPolicy("all")
  15. */
  16. class Feedback
  17. {
  18. /**
  19. * @ORM\Id
  20. * @ORM\GeneratedValue
  21. * @ORM\Column(type="integer")
  22. * @JMS\Expose
  23. */
  24. private $id;
  25. /**
  26. * @var int
  27. *
  28. * @ORM\Column(name="status", type="smallint")
  29. * @JMS\Expose
  30. */
  31. private $status;
  32. /**
  33. * @var boolean
  34. *
  35. * @ORM\Column(name="self_evaluation", type="boolean")
  36. * @JMS\Expose
  37. */
  38. private $selfEvaluation = false;
  39. /**
  40. *
  41. * @var User $sender
  42. *
  43. * @ORM\ManyToOne(targetEntity="User", inversedBy="sentFeedbacks")
  44. * @ORM\JoinColumn(name="sender_id", referencedColumnName="id", onDelete="CASCADE")
  45. */
  46. private $sender;
  47. /**
  48. *
  49. * @var User $recipient
  50. *
  51. * @ORM\ManyToOne(targetEntity="User", inversedBy="receivedFeedbacks")
  52. * @ORM\JoinColumn(name="recipient_id", referencedColumnName="id", onDelete="CASCADE")
  53. */
  54. private $recipient;
  55. /**
  56. *
  57. * @var Skill $skill
  58. *
  59. * @ORM\ManyToOne(targetEntity="Skill", fetch="EAGER")
  60. * @ORM\JoinColumn(name="skill_id", referencedColumnName="id")
  61. * @JMS\Expose
  62. */
  63. private $skill;
  64. /**
  65. * @var array
  66. *
  67. * @ORM\Column(name="strengths", type="array", nullable=true)
  68. * @JMS\Expose
  69. */
  70. private $strengths;
  71. /**
  72. * @var array
  73. *
  74. * @ORM\Column(name="weaknesses", type="array", nullable=true)
  75. * @JMS\Expose
  76. */
  77. private $weaknesses;
  78. /**
  79. * @ORM\OneToMany(targetEntity="Rating", mappedBy="feedback")
  80. * @JMS\Expose
  81. */
  82. private $ratings;
  83. /**
  84. * @var \DateTime
  85. *
  86. * @ORM\Column(name="answered_at", type="datetime", nullable=true)
  87. * @JMS\Expose
  88. */
  89. private $answeredAt;
  90. /**
  91. * @var \DateTime
  92. *
  93. * @ORM\Column(name="notified_at", type="datetime", nullable=true)
  94. */
  95. private $notifiedAt;
  96. /**
  97. * @var \DateTime
  98. *
  99. * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  100. */
  101. private $updatedAt;
  102. /**
  103. * @var \DateTime
  104. * @JMS\Expose
  105. * @ORM\Column(name="created_at", type="datetime")
  106. */
  107. private $createdAt;
  108. /**
  109. * @var boolean
  110. *
  111. * @ORM\Column(name="resetted", type="boolean")
  112. */
  113. private $resetted = false;
  114. /**
  115. * @ORM\OneToMany(targetEntity="BatchFeedbackEmail", mappedBy="feedback")
  116. */
  117. private $batchFeedbackEmails;
  118. /**
  119. * @ORM\OneToOne(targetEntity="Recommendation", mappedBy="feedback")
  120. * @ORM\JoinColumn(name="recommendation_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  121. */
  122. private $recommendation;
  123. public function __construct()
  124. {
  125. $this->ratings = new ArrayCollection();
  126. }
  127. /**
  128. * @ORM\PrePersist
  129. */
  130. public function setCreatedAtValue()
  131. {
  132. $this->createdAt = new \DateTime();
  133. }
  134. /**
  135. * @ORM\PreUpdate
  136. */
  137. public function setUpdatedAtValue()
  138. {
  139. $this->updatedAt = new \DateTime();
  140. }
  141. function __toString()
  142. {
  143. return "{$this->sender} -> {$this->recipient} : {$this->skill}";
  144. }
  145. /**
  146. * @JMS\VirtualProperty()
  147. */
  148. public function getStrengthsTranslated()
  149. {
  150. $tagsFr = $this->getSkill()->translate('fr')->getTags();
  151. $tagsUserLanguage = $this->getSkill()->translate()->getTags();
  152. if($this->getStrengths() != null) {
  153. $strengths = array();
  154. $keys = array();
  155. foreach ($this->getStrengths() as $strength) {
  156. $keys[] = array_search($strength, $tagsFr);
  157. }
  158. $translatedStrengths = array();
  159. foreach ($keys as $key) {
  160. $translatedStrengths[] = $tagsUserLanguage[$key];
  161. }
  162. foreach ($this->getStrengths() as $i => $strength) {
  163. $strengths[] = $translatedStrengths[$i];
  164. }
  165. return $strengths;
  166. } else {
  167. return array();
  168. }
  169. }
  170. public function getStrengthsString(){
  171. $strengthsString = "";
  172. if($this->strengths && count($this->strengths) > 0) {
  173. foreach ($this->strengths as $strength) {
  174. $strengthsString = $strengthsString . $strength;
  175. if ($strength != end($this->strengths)) {
  176. $strengthsString = $strengthsString . " - ";
  177. }
  178. }
  179. }
  180. return $strengthsString;
  181. }
  182. /**
  183. * @JMS\VirtualProperty()
  184. */
  185. public function getWeaknessesTranslated()
  186. {
  187. $tagsFr = $this->getSkill()->translate('fr')->getTags();
  188. $tagsUserLanguage = $this->getSkill()->translate()->getTags();
  189. if($this->getWeaknesses() != null) {
  190. $weaknesses = array();
  191. $keys = array();
  192. foreach ($this->getWeaknesses() as $weakness) {
  193. $keys[] = array_search($weakness, $tagsFr);
  194. }
  195. $translatedWeaknesses = array();
  196. foreach ($keys as $key) {
  197. $translatedWeaknesses[] = $tagsUserLanguage[$key];
  198. }
  199. foreach ($this->getWeaknesses() as $i => $weakness) {
  200. $weaknesses[] = $translatedWeaknesses[$i];
  201. }
  202. return $weaknesses;
  203. } else {
  204. return array();
  205. }
  206. }
  207. public function getWeaknessesString(){
  208. $weaknessesString = "";
  209. if($this->weaknesses && count($this->weaknesses) > 0){
  210. foreach ($this->weaknesses as $weakness){
  211. $weaknessesString = $weaknessesString . $weakness;
  212. if($weakness != end($this->weaknesses)){
  213. $weaknessesString = $weaknessesString . " - ";
  214. }
  215. }
  216. }
  217. return $weaknessesString;
  218. }
  219. public function getFirstQuestionString(){
  220. if($this->ratings[0] != null){
  221. return $this->ratings[0]->getQuestion()->getTitle();
  222. } else {
  223. return "";
  224. }
  225. }
  226. public function getFirstRatingString(){
  227. if($this->ratings[0] != null){
  228. return $this->ratings[0]->getScore();
  229. } else {
  230. return "";
  231. }
  232. }
  233. public function getFirstBehaviorString(){
  234. if($this->ratings[0] != null){
  235. return $this->ratings[0]->getQuestion()->getBehavior();
  236. } else {
  237. return "";
  238. }
  239. }
  240. public function getSecondQuestionString(){
  241. if($this->ratings[0] != null){
  242. return $this->ratings[1]->getQuestion()->getTitle();
  243. } else {
  244. return "";
  245. }
  246. }
  247. public function getSecondRatingString(){
  248. if($this->ratings[1] != null){
  249. return $this->ratings[1]->getScore();
  250. } else {
  251. return "";
  252. }
  253. }
  254. public function getSecondBehaviorString(){
  255. if($this->ratings[1] != null){
  256. return $this->ratings[1]->getQuestion()->getBehavior();
  257. } else {
  258. return "";
  259. }
  260. }
  261. public function getThirdQuestionString(){
  262. if($this->ratings[0] != null){
  263. return $this->ratings[2]->getQuestion()->getTitle();
  264. } else {
  265. return "";
  266. }
  267. }
  268. public function getThirdRatingString(){
  269. if($this->ratings[2] != null){
  270. return $this->ratings[2]->getScore();
  271. } else {
  272. return "";
  273. }
  274. }
  275. public function getThirdBehaviorString(){
  276. if($this->ratings[2] != null){
  277. return $this->ratings[2]->getQuestion()->getBehavior();
  278. } else {
  279. return "";
  280. }
  281. }
  282. public function getFourthQuestionString(){
  283. if($this->ratings[0] != null){
  284. return $this->ratings[3]->getQuestion()->getTitle();
  285. } else {
  286. return "";
  287. }
  288. }
  289. public function getFourthRatingString(){
  290. if($this->ratings[3] != null){
  291. return $this->ratings[3]->getScore();
  292. } else {
  293. return "";
  294. }
  295. }
  296. public function getFourthBehaviorString(){
  297. if($this->ratings[3] != null){
  298. return $this->ratings[3]->getQuestion()->getBehavior();
  299. } else {
  300. return "";
  301. }
  302. }
  303. public function getGuestToken(){
  304. $data = $this->getId()."-guest-".$this->getSender()->getId().$this->getSkill()->getId();
  305. $r = hash("sha512", $data, false);
  306. return $r;
  307. }
  308. public function getGuestUrl($locale){
  309. $baseUrl = (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] === 'prod')
  310. ? "https://app.coss-certification.com"
  311. : "https://coss-b2c.web.app";
  312. return $baseUrl . "/guest-answer/".$this->getGuestToken()."/".$locale."/".$this->getId();
  313. }
  314. public function getId(): ?int
  315. {
  316. return $this->id;
  317. }
  318. public function getStatus(): ?int
  319. {
  320. return $this->status;
  321. }
  322. public function setStatus(int $status): self
  323. {
  324. $this->status = $status;
  325. return $this;
  326. }
  327. public function getSelfEvaluation(): ?bool
  328. {
  329. return $this->selfEvaluation;
  330. }
  331. public function setSelfEvaluation(bool $selfEvaluation): self
  332. {
  333. $this->selfEvaluation = $selfEvaluation;
  334. return $this;
  335. }
  336. public function getStrengths(): ?array
  337. {
  338. return $this->strengths;
  339. }
  340. public function setStrengths(?array $strengths): self
  341. {
  342. $this->strengths = $strengths;
  343. return $this;
  344. }
  345. public function getWeaknesses(): ?array
  346. {
  347. return $this->weaknesses;
  348. }
  349. public function setWeaknesses(?array $weaknesses): self
  350. {
  351. $this->weaknesses = $weaknesses;
  352. return $this;
  353. }
  354. public function getAnsweredAt(): ?\DateTimeInterface
  355. {
  356. return $this->answeredAt;
  357. }
  358. public function getAnsweredAtTime(): ?string
  359. {
  360. return $this->answeredAt ? $this->answeredAt->format('H:i:s') : '';
  361. }
  362. public function setAnsweredAt(?\DateTimeInterface $answeredAt): self
  363. {
  364. $this->answeredAt = $answeredAt;
  365. return $this;
  366. }
  367. public function getNotifiedAt(): ?\DateTimeInterface
  368. {
  369. return $this->notifiedAt;
  370. }
  371. public function setNotifiedAt(?\DateTimeInterface $notifiedAt): self
  372. {
  373. $this->notifiedAt = $notifiedAt;
  374. return $this;
  375. }
  376. public function getUpdatedAt(): ?\DateTimeInterface
  377. {
  378. return $this->updatedAt;
  379. }
  380. public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  381. {
  382. $this->updatedAt = $updatedAt;
  383. return $this;
  384. }
  385. public function getCreatedAt(): ?\DateTimeInterface
  386. {
  387. return $this->createdAt;
  388. }
  389. public function getCreatedAtTime(): ?string
  390. {
  391. return $this->createdAt->format('H:i:s');
  392. }
  393. public function setCreatedAt(\DateTimeInterface $createdAt): self
  394. {
  395. $this->createdAt = $createdAt;
  396. return $this;
  397. }
  398. public function getResetted(): ?bool
  399. {
  400. return $this->resetted;
  401. }
  402. public function setResetted(bool $resetted): self
  403. {
  404. $this->resetted = $resetted;
  405. return $this;
  406. }
  407. public function getSender(): ?User
  408. {
  409. return $this->sender;
  410. }
  411. public function setSender(?User $sender): self
  412. {
  413. $this->sender = $sender;
  414. return $this;
  415. }
  416. public function getRecipient(): ?User
  417. {
  418. return $this->recipient;
  419. }
  420. public function setRecipient(?User $recipient): self
  421. {
  422. $this->recipient = $recipient;
  423. return $this;
  424. }
  425. public function getSkill(): ?Skill
  426. {
  427. return $this->skill;
  428. }
  429. public function setSkill(?Skill $skill): self
  430. {
  431. $this->skill = $skill;
  432. return $this;
  433. }
  434. /**
  435. * @return Collection<int, Rating>
  436. */
  437. public function getRatings(): Collection
  438. {
  439. return $this->ratings;
  440. }
  441. public function addRating(Rating $rating): self
  442. {
  443. if (!$this->ratings->contains($rating)) {
  444. $this->ratings[] = $rating;
  445. $rating->setFeedback($this);
  446. }
  447. return $this;
  448. }
  449. public function removeRating(Rating $rating): self
  450. {
  451. if ($this->ratings->removeElement($rating)) {
  452. // set the owning side to null (unless already changed)
  453. if ($rating->getFeedback() === $this) {
  454. $rating->setFeedback(null);
  455. }
  456. }
  457. return $this;
  458. }
  459. /**
  460. * @return Collection<int, Rating>
  461. */
  462. public function getBatchFeedbackEmails(): Collection
  463. {
  464. return $this->batchFeedbackEmails;
  465. }
  466. public function addBatchFeedbackEmail(BatchFeedbackEmail $batchFeedbackEmail): self
  467. {
  468. if (!$this->batchFeedbackEmails->contains($batchFeedbackEmail)) {
  469. $this->batchFeedbackEmails[] = $batchFeedbackEmail;
  470. $batchFeedbackEmail->setFeedback($this);
  471. }
  472. return $this;
  473. }
  474. public function removeBatchFeedbackEmail(BatchFeedbackEmail $batchFeedbackEmail): self
  475. {
  476. if ($this->batchFeedbackEmails->removeElement($batchFeedbackEmail)) {
  477. // set the owning side to null (unless already changed)
  478. if ($batchFeedbackEmail->getFeedback() === $this) {
  479. $batchFeedbackEmail->setFeedback(null);
  480. }
  481. }
  482. return $this;
  483. }
  484. public function getRecommendation(): ?Recommendation
  485. {
  486. return $this->recommendation;
  487. }
  488. public function setRecommendation(?Recommendation $recommendation): self
  489. {
  490. $this->recommendation = $recommendation;
  491. return $this;
  492. }
  493. }