ninesurvey/src/ninesurvey-1.0/src/Entity/Survey.php

345 lines
7.1 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\SurveyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=SurveyRepository::class)
*/
class Survey
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(name="label", type="string", length=255)
*/
private $title;
/**
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(name="private", type="boolean")
*/
private $private;
/**
* @ORM\Column(name="notification", type="boolean")
*/
private $notification;
/**
* @ORM\Column(name="keyaccess", type="string", length=255)
*/
private $key;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="boolean")
*/
private $tonotifyclose;
/**
* @ORM\Column(type="boolean")
*/
private $tonotifyopen;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $tonotifymessage;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="surveys")
*/
private $user;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Option", mappedBy="survey", cascade={"persist"}, orphanRemoval=true)
*/
private $options;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Guest", mappedBy="survey", cascade={"persist"}, orphanRemoval=true)
*/
private $guests;
/**
* Calculate
* jsonoptions = formatage des options du survey en une chaine json
* jsonguests = formatage des guests du survey en une chaine json
*/
private $jsonoptions;
private $jsonguests;
private $result;
private $datepurge;
public function setJsonoptions(string $jsonoptions): self
{
$this->jsonoptions = $jsonoptions;
return $this;
}
public function getJsonoptions(): ?string
{
return $this->jsonoptions;
}
public function setJsonguests(string $jsonguests): self
{
$this->jsonguests = $jsonguests;
return $this;
}
public function getJsonguests(): ?string
{
return $this->jsonguests;
}
public function getResult(): ?array
{
$this->result=[];
foreach($this->guests as $guest) {
foreach($guest->getVotes() as $vote) {
$key=$vote->getOption()->getId();
$val=$vote->getVote();
if(!array_key_exists($key,$this->result))
$this->result[$key]=["id"=>$key,"date"=>$vote->getOption()->getDate(),"count"=>0];
if(!is_null($val))
$this->result[$key]["count"]+=$val;
}
}
$columns = array_column($this->result, 'count');
array_multisort($columns, SORT_DESC, $this->result);
return $this->result;
}
public function getDatepurge()
{
$this->datepurge=new \DateTime('2000-01-01');
foreach($this->options as $option) {
if($option->getDate()>$this->datepurge)
$this->datepurge=clone($option->getDate());
}
$this->datepurge->modify('+10 day');
return $this->datepurge;
}
public function __construct()
{
$this->options = new ArrayCollection();
$this->guests = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getPrivate(): ?bool
{
return $this->private;
}
public function setPrivate(bool $private): self
{
$this->private = $private;
return $this;
}
public function getNotification(): ?bool
{
return $this->notification;
}
public function setNotification(bool $notification): self
{
$this->notification = $notification;
return $this;
}
public function getKey(): ?string
{
return $this->key;
}
public function setKey(string $key): self
{
$this->key = $key;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|Option[]
*/
public function getOptions(): Collection
{
return $this->options;
}
public function addOption(Option $option): self
{
if (!$this->options->contains($option)) {
$this->options[] = $option;
$option->setSurvey($this);
}
return $this;
}
public function removeOption(Option $option): self
{
if ($this->options->contains($option)) {
$this->options->removeElement($option);
// set the owning side to null (unless already changed)
if ($option->getSurvey() === $this) {
$option->setSurvey(null);
}
}
return $this;
}
/**
* @return Collection|Guest[]
*/
public function getGuests(): Collection
{
return $this->guests;
}
public function addGuest(Guest $guest): self
{
if (!$this->guests->contains($guest)) {
$this->guests[] = $guest;
$guest->setSurvey($this);
}
return $this;
}
public function removeGuest(Guest $guest): self
{
if ($this->guests->contains($guest)) {
$this->guests->removeElement($guest);
// set the owning side to null (unless already changed)
if ($guest->getSurvey() === $this) {
$guest->setSurvey(null);
}
}
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getTonotifyclose(): ?bool
{
return $this->tonotifyclose;
}
public function setTonotifyclose(bool $tonotifyclose): self
{
$this->tonotifyclose = $tonotifyclose;
return $this;
}
public function getTonotifyopen(): ?bool
{
return $this->tonotifyopen;
}
public function setTonotifyopen(bool $tonotifyopen): self
{
$this->tonotifyopen = $tonotifyopen;
return $this;
}
public function getTonotifymessage(): ?string
{
return $this->tonotifymessage;
}
public function setTonotifymessage(?string $tonotifymessage): self
{
$this->tonotifymessage = $tonotifymessage;
return $this;
}
}