- fixed user settings database #9 - added dynamic user preferences #9 - added form to edit user preferences #9 - removed user language #7
This commit is contained in:
@@ -3,56 +3,124 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* UserPreference
|
||||
*
|
||||
* @ORM\Table(name="preferences",indexes={@ORM\Index(columns={"userid", "option"})}))
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(
|
||||
* name="user_preferences",
|
||||
* uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(columns={"user_id", "name"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class UserPreference
|
||||
{
|
||||
const HOURLY_RATE = 'hourly_rate';
|
||||
const SKIN = 'skin';
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(name="userID", type="integer")
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
*/
|
||||
private $userid;
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="preferences")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE")
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="option", type="string", length=255)
|
||||
* @ORM\Column(name="name", type="string", length=50, nullable=false)
|
||||
* @Assert\Length(min=2, max=50)
|
||||
*/
|
||||
private $option;
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="value", type="string", length=255, nullable=false)
|
||||
* @ORM\Column(name="value", type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Set value
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = TextType::class;
|
||||
|
||||
/**
|
||||
* @var Constraint[]
|
||||
*/
|
||||
protected $constraints = [];
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setValue($value)
|
||||
public function setId(int $id): UserPreference
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setUser(User $user): UserPreference
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setName(string $name): UserPreference
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
@@ -61,50 +129,64 @@ class UserPreference
|
||||
}
|
||||
|
||||
/**
|
||||
* Set option
|
||||
*
|
||||
* @param string $option
|
||||
*
|
||||
* @param string $value
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setOption($option)
|
||||
public function setValue(string $value): UserPreference
|
||||
{
|
||||
$this->option = $option;
|
||||
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get option
|
||||
* Sets the form type to edit that setting.
|
||||
*
|
||||
* @param string $type
|
||||
* @return UserPreference
|
||||
*/
|
||||
public function setType(string $type)
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOption()
|
||||
public function getType()
|
||||
{
|
||||
return $this->option;
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set userid
|
||||
* Set the constraints which are used for validation of the value.
|
||||
*
|
||||
* @param integer $userid
|
||||
*
|
||||
* @return UserPreference
|
||||
* @param Constraint[] $constraints
|
||||
* @return $this
|
||||
*/
|
||||
public function setUserid($userid)
|
||||
public function setConstraints(array $constraints)
|
||||
{
|
||||
$this->userid = $userid;
|
||||
|
||||
$this->constraints = $constraints;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get userid
|
||||
* Adds a constraint which is used for validation of the value.
|
||||
*
|
||||
* @return integer
|
||||
* @param Constraint $constraint
|
||||
* @return $this
|
||||
*/
|
||||
public function getUserid()
|
||||
public function addConstraint(Constraint $constraint)
|
||||
{
|
||||
return $this->userid;
|
||||
$this->constraints[] = $constraint;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Constraint[]
|
||||
*/
|
||||
public function getConstraints()
|
||||
{
|
||||
return $this->constraints;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user