Example #1
0
 public function save($con = null)
 {
     $con = Propel::getConnection();
     try {
         $con->begin();
         $ret = parent::save($con);
         // update agent_has_user table
         $userId = sfContext::getInstance()->getUser()->getSubscriberId();
         $agentId = $this->getId();
         $mode = sfContext::getInstance()->getRequest()->getParameter('action');
         //see if there's already an entry in the table and if not, add it
         $criteria = new Criteria();
         $criteria->add(AgentHasUserPeer::USER_ID, $userId);
         $AgentHasUsersColl = $this->getAgentHasUsers($criteria, $con);
         if (!count($AgentHasUsersColl)) {
             $agentUser = new AgentHasUser();
             $agentUser->setAgentId($agentId);
             $agentUser->setUserId($userId);
             $agentUser->save($con);
         }
         $con->commit();
         sfContext::getInstance()->getUser()->setHasAgents();
         return $ret;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
 /**
  * Method called to associate a AgentHasUser object to this object
  * through the AgentHasUser foreign key attribute
  *
  * @param      AgentHasUser $l AgentHasUser
  * @return     void
  * @throws     PropelException
  */
 public function addAgentHasUser(AgentHasUser $l)
 {
     $this->collAgentHasUsers[] = $l;
     $l->setAgent($this);
 }