Ejemplo n.º 1
0
 /**
  * @param UserProfile $userProfile
  * @param string      $key
  */
 private function unsetEntity(UserProfile $userProfile, $key)
 {
     if (!$userProfile->isNew()) {
         $activePreferences = json_decode($userProfile->getActivePreferences(), true);
         if (array_key_exists($key . '_id', $activePreferences)) {
             $userProfile->unsetPreference($key . '_id');
             $this->userProfile->save();
         }
     }
     $this->unsetPreferenceCookie($key);
 }
Ejemplo n.º 2
0
 /**
  * @Template("PGSCoreDomainBundle:UserProfile:new.html.twig")
  */
 public function editAction(Request $request)
 {
     $id = $request->get('id');
     if (!($user = $this->userManager->findOneById($id))) {
         throw $this->createNotFoundException('Invalid `user` given');
     }
     if (!($userProfile = $this->userProfileManager->findOneById($id))) {
         $userProfile = new UserProfile();
         $userProfile->setId($id);
     }
     $form = $this->createForm($this->get('pgs.core.form.type.user_profile'), $userProfile);
     if ($request->getMethod() == "POST") {
         $form->submit($request);
         if ($form->isValid()) {
             $this->processForm($form);
             return new RedirectResponse($this->generateUrl('homepage'));
         }
     }
     return ['model' => 'User Profile', 'userProfile' => $userProfile, 'form' => $form->createView()];
 }
Ejemplo n.º 3
0
 /**
  * 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->userQuery->findOneById($userProfile->getId());
         $userProfile = $user->getUserProfile();
     }
     return $userProfile;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('prefix', 'choice', ['label' => 'Select a title', 'multiple' => false, 'choices' => ['Mr' => 'Mr', 'Mrs' => 'Mrs', 'Ms' => 'Ms'], 'attr' => ['style' => 'width:75px'], 'required' => false]);
     $builder->add('nickName', 'text', ['label' => 'form.name.nick', 'required' => false]);
     $builder->add('firstName', 'text', ['label' => 'form.name.first', 'required' => false, 'constraints' => [new NotBlank()]]);
     $builder->add('middleName', 'text', ['label' => 'form.name.middle', 'required' => false]);
     $builder->add('lastName', 'text', ['label' => 'form.name.last', 'required' => false]);
     $builder->add('phone', 'text', ['label' => 'form.phone', 'required' => false, 'attr' => ['style' => 'width:150px']]);
     $builder->add('mobile', 'text', ['label' => 'form.mobile', 'required' => false, 'attr' => ['style' => 'width:150px']]);
     $builder->add('address', 'text', ['label' => 'form.address', 'required' => false]);
     $builder->add('city', 'text', ['label' => 'form.city', 'required' => false, 'constraints' => [new NotBlank()]]);
     $builder->add('zip', 'text', ['label' => 'form.zipcode', 'required' => false, 'attr' => ['style' => 'width:100px']]);
     $builder->add('country', 'model', ['label' => 'form.country', 'class' => 'PGS\\CoreDomainBundle\\Model\\Country', 'empty_value' => 'form.country.select', 'query' => $this->countryQuery, 'constraints' => [new NotBlank()]]);
     $builder->add('state', 'model', ['label' => 'form.state', 'class' => 'PGS\\CoreDomainBundle\\Model\\State', 'empty_value' => 'form.state.select', 'constraints' => [new NotBlank()], 'required' => false]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         /** @var UserProfile $profile*/
         $profile = new UserProfile();
         $form = $event->getForm();
         $query = $this->stateQuery->getNoStateChoice();
         if ($profile->getCountry()) {
             $query = $this->stateQuery->getStatesByCountryChoices($profile->getCountry());
         }
         $form->add('state', 'model', ['label' => 'form.state', 'class' => 'PGS\\CoreDomainBundle\\Model\\State', 'empty_value' => 'form.state.select', 'query' => $query, 'constraints' => [new NotBlank()]]);
     });
     $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
         /** @var UserProfile $profile */
         $profile = $event->getData();
         $form = $event->getForm();
         $query = $this->stateQuery->getNoStateChoice();
         $country = $this->countryQuery->findOneById($profile['country']);
         if (count($country)) {
             $query = $this->stateQuery->getStatesByCountryChoices($country);
         }
         $form->add('state', 'model', ['label' => 'form.state', 'class' => 'PGS\\CoreDomainBundle\\Model\\State', 'empty_value' => 'form.state.select', 'query' => $query, 'constraints' => [new NotBlank()], 'required' => false]);
     });
 }
Ejemplo n.º 5
0
 /**
  * @param	UserProfile $userProfile The userProfile object to add.
  */
 protected function doAddUserProfile($userProfile)
 {
     $this->collUserProfiles[] = $userProfile;
     $userProfile->setState($this);
 }
Ejemplo n.º 6
0
 /**
  * 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                 PrincipalQuery 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(PrincipalPeer::ID, $userProfile->getPrincipalId(), $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');
     }
 }
Ejemplo n.º 7
0
 /**
  * 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;
 }
Ejemplo n.º 8
0
 /**
  * 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;
 }
Ejemplo n.º 9
0
 /**
  * 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;
     }
 }