protected function saveCiclolectivo($ciclolectivo) { //si se guarda el ciclo y se marca como actual //los demas ciclo del establecimiento tiene que quedar como ACUAL = false $con = Propel::getConnection(); try { $con->beginTransaction(); if ($ciclolectivo->getActual()) { $c1 = new Criteria(); $c1->add(CiclolectivoPeer::FK_ESTABLECIMIENTO_ID, $this->getUser()->getAttribute('fk_establecimiento_id')); $c2 = new Criteria(); $c2->add(CiclolectivoPeer::ACTUAL, false); BasePeer::doUpdate($c1, $c2, $con); } $ciclolectivo->setFkEstablecimientoId($this->getUser()->getAttribute('fk_establecimiento_id')); $isNew = $ciclolectivo->isNew(); $ciclolectivo->save(); if ($isNew) { # Codigo para copiar las divisiones del ciclo lectivo actual al nuevo # La consulta debe contemplar que lo haga desde el ciclo lectivo actual if ($this->getRequestParameter('importar')) { $ciclo_actual = CiclolectivoPeer::retrieveByPk($this->getUser()->getAttribute('fk_ciclolectivo_id')); if ($ciclo_actual) { $this->logMessage('ciclo_actual: ' . $ciclo_actual, 'debug'); //clonar turnos foreach ($ciclo_actual->getTurnos() as $turno) { $nt = new Turno(); $nt->setFkCiclolectivoId($ciclolectivo->getId()); $nt->setHoraInicio($turno->getHoraInicio()); $nt->setHoraFin($turno->getHoraFin()); $nt->setDescripcion($turno->getDescripcion()); $nt->save(); //clonar las divisiones foreach ($turno->getDivisions() as $division) { $this->logMessage('division: ' . $division, 'debug'); $nd = new Division(); $nd->setFkAnioId($division->getFkAnioId()); $nd->setDescripcion($division->getDescripcion()); $nd->setFkTurnoId($nt->getId()); $nd->setFkOrientacionId($division->getFkOrientacionId()); $nd->setOrden($division->getOrden()); $nd->save(); } } } else { //no existe el ciclo actual $this->getUser()->setFlash('error', 'No hay un ciclo actual seleccionado'); } } } $con->commit(); if ($ciclolectivo->getActual()) { //cambio el attributo porque se cambio el ciclo actual $this->getUser()->setAttribute('fk_ciclolectivo_id', $ciclolectivo->getId()); $this->getUser()->setAttribute('ciclolectivo_descripcion', $ciclolectivo->getDescripcion()); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Exclude object from result * * @param Turno $turno Object to remove from the list of results * * @return TurnoQuery The current query, for fluid interface */ public function prune($turno = null) { if ($turno) { $this->addUsingAlias(TurnoPeer::ID, $turno->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Turno $obj A Turno object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null TurnoPeer::$instances[$key] = $obj; } }
public function setTurno(Turno $v = null) { if ($v === null) { $this->setFkTurnoId(0); } else { $this->setFkTurnoId($v->getId()); } $this->aTurno = $v; if ($v !== null) { $v->addDivision($this); } return $this; }