Пример #1
0
 /**
  * gets an array of User objects NOT related to the current agent
  *
  * The user group is defined by removing users already related to the supplied agentId
  *
  * @param Agent $agent The current agent
  * @return array An array of User objects
  */
 public static function getNewUsersForAgent($criteria)
 {
     $con = Propel::getConnection(self::DATABASE_NAME);
     $agent = sfContext::getInstance()->getUser()->getAttribute('agent', '');
     if ($agent) {
         $agentId = $agent->getId();
     }
     /**
     * @todo speed this up by making an array of current users and passing that to the query a 'not in array[]'
     **/
     //get the current user list for this agent
     $c = new Criteria();
     $c->add(AgentHasUserPeer::AGENT_ID, $agent->getId());
     $curUsers = AgentHasUserPeer::doSelect($c);
     $c = new Criteria();
     $c->addAscendingOrderByColumn(self::NICKNAME);
     $newUsers = UserPeer::doSelect($c);
     foreach ($curUsers as $curUser) {
         $curId = $curUser->getUserId();
         foreach ($newUsers as $key => $newUser) {
             if ($newUser->getId() == $curId) {
                 unset($newUsers[$key]);
                 break;
             }
         }
     }
     //make sure the array is contiguous
     $newUsers = array_merge($newUsers);
     return $newUsers;
 }
Пример #2
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Agent has previously
  * been saved, it will retrieve related AgentHasUsers from storage.
  * If this Agent is new, it will return
  * an empty collection or the current collection, the criteria
  * is ignored on a new object.
  *
  * @param      Connection $con
  * @param      Criteria $criteria
  * @throws     PropelException
  */
 public function getAgentHasUsers($criteria = null, $con = null)
 {
     // include the Peer class
     include_once 'lib/model/om/BaseAgentHasUserPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collAgentHasUsers === null) {
         if ($this->isNew()) {
             $this->collAgentHasUsers = array();
         } else {
             $criteria->add(AgentHasUserPeer::AGENT_ID, $this->getId());
             AgentHasUserPeer::addSelectColumns($criteria);
             $this->collAgentHasUsers = AgentHasUserPeer::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(AgentHasUserPeer::AGENT_ID, $this->getId());
             AgentHasUserPeer::addSelectColumns($criteria);
             if (!isset($this->lastAgentHasUserCriteria) || !$this->lastAgentHasUserCriteria->equals($criteria)) {
                 $this->collAgentHasUsers = AgentHasUserPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastAgentHasUserCriteria = $criteria;
     return $this->collAgentHasUsers;
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      Connection $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(AgentHasUserPeer::ID, $pks, Criteria::IN);
         $objs = AgentHasUserPeer::doSelect($criteria, $con);
     }
     return $objs;
 }