private function corroborarReservas() { $reservas = array(); //seteo el maximo tiempo de reserva de pelicula $max_time = date('00:30:00'); //obtengo la hora ctual $ahora = date('H:i:s'); //me fijo todas las reservas que no expiraron $con = ReservasQuery::create(); $con->filterByExpiroReserva(false); $reservas = $con->find(); foreach ($reservas as $res) { $hora_res = $res->getHoraReserva(); $h2 = $this->hora_a_segundos($hora_res); $h1 = $this->hora_a_segundos($ahora); $dif = $h1 - $h2; $dif = $this->segundos_a_hora($dif); if ($dif > $max_time) { //updateo la base de datos cn las reservas expiradas $res_exp = ReservasQuery::create(); $res_exp->filterById($res->getId()); $res_exp->update(array('ExpiroReserva' => true)); } } }
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; } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Pelicula is new, it will return * an empty collection; or if this Pelicula has previously * been saved, it will retrieve related Reservass from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Pelicula. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelCollection|array Reservas[] List of Reservas objects */ public function getReservassJoinSocio($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = ReservasQuery::create(null, $criteria); $query->joinWith('Socio', $join_behavior); return $this->getReservass($query, $con); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(ReservasPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = ReservasQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // symfony_behaviors behavior foreach (sfMixer::getCallables('BaseReservas:delete:pre') as $callable) { if (call_user_func($callable, $this, $con)) { $con->commit(); return; } } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); // symfony_behaviors behavior foreach (sfMixer::getCallables('BaseReservas:delete:post') as $callable) { call_user_func($callable, $this, $con); } $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }