/** * 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); }
public function getResults($geoName = false, $sorted = true) { $aKey = "Convocatoria_" . $this->getId() . "-{$geoName}-{$sorted}"; $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false; if ($cache) { $key = md5($aKey); $data = unserialize($cache->get($key)); } else { $data = false; } if (!$data) { $res = array(); $c = new Criteria(); $c->addJoin(ListaPeer::PARTIDO_ID, PartidoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->getId()); $c->setDistinct(); $res['partidos'] = PartidoPeer::doSelect($c); // Circus $c = new Criteria(); $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID); $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->getId()); $c->addAscendingOrderByColumn(GeoPeer::NOMBRE); $c->setDistinct(); //$this->geos = GeoPeer::doSelect( $c ); $res['circus'] = CircunscripcionPeer::doSelect($c); $instituciones = $this->getEleccion()->getEleccionInstitucions(); //$this->institucionName = $instituciones[0]->getInstitucion(); $res['institucionName'] = $instituciones[0]->getInstitucion(); // Minimo de votos necesario para obtener escaño $listas = $this->getListas(); if ($geoName) { $c = new Criteria(); $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID); $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->getId()); $c->add(GeoPeer::NOMBRE, $geoName); //$this->geos = GeoPeer::doSelect( $c ); $circu = CircunscripcionPeer::doSelectOne($c); $numEscanyos = $circu->getEscanyos(); } else { $numEscanyos = 0; $circuCounted = array(); foreach ($listas as $lista) { if (!in_array($lista->getCircunscripcion()->getId(), $circuCounted)) { $circuCounted[] = $lista->getCircunscripcion()->getId(); $numEscanyos += $lista->getCircunscripcion()->getEscanyos(); } } } $listaElectoral = ListaElectoral::getInstance($this->getId(), false, $geoName); $politicos = $listaElectoral->getPoliticos(); $idx = 0; //$this->minSumu = 0; $res['minSumu'] = 0; //$this->minSumd = 0; $res['minSumd'] = 0; $res['lastDate'] = null; $res['apellidos'] = ''; $res['nombre'] = ''; foreach ($politicos as $politico) { $idx++; if ($idx == $numEscanyos + 1) { $res['minSumu'] = $politico->getSumu(); $res['minSumd'] = $politico->getSumd(); $res['lastDate'] = $politico->getLastDate(); $res['apellidos'] = $politico->getApellidos(); $res['nombre'] = $politico->getNombre(); } } // Ordenar por escaños if ($sorted) { $idx = 0; $res['totalEscanyos'] = 0; foreach ($res['partidos'] as $partido) { $listaElectoral = new ListaElectoral($this->getId(), $partido->getId(), $geoName); $escanyos = $listaElectoral->getEscanyos($res['minSumu'], $res['minSumd'], $res['lastDate'], $res['apellidos']); $res['totalEscanyos'] += $escanyos; for ($j = 0; $j < $idx; $j++) { $listaElectoral2 = ListaElectoral::getInstance($this->getId(), $res['partidos'][$j]->getId(), $geoName); if ($listaElectoral2->getEscanyos($res['minSumu'], $res['minSumd'], $res['lastDate'], $res['apellidos']) < $escanyos) { $partidoTmp = clone $res['partidos'][$idx]; $res['partidos'][$idx] = $res['partidos'][$j]; $res['partidos'][$j] = $partidoTmp; } } $idx++; } } $data = $res; if ($cache) { $n = rand(0, 100); $cache->set($key, serialize($data ? $data : "zero"), 3600 * $n / 100); } } return $data == "zero" ? 0 : $data; }
public function executePartidoLista() { $listaElectoral = new ListaElectoral($this->convocatoria->getId(), $this->partido->getId(), $this->geoName); $this->politicos = $listaElectoral->getPoliticos(); $this->numEscanyos = $listaElectoral->getEscanyos($this->minSumu, $this->minSumd, $this->lastDate, $this->apellidos); }
public function getEscanyos($minSumu, $minSumd, $lastDate, $apellidos) { $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false; if ($cache) { $aKey = "Escanyos_" . $this->convocatoriaId . "-" . $this->partidoId . "-" . $this->geoName . "-{$minSumu}-{$minSumd}-{$lastDate}-{$apellidos}"; $key = md5($aKey); $data = unserialize($cache->get($key)); } else { $data = false; } if (!$data) { //echo "($aKey-$key)"; if ($this->geoName) { if (!$this->numEscanyos) { $this->numEscanyos = 0; foreach ($this->politicos as $politico) { if ($politico->getSumu() > $minSumu || $politico->getSumu() == $minSumu && $politico->getSumd() < $minSumd || $politico->getSumu() == $minSumu && $politico->getSumd() == $minSumd && $politico->getLastDate() > $lastDate && $minSumu != 0 || $politico->getSumu() == $minSumu && $politico->getSumd() == $minSumd && $politico->getLastDate() == $lastDate && $politico->getApellidos() > $apellidos && $minSumu != 0) { //echo "(".$politico->getApellidos().",".$politico->getSumu().",".$politico->getSumd().",".$politico->getLastDate().")"; $this->numEscanyos++; } } } } else { // Circus $c = new Criteria(); $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID); $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->convocatoriaId); $c->addAscendingOrderByColumn(GeoPeer::NOMBRE); $c->setDistinct(); $circus = CircunscripcionPeer::doSelect($c); $this->numEscanyos = 0; foreach ($circus as $circu) { $listaElectoral = new ListaElectoral($this->convocatoriaId, $this->partidoId, $circu->getGeo()->getNombre()); $res = $this->convocatoria->getResults($circu->getGeo()->getNombre(), false); $sum = $listaElectoral->getEscanyos($res['minSumu'], $res['minSumd'], $res['lastDate'], $res['apellidos']); $this->numEscanyos += $sum; } } $data = $this->numEscanyos; if ($cache) { $cache->set($key, serialize($data ? $data : "zero"), 3600); } } return $data == "zero" ? 0 : $data; }