<?php
namespace App\Entity;
use App\Repository\FeedbackRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
/**
* @ORM\Table(name="feedback")
* @ORM\Entity(repositoryClass=FeedbackRepository::class)
* @ORM\HasLifecycleCallbacks()
* @JMS\ExclusionPolicy("all")
*/
class Feedback
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @JMS\Expose
*/
private $id;
/**
* @var int
*
* @ORM\Column(name="status", type="smallint")
* @JMS\Expose
*/
private $status;
/**
* @var boolean
*
* @ORM\Column(name="self_evaluation", type="boolean")
* @JMS\Expose
*/
private $selfEvaluation = false;
/**
*
* @var User $sender
*
* @ORM\ManyToOne(targetEntity="User", inversedBy="sentFeedbacks")
* @ORM\JoinColumn(name="sender_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $sender;
/**
*
* @var User $recipient
*
* @ORM\ManyToOne(targetEntity="User", inversedBy="receivedFeedbacks")
* @ORM\JoinColumn(name="recipient_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $recipient;
/**
*
* @var Skill $skill
*
* @ORM\ManyToOne(targetEntity="Skill", fetch="EAGER")
* @ORM\JoinColumn(name="skill_id", referencedColumnName="id")
* @JMS\Expose
*/
private $skill;
/**
* @var array
*
* @ORM\Column(name="strengths", type="array", nullable=true)
* @JMS\Expose
*/
private $strengths;
/**
* @var array
*
* @ORM\Column(name="weaknesses", type="array", nullable=true)
* @JMS\Expose
*/
private $weaknesses;
/**
* @ORM\OneToMany(targetEntity="Rating", mappedBy="feedback")
* @JMS\Expose
*/
private $ratings;
/**
* @var \DateTime
*
* @ORM\Column(name="answered_at", type="datetime", nullable=true)
* @JMS\Expose
*/
private $answeredAt;
/**
* @var \DateTime
*
* @ORM\Column(name="notified_at", type="datetime", nullable=true)
*/
private $notifiedAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @var \DateTime
* @JMS\Expose
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @var boolean
*
* @ORM\Column(name="resetted", type="boolean")
*/
private $resetted = false;
/**
* @ORM\OneToMany(targetEntity="BatchFeedbackEmail", mappedBy="feedback")
*/
private $batchFeedbackEmails;
/**
* @ORM\OneToOne(targetEntity="Recommendation", mappedBy="feedback")
* @ORM\JoinColumn(name="recommendation_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
private $recommendation;
public function __construct()
{
$this->ratings = new ArrayCollection();
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->createdAt = new \DateTime();
}
/**
* @ORM\PreUpdate
*/
public function setUpdatedAtValue()
{
$this->updatedAt = new \DateTime();
}
function __toString()
{
return "{$this->sender} -> {$this->recipient} : {$this->skill}";
}
/**
* @JMS\VirtualProperty()
*/
public function getStrengthsTranslated()
{
$tagsFr = $this->getSkill()->translate('fr')->getTags();
$tagsUserLanguage = $this->getSkill()->translate()->getTags();
if($this->getStrengths() != null) {
$strengths = array();
$keys = array();
foreach ($this->getStrengths() as $strength) {
$keys[] = array_search($strength, $tagsFr);
}
$translatedStrengths = array();
foreach ($keys as $key) {
$translatedStrengths[] = $tagsUserLanguage[$key];
}
foreach ($this->getStrengths() as $i => $strength) {
$strengths[] = $translatedStrengths[$i];
}
return $strengths;
} else {
return array();
}
}
public function getStrengthsString(){
$strengthsString = "";
if($this->strengths && count($this->strengths) > 0) {
foreach ($this->strengths as $strength) {
$strengthsString = $strengthsString . $strength;
if ($strength != end($this->strengths)) {
$strengthsString = $strengthsString . " - ";
}
}
}
return $strengthsString;
}
/**
* @JMS\VirtualProperty()
*/
public function getWeaknessesTranslated()
{
$tagsFr = $this->getSkill()->translate('fr')->getTags();
$tagsUserLanguage = $this->getSkill()->translate()->getTags();
if($this->getWeaknesses() != null) {
$weaknesses = array();
$keys = array();
foreach ($this->getWeaknesses() as $weakness) {
$keys[] = array_search($weakness, $tagsFr);
}
$translatedWeaknesses = array();
foreach ($keys as $key) {
$translatedWeaknesses[] = $tagsUserLanguage[$key];
}
foreach ($this->getWeaknesses() as $i => $weakness) {
$weaknesses[] = $translatedWeaknesses[$i];
}
return $weaknesses;
} else {
return array();
}
}
public function getWeaknessesString(){
$weaknessesString = "";
if($this->weaknesses && count($this->weaknesses) > 0){
foreach ($this->weaknesses as $weakness){
$weaknessesString = $weaknessesString . $weakness;
if($weakness != end($this->weaknesses)){
$weaknessesString = $weaknessesString . " - ";
}
}
}
return $weaknessesString;
}
public function getFirstQuestionString(){
if($this->ratings[0] != null){
return $this->ratings[0]->getQuestion()->getTitle();
} else {
return "";
}
}
public function getFirstRatingString(){
if($this->ratings[0] != null){
return $this->ratings[0]->getScore();
} else {
return "";
}
}
public function getFirstBehaviorString(){
if($this->ratings[0] != null){
return $this->ratings[0]->getQuestion()->getBehavior();
} else {
return "";
}
}
public function getSecondQuestionString(){
if($this->ratings[0] != null){
return $this->ratings[1]->getQuestion()->getTitle();
} else {
return "";
}
}
public function getSecondRatingString(){
if($this->ratings[1] != null){
return $this->ratings[1]->getScore();
} else {
return "";
}
}
public function getSecondBehaviorString(){
if($this->ratings[1] != null){
return $this->ratings[1]->getQuestion()->getBehavior();
} else {
return "";
}
}
public function getThirdQuestionString(){
if($this->ratings[0] != null){
return $this->ratings[2]->getQuestion()->getTitle();
} else {
return "";
}
}
public function getThirdRatingString(){
if($this->ratings[2] != null){
return $this->ratings[2]->getScore();
} else {
return "";
}
}
public function getThirdBehaviorString(){
if($this->ratings[2] != null){
return $this->ratings[2]->getQuestion()->getBehavior();
} else {
return "";
}
}
public function getFourthQuestionString(){
if($this->ratings[0] != null){
return $this->ratings[3]->getQuestion()->getTitle();
} else {
return "";
}
}
public function getFourthRatingString(){
if($this->ratings[3] != null){
return $this->ratings[3]->getScore();
} else {
return "";
}
}
public function getFourthBehaviorString(){
if($this->ratings[3] != null){
return $this->ratings[3]->getQuestion()->getBehavior();
} else {
return "";
}
}
public function getGuestToken(){
$data = $this->getId()."-guest-".$this->getSender()->getId().$this->getSkill()->getId();
$r = hash("sha512", $data, false);
return $r;
}
public function getGuestUrl($locale){
$baseUrl = (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] === 'prod')
? "https://app.coss-certification.com"
: "https://coss-b2c.web.app";
return $baseUrl . "/guest-answer/".$this->getGuestToken()."/".$locale."/".$this->getId();
}
public function getId(): ?int
{
return $this->id;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getSelfEvaluation(): ?bool
{
return $this->selfEvaluation;
}
public function setSelfEvaluation(bool $selfEvaluation): self
{
$this->selfEvaluation = $selfEvaluation;
return $this;
}
public function getStrengths(): ?array
{
return $this->strengths;
}
public function setStrengths(?array $strengths): self
{
$this->strengths = $strengths;
return $this;
}
public function getWeaknesses(): ?array
{
return $this->weaknesses;
}
public function setWeaknesses(?array $weaknesses): self
{
$this->weaknesses = $weaknesses;
return $this;
}
public function getAnsweredAt(): ?\DateTimeInterface
{
return $this->answeredAt;
}
public function getAnsweredAtTime(): ?string
{
return $this->answeredAt ? $this->answeredAt->format('H:i:s') : '';
}
public function setAnsweredAt(?\DateTimeInterface $answeredAt): self
{
$this->answeredAt = $answeredAt;
return $this;
}
public function getNotifiedAt(): ?\DateTimeInterface
{
return $this->notifiedAt;
}
public function setNotifiedAt(?\DateTimeInterface $notifiedAt): self
{
$this->notifiedAt = $notifiedAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function getCreatedAtTime(): ?string
{
return $this->createdAt->format('H:i:s');
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getResetted(): ?bool
{
return $this->resetted;
}
public function setResetted(bool $resetted): self
{
$this->resetted = $resetted;
return $this;
}
public function getSender(): ?User
{
return $this->sender;
}
public function setSender(?User $sender): self
{
$this->sender = $sender;
return $this;
}
public function getRecipient(): ?User
{
return $this->recipient;
}
public function setRecipient(?User $recipient): self
{
$this->recipient = $recipient;
return $this;
}
public function getSkill(): ?Skill
{
return $this->skill;
}
public function setSkill(?Skill $skill): self
{
$this->skill = $skill;
return $this;
}
/**
* @return Collection<int, Rating>
*/
public function getRatings(): Collection
{
return $this->ratings;
}
public function addRating(Rating $rating): self
{
if (!$this->ratings->contains($rating)) {
$this->ratings[] = $rating;
$rating->setFeedback($this);
}
return $this;
}
public function removeRating(Rating $rating): self
{
if ($this->ratings->removeElement($rating)) {
// set the owning side to null (unless already changed)
if ($rating->getFeedback() === $this) {
$rating->setFeedback(null);
}
}
return $this;
}
/**
* @return Collection<int, Rating>
*/
public function getBatchFeedbackEmails(): Collection
{
return $this->batchFeedbackEmails;
}
public function addBatchFeedbackEmail(BatchFeedbackEmail $batchFeedbackEmail): self
{
if (!$this->batchFeedbackEmails->contains($batchFeedbackEmail)) {
$this->batchFeedbackEmails[] = $batchFeedbackEmail;
$batchFeedbackEmail->setFeedback($this);
}
return $this;
}
public function removeBatchFeedbackEmail(BatchFeedbackEmail $batchFeedbackEmail): self
{
if ($this->batchFeedbackEmails->removeElement($batchFeedbackEmail)) {
// set the owning side to null (unless already changed)
if ($batchFeedbackEmail->getFeedback() === $this) {
$batchFeedbackEmail->setFeedback(null);
}
}
return $this;
}
public function getRecommendation(): ?Recommendation
{
return $this->recommendation;
}
public function setRecommendation(?Recommendation $recommendation): self
{
$this->recommendation = $recommendation;
return $this;
}
}