Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 /**
  * Gets the number of User objects related by a many-to-many relationship
  * to the current object by way of the fos_user_group cross-reference table.
  *
  * @param Criteria $criteria Optional query object to filter the query
  * @param boolean $distinct Set to true to force count distinct
  * @param PropelPDO $con Optional connection object
  *
  * @return int the number of related User objects
  */
 public function countUsers($criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collUsers || null !== $criteria) {
         if ($this->isNew() && null === $this->collUsers) {
             return 0;
         } else {
             $query = UserQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByGroup($this)->count($con);
         }
     } else {
         return count($this->collUsers);
     }
 }
Exemplo n.º 3
0
 /**
  * Get the associated User object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return User The associated User object.
  * @throws PropelException
  */
 public function getUser(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aUser === null && $this->id !== null && $doQuery) {
         $this->aUser = UserQuery::create()->findPk($this->id, $con);
         // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association.
         $this->aUser->setUserProfile($this);
     }
     return $this->aUser;
 }
Exemplo n.º 4
0
 /**
  * Get the associated User object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return User The associated User object.
  * @throws PropelException
  */
 public function getUser(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aUser === null && $this->user_id !== null && $doQuery) {
         $this->aUser = UserQuery::create()->findPk($this->user_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aUser->addAreaAssignments($this);
            */
     }
     return $this->aUser;
 }
Exemplo n.º 5
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(UserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         EventDispatcherProxy::trigger(array('delete.pre', 'model.delete.pre'), new ModelEvent($this));
         $deleteQuery = UserQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // event behavior
             EventDispatcherProxy::trigger(array('delete.post', 'model.delete.post'), new ModelEvent($this));
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }