/** * 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; }
/** * Filter the query by a related UserProfile object * * @param UserProfile|PropelObjectCollection $userProfile the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return UserQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterByUserProfile($userProfile, $comparison = null) { if ($userProfile instanceof UserProfile) { return $this->addUsingAlias(UserPeer::ID, $userProfile->getId(), $comparison); } elseif ($userProfile instanceof PropelObjectCollection) { return $this->useUserProfileQuery()->filterByPrimaryKeys($userProfile->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByUserProfile() only accepts arguments of type UserProfile or PropelCollection'); } }
/** * Exclude object from result * * @param UserProfile $userProfile Object to remove from the list of results * * @return UserProfileQuery The current query, for fluid interface */ public function prune($userProfile = null) { if ($userProfile) { $this->addUsingAlias(UserProfilePeer::ID, $userProfile->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param UserProfile $obj A UserProfile object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null UserProfilePeer::$instances[$key] = $obj; } }