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);
 }
Exemple #2
0
 public function executeList(sfWebRequest $request)
 {
     $culture = $this->getUser()->getCulture("es");
     $page = $request->getParameter("page", "");
     $this->autonomicas = $request->getParameter("a", false);
     $this->municipales = $request->getParameter("m", false);
     $this->partido = $request->getParameter("partido", false);
     if ($this->partido) {
         $c = new Criteria();
         $c->add(PartidoPeer::ABREVIATURA, $this->partido);
         $partido = PartidoPeer::doSelectOne($c);
     }
     $this->route = "lista/list";
     #$this->pager = EntityManager::getConvocatorias($culture, $page, 100, $this->autonomicas, $this->municipales, &$totalUp, &$totalDown);
     $this->pager = EntityManager::getListas($culture, $page, 100, $this->autonomicas, $this->municipales, $this->partido, &$totalUp, &$totalDown);
     $o = false;
     if ($this->autonomicas) {
         $o = EntityManager::getListas($culture, $page, 100, false, 1, $this->partido, &$totalUp, &$totalDown);
     }
     if ($this->municipales) {
         $o = EntityManager::getListas($culture, $page, 100, 1, false, $this->partido, &$totalUp, &$totalDown);
     }
     $this->hide = $o && $o->getNbResults() == 0;
     // Metas
     $this->title = sfContext::getInstance()->getI18N()->__("Listas%partido% a las elecciones%tipo%%pag%", array('%partido%' => $this->partido ? " de {$this->partido}" : '', '%tipo%' => $this->municipales ? " municipales" : ($this->autonomicas ? " autonómicas" : ''), '%pag%' => $page && $page > 1 ? ", pág. {$page}" : ''));
     $this->response->setTitle($this->title);
     $description = sfContext::getInstance()->getI18N()->__("Candidaturas y listas%partido% a las elecciones%tipo%%pag%", array('%partido%' => $this->partido ? " de " . $partido->getNombre() . " (" . $this->partido . ")" : '', '%tipo%' => $this->municipales ? " municipales" : ($this->autonomicas ? " autonómicas" : ''), '%pag%' => $page && $page > 1 ? ", pág. {$page}" : ''));
     $this->response->addMeta('Description', $description);
 }
Exemple #3
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);
 }
