vendor/uvdesk/core-framework/Entity/User.php line 14

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Entity;
  3. use Symfony\Component\Security\Core\User\UserInterface;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * User
  7. * @ORM\Entity(repositoryClass="Webkul\UVDesk\CoreFrameworkBundle\Repository\UserRepository")
  8. * @ORM\HasLifecycleCallbacks()
  9. * @ORM\Table(name="uv_user")
  10. */
  11. class User implements UserInterface
  12. {
  13. /**
  14. * @var integer
  15. * @ORM\Id()
  16. * @ORM\Column(type="integer")
  17. * @ORM\GeneratedValue(strategy="AUTO")
  18. */
  19. private $id;
  20. /**
  21. * @var string
  22. * @ORM\Column(type="string", length=191, unique=true, nullable=true)
  23. */
  24. private $email;
  25. /**
  26. * @var string
  27. * @ORM\Column(type="string", length=191, unique=true, nullable=true)
  28. */
  29. private $proxyId;
  30. /**
  31. * @var string
  32. * @ORM\Column(type="string", length=191, nullable=true)
  33. */
  34. private $password;
  35. /**
  36. * @var string
  37. * @ORM\Column(type="string", length=191)
  38. */
  39. private $firstName;
  40. /**
  41. * @var string
  42. * @ORM\Column(type="string", length=191, nullable=true)
  43. */
  44. private $lastName;
  45. /**
  46. * @var boolean
  47. * @ORM\Column(type="boolean", options={"default": false})
  48. */
  49. private $isEnabled;
  50. /**
  51. * @var string
  52. * @ORM\Column(type="string", length=191, unique=true, nullable=true)
  53. */
  54. private $verificationCode;
  55. /**
  56. * @var \Doctrine\Common\Collections\Collection
  57. * @ORM\OneToMany(targetEntity="UserInstance", mappedBy="user")
  58. */
  59. private $userInstance;
  60. /**
  61. * @var array
  62. */
  63. private $grantedRoles = [];
  64. /**
  65. * @var \Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance
  66. */
  67. private $activeInstance;
  68. /**
  69. * @var string
  70. * @ORM\Column(type="string", length=191, nullable=true)
  71. */
  72. private $timezone;
  73. /**
  74. * @var string
  75. * @ORM\Column(type="string", length=191, nullable=true)
  76. */
  77. private $timeformat;
  78. /**
  79. * @var \DateTime
  80. * @ORM\Column(type="datetime", nullable=true)
  81. */
  82. private $lastOtpGeneratedAt;
  83. /**
  84. * Constructor
  85. */
  86. public function __construct()
  87. {
  88. $this->userInstance = new \Doctrine\Common\Collections\ArrayCollection();
  89. }
  90. /**
  91. * Get id
  92. *
  93. * @return integer
  94. */
  95. public function getId()
  96. {
  97. return $this->id;
  98. }
  99. /**
  100. * Set lastOtpGeneratedAt
  101. *
  102. * @param \DateTime $lastOtpGeneratedAt
  103. *
  104. */
  105. public function setLastOtpGeneratedAt($lastOtpGeneratedAt)
  106. {
  107. $this->lastOtpGeneratedAt = $lastOtpGeneratedAt;
  108. return $this;
  109. }
  110. /**
  111. * Get lastOtpGeneratedAt
  112. *
  113. * @return \DateTime
  114. */
  115. public function getLastOtpGeneratedAt()
  116. {
  117. return $this->lastOtpGeneratedAt;
  118. }
  119. /**
  120. * Set email
  121. *
  122. * @param string $email
  123. *
  124. * @return User
  125. */
  126. public function setEmail($email)
  127. {
  128. $this->email = $email;
  129. return $this;
  130. }
  131. /**
  132. * Get email
  133. *
  134. * @return string
  135. */
  136. public function getEmail()
  137. {
  138. return $this->email;
  139. }
  140. /**
  141. * Set proxyId
  142. *
  143. * @param string $proxyId
  144. *
  145. * @return User
  146. */
  147. public function setProxyId($proxyId)
  148. {
  149. $this->proxyId = $proxyId;
  150. return $this;
  151. }
  152. /**
  153. * Get proxyId
  154. *
  155. * @return string
  156. */
  157. public function getProxyId()
  158. {
  159. return $this->proxyId;
  160. }
  161. /**
  162. * Get username
  163. *
  164. * @return string
  165. */
  166. public function getUsername()
  167. {
  168. return $this->email;
  169. }
  170. /**
  171. * Set password
  172. *
  173. * @param string $password
  174. *
  175. * @return User
  176. */
  177. public function setPassword($password)
  178. {
  179. $this->password = $password;
  180. return $this;
  181. }
  182. /**
  183. * Get password
  184. *
  185. * @return string
  186. */
  187. public function getPassword()
  188. {
  189. return $this->password;
  190. }
  191. /**
  192. * Get salt
  193. *
  194. * @return string
  195. */
  196. public function getSalt()
  197. {
  198. return null;
  199. }
  200. /**
  201. * Set user instance's granted roles
  202. *
  203. * @param array $grantedRoles
  204. *
  205. * @return User
  206. */
  207. public function setRoles(array $grantedRoles = [])
  208. {
  209. $this->grantedRoles = $grantedRoles;
  210. return $this;
  211. }
  212. /**
  213. * Get user's granted roles
  214. *
  215. * @return array
  216. */
  217. public function getRoles()
  218. {
  219. return $this->grantedRoles;
  220. }
  221. /**
  222. * Set firstName
  223. *
  224. * @param string $firstName
  225. *
  226. * @return User
  227. */
  228. public function setFirstName($firstName)
  229. {
  230. $this->firstName = $firstName;
  231. return $this;
  232. }
  233. /**
  234. * Get firstName
  235. *
  236. * @return string
  237. */
  238. public function getFirstName()
  239. {
  240. return $this->firstName;
  241. }
  242. /**
  243. * Set lastName
  244. *
  245. * @param string $lastName
  246. *
  247. * @return User
  248. */
  249. public function setLastName($lastName)
  250. {
  251. $this->lastName = $lastName;
  252. return $this;
  253. }
  254. /**
  255. * Get lastName
  256. *
  257. * @return string
  258. */
  259. public function getLastName()
  260. {
  261. return $this->lastName;
  262. }
  263. /**
  264. * Get fullName
  265. *
  266. * @return string
  267. */
  268. public function getFullName()
  269. {
  270. return trim(implode(' ', array($this->getFirstName(), $this->getLastName())));
  271. }
  272. /**
  273. * Set isEnabled
  274. *
  275. * @param boolean $isEnabled
  276. *
  277. * @return User
  278. */
  279. public function setIsEnabled($isEnabled)
  280. {
  281. $this->isEnabled = $isEnabled;
  282. return $this;
  283. }
  284. /**
  285. * Get isEnabled
  286. *
  287. * @return boolean
  288. */
  289. public function getIsEnabled()
  290. {
  291. return $this->isEnabled;
  292. }
  293. /**
  294. * Set verificationCode
  295. *
  296. * @param string $verificationCode
  297. *
  298. * @return User
  299. */
  300. public function setVerificationCode($verificationCode)
  301. {
  302. $this->verificationCode = $verificationCode;
  303. return $this;
  304. }
  305. /**
  306. * Get email
  307. *
  308. * @return string
  309. */
  310. public function getVerificationCode()
  311. {
  312. return $this->verificationCode;
  313. }
  314. /**
  315. * Clears not so important user's credentials
  316. *
  317. * @return void
  318. */
  319. public function eraseCredentials()
  320. {
  321. return;
  322. }
  323. /**
  324. * Checks whether the user's account has expired
  325. *
  326. * @return bool
  327. */
  328. public function isAccountNonExpired()
  329. {
  330. return true;
  331. }
  332. /**
  333. * Checks whether the user is locked
  334. *
  335. * @return bool
  336. */
  337. public function isAccountNonLocked()
  338. {
  339. return true;
  340. }
  341. /**
  342. * Checks whether the user's credentials has expired
  343. *
  344. * @return bool
  345. */
  346. public function isCredentialsNonExpired()
  347. {
  348. return true;
  349. }
  350. /**
  351. * Checks whether the user is enabled
  352. *
  353. * @return bool
  354. */
  355. public function isEnabled()
  356. {
  357. return $this->isEnabled;
  358. }
  359. /**
  360. * Add userInstance
  361. *
  362. * @param \Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance $userInstance
  363. *
  364. * @return User
  365. */
  366. public function addUserInstance(\Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance $userInstance)
  367. {
  368. $this->userInstance[] = $userInstance;
  369. return $this;
  370. }
  371. /**
  372. * Remove userInstance
  373. *
  374. * @param \Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance $userInstance
  375. */
  376. public function removeUserInstance(\Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance $userInstance)
  377. {
  378. $this->userInstance->removeElement($userInstance);
  379. }
  380. /**
  381. * Get userInstance
  382. *
  383. * @return \Doctrine\Common\Collections\Collection
  384. */
  385. public function getUserInstance()
  386. {
  387. return $this->userInstance;
  388. }
  389. public function getAgentInstance()
  390. {
  391. foreach ($this->getUserInstance()->getValues() as $userInstance) {
  392. if (in_array($userInstance->getSupportRole()->getCode(), ['ROLE_AGENT', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN'])) {
  393. return $userInstance;
  394. }
  395. }
  396. return null;
  397. }
  398. public function getCustomerInstance()
  399. {
  400. foreach ($this->getUserInstance()->getValues() as $userInstance) {
  401. if (in_array($userInstance->getSupportRole()->getCode(), ['ROLE_CUSTOMER', 'ROLE_CUSTOMER_READ_ONLY'])) {
  402. return $userInstance;
  403. }
  404. }
  405. return null;
  406. }
  407. /**
  408. * Set currently active user instance
  409. *
  410. * @param \Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance $userInstance
  411. *
  412. * @return User
  413. */
  414. public function setCurrentInstance(\Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance $userInstance = null)
  415. {
  416. $this->activeInstance = $userInstance;
  417. return $this;
  418. }
  419. /**
  420. * Get currently active user instance
  421. *
  422. * @return \Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance
  423. */
  424. public function getCurrentInstance()
  425. {
  426. return $this->activeInstance;
  427. }
  428. /**
  429. * Set timezone
  430. *
  431. * @param string $timezone
  432. * @return User
  433. */
  434. public function setTimezone($timezone)
  435. {
  436. $this->timezone = $timezone;
  437. return $this;
  438. }
  439. /**
  440. * Get timezone
  441. *
  442. * @return string
  443. */
  444. public function getTimezone()
  445. {
  446. return $this->timezone;
  447. }
  448. /**
  449. * Set timeformat
  450. *
  451. * @param string $timeformat
  452. * @return User
  453. */
  454. public function setTimeformat($timeformat)
  455. {
  456. $this->timeformat = $timeformat;
  457. return $this;
  458. }
  459. /**
  460. * Get timeformat
  461. *
  462. * @return string
  463. */
  464. public function getTimeformat()
  465. {
  466. return $this->timeformat;
  467. }
  468. }