protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $c = new Criteria(); #$c->add(PoliticoPeer::ID, 18256, Criteria::EQUAL); $politicos = PoliticoPeer::doSelect($c); #echo SfVoUtil::myUcfirst("Casilda")."\n";die; foreach ($politicos as $politico) { $vanity = $politico->getVanity(); $nombre = $politico->getNombre(); $apellidos = $politico->getApellidos(); if (strcmp($vanity, $newVanity = SfVoUtil::fixCase($vanity))) { echo "politico:{$vanity} -> {$newVanity}\n"; $politico->setVanity($newVanity); } if ($nombre != ($newNombre = SfVoUtil::fixCase($nombre))) { echo "politico:{$nombre} -> {$newNombre}\n"; $politico->setNombre($newNombre); } if ($apellidos != ($newApellidos = SfVoUtil::fixCase($apellidos))) { echo "politico:{$apellidos} -> {$newApellidos}\n"; $politico->setApellidos($newApellidos); } $politico->save(); } $instituciones = InstitucionI18nPeer::doSelect($c); foreach ($instituciones as $institucion) { $vanity = $institucion->getVanity(); $nombreCorto = $institucion->getNombreCorto(); $nombre = $institucion->getNombre(); if (strcmp($vanity, $newVanity = SfVoUtil::fixCase($vanity))) { echo "institucion:{$vanity} -> {$newVanity}\n"; $institucion->setVanity($newVanity); } if (strcmp($nombreCorto, $newNombreCorto = SfVoUtil::fixCase($nombreCorto))) { echo "institucion:{$nombreCorto} -> {$newNombreCorto}\n"; $institucion->setNombreCorto($newNombreCorto); } if (strcmp($nombre, $newNombre = SfVoUtil::fixCase($nombre))) { echo "institucion:{$nombre} -> {$newNombre}\n"; $institucion->setNombre($newNombre); } $institucion->save(); } $geos = GeoPeer::doSelect($c); foreach ($geos as $geo) { $nombre = $geo->getNombre(); if (strcmp($nombre, $newNombre = SfVoUtil::fixCase($nombre))) { echo "geo:{$nombre} -> {$newNombre}\n"; $geo->setNombre($newNombre); } $geo->save(); } }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(GeoPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(GeoPeer::DATABASE_NAME); $criteria->add(GeoPeer::ID, $pks, Criteria::IN); $objs = GeoPeer::doSelect($criteria, $con); } return $objs; }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $handle = fopen("php://stdin", "r"); $line = fgets($handle); while ($line = fgets($handle)) { $data = explode(";", "{$line}"); $c = new Criteria(); $c->add(GeoPeer::NOMBRE, $data[3]); $geos = GeoPeer::doSelect($c); $aGeo = false; foreach ($geos as $geo) { if ($geo->getGeoRelatedByGeoId() != null && $geo->getGeoRelatedByGeoId()->getCodigo() && $geo->getGeoRelatedByGeoId()->getCodigo() != '') { //echo 'geo: ' . $geo->getNombre() . "\n"; $aGeo = $geo; } } if (!$aGeo) { echo 'Geo not found: (' . $data[3] . ")\n"; continue; } $c = new Criteria(); $c->add(PartidoPeer::ABREVIATURA, $data[5]); $partido = PartidoPeer::doSelectOne($c); if (!$partido) { $partido = new Partido(); $partido->setAbreviatura($data[5]); $partido->setIsActive(true); $partido->setNombre($data[5], 'es'); $partido->setNombre($data[5], 'ca'); $partido->save(); echo "Created partido ({$partido})\n"; } $c = new Criteria(); $c->add(CircunscripcionPeer::GEO_ID, $aGeo->getId()); $circu = CircunscripcionPeer::doSelectOne($c); $c = new Criteria(); $c->addJoin(ConvocatoriaPeer::ELECCION_ID, EleccionPeer::ID); $c->addJoin(EleccionInstitucionPeer::ELECCION_ID, EleccionPeer::ID); $c->addJoin(InstitucionPeer::ID, EleccionInstitucionPeer::INSTITUCION_ID); $c->add(InstitucionPeer::GEO_ID, $aGeo->getId()); $convocatoria = ConvocatoriaPeer::doSelectOne($c); if (!$convocatoria) { echo "Convocatoria not found: ({$geo})\n"; continue; } $c = new Criteria(); $c->add(ListaPeer::CONVOCATORIA_ID, $convocatoria->getId()); $c->add(ListaPeer::CIRCUNSCRIPCION_ID, $circu->getId()); $c->add(ListaPeer::PARTIDO_ID, $partido->getId()); $lista = ListaPeer::doSelectOne($c); if (!$lista) { $lista = new Lista(); $lista->setPartido($partido); $lista->setCircunscripcion($circu); $lista->setConvocatoria($convocatoria); $lista->save(); echo "Created lista ({$partido}, {$circu})\n"; } $politicos = false; $c = new Criteria(); $c->add("concat(nombre, ' ', apellidos)", trim($data[2])); //$c->add('fullname', utf8_encode( trim($data[2]) ), Criteria::EQUAL); $politicos = PoliticoPeer::doSelect($c); if (count($politicos) != 0) { echo "(ASIGNADO) " . $data[2] . "\n"; $politico = $politicos[0]; } else { echo "(NUEVO) " . $data[2] . "\n"; $politico = new Politico(); $nombreApellidos = explode(" ", $data[2]); $nombre = array_shift($nombreApellidos); $apellidos = implode(" ", $nombreApellidos); $politico->setNombre($nombre); $politico->setApellidos($apellidos); if ($data[7] != '1') { if (trim($data[10]) != '') { $c = new Criteria(); $c->add(PartidoPeer::ABREVIATURA, $data[5]); $partido = PartidoPeer::doSelectOne($c); if ($partido) { $politico->setPartido($partido); } } else { $politico->setPartido($lista->getPartido()); } } $politico->setSexo($data[1] == "hombre" ? 'H' : 'M'); $politico->save(); $politicoI18n = new PoliticoI18n(); $politicoI18n->setPolitico($politico); $politicoI18n->setCulture('es'); $politicoI18n->save(); $politicoI18n = new PoliticoI18n(); $politicoI18n->setPolitico($politico); $politicoI18n->setCulture('ca'); $politicoI18n->save(); } $c = new Criteria(); $c->add(PoliticoListaPeer::LISTA_ID, $lista->getId()); $c->add(PoliticoListaPeer::POLITICO_ID, $politico->getId()); $pl = PoliticoListaPeer::doSelectOne($c); if (!$pl) { $pl = new PoliticoLista(); $pl->setLista($lista); $pl->setPolitico($politico); } else { echo "Ya estaba.\n"; } $pl->setOrden($data[0]); $pl->save(); } fclose($handle); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeShow(sfWebRequest $request) { $vanity = $request->getParameter('vanity'); $convocatoria = $request->getParameter('convocatoria'); $this->geoName = $request->getParameter('geo'); $partido = $request->getParameter('partido'); $order = $request->getParameter("o", ""); $c = new Criteria(); $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID); $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID); $c->addJoin(ListaPeer::PARTIDO_ID, PartidoPeer::ID); $c->addJoin(ListaPeer::CONVOCATORIA_ID, ConvocatoriaPeer::ID); $c->addJoin(ConvocatoriaPeer::ELECCION_ID, EleccionPeer::ID); $c->add(ConvocatoriaPeer::NOMBRE, $convocatoria); $c->add(GeoPeer::NOMBRE, $this->geoName); $c->add(PartidoPeer::ABREVIATURA, $partido); $c->add(EleccionPeer::VANITY, $vanity); $this->lista = ListaPeer::doSelectOne($c); $this->forward404Unless($this->lista); // Geos $c = new Criteria(); $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID); $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->lista->getConvocatoria()->getId()); $c->add(ListaPeer::PARTIDO_ID, $this->lista->getPartido()->getId()); $c->addAscendingOrderByColumn(GeoPeer::NOMBRE); $c->setDistinct(); $this->geos = GeoPeer::doSelect($c); $instituciones = $this->lista->getConvocatoria()->getEleccion()->getEleccionInstitucions(); $this->institucionName = $instituciones[0]->getInstitucion(); // Lista Voota $c = new Criteria(); $c->add(ConvocatoriaPeer::NOMBRE, $convocatoria); $this->convocatoria = ConvocatoriaPeer::doSelectOne($c); $this->order = $order ? $order : 'pd'; /* if ($this->convocatoria->getClosedAt()){ $c = new Criteria(); $c->addJoin(ListaCallePeer::POLITICO_ID, PoliticoPeer::ID); $c->addJoin(PoliticoListaPeer::POLITICO_ID, PoliticoPeer::ID); $c->add(PoliticoListaPeer::LISTA_ID, $this->lista->getId()); if ($this->order == "pa"){ $c->addAscendingOrderByColumn(ListaCallePeer::SUMU); } else if ($this->order == "pd") { $c->addDescendingOrderByColumn(ListaCallePeer::SUMU); $c->addAscendingOrderByColumn(ListaCallePeer::SUMD); } else if ($this->order == "na"){ $c->addAscendingOrderByColumn(ListaCallePeer::SUMD); } else if ($this->order == "nd") { $c->addDescendingOrderByColumn(ListaCallePeer::SUMD); $c->addAscendingOrderByColumn(ListaCallePeer::SUMU); } $c->setDistinct(); $this->politicosListaVoota = PoliticoPeer::doSelect( $c ); } else { $c = new Criteria(); $c->addJoin(PoliticoListaPeer::POLITICO_ID, PoliticoPeer::ID); $c->add(PoliticoListaPeer::LISTA_ID, $this->lista->getId()); if ($this->order == "pa"){ $c->addAscendingOrderByColumn(PoliticoPeer::SUMU); } else if ($this->order == "pd") { $c->addDescendingOrderByColumn(PoliticoPeer::SUMU); $c->addAscendingOrderByColumn(PoliticoPeer::SUMD); } else if ($this->order == "na"){ $c->addAscendingOrderByColumn(PoliticoPeer::SUMD); } else if ($this->order == "nd") { $c->addDescendingOrderByColumn(PoliticoPeer::SUMD); $c->addAscendingOrderByColumn(PoliticoPeer::SUMU); } $this->politicosListaVoota = PoliticoPeer::doSelect( $c ); } */ $listaElectoral = new ListaElectoral($this->lista->getConvocatoriaId(), $this->lista->getPartidoId(), $this->lista->getCircunscripcion()->getGeo()->getNombre(), $this->order); $this->politicosListaVoota = $listaElectoral->getPoliticos(); // Lista oficial $c = new Criteria(); $c->addJoin(PoliticoListaPeer::POLITICO_ID, PoliticoPeer::ID); $c->add(PoliticoListaPeer::LISTA_ID, $this->lista->getId()); $c->add(PoliticoListaPeer::ORDEN, null, Criteria::ISNOTNULL); $c->add(PoliticoListaPeer::ORDEN, 0, Criteria::GREATER_THAN); $c->addAscendingOrderByColumn(PoliticoListaPeer::ORDEN); $this->politicosListaOficial = PoliticoPeer::doSelect($c); // Metas $this->title = sfContext::getInstance()->getI18N()->__("Lista electoral %1% %2% %3%, %4%", array('%1%' => $this->lista->getPartido(), '%2%' => $this->lista->getConvocatoria()->getEleccion()->getNombre(), '%3%' => $this->lista->getConvocatoria()->getNombre(), '%4%' => $this->lista->getCircunscripcion()->getGeo())); $this->response->setTitle($this->title); $description = sfContext::getInstance()->getI18N()->__("Lista oficial del partido vs Lo que dice la calle: %1%, circunscripcón de %2%, %3% %4%", array('%1%' => $this->lista->getPartido()->getNombre(), '%2%' => $this->lista->getCircunscripcion()->getGeo(), '%3%' => $this->lista->getConvocatoria()->getEleccion()->getNombre(), '%4%' => $this->lista->getConvocatoria()->getNombre())); $this->response->addMeta('Description', $description); }
/** * Gets an array of Geo objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this Geo has previously been saved, it will retrieve * related GeosRelatedByGeoId from storage. If this Geo is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array Geo[] * @throws PropelException */ public function getGeosRelatedByGeoId($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(GeoPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collGeosRelatedByGeoId === null) { if ($this->isNew()) { $this->collGeosRelatedByGeoId = array(); } else { $criteria->add(GeoPeer::GEO_ID, $this->id); GeoPeer::addSelectColumns($criteria); $this->collGeosRelatedByGeoId = GeoPeer::doSelect($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(GeoPeer::GEO_ID, $this->id); GeoPeer::addSelectColumns($criteria); if (!isset($this->lastGeoRelatedByGeoIdCriteria) || !$this->lastGeoRelatedByGeoIdCriteria->equals($criteria)) { $this->collGeosRelatedByGeoId = GeoPeer::doSelect($criteria, $con); } } } $this->lastGeoRelatedByGeoIdCriteria = $criteria; return $this->collGeosRelatedByGeoId; }