UserPreference.php (2457B)
1 <?php 2 3 namespace PartKeepr\AuthBundle\Entity; 4 5 use Doctrine\ORM\Mapping as ORM; 6 use PartKeepr\DoctrineReflectionBundle\Annotation\IgnoreIds; 7 use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; 8 use Symfony\Component\Serializer\Annotation\Groups; 9 10 /** 11 * Represents a user preference entry. 12 * 13 * User preferences are a simple key => value mechanism, where the developer can 14 * specify the key and value himself. 15 * 16 * Note that values are stored internally as serialized PHP values to keep their type. 17 * 18 * @ORM\Entity 19 * @TargetService(uri="/api/user_preferences") 20 * @IgnoreIds() 21 **/ 22 class UserPreference 23 { 24 /** 25 * Defines the key of the user preference. 26 * 27 * @ORM\Column(type="string",length=255) 28 * @ORM\Id() 29 * 30 * @Groups({"default"}) 31 * 32 * @var string 33 */ 34 private $preferenceKey; 35 36 /** 37 * Defines the value. Note that the value is internally stored as a serialized string. 38 * 39 * @ORM\Column(type="text") 40 * 41 * @Groups({"default"}) 42 * 43 * @var mixed 44 */ 45 private $preferenceValue; 46 47 /** 48 * Defines the user. 49 * 50 * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") 51 * @ORM\Id() 52 * 53 * @var \PartKeepr\AuthBundle\Entity\User 54 */ 55 private $user; 56 57 /** 58 * Sets the user for this entry. 59 * 60 * @param \PartKeepr\AuthBundle\Entity\User $user 61 */ 62 public function setUser(User $user) 63 { 64 $this->user = $user; 65 } 66 67 /** 68 * Returns the user associated with this entry. 69 * 70 * @return \PartKeepr\AuthBundle\Entity\User 71 */ 72 public function getUser() 73 { 74 return $this->user; 75 } 76 77 /** 78 * Sets the key for this user preference. 79 * 80 * @param string $key The key name 81 */ 82 public function setPreferenceKey($key) 83 { 84 $this->preferenceKey = $key; 85 } 86 87 /** 88 * Returns the key of this entry. 89 * 90 * @return string 91 */ 92 public function getPreferenceKey() 93 { 94 return $this->preferenceKey; 95 } 96 97 /** 98 * Sets the value for this entry. 99 * 100 * @param mixed $value 101 */ 102 public function setPreferenceValue($value) 103 { 104 $this->preferenceValue = serialize($value); 105 } 106 107 /** 108 * Returns the value for this entry. 109 * 110 * @return mixed The value 111 */ 112 public function getPreferenceValue() 113 { 114 return unserialize($this->preferenceValue); 115 } 116 }