Beispiel #1
0
 public function getRoles()
 {
     $c = new Criteria();
     $c->add(UserHasRolePeer::USER_ID, $this->getId(), Criteria::EQUAL);
     $result = array();
     $userHasRoles = UserHasRolePeer::doSelect($c);
     if (!empty($userHasRoles)) {
         foreach ($userHasRoles as $userHasRole) {
             $result[] = $userHasRole->getRole();
         }
     }
     return $result;
 }
Beispiel #2
0
 /**
  * Gets an array of UserHasRole objects which contain a foreign key that references this object.
  *
  * If this collection has already been initialized with an identical Criteria, it returns the collection.
  * Otherwise if this User has previously been saved, it will retrieve
  * related UserHasRoles from storage. If this User is new, it will return
  * an empty collection or the current collection, the criteria is ignored on a new object.
  *
  * @param      PropelPDO $con
  * @param      Criteria $criteria
  * @return     array UserHasRole[]
  * @throws     PropelException
  */
 public function getUserHasRoles($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(UserPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collUserHasRoles === null) {
         if ($this->isNew()) {
             $this->collUserHasRoles = array();
         } else {
             $criteria->add(UserHasRolePeer::USER_ID, $this->id);
             UserHasRolePeer::addSelectColumns($criteria);
             $this->collUserHasRoles = UserHasRolePeer::doSelect($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return the collection.
             $criteria->add(UserHasRolePeer::USER_ID, $this->id);
             UserHasRolePeer::addSelectColumns($criteria);
             if (!isset($this->lastUserHasRoleCriteria) || !$this->lastUserHasRoleCriteria->equals($criteria)) {
                 $this->collUserHasRoles = UserHasRolePeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastUserHasRoleCriteria = $criteria;
     return $this->collUserHasRoles;
 }
 /**
 * Retrieve object using using composite pkey values.
 * @param      int $user_id
   @param      string $role_id
   
 * @param      PropelPDO $con
 * @return     UserHasRole
 */
 public static function retrieveByPK($user_id, $role_id, PropelPDO $con = null)
 {
     $key = serialize(array((string) $user_id, (string) $role_id));
     if (null !== ($obj = UserHasRolePeer::getInstanceFromPool($key))) {
         return $obj;
     }
     if ($con === null) {
         $con = Propel::getConnection(UserHasRolePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $criteria = new Criteria(UserHasRolePeer::DATABASE_NAME);
     $criteria->add(UserHasRolePeer::USER_ID, $user_id);
     $criteria->add(UserHasRolePeer::ROLE_ID, $role_id);
     $v = UserHasRolePeer::doSelect($criteria, $con);
     return !empty($v) ? $v[0] : null;
 }