/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aAlquiler !== null) { if ($this->aAlquiler->isModified() || $this->aAlquiler->isNew()) { $affectedRows += $this->aAlquiler->save($con); } $this->setAlquiler($this->aAlquiler); } if ($this->aPelicula !== null) { if ($this->aPelicula->isModified() || $this->aPelicula->isNew()) { $affectedRows += $this->aPelicula->save($con); } $this->setPelicula($this->aPelicula); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
public function executeAlquilarPeliculas(sfWebRequest $request) { //obtengo socio y todas las peliculas que alquila $peliculasId = array(); $peliculasId = $request->getParameter("id_pelis"); $socio = $request->getParameter("id_socio"); //calculo precio total $total_a_cobrar = sizeof($peliculasId) * 8; //corroboro que las peliculas esten todas libres $todo_bien = true; foreach ($peliculasId as $peli_id) { if ($this->peliculaAlquilada($peli_id)) { $todo_bien = false; } } if ($todo_bien) { //cargo el alquiler en la base $alquiler = new Alquiler(); $alquiler->setFechaAlquiler(date("d-m-Y")); $alquiler->setTotalACobrar($total_a_cobrar); $alquiler->setSocioId($socio); $alquiler->save(); //capturo el id de la reserva $id_alquiler = $alquiler->getId(); foreach ($peliculasId as $peli_id) { //cargo el alquiler en socio_alquiler $socio_alquiler = new SocioAlquiler(); $socio_alquiler->setAlquilerId($id_alquiler); $socio_alquiler->setPeliculaId($peli_id); $socio_alquiler->save(); //marco las peliculas como alquiladas $pelicula_alquilada = PeliculaQuery::create()->filterById($peli_id)->update(array('Estado' => 3)); //marco la reserva como alquilada $reserva = ReservasQuery::create()->filterByPeliculaId($peli_id)->filterBySocioId($socio)->filterByAlquilada(false)->filterByExpiroReserva(false)->update(array('Alquilada' => true)); $this->mje = "Las peliculas: se alquilaron correctamente!!"; } } else { $this->mje = "Las peliculas NO se alquilaron!!"; return sfView::ERROR; } }