User.php 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. <?php
  2. namespace Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\Criteria;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  8. use Symfony\Component\Security\Core\User\EquatableInterface;
  9. use Symfony\Component\Validator\Mapping\ClassMetadata;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Validator\Constraints\DateTime;
  13. use ChamiloLMS\Component\Auth;
  14. /**
  15. * User
  16. *
  17. * @ORM\Table(name="user")
  18. * @ORM\Entity(repositoryClass="Entity\Repository\UserRepository")
  19. */
  20. class User implements AdvancedUserInterface, \Serializable , EquatableInterface
  21. {
  22. /**
  23. * @var integer
  24. *
  25. * @ORM\Column(name="user_id", type="integer", precision=0, scale=0, nullable=false, unique=false)
  26. * @ORM\Id
  27. * @ORM\GeneratedValue(strategy="IDENTITY")
  28. */
  29. private $userId;
  30. /**
  31. * @var string
  32. *
  33. * @ORM\Column(name="lastname", type="string", length=60, precision=0, scale=0, nullable=true, unique=false)
  34. */
  35. private $lastname;
  36. /**
  37. * @var string
  38. *
  39. * @ORM\Column(name="firstname", type="string", length=60, precision=0, scale=0, nullable=true, unique=false)
  40. */
  41. private $firstname;
  42. /**
  43. * @var string
  44. *
  45. * @ORM\Column(name="username", type="string", length=100, precision=0, scale=0, nullable=false, unique=false)
  46. */
  47. private $username;
  48. /**
  49. * @var string
  50. *
  51. * @ORM\Column(name="password", type="string", length=50, precision=0, scale=0, nullable=false, unique=false)
  52. */
  53. private $password;
  54. /**
  55. * @var string
  56. *
  57. * @ORM\Column(name="auth_source", type="string", length=50, precision=0, scale=0, nullable=true, unique=false)
  58. */
  59. private $authSource;
  60. /**
  61. * @var string
  62. *
  63. * @ORM\Column(name="email", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
  64. */
  65. private $email;
  66. /**
  67. * @var boolean
  68. *
  69. * @ORM\Column(name="status", type="integer", precision=0, scale=0, nullable=false, unique=false)
  70. */
  71. private $status;
  72. /**
  73. * @var string
  74. *
  75. * @ORM\Column(name="official_code", type="string", length=40, precision=0, scale=0, nullable=true, unique=false)
  76. */
  77. private $officialCode;
  78. /**
  79. * @var string
  80. *
  81. * @ORM\Column(name="phone", type="string", length=30, precision=0, scale=0, nullable=true, unique=false)
  82. */
  83. private $phone;
  84. /**
  85. * @var string
  86. *
  87. * @ORM\Column(name="picture_uri", type="string", length=250, precision=0, scale=0, nullable=true, unique=false)
  88. */
  89. private $pictureUri;
  90. /**
  91. * @var integer
  92. *
  93. * @ORM\Column(name="creator_id", type="integer", precision=0, scale=0, nullable=true, unique=false)
  94. */
  95. private $creatorId;
  96. /**
  97. * @var string
  98. *
  99. * @ORM\Column(name="competences", type="text", precision=0, scale=0, nullable=true, unique=false)
  100. */
  101. private $competences;
  102. /**
  103. * @var string
  104. *
  105. * @ORM\Column(name="diplomas", type="text", precision=0, scale=0, nullable=true, unique=false)
  106. */
  107. private $diplomas;
  108. /**
  109. * @var string
  110. *
  111. * @ORM\Column(name="openarea", type="text", precision=0, scale=0, nullable=true, unique=false)
  112. */
  113. private $openarea;
  114. /**
  115. * @var string
  116. *
  117. * @ORM\Column(name="teach", type="text", precision=0, scale=0, nullable=true, unique=false)
  118. */
  119. private $teach;
  120. /**
  121. * @var string
  122. *
  123. * @ORM\Column(name="productions", type="string", length=250, precision=0, scale=0, nullable=true, unique=false)
  124. */
  125. private $productions;
  126. /**
  127. * @var integer
  128. *
  129. * @ORM\Column(name="chatcall_user_id", type="integer", precision=0, scale=0, nullable=false, unique=false)
  130. */
  131. private $chatcallUserId;
  132. /**
  133. * @var \DateTime
  134. *
  135. * @ORM\Column(name="chatcall_date", type="datetime", precision=0, scale=0, nullable=false, unique=false)
  136. */
  137. private $chatcallDate;
  138. /**
  139. * @var string
  140. *
  141. * @ORM\Column(name="chatcall_text", type="string", length=50, precision=0, scale=0, nullable=false, unique=false)
  142. */
  143. private $chatcallText;
  144. /**
  145. * @var string
  146. *
  147. * @ORM\Column(name="language", type="string", length=40, precision=0, scale=0, nullable=true, unique=false)
  148. */
  149. private $language;
  150. /**
  151. * @var \DateTime
  152. *
  153. * @ORM\Column(name="registration_date", type="datetime", precision=0, scale=0, nullable=false, unique=false)
  154. */
  155. private $registrationDate;
  156. /**
  157. * @var \DateTime
  158. *
  159. * @ORM\Column(name="expiration_date", type="datetime", precision=0, scale=0, nullable=false, unique=false)
  160. */
  161. private $expirationDate;
  162. /**
  163. * @var boolean
  164. *
  165. * @ORM\Column(name="active", type="boolean", precision=0, scale=0, nullable=false, unique=false)
  166. */
  167. private $active;
  168. /**
  169. * @var string
  170. *
  171. * @ORM\Column(name="openid", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
  172. */
  173. private $openid;
  174. /**
  175. * @var string
  176. *
  177. * @ORM\Column(name="theme", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
  178. */
  179. private $theme;
  180. /**
  181. * @var integer
  182. *
  183. * @ORM\Column(name="hr_dept_id", type="smallint", precision=0, scale=0, nullable=false, unique=false)
  184. */
  185. private $hrDeptId;
  186. /**
  187. * @ORM\OneToMany(targetEntity="CourseRelUser", mappedBy="user")
  188. **/
  189. private $courses;
  190. /**
  191. * @ORM\OneToMany(targetEntity="CItemProperty", mappedBy="user")
  192. **/
  193. private $items;
  194. /**
  195. * @ORM\OneToMany(targetEntity="UsergroupRelUser", mappedBy="user")
  196. **/
  197. private $classes;
  198. /**
  199. * @var ArrayCollection
  200. * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
  201. * @ORM\JoinTable(
  202. * name="users_roles",
  203. * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="user_id")},
  204. * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
  205. * )
  206. */
  207. private $roles;
  208. /**
  209. * @ORM\Column(type="string", length=255)
  210. */
  211. private $salt;
  212. private $isActive;
  213. /**
  214. * @ORM\OneToMany(targetEntity="CurriculumItemRelUser", mappedBy="user")
  215. **/
  216. private $curriculumItems;
  217. /**
  218. * @ORM\ManyToMany(targetEntity="AccessUrl")
  219. * @ORM\JoinTable(name="access_url_rel_user",
  220. * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="user_id")},
  221. * inverseJoinColumns={@ORM\JoinColumn(name="access_url_id", referencedColumnName="id")}
  222. * )
  223. */
  224. private $portals;
  225. /**
  226. *
  227. */
  228. public function __construct()
  229. {
  230. $this->courses = new ArrayCollection();
  231. $this->items = new ArrayCollection();
  232. $this->classes = new ArrayCollection();
  233. $this->roles = new ArrayCollection();
  234. $this->curriculumItems = new ArrayCollection();
  235. $this->salt = sha1(uniqid(null, true));
  236. $this->isActive = true;
  237. $this->registrationDate = new \DateTime();
  238. $this->curriculumItems = new ArrayCollection();
  239. $this->portals = new ArrayCollection();
  240. }
  241. /**
  242. * @param ClassMetadata $metadata
  243. */
  244. public static function loadValidatorMetadata(ClassMetadata $metadata)
  245. {
  246. $metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
  247. $metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
  248. $metadata->addPropertyConstraint('email', new Assert\Email());
  249. $metadata->addConstraint(new UniqueEntity(array(
  250. 'fields' => 'username',
  251. 'message' => 'This value is already used.',
  252. )));
  253. $metadata->addPropertyConstraint('username', new Assert\Length(array(
  254. 'min' => 2,
  255. 'max' => 50,
  256. 'minMessage' => 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.',
  257. 'maxMessage' => 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.',
  258. )));
  259. }
  260. /**
  261. * @inheritDoc
  262. */
  263. public function isEqualTo(UserInterface $user)
  264. {
  265. if (!$user instanceof User) {
  266. return false;
  267. }
  268. if ($this->password !== $user->getPassword()) {
  269. return false;
  270. }
  271. if ($this->getSalt() !== $user->getSalt()) {
  272. return false;
  273. }
  274. if ($this->username !== $user->getUsername()) {
  275. return false;
  276. }
  277. return true;
  278. }
  279. /**
  280. * @return ArrayCollection
  281. */
  282. public function getPortals()
  283. {
  284. return $this->portals;
  285. }
  286. /**
  287. * @param $portal
  288. */
  289. public function setPortal($portal)
  290. {
  291. $this->portals->add($portal);
  292. }
  293. /**
  294. * @return ArrayCollection
  295. */
  296. public function getCurriculumItems()
  297. {
  298. return $this->curriculumItems;
  299. }
  300. /**
  301. * @param $items
  302. */
  303. public function setCurriculumItems($items)
  304. {
  305. $this->curriculumItems = $items;
  306. }
  307. /**
  308. * @return bool
  309. */
  310. public function getIsActive()
  311. {
  312. return $this->active == 1;
  313. }
  314. /**
  315. * @inheritDoc
  316. */
  317. public function isAccountNonExpired()
  318. {
  319. return true;
  320. /*$now = new \DateTime();
  321. return $this->getExpirationDate() < $now;*/
  322. }
  323. /**
  324. * @inheritDoc
  325. */
  326. public function isAccountNonLocked()
  327. {
  328. return true;
  329. }
  330. /**
  331. * @inheritDoc
  332. */
  333. public function isCredentialsNonExpired()
  334. {
  335. return true;
  336. }
  337. /**
  338. * @inheritDoc
  339. */
  340. public function isEnabled()
  341. {
  342. return $this->getActive() == 1;
  343. }
  344. /**
  345. * @inheritDoc
  346. */
  347. public function eraseCredentials()
  348. {
  349. }
  350. /**
  351. *
  352. * @return ArrayCollection
  353. */
  354. public function getRolesObj()
  355. {
  356. return $this->roles;
  357. }
  358. /**
  359. * This function is needed in order to pass roles to the security component
  360. * @inheritDoc
  361. */
  362. public function getRoles()
  363. {
  364. $roles = $this->roles->toArray();
  365. //$roles[] = new Auth\Role($this);
  366. return $roles;
  367. }
  368. /**
  369. * @param $role
  370. * @return $this
  371. */
  372. public function setRoles($role)
  373. {
  374. $this->roles->add($role);
  375. return $this;
  376. }
  377. /**
  378. * @see https://github.com/symfony/symfony/issues/3691
  379. * @see \Serializable::serialize()
  380. */
  381. public function serialize()
  382. {
  383. /*
  384. * ! Don't serialize $roles field !
  385. */
  386. return \serialize(
  387. array(
  388. $this->userId,
  389. $this->username,
  390. $this->email,
  391. $this->salt,
  392. $this->password,
  393. $this->isActive
  394. )
  395. );
  396. }
  397. /**
  398. * @see \Serializable::unserialize()
  399. */
  400. public function unserialize($serialized)
  401. {
  402. list (
  403. $this->userId,
  404. $this->username,
  405. $this->email,
  406. $this->salt,
  407. $this->password,
  408. $this->isActive
  409. ) = \unserialize($serialized);
  410. }
  411. /**
  412. * Set salt
  413. *
  414. * @param string $salt
  415. *
  416. * @return User
  417. */
  418. public function setSalt($salt)
  419. {
  420. $this->salt = $salt;
  421. return $this;
  422. }
  423. /**
  424. * Get salt
  425. *
  426. * @return string
  427. */
  428. public function getSalt()
  429. {
  430. return $this->salt;
  431. }
  432. /**
  433. * @return ArrayCollection
  434. */
  435. public function getClasses()
  436. {
  437. return $this->classes;
  438. }
  439. /**
  440. *
  441. */
  442. public function getLps()
  443. {
  444. //return $this->lps;
  445. /*$criteria = Criteria::create()
  446. ->where(Criteria::expr()->eq("id", "666"))
  447. //->orderBy(array("username" => "ASC"))
  448. //->setFirstResult(0)
  449. //->setMaxResults(20)
  450. ;
  451. $lps = $this->lps->matching($criteria);*/
  452. /*return $this->lps->filter(
  453. function($entry) use ($idsToFilter) {
  454. return $entry->getId() == 1;
  455. });*/
  456. }
  457. /**
  458. * @return string
  459. */
  460. public function getCompleteName()
  461. {
  462. return $this->lastname .', '. $this->firstname;
  463. }
  464. /**
  465. * Returns the list of classes for the user
  466. * @return string
  467. */
  468. public function getCompleteNameWithClasses()
  469. {
  470. $classSubscription = $this->getClasses();
  471. $classList = array();
  472. foreach ($classSubscription as $subscription) {
  473. $class = $subscription->getClass();
  474. $classList[] = $class->getName();
  475. }
  476. $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
  477. return $this->getCompleteName().$classString;
  478. }
  479. /**
  480. * Get userId
  481. *
  482. * @return integer
  483. */
  484. public function getUserId()
  485. {
  486. return $this->userId;
  487. }
  488. /**
  489. * Set lastname
  490. *
  491. * @param string $lastname
  492. *
  493. * @return User
  494. */
  495. public function setLastname($lastname)
  496. {
  497. $this->lastname = $lastname;
  498. return $this;
  499. }
  500. /**
  501. * Get lastname
  502. *
  503. * @return string
  504. */
  505. public function getLastname()
  506. {
  507. return $this->lastname;
  508. }
  509. /**
  510. * Set firstname
  511. *
  512. * @param string $firstname
  513. *
  514. * @return User
  515. */
  516. public function setFirstname($firstname)
  517. {
  518. $this->firstname = $firstname;
  519. return $this;
  520. }
  521. /**
  522. * Get firstname
  523. *
  524. * @return string
  525. */
  526. public function getFirstname()
  527. {
  528. return $this->firstname;
  529. }
  530. /**
  531. * Set username
  532. *
  533. * @param string $username
  534. * @return User
  535. */
  536. public function setUsername($username)
  537. {
  538. $this->username = $username;
  539. return $this;
  540. }
  541. /**
  542. * Get username
  543. *
  544. * @return string
  545. */
  546. public function getUsername()
  547. {
  548. return $this->username;
  549. }
  550. /**
  551. * Set password
  552. *
  553. * @param string $password
  554. * @return User
  555. */
  556. public function setPassword($password)
  557. {
  558. $this->password = $password;
  559. return $this;
  560. }
  561. /**
  562. * Get password
  563. *
  564. * @return string
  565. */
  566. public function getPassword()
  567. {
  568. return $this->password;
  569. }
  570. /**
  571. * Set authSource
  572. *
  573. * @param string $authSource
  574. * @return User
  575. */
  576. public function setAuthSource($authSource)
  577. {
  578. $this->authSource = $authSource;
  579. return $this;
  580. }
  581. /**
  582. * Get authSource
  583. *
  584. * @return string
  585. */
  586. public function getAuthSource()
  587. {
  588. return $this->authSource;
  589. }
  590. /**
  591. * Set email
  592. *
  593. * @param string $email
  594. * @return User
  595. */
  596. public function setEmail($email)
  597. {
  598. $this->email = $email;
  599. return $this;
  600. }
  601. /**
  602. * Get email
  603. *
  604. * @return string
  605. */
  606. public function getEmail()
  607. {
  608. return $this->email;
  609. }
  610. /**
  611. * Set status
  612. *
  613. * @param boolean $status
  614. * @return User
  615. */
  616. public function setStatus($status)
  617. {
  618. $this->status = $status;
  619. return $this;
  620. }
  621. /**
  622. * Get status
  623. *
  624. * @return boolean
  625. */
  626. public function getStatus()
  627. {
  628. return $this->status;
  629. }
  630. /**
  631. * Set officialCode
  632. *
  633. * @param string $officialCode
  634. * @return User
  635. */
  636. public function setOfficialCode($officialCode)
  637. {
  638. $this->officialCode = $officialCode;
  639. return $this;
  640. }
  641. /**
  642. * Get officialCode
  643. *
  644. * @return string
  645. */
  646. public function getOfficialCode()
  647. {
  648. return $this->officialCode;
  649. }
  650. /**
  651. * Set phone
  652. *
  653. * @param string $phone
  654. * @return User
  655. */
  656. public function setPhone($phone)
  657. {
  658. $this->phone = $phone;
  659. return $this;
  660. }
  661. /**
  662. * Get phone
  663. *
  664. * @return string
  665. */
  666. public function getPhone()
  667. {
  668. return $this->phone;
  669. }
  670. /**
  671. * Set pictureUri
  672. *
  673. * @param string $pictureUri
  674. * @return User
  675. */
  676. public function setPictureUri($pictureUri)
  677. {
  678. $this->pictureUri = $pictureUri;
  679. return $this;
  680. }
  681. /**
  682. * Get pictureUri
  683. *
  684. * @return string
  685. */
  686. public function getPictureUri()
  687. {
  688. return $this->pictureUri;
  689. }
  690. /**
  691. * Set creatorId
  692. *
  693. * @param integer $creatorId
  694. * @return User
  695. */
  696. public function setCreatorId($creatorId)
  697. {
  698. $this->creatorId = $creatorId;
  699. return $this;
  700. }
  701. /**
  702. * Get creatorId
  703. *
  704. * @return integer
  705. */
  706. public function getCreatorId()
  707. {
  708. return $this->creatorId;
  709. }
  710. /**
  711. * Set competences
  712. *
  713. * @param string $competences
  714. * @return User
  715. */
  716. public function setCompetences($competences)
  717. {
  718. $this->competences = $competences;
  719. return $this;
  720. }
  721. /**
  722. * Get competences
  723. *
  724. * @return string
  725. */
  726. public function getCompetences()
  727. {
  728. return $this->competences;
  729. }
  730. /**
  731. * Set diplomas
  732. *
  733. * @param string $diplomas
  734. * @return User
  735. */
  736. public function setDiplomas($diplomas)
  737. {
  738. $this->diplomas = $diplomas;
  739. return $this;
  740. }
  741. /**
  742. * Get diplomas
  743. *
  744. * @return string
  745. */
  746. public function getDiplomas()
  747. {
  748. return $this->diplomas;
  749. }
  750. /**
  751. * Set openarea
  752. *
  753. * @param string $openarea
  754. * @return User
  755. */
  756. public function setOpenarea($openarea)
  757. {
  758. $this->openarea = $openarea;
  759. return $this;
  760. }
  761. /**
  762. * Get openarea
  763. *
  764. * @return string
  765. */
  766. public function getOpenarea()
  767. {
  768. return $this->openarea;
  769. }
  770. /**
  771. * Set teach
  772. *
  773. * @param string $teach
  774. * @return User
  775. */
  776. public function setTeach($teach)
  777. {
  778. $this->teach = $teach;
  779. return $this;
  780. }
  781. /**
  782. * Get teach
  783. *
  784. * @return string
  785. */
  786. public function getTeach()
  787. {
  788. return $this->teach;
  789. }
  790. /**
  791. * Set productions
  792. *
  793. * @param string $productions
  794. * @return User
  795. */
  796. public function setProductions($productions)
  797. {
  798. $this->productions = $productions;
  799. return $this;
  800. }
  801. /**
  802. * Get productions
  803. *
  804. * @return string
  805. */
  806. public function getProductions()
  807. {
  808. return $this->productions;
  809. }
  810. /**
  811. * Set chatcallUserId
  812. *
  813. * @param integer $chatcallUserId
  814. * @return User
  815. */
  816. public function setChatcallUserId($chatcallUserId)
  817. {
  818. $this->chatcallUserId = $chatcallUserId;
  819. return $this;
  820. }
  821. /**
  822. * Get chatcallUserId
  823. *
  824. * @return integer
  825. */
  826. public function getChatcallUserId()
  827. {
  828. return $this->chatcallUserId;
  829. }
  830. /**
  831. * Set chatcallDate
  832. *
  833. * @param \DateTime $chatcallDate
  834. * @return User
  835. */
  836. public function setChatcallDate($chatcallDate)
  837. {
  838. $this->chatcallDate = $chatcallDate;
  839. return $this;
  840. }
  841. /**
  842. * Get chatcallDate
  843. *
  844. * @return \DateTime
  845. */
  846. public function getChatcallDate()
  847. {
  848. return $this->chatcallDate;
  849. }
  850. /**
  851. * Set chatcallText
  852. *
  853. * @param string $chatcallText
  854. * @return User
  855. */
  856. public function setChatcallText($chatcallText)
  857. {
  858. $this->chatcallText = $chatcallText;
  859. return $this;
  860. }
  861. /**
  862. * Get chatcallText
  863. *
  864. * @return string
  865. */
  866. public function getChatcallText()
  867. {
  868. return $this->chatcallText;
  869. }
  870. /**
  871. * Set language
  872. *
  873. * @param string $language
  874. * @return User
  875. */
  876. public function setLanguage($language)
  877. {
  878. $this->language = $language;
  879. return $this;
  880. }
  881. /**
  882. * Get language
  883. *
  884. * @return string
  885. */
  886. public function getLanguage()
  887. {
  888. return $this->language;
  889. }
  890. /**
  891. * Set registrationDate
  892. *
  893. * @param \DateTime $registrationDate
  894. * @return User
  895. */
  896. public function setRegistrationDate($registrationDate)
  897. {
  898. $this->registrationDate = $registrationDate;
  899. return $this;
  900. }
  901. /**
  902. * Get registrationDate
  903. *
  904. * @return \DateTime
  905. */
  906. public function getRegistrationDate()
  907. {
  908. return $this->registrationDate;
  909. }
  910. /**
  911. * Set expirationDate
  912. *
  913. * @param \DateTime $expirationDate
  914. * @return User
  915. */
  916. public function setExpirationDate($expirationDate)
  917. {
  918. $this->expirationDate = $expirationDate;
  919. return $this;
  920. }
  921. /**
  922. * Get expirationDate
  923. *
  924. * @return \DateTime
  925. */
  926. public function getExpirationDate()
  927. {
  928. return $this->expirationDate;
  929. }
  930. /**
  931. * Set active
  932. *
  933. * @param boolean $active
  934. * @return User
  935. */
  936. public function setActive($active)
  937. {
  938. $this->active = $active;
  939. return $this;
  940. }
  941. /**
  942. * Get active
  943. *
  944. * @return boolean
  945. */
  946. public function getActive()
  947. {
  948. return $this->active;
  949. }
  950. /**
  951. * Set openid
  952. *
  953. * @param string $openid
  954. * @return User
  955. */
  956. public function setOpenid($openid)
  957. {
  958. $this->openid = $openid;
  959. return $this;
  960. }
  961. /**
  962. * Get openid
  963. *
  964. * @return string
  965. */
  966. public function getOpenid()
  967. {
  968. return $this->openid;
  969. }
  970. /**
  971. * Set theme
  972. *
  973. * @param string $theme
  974. * @return User
  975. */
  976. public function setTheme($theme)
  977. {
  978. $this->theme = $theme;
  979. return $this;
  980. }
  981. /**
  982. * Get theme
  983. *
  984. * @return string
  985. */
  986. public function getTheme()
  987. {
  988. return $this->theme;
  989. }
  990. /**
  991. * Set hrDeptId
  992. *
  993. * @param integer $hrDeptId
  994. * @return User
  995. */
  996. public function setHrDeptId($hrDeptId)
  997. {
  998. $this->hrDeptId = $hrDeptId;
  999. return $this;
  1000. }
  1001. /**
  1002. * Get hrDeptId
  1003. *
  1004. * @return integer
  1005. */
  1006. public function getHrDeptId()
  1007. {
  1008. return $this->hrDeptId;
  1009. }
  1010. /**
  1011. * @todo use SUM
  1012. * @return int
  1013. */
  1014. public function getCurriculumScore()
  1015. {
  1016. $items = $this->getCurriculumItems();
  1017. $scorePerCategory = array();
  1018. $maxPerCategory = array();
  1019. /** @var \Entity\CurriculumItemRelUser $itemRelUser */
  1020. $mainParentList = array();
  1021. $parentList = array();
  1022. foreach ($items as $itemRelUser) {
  1023. $parentId = $itemRelUser->getItem()->getCategory()->getParent()->getId();
  1024. $mainParent = $itemRelUser->getItem()->getCategory()->getParent()->getParent();
  1025. $mainParentList[$mainParent->getId()] = $mainParent->getMaxScore();
  1026. $parentList[$parentId] = $mainParent->getId();
  1027. if (!isset($scorePerCategory[$parentId])) {
  1028. $scorePerCategory[$parentId] = 0;
  1029. }
  1030. $scorePerCategory[$parentId] += $itemRelUser->getItem()->getScore();
  1031. if (!isset($scorePerCategory[$parentId])) {
  1032. $maxPerCategory[$parentId] = 0;
  1033. }
  1034. $maxPerCategory[$parentId] =
  1035. $itemRelUser->getItem()->getCategory()->getParent()->getMaxScore();
  1036. }
  1037. $newScorePerCategory = array();
  1038. foreach ($scorePerCategory as $categoryId => $scoreInCategory) {
  1039. $mainParentId = $parentList[$categoryId];
  1040. if ($scoreInCategory >= $maxPerCategory[$categoryId]) {
  1041. $score = $maxPerCategory[$categoryId];
  1042. } else {
  1043. $score = $scoreInCategory;
  1044. }
  1045. if (!isset($newScorePerCategory[$categoryId])) {
  1046. $newScorePerCategory[$mainParentId][$categoryId] = 0;
  1047. }
  1048. $newScorePerCategory[$mainParentId][$categoryId] += $score;
  1049. }
  1050. $finalScore = 0;
  1051. foreach ($newScorePerCategory as $mainParentId => $scoreList) {
  1052. $maxScore = $mainParentList[$mainParentId];
  1053. $subScore = 0;
  1054. foreach ($scoreList as $score) {
  1055. $subScore += $score;
  1056. }
  1057. if ($subScore >= $maxScore) {
  1058. $finalScore += $maxScore;
  1059. } else {
  1060. $finalScore += $score;
  1061. }
  1062. }
  1063. return $finalScore;
  1064. }
  1065. }