courses = new ArrayCollection(); $this->items = new ArrayCollection(); $this->classes = new ArrayCollection(); $this->roles = new ArrayCollection(); $this->curriculumItems = new ArrayCollection(); $this->salt = sha1(uniqid(null, true)); $this->isActive = true; $this->registrationDate = new \DateTime(); $this->curriculumItems = new ArrayCollection(); $this->portals = new ArrayCollection(); } /** * @param ClassMetadata $metadata */ public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('firstname', new Assert\NotBlank()); $metadata->addPropertyConstraint('lastname', new Assert\NotBlank()); $metadata->addPropertyConstraint('email', new Assert\Email()); $metadata->addConstraint(new UniqueEntity(array( 'fields' => 'username', 'message' => 'This value is already used.', ))); $metadata->addPropertyConstraint('username', new Assert\Length(array( 'min' => 2, 'max' => 50, '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.', '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.', ))); } /** * @inheritDoc */ public function isEqualTo(UserInterface $user) { if (!$user instanceof User) { return false; } if ($this->password !== $user->getPassword()) { return false; } if ($this->getSalt() !== $user->getSalt()) { return false; } if ($this->username !== $user->getUsername()) { return false; } return true; } /** * @return ArrayCollection */ public function getPortals() { return $this->portals; } /** * @param $portal */ public function setPortal($portal) { $this->portals->add($portal); } /** * @return ArrayCollection */ public function getCurriculumItems() { return $this->curriculumItems; } /** * @param $items */ public function setCurriculumItems($items) { $this->curriculumItems = $items; } /** * @return bool */ public function getIsActive() { return $this->active == 1; } /** * @inheritDoc */ public function isAccountNonExpired() { return true; /*$now = new \DateTime(); return $this->getExpirationDate() < $now;*/ } /** * @inheritDoc */ public function isAccountNonLocked() { return true; } /** * @inheritDoc */ public function isCredentialsNonExpired() { return true; } /** * @inheritDoc */ public function isEnabled() { return $this->getActive() == 1; } /** * @inheritDoc */ public function eraseCredentials() { } /** * * @return ArrayCollection */ public function getRolesObj() { return $this->roles; } /** * This function is needed in order to pass roles to the security component * @inheritDoc */ public function getRoles() { $roles = $this->roles->toArray(); //$roles[] = new Auth\Role($this); return $roles; } /** * @param $role * @return $this */ public function setRoles($role) { $this->roles->add($role); return $this; } /** * @see https://github.com/symfony/symfony/issues/3691 * @see \Serializable::serialize() */ public function serialize() { /* * ! Don't serialize $roles field ! */ return \serialize( array( $this->userId, $this->username, $this->email, $this->salt, $this->password, $this->isActive ) ); } /** * @see \Serializable::unserialize() */ public function unserialize($serialized) { list ( $this->userId, $this->username, $this->email, $this->salt, $this->password, $this->isActive ) = \unserialize($serialized); } /** * Set salt * * @param string $salt * * @return User */ public function setSalt($salt) { $this->salt = $salt; return $this; } /** * Get salt * * @return string */ public function getSalt() { return $this->salt; } /** * @return ArrayCollection */ public function getClasses() { return $this->classes; } /** * */ public function getLps() { //return $this->lps; /*$criteria = Criteria::create() ->where(Criteria::expr()->eq("id", "666")) //->orderBy(array("username" => "ASC")) //->setFirstResult(0) //->setMaxResults(20) ; $lps = $this->lps->matching($criteria);*/ /*return $this->lps->filter( function($entry) use ($idsToFilter) { return $entry->getId() == 1; });*/ } /** * @return string */ public function getCompleteName() { return $this->lastname .', '. $this->firstname; } /** * Returns the list of classes for the user * @return string */ public function getCompleteNameWithClasses() { $classSubscription = $this->getClasses(); $classList = array(); foreach ($classSubscription as $subscription) { $class = $subscription->getClass(); $classList[] = $class->getName(); } $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null; return $this->getCompleteName().$classString; } /** * Get userId * * @return integer */ public function getUserId() { return $this->userId; } /** * Set lastname * * @param string $lastname * * @return User */ public function setLastname($lastname) { $this->lastname = $lastname; return $this; } /** * Get lastname * * @return string */ public function getLastname() { return $this->lastname; } /** * Set firstname * * @param string $firstname * * @return User */ public function setFirstname($firstname) { $this->firstname = $firstname; return $this; } /** * Get firstname * * @return string */ public function getFirstname() { return $this->firstname; } /** * Set username * * @param string $username * @return User */ public function setUsername($username) { $this->username = $username; return $this; } /** * Get username * * @return string */ public function getUsername() { return $this->username; } /** * Set password * * @param string $password * @return User */ public function setPassword($password) { $this->password = $password; return $this; } /** * Get password * * @return string */ public function getPassword() { return $this->password; } /** * Set authSource * * @param string $authSource * @return User */ public function setAuthSource($authSource) { $this->authSource = $authSource; return $this; } /** * Get authSource * * @return string */ public function getAuthSource() { return $this->authSource; } /** * Set email * * @param string $email * @return User */ public function setEmail($email) { $this->email = $email; return $this; } /** * Get email * * @return string */ public function getEmail() { return $this->email; } /** * Set status * * @param boolean $status * @return User */ public function setStatus($status) { $this->status = $status; return $this; } /** * Get status * * @return boolean */ public function getStatus() { return $this->status; } /** * Set officialCode * * @param string $officialCode * @return User */ public function setOfficialCode($officialCode) { $this->officialCode = $officialCode; return $this; } /** * Get officialCode * * @return string */ public function getOfficialCode() { return $this->officialCode; } /** * Set phone * * @param string $phone * @return User */ public function setPhone($phone) { $this->phone = $phone; return $this; } /** * Get phone * * @return string */ public function getPhone() { return $this->phone; } /** * Set pictureUri * * @param string $pictureUri * @return User */ public function setPictureUri($pictureUri) { $this->pictureUri = $pictureUri; return $this; } /** * Get pictureUri * * @return string */ public function getPictureUri() { return $this->pictureUri; } /** * Set creatorId * * @param integer $creatorId * @return User */ public function setCreatorId($creatorId) { $this->creatorId = $creatorId; return $this; } /** * Get creatorId * * @return integer */ public function getCreatorId() { return $this->creatorId; } /** * Set competences * * @param string $competences * @return User */ public function setCompetences($competences) { $this->competences = $competences; return $this; } /** * Get competences * * @return string */ public function getCompetences() { return $this->competences; } /** * Set diplomas * * @param string $diplomas * @return User */ public function setDiplomas($diplomas) { $this->diplomas = $diplomas; return $this; } /** * Get diplomas * * @return string */ public function getDiplomas() { return $this->diplomas; } /** * Set openarea * * @param string $openarea * @return User */ public function setOpenarea($openarea) { $this->openarea = $openarea; return $this; } /** * Get openarea * * @return string */ public function getOpenarea() { return $this->openarea; } /** * Set teach * * @param string $teach * @return User */ public function setTeach($teach) { $this->teach = $teach; return $this; } /** * Get teach * * @return string */ public function getTeach() { return $this->teach; } /** * Set productions * * @param string $productions * @return User */ public function setProductions($productions) { $this->productions = $productions; return $this; } /** * Get productions * * @return string */ public function getProductions() { return $this->productions; } /** * Set chatcallUserId * * @param integer $chatcallUserId * @return User */ public function setChatcallUserId($chatcallUserId) { $this->chatcallUserId = $chatcallUserId; return $this; } /** * Get chatcallUserId * * @return integer */ public function getChatcallUserId() { return $this->chatcallUserId; } /** * Set chatcallDate * * @param \DateTime $chatcallDate * @return User */ public function setChatcallDate($chatcallDate) { $this->chatcallDate = $chatcallDate; return $this; } /** * Get chatcallDate * * @return \DateTime */ public function getChatcallDate() { return $this->chatcallDate; } /** * Set chatcallText * * @param string $chatcallText * @return User */ public function setChatcallText($chatcallText) { $this->chatcallText = $chatcallText; return $this; } /** * Get chatcallText * * @return string */ public function getChatcallText() { return $this->chatcallText; } /** * Set language * * @param string $language * @return User */ public function setLanguage($language) { $this->language = $language; return $this; } /** * Get language * * @return string */ public function getLanguage() { return $this->language; } /** * Set registrationDate * * @param \DateTime $registrationDate * @return User */ public function setRegistrationDate($registrationDate) { $this->registrationDate = $registrationDate; return $this; } /** * Get registrationDate * * @return \DateTime */ public function getRegistrationDate() { return $this->registrationDate; } /** * Set expirationDate * * @param \DateTime $expirationDate * @return User */ public function setExpirationDate($expirationDate) { $this->expirationDate = $expirationDate; return $this; } /** * Get expirationDate * * @return \DateTime */ public function getExpirationDate() { return $this->expirationDate; } /** * Set active * * @param boolean $active * @return User */ public function setActive($active) { $this->active = $active; return $this; } /** * Get active * * @return boolean */ public function getActive() { return $this->active; } /** * Set openid * * @param string $openid * @return User */ public function setOpenid($openid) { $this->openid = $openid; return $this; } /** * Get openid * * @return string */ public function getOpenid() { return $this->openid; } /** * Set theme * * @param string $theme * @return User */ public function setTheme($theme) { $this->theme = $theme; return $this; } /** * Get theme * * @return string */ public function getTheme() { return $this->theme; } /** * Set hrDeptId * * @param integer $hrDeptId * @return User */ public function setHrDeptId($hrDeptId) { $this->hrDeptId = $hrDeptId; return $this; } /** * Get hrDeptId * * @return integer */ public function getHrDeptId() { return $this->hrDeptId; } /** * @todo use SUM * @return int */ public function getCurriculumScore() { $items = $this->getCurriculumItems(); $scorePerCategory = array(); $maxPerCategory = array(); /** @var \Entity\CurriculumItemRelUser $itemRelUser */ $mainParentList = array(); $parentList = array(); foreach ($items as $itemRelUser) { $parentId = $itemRelUser->getItem()->getCategory()->getParent()->getId(); $mainParent = $itemRelUser->getItem()->getCategory()->getParent()->getParent(); $mainParentList[$mainParent->getId()] = $mainParent->getMaxScore(); $parentList[$parentId] = $mainParent->getId(); if (!isset($scorePerCategory[$parentId])) { $scorePerCategory[$parentId] = 0; } $scorePerCategory[$parentId] += $itemRelUser->getItem()->getScore(); if (!isset($scorePerCategory[$parentId])) { $maxPerCategory[$parentId] = 0; } $maxPerCategory[$parentId] = $itemRelUser->getItem()->getCategory()->getParent()->getMaxScore(); } $newScorePerCategory = array(); foreach ($scorePerCategory as $categoryId => $scoreInCategory) { $mainParentId = $parentList[$categoryId]; if ($scoreInCategory >= $maxPerCategory[$categoryId]) { $score = $maxPerCategory[$categoryId]; } else { $score = $scoreInCategory; } if (!isset($newScorePerCategory[$categoryId])) { $newScorePerCategory[$mainParentId][$categoryId] = 0; } $newScorePerCategory[$mainParentId][$categoryId] += $score; } $finalScore = 0; foreach ($newScorePerCategory as $mainParentId => $scoreList) { $maxScore = $mainParentList[$mainParentId]; $subScore = 0; foreach ($scoreList as $score) { $subScore += $score; } if ($subScore >= $maxScore) { $finalScore += $maxScore; } else { $finalScore += $score; } } return $finalScore; } }