Exemplo n.º 1
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Convocatoria is new, it will return
  * an empty collection; or if this Convocatoria has previously
  * been saved, it will retrieve related Listas 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 Convocatoria.
  */
 public function getListasJoinCircunscripcion($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(ConvocatoriaPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collListas === null) {
         if ($this->isNew()) {
             $this->collListas = array();
         } else {
             $criteria->add(ListaPeer::CONVOCATORIA_ID, $this->id);
             $this->collListas = ListaPeer::doSelectJoinCircunscripcion($criteria, $con, $join_behavior);
         }
     } else {
         // 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(ListaPeer::CONVOCATORIA_ID, $this->id);
         if (!isset($this->lastListaCriteria) || !$this->lastListaCriteria->equals($criteria)) {
             $this->collListas = ListaPeer::doSelectJoinCircunscripcion($criteria, $con, $join_behavior);
         }
     }
     $this->lastListaCriteria = $criteria;
     return $this->collListas;
 }
Exemplo n.º 2
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = ListaPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setNombre($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setFecha($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setId_usuario($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setId_genero($arr[$keys[4]]);
     }
 }
Exemplo n.º 3
0
 /**
  * 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(ListaPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(ListaPeer::DATABASE_NAME);
         $criteria->add(ListaPeer::ID, $pks, Criteria::IN);
         $objs = ListaPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemplo n.º 4
0
 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(PartidoPeer::ABREVIATURA, $data[5]);
         $partido = PartidoPeer::doSelectOne($c);
         if (!$partido) {
             echo "Not found: (" . $data[5] . ")\n";
             continue;
         }
         $circu = CircunscripcionPeer::retrieveByPK($data[4]);
         $convocatoria = ConvocatoriaPeer::retrieveByPK($data[3]);
         $c = new Criteria();
         $c->add(ListaPeer::CONVOCATORIA_ID, $data[3]);
         $c->add(ListaPeer::CIRCUNSCRIPCION_ID, $data[4]);
         $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 (count($data) > 10 && 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());
                 }
             }
             if ($data[1] && trim($data[1]) != '') {
                 $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";
         }
         if ($data[6] != '1') {
             $pl->setOrden($data[0]);
         }
         $pl->save();
         //echo $data[2];
     }
     fclose($handle);
 }
Exemplo n.º 5
0
 /**
  * Selects a collection of PoliticoLista objects pre-filled with all related objects except Politico.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of PoliticoLista objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptPolitico(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     // $criteria->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     PoliticoListaPeer::addSelectColumns($criteria);
     $startcol2 = PoliticoListaPeer::NUM_COLUMNS - PoliticoListaPeer::NUM_LAZY_LOAD_COLUMNS;
     ListaPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (ListaPeer::NUM_COLUMNS - ListaPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(PoliticoListaPeer::LISTA_ID, ListaPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BasePoliticoListaPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = PoliticoListaPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = PoliticoListaPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = PoliticoListaPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             PoliticoListaPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Lista rows
         $key2 = ListaPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = ListaPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = ListaPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 ListaPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (PoliticoLista) to the collection in $obj2 (Lista)
             $obj2->addPoliticoLista($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Exemplo n.º 6
0
 /**
  * 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);
 }
Exemplo n.º 7
0
 /**
  * Get the associated Lista object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Lista The associated Lista object.
  * @throws     PropelException
  */
 public function getLista(PropelPDO $con = null)
 {
     if ($this->aLista === null && $this->lista_id !== null) {
         $this->aLista = ListaPeer::retrieveByPk($this->lista_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aLista->addPartidoListas($this);
         		 */
     }
     return $this->aLista;
 }
Exemplo n.º 8
0
 public function executeShow(sfWebRequest $request)
 {
     $abreviatura = $request->getParameter('id');
     $culture = $this->getUser()->getCulture("es");
     $this->institucion = $request->getParameter("institucion");
     if ($this->institucion == '') {
         $this->institucion = "0";
     }
     $c = new Criteria();
     $c->add(PartidoPeer::ABREVIATURA, $abreviatura, Criteria::EQUAL);
     $this->partido = PartidoPeer::doSelectOne($c);
     $this->forward404Unless($this->partido);
     $this->forward404Unless($this->partido->getIsActive());
     if ($this->partido->getAbreviatura() != $abreviatura) {
         $this->redirect('partido/show?id=' . $this->partido->getAbreviatura(), 301);
     }
     // Estabamos vootando antes del login ?
     $sfr_status = $this->getUser()->getAttribute('sfr_status', false, 'sf_review');
     if ($sfr_status) {
         $aSfrStatus = array();
         foreach ($sfr_status as $key => $value) {
             $aSfrStatus[$key] = $value;
         }
         $this->sfr_status = $aSfrStatus;
         $request->setAttribute('sfr_status', $aSfrStatus);
         $this->getUser()->setAttribute('sfr_status', false, 'sf_review');
     } else {
         $this->getUser()->setAttribute('sfr_status', false, 'sf_review');
         $this->sfr_status = false;
     }
     if ($this->partido->getImagen() != '') {
         $imageFileName = $this->partido->getImagen();
     } else {
         $imageFileName = "p_unknown.png";
     }
     $this->image = "cc_{$imageFileName}";
     $pu = $this->getUser()->getAttribute('pageU');
     $pd = $this->getUser()->getAttribute('pageD');
     $c = $this->getUser()->getAttribute('review_c');
     if ($c != '' && $pu != '') {
         $resU = BaseSfReviewManager::NUM_REVIEWS * ($pu - 1);
         $this->pageU = $pu;
     } else {
         $resU = BaseSfReviewManager::NUM_REVIEWS;
         $this->pageU = 2;
     }
     if ($c != '' && $pd != '') {
         $resD = BaseSfReviewManager::NUM_REVIEWS * ($pd - 1);
         $this->pageD = $pd;
     } else {
         $resD = BaseSfReviewManager::NUM_REVIEWS;
         $this->pageD = 2;
     }
     $id = $this->partido->getId();
     $this->positives = SfReviewManager::getReviewsByEntityAndValue($request, Partido::NUM_ENTITY, $id, 1, $resU);
     $this->negatives = SfReviewManager::getReviewsByEntityAndValue($request, Partido::NUM_ENTITY, $id, -1, $resD);
     $positiveCount = $this->positives->getNbResults();
     $negativeCount = $this->negatives->getNbResults();
     $this->getUser()->setAttribute('pageU', '');
     $this->getUser()->setAttribute('pageD', '');
     $this->totalCount = $positiveCount + $negativeCount;
     if ($this->totalCount > 0) {
         $this->positivePerc = intval($positiveCount * 100 / $this->totalCount);
         $this->negativePerc = 100 - $this->positivePerc;
     } else {
         $this->positivePerc = 0;
         $this->negativePerc = 0;
     }
     // Enlaces
     $c = new Criteria();
     $rCriterion = $c->getNewCriterion(EnlacePeer::CULTURE, null, Criteria::ISNULL);
     $rCriterion->addOr($c->getNewCriterion(EnlacePeer::CULTURE, $this->getUser()->getCulture()));
     $rCriterion->addOr($c->getNewCriterion(EnlacePeer::CULTURE, ''));
     $c->add($rCriterion);
     $c->add(EnlacePeer::PARTIDO_ID, $id);
     $c->addAscendingOrderByColumn(EnlacePeer::ORDEN);
     $this->activeEnlaces = EnlacePeer::doSelect($c);
     $this->twitterUser = FALSE;
     foreach ($this->activeEnlaces as $enlace) {
         if (preg_match("/twitter\\.com\\/#!\\/(.*)\$/is", $enlace->getUrl(), $matches)) {
             $this->twitterUser = $matches[1];
             break;
         }
         if (preg_match("/twitter\\.com\\/(.*)\$/is", $enlace->getUrl(), $matches)) {
             $this->twitterUser = $matches[1];
             break;
         }
     }
     // Politicos mas votados
     $c = new Criteria();
     $c->addJoin(array(PoliticoPeer::ID, PoliticoI18nPeer::CULTURE), array(PoliticoI18nPeer::ID, "'{$culture}'"), Criteria::LEFT_JOIN);
     $c->add(PoliticoPeer::VANITY, null, Criteria::ISNOTNULL);
     $c->add(PoliticoPeer::PARTIDO_ID, $this->partido->getId());
     $c->addDescendingOrderByColumn(PoliticoPeer::SUMU);
     $c->addAscendingOrderByColumn(PoliticoPeer::SUMD);
     $this->politicos = new sfPropelPager('Politico', 6);
     $this->politicos->setCriteria($c);
     $this->politicos->init();
     // Lista de instituciones
     $c = new Criteria();
     $c->addJoin(InstitucionPeer::ID, PoliticoInstitucionPeer::INSTITUCION_ID);
     $c->addJoin(PoliticoInstitucionPeer::POLITICO_ID, PoliticoPeer::ID);
     $c->addJoin(PoliticoPeer::PARTIDO_ID, PartidoPeer::ID);
     $c->add(PoliticoPeer::PARTIDO_ID, $this->partido->getId());
     $c->add(InstitucionPeer::IS_MAIN, true);
     $c->setDistinct();
     $c->addAscendingOrderByColumn(InstitucionPeer::ORDEN);
     $this->instituciones = InstitucionPeer::doSelect($c);
     // Lista de listas
     $this->listasGenerales = false;
     $this->listasAutonomicas = false;
     $this->listasMunicipales = false;
     foreach ($this->partido->getListas() as $lista) {
         //$lista->getCircunscripcion()->getGeo()
         foreach ($lista->getConvocatoria()->getEleccion()->getEleccionInstitucions() as $insti) {
             $geo = $insti->getInstitucion()->getGeo();
             if ($geo->getId() == 1) {
                 $this->listasGenerales = true;
             } elseif ($geo->getGeoRelatedByGeoId()->getId() == 1) {
                 $this->listasAutonomicas = true;
             } elseif ($geo->getGeoRelatedByGeoId()->getGeoRelatedByGeoId()->getId() == 1) {
             } elseif ($geo->getGeoRelatedByGeoId()->getGeoRelatedByGeoId()->getGeoRelatedByGeoId()->getId() == 1) {
                 $this->listasMunicipales = true;
             }
         }
     }
     $this->pageTitle = $this->partido->getNombre() . " (" . $this->partido->getAbreviatura() . ")";
     $this->title = $this->pageTitle . ' - Voota';
     $this->response->addMeta('Title', $this->title);
     $descripcion = $this->partido->getAbreviatura() . ": " . sfContext::getInstance()->getI18N()->__('presentación, opiniones de usuarios a favor y en contra, políticos mejor valorados y enlaces. ', array()) . SfVoUtil::cutToLength($this->partido->getPresentacion(), 140, '...', true);
     $this->response->addMeta('Descripcion', $descripcion);
     // Listas de electorales
     $convocatoriaActiva = sfConfig::get('sf_convocatoria_activa');
     $this->convocatoria = ConvocatoriaPeer::retrieveByPk($convocatoriaActiva);
     $c = new Criteria();
     $c->add(ListaPeer::PARTIDO_ID, $this->partido->getId());
     $c->add(ListaPeer::CONVOCATORIA_ID, $convocatoriaActiva);
     $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID);
     $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID);
     $c->addAscendingOrderByColumn(GeoPeer::NOMBRE);
     $this->listas = ListaPeer::doSelect($c);
     /* paginador */
     $this->partidosPager = EntityManager::getPager($this->partido);
     /* / paginador */
     // Feed
     $request->setAttribute('rssTitle', $this->title . " Feed RSS");
     $request->setAttribute('rssFeed', 'partido/feed?id=' . $this->partido->getVanity());
 }
