예제 #1
0
 public function saveLocacion($locacion)
 {
     $id = $locacion->getId();
     //new sfUser(); // nasty hack to load propel
     $con = Propel::getConnection();
     try {
         $con->beginTransaction();
         if ($locacion->getPrincipal()) {
             // Aparentemente propel no soporta aun joins dentro del update
             $s = "UPDATE rel_establecimiento_locacion,locacion SET locacion.principal = 0 ";
             $s .= "WHERE locacion.id = rel_establecimiento_locacion.fk_locacion_id AND ";
             $s .= "rel_establecimiento_locacion.fk_establecimiento_id = " . $this->getUser()->getAttribute('fk_establecimiento_id');
             $alumnos = $con->query($s);
         }
         $locacion->save();
         if (!$id) {
             $relEstablecimientoLocacion = new RelEstablecimientoLocacion();
             $relEstablecimientoLocacion->setFkEstablecimientoId($this->getUser()->getAttribute('fk_establecimiento_id'));
             $relEstablecimientoLocacion->setFkLocacionId($locacion->getId());
             $relEstablecimientoLocacion->save();
         }
         $con->commit();
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
예제 #2
0
 function executeSaveLocacion()
 {
     // borrar todas las locaciones para un establecimientos determinado
     $establecimientoId = $this->getRequestParameter('id');
     $aLocacion = $this->getRequest()->getParameterHolder()->get('establecimientoLocacion');
     $c = new Criteria();
     $c->add(RelEstablecimientoLocacionPeer::FK_ESTABLECIMIENTO_ID, $establecimientoId);
     RelEstablecimientoLocacionPeer::doDelete($c);
     if (count($aLocacion) > 0) {
         // grabar todos los que vienen seleccionados
         // aqui se debe poder grabar haciendo un solo insert
         $c = new Criteria();
         foreach ($aLocacion as $locacionId) {
             $p = new RelEstablecimientoLocacion();
             $p->setFkLocacionId($locacionId);
             $p->setFkEstablecimientoId($establecimientoId);
             $p->save();
             unset($p);
         }
     }
     $this->getUser()->setFlash('notice', 'Se ha grabado correctamente.');
     return $this->redirect('establecimiento/editLocacion?id=' . $establecimientoId);
 }
 public static function addInstanceToPool(RelEstablecimientoLocacion $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         self::$instances[$key] = $obj;
     }
 }