/** * Get the UserProfile from the current security user. * Reload UserProfile from the db when $reload = true * * @param bool $reload * * @return null|UserProfile */ public function getCurrentUserProfile($reload = false) { $user = $this->securityContext->getToken()->getUser(); if ($user instanceof User) { // check if there is no profile record for the user if (!($userProfile = $user->getUserProfile())) { $userProfile = new UserProfile(); $userProfile->setUser($user); $userProfile->setFirstName($user->getUsername()); $userProfile->setCountryId(Country::UNKNOWN); $userProfile->save(); } } else { return null; } if ($reload) { $user = $this->userRepository->findOneById($userProfile->getId()); $userProfile = $user->getUserProfile(); } return $userProfile; }
/** * Sets a single UserProfile object as related to this object by a one-to-one relationship. * * @param UserProfile $v UserProfile * @return User The current object (for fluent API support) * @throws PropelException */ public function setUserProfile(UserProfile $v = null) { $this->singleUserProfile = $v; // Make sure that that the passed-in UserProfile isn't already associated with this object if ($v !== null && $v->getUser(null, false) === null) { $v->setUser($this); } return $this; }