<?php
// src/AppBundle/Entity/User.php
namespace App\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Exclude;
/**
* @ORM\Entity
* @ORM\Table(name="users")
* @ExclusionPolicy("none")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity="Survey", inversedBy="users", cascade={"persist"})
* @ORM\JoinTable(
* joinColumns={@ORM\JoinColumn(nullable=true, onDelete="SET NULL")},
* inverseJoinColumns={@ORM\JoinColumn(nullable=true, onDelete="SET NULL")}
* )
* @Exclude()
*/
private $surveys;
/**
* @ORM\OneToMany(targetEntity="Result", mappedBy="user")
* @Exclude()
*/
private $results;
public function __construct()
{
parent::__construct();
$this->surveys = new \Doctrine\Common\Collections\ArrayCollection();
}
public function __toString()
{
if (!$this->name) {
return '';
}
return $this->name;
}
/**
* Set name
*
* @param string $name
*
* @return User
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set email
*
* @param string $email
*
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
$this->username = $email;
return $this;
}
/**
* Set surveys
*
* @param \App\Entity\Survey $surveys
*
* @return Result
*/
public function setSurveys(\App\Entity\Survey $surveys)
{
$this->surveys = $surveys;
return $this;
}
/**
* Get surveys
*
* @return int
*/
public function getSurveys()
{
return $this->surveys;
}
/**
* Set results
*
* @param \App\Entity\Result $results
*
* @return Result
*/
public function setResults(\App\Entity\Result $results)
{
$this->results = $results;
return $this;
}
/**
* Get results
*
* @return int
*/
public function getResults()
{
return $this->results;
}
/**
* Add survey
*
* @param \App\Entity\Survey $survey
*
* @return User
*/
public function addSurvey(\App\Entity\Survey $survey)
{
$this->surveys[] = $survey;
return $this;
}
/**
* Remove survey
*
* @param \App\Entity\Survey $survey
*/
public function removeSurvey(\App\Entity\Survey $survey)
{
$this->surveys->removeElement($survey);
}
/**
* Add result
*
* @param \App\Entity\Result $result
*
* @return User
*/
public function addResult(\App\Entity\Result $result)
{
$this->results[] = $result;
return $this;
}
/**
* Remove result
*
* @param \App\Entity\Result $result
*/
public function removeResult(\App\Entity\Result $result)
{
$this->results->removeElement($result);
}
}