Exemple #4
0
 public function executeFeed(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);
     $entity = PartidoPeer::doSelectOne($c);
     $this->forward404Unless($entity);
     $this->forward404Unless($entity->getIsActive());
     $filter = array();
     $filter['type_id'] = Partido::NUM_ENTITY;
     $filter['entity_id'] = $entity->getId();
     $reviews = SfReviewManager::getReviews($filter);
     $title = sfContext::getInstance()->getI18N()->__('%1% en Voota.es', array('%1%' => $entity));
     $description = sfContext::getInstance()->getI18N()->__('Opiniones sobre %1%, %2% votos a favor y %3% votos en contra', array('%1%' => $entity->getNombre(), '%2%' => $entity->getSumu(), '%3%' => $entity->getSumd()));
     $feed = new sfRssFeed();
     $feed->setTitle($title);
     $feed->setLanguage($culture);
     $feed->setSubtitle($description);
     $feed->setDescription($description);
     $feed->setLink('partido/show?id=' . $entity->getVanity());
     $domainExt = $culture == 'ca' ? "cat" : $culture;
     $feed->setAuthorName("Voota.{$domainExt}");
     $feedImage = new sfFeedImage();
     $feedImage->setLink('partido/show?id=' . $entity->getVanity());
     $feedImage->setImage(S3Voota::getImagesUrl() . '/' . $entity->getImagePath() . '/cc_' . $entity->getImagen());
     $feedImage->setTitle($entity);
     $feed->setImage($feedImage);
     foreach ($reviews as $review) {
         $item = new sfFeedItem();
         $item->setTitle(sfContext::getInstance()->getI18N()->__('%1%, voota %2%.', array('%1%' => $review->getSfGuardUser(), '%2%' => $review->getValue() == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'))));
         $item->setLink('sfReviewFront/show?id=' . SfVoUtil::reviewPermalink($review));
         $item->setAuthorName($review->getSfGuardUser());
         $item->setPubdate($review->getCreatedAt('U'));
         $item->setUniqueId($review->getId());
         $avatar = S3Voota::getImagesUrl() . '/usuarios/cc_s_' . $review->getSfGuardUser()->getProfile()->getImagen();
         $text = $culture == $review->getCulture() || !$review->getCulture() ? $review->getText() : '';
         $img = $review->getSfGuardUser()->getProfile()->getImagen() ? "<img src=\"{$avatar}\" alt =\"" . $review->getSfGuardUser() . "\" /> " : "";
         $content = "{$text}";
         $item->setDescription($content);
         $feed->addItem($item);
     }
     $this->feed = $feed;
 }
Exemple #5
0
 public function executeRanking(sfWebRequest $request)
 {
     $p = $request->getParameter("p");
     $i = $request->getParameter("i");
     $culture = $this->getUser()->getCulture("es");
     $partido = $request->getParameter("partido", false);
     $institucion = $request->getParameter("institucion", false);
     $redir = false;
     if ($institucion === ALL_FORM_VALUE) {
         $redir = true;
         $institucion = false;
     }
     $page = $request->getParameter("page", "");
     $order = $request->getParameter("o", "");
     $this->forward404Unless(!($order && $order != 'pd' && $order != 'pa' && $order != 'nd' && $order != 'na'));
     if ($order == 'pd' || $page == '1' || !$institucion && $partido == ALL_URL_STRING) {
         $qs = '';
         foreach ($request->getParameterHolder()->getAll() as $key => $value) {
             if ($key != 'module' && $key != 'action' && !($order == 'pd' && $key == 'o' || $page == '1' && $key == 'page') && ($key != 'partido' || ($institucion || $partido != ALL_URL_STRING))) {
                 $qs .= ($qs ? '&' : '?') . "{$key}={$value}";
             }
         }
         $this->redirect("politico/ranking{$qs}", 301);
     }
     $this->order = $order ? $order : 'pd';
     $page = $page ? $page : 1;
     if (!$partido) {
         $partido = ALL_FORM_VALUE;
     }
     if (!$institucion) {
         $institucion = ALL_FORM_VALUE;
     }
     $this->partido = ALL_FORM_VALUE;
     $this->institucion = ALL_FORM_VALUE;
     if ($p != '' || $i != '' || $redir) {
         $url = $this->generateRankingUrl($partido, $institucion, $p, $i, $page);
         $this->redirect($url);
     }
     $this->partidoAC = '';
     if ($partido && $partido != ALL_URL_STRING) {
         $this->partido = $partido;
         $aPartidoCriteria = new Criteria();
         $aPartidoCriteria->add(PartidoPeer::ABREVIATURA, $this->partido);
         $aaPartido = PartidoPeer::doSelectOne($aPartidoCriteria);
         $this->forward404Unless($aaPartido);
         $this->partidoAC = $aaPartido->getAbreviatura() . ', ' . $aaPartido->getNombre();
     } else {
         $this->partido = ALL_URL_STRING;
     }
     $this->institucionAC = '';
     if ($institucion && $institucion != ALL_URL_STRING) {
         $this->institucion = $institucion;
         $aInstitucionCriteria = new Criteria();
         $aInstitucionCriteria->addJoin(array(InstitucionPeer::ID, InstitucionI18nPeer::CULTURE), array(InstitucionI18nPeer::ID, "'{$culture}'"), Criteria::INNER_JOIN);
         $aInstitucionCriteria->add(InstitucionI18nPeer::VANITY, $this->institucion);
         $aInstitucion = InstitucionPeer::doSelectOne($aInstitucionCriteria);
         $this->forward404Unless($aInstitucion);
         if ($aInstitucion->getVanity() != $institucion) {
             $url = $this->generateRankingUrl($partido, $aInstitucion->getVanity());
             $params = $request->getParameterHolder()->getAll();
             foreach ($params as $key => $value) {
                 if ($key != 'module' && $key != 'action' && $key != 'partido' && $key != 'institucion') {
                     $url .= "&{$key}={$value}";
                 }
             }
             $this->redirect($url, 301);
         }
         $this->institucionAC = $aInstitucion->getNombre();
     }
     $filter = array('type' => 'politico', 'partido' => $partido, 'institucion' => $institucion, 'culture' => $culture, 'page' => $page, 'order' => $this->order);
     $this->getUser()->setAttribute("filter_" . Politico::NUM_ENTITY, $filter);
     $this->politicosPager = EntityManager::getPoliticos($partido, $institucion, $culture, $page, $this->order, EntityManager::PAGE_SIZE, &$totalUp, &$totalDown);
     $this->totalUp = $totalUp;
     $this->totalDown = $totalDown;
     $rule = sfContext::getInstance()->getRouting()->getCurrentRouteName();
     $params = "";
     foreach ($request->getParameterHolder()->getAll() as $name => $value) {
         if ($name != 'module' && $name != 'action' && $name != 'o' && $name != 'page') {
             if ($params === "") {
                 $params .= "?";
             } else {
                 $params .= "&";
             }
             $params .= "{$name}={$value}";
         }
     }
     $this->route = "politico/ranking{$params}";
     $this->pageTitle = sfContext::getInstance()->getI18N()->__('Ranking de políticos', array());
     $this->pageTitle .= $this->partido == 'all' ? '' : ', ' . $this->partido;
     $this->pageTitle .= $this->institucion == '0' ? '' : ", ";
     if (isset($aInstitucion)) {
         $this->pageTitle .= $aInstitucion->getNombre();
     }
     switch ($this->order) {
         case 'pa':
             $orderTxt = sfContext::getInstance()->getI18N()->__('votos positivos inverso');
             break;
         case 'nd':
             $orderTxt = sfContext::getInstance()->getI18N()->__('votos negativos');
             break;
         case 'na':
             $orderTxt = sfContext::getInstance()->getI18N()->__('votos negativos inverso');
             break;
         default:
             $orderTxt = sfContext::getInstance()->getI18N()->__('ordenado por votos positivos inverso');
     }
     if ($this->order != 'pd') {
         $this->pageTitle .= ", {$orderTxt}";
     }
     if ($page && $page != 1) {
         $this->pageTitle .= " " . sfContext::getInstance()->getI18N()->__('(Pág. %1%)', array('%1%' => $page));
     }
     $this->title = $this->pageTitle . ' - Voota';
     $description = sfContext::getInstance()->getI18N()->__('Ranking de políticos', array());
     if (isset($aaPartido)) {
         if ($this->partido != '0' && $aaPartido) {
             $description .= ", " . $aaPartido->getNombre();
         }
     } else {
         $description .= ", " . sfContext::getInstance()->getI18N()->__('todos los partidos');
     }
     if ($aInstitucion && $aInstitucion->getGeo() && $this->institucion != '0') {
         $description .= ", " . $aInstitucion->getNombre() . " (" . $aInstitucion->getGeo()->getNombre() . ", España)";
     }
     $description .= ", {$orderTxt}";
     if ($page && $page != 1) {
         $description .= " " . sfContext::getInstance()->getI18N()->__('(Pág. %1%)', array('%1%' => $page));
     }
     $this->response->addMeta('Description', $description);
     $this->response->setTitle($this->title);
 }