Exemplo n.º 9
0
 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);
 }
 /**
  * Selects a collection of Lista_audiolibro objects pre-filled with all related objects except Audiolibro.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of Lista_audiolibro objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptAudiolibro(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     // $criteria->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     Lista_audiolibroPeer::addSelectColumns($criteria);
     $startcol2 = Lista_audiolibroPeer::NUM_HYDRATE_COLUMNS;
     ListaPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + ListaPeer::NUM_HYDRATE_COLUMNS;
     $criteria->addJoin(Lista_audiolibroPeer::ID_LISTA, ListaPeer::ID, $join_behavior);
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = Lista_audiolibroPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = Lista_audiolibroPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://www.propelorm.org/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = Lista_audiolibroPeer::getOMClass();
             $obj1 = new $cls();
             $obj1->hydrate($row);
             Lista_audiolibroPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Lista rows
         $key2 = ListaPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = ListaPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = ListaPeer::getOMClass();
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 ListaPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (Lista_audiolibro) to the collection in $obj2 (Lista)
             $obj2->addLista_audiolibro($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Exemplo n.º 11
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return    Lista A model object, or null if the key is not found
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `ID`, `NOMBRE`, `FECHA`, `ID_USUARIO`, `ID_GENERO` FROM `lista` WHERE `ID` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new Lista();
         $obj->hydrate($row);
         ListaPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }