Exemplo n.º 1
0
 protected function doSave($con = null)
 {
     $institucion = $this->getObject();
     if ($this->getValue('vanity') == '') {
         $vanityUrl = SfVoUtil::encodeVanity($this->getValue('nombre_corto'));
         $c2 = new Criteria();
         $c2->add(InstitucionI18nPeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
         $c2->add(InstitucionPeer::ID, $institucion->getId(), Criteria::NOT_EQUAL);
         $usuariosLikeMe = InstitucionPeer::doSelect($c2);
         $counter = 0;
         foreach ($usuariosLikeMe as $usuarioLikeMe) {
             $counter++;
         }
         $this->setValue('vanity', "{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"));
     }
     parent::doSave($con);
 }
Exemplo n.º 2
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();
     $c = new Criteria();
     $instituciones = InstitucionPeer::doSelect($c);
     foreach ($instituciones as $institucion) {
         if (preg_match("/Ayuntamiento\\-de\\-/is", $institucion->getVanity('es')) || preg_match("/Ayuntamiento de /is", $institucion->getNombreCorto())) {
             echo "Setting vanity of  " . $institucion->getId() . " ";
             echo " from  " . $institucion->getVanity('es') . " ";
             echo " to  " . str_replace("-de-", "-", $institucion->getVanity('es')) . ", ";
             echo " nombre_corto from  " . $institucion->getNombreCorto('es') . " ";
             $newNombreCorto = str_replace(" de ", " ", $institucion->getNombreCorto('es'));
             $newNombreCorto = str_replace("  ", " ", $newNombreCorto);
             $newNombreCorto = str_replace("  ", " ", $newNombreCorto);
             echo " to  " . $newNombreCorto . " ...\n";
             $institucion->setVanity(str_replace("Ayuntamiento-de-", "Ayuntamiento-", $institucion->getVanity('es')), 'es');
             $institucion->setNombreCorto(str_replace("Ayuntamiento de ", "Ayuntamiento ", $newNombreCorto), 'es');
             $institucion->save();
             /*
             $vanityUrl = SfVoUtil::encodeVanity($institucion->getNombreCorto()) ;
             
             		    $c2 = new Criteria();
             		    $c2->add(InstitucionPeer::VANITY, "$vanityUrl%", Criteria::LIKE);
             		    $c2->add(InstitucionPeer::ID, $institucion->getId(), Criteria::NOT_EQUAL);
             		    $institucionesLikeMe = InstitucionPeer::doSelect( $c2 );
             		    $counter = 0;
             foreach ($institucionesLikeMe as $institucionLikeMe){
             	$counter++;
             }
             InstitucionPeer::doUpdate( $institucion );
             */
         }
         //if ($institucion->getVanity('ca') == '' || $institucion->getVanity('ca') == null){
         echo "creando ca en " . $institucion->getId() . "... \n";
         $institucion->setVanity(str_replace("Ayuntamiento", "Ajuntament", $institucion->getVanity('es')), 'ca');
         $institucion->setNombreCorto(str_replace("Ayuntamiento ", "Ajuntament ", $institucion->getNombreCorto('es')), 'ca');
         $institucion->setNombre(str_replace("Ayuntamiento ", "Ajuntament ", $institucion->getNombre('es')), 'ca');
         $institucion->save();
         //}
     }
 }
Exemplo n.º 3
0
 public function executeSearch(sfWebRequest $request)
 {
     $culture = $this->getUser()->getCulture();
     $this->page = $this->getRequestParameter('page', 1);
     $tag = $request->getParameter("tag", false);
     $tag = str_replace("_2E_", ".", $tag);
     if ($tag) {
         $this->q = "#{$tag}";
     } else {
         $this->q = $request->getParameter("q");
     }
     $request->setAttribute("q", $this->q);
     $resultsArray = array();
     $cl = $this->resetSphinxClient();
     $needle = $this->q;
     $this->ext = "";
     if (strlen($needle) > 0 && strpos($needle, '#') === 0) {
         $this->ext = "_tag";
         $needle = substr($needle, 1);
     } else {
         $needle = SfVoUtil::stripAccents($this->q);
     }
     $this->politicoCounts = false;
     $this->partidoCounts = false;
     $this->propuestaCounts = false;
     if ($needle) {
         if ($this->ext == "_tag") {
             $cl->SetMatchMode(SPH_MATCH_PHRASE);
             $cl->SetSortMode(SPH_SORT_EXTENDED, "cnt DESC");
             $this->politicoCounts = array();
             $this->partidoCounts = array();
             $this->propuestaCounts = array();
             $indexes = "partido_tag_{$culture}, politico_tag_{$culture}, propuesta_tag_{$culture}";
             $this->res = $cl->Query($needle, $indexes);
             if ($this->res !== false) {
                 $this->total = $this->res['total'];
                 $this->totalFound = $this->res['total_found'];
                 $cl->SetLimits(($this->page - 1) * $this->limit, $this->limit);
                 $this->res = $cl->Query($needle, $indexes);
             }
         } else {
             $cl->SetFieldWeights(array('abreviatura_partido' => 5, 'nombre' => 5, 'apellidos' => 5, 'alias' => 5, 'titulo' => 5, 'nombre_insti' => 8, 'nombre_ele' => 9));
             $cl->SetSortMode(SPH_SORT_EXPR, "@weight + ( 1 * votes/max_votes )");
             $indexes = "politico_{$culture}, partido_{$culture},propuesta_{$culture}, institucion_{$culture}, usuario, eleccion_{$culture}";
             $this->res = $cl->Query($needle, $indexes);
             if ($this->res !== false) {
                 $this->total = $this->res['total'];
                 $this->totalFound = $this->res['total_found'];
                 $cl->SetLimits(($this->page - 1) * $this->limit, $this->limit);
                 $this->res = $cl->Query($needle, $indexes);
             }
         }
         if ($this->res !== false && isset($this->res["matches"]) && is_array($this->res["matches"])) {
             foreach ($this->res["matches"] as $match) {
                 //echo "<pre>";print_r( $match );echo "</pre>";
                 switch ($match['attrs']['type']) {
                     case 1:
                         if ($this->ext == "_tag") {
                             $this->politicoCounts[$match['attrs']['politico_id']] = $match['attrs']['cnt'];
                             $resultsArray[] = PoliticoPeer::retrieveByPK($match['attrs']['politico_id']);
                         } else {
                             $resultsArray[] = PoliticoPeer::retrieveByPK($match['id']);
                         }
                         break;
                     case 2:
                         if ($this->ext == "_tag") {
                             $this->partidoCounts[$match['attrs']['partido_id']] = $match['attrs']['cnt'];
                             $resultsArray[] = PartidoPeer::retrieveByPK($match['attrs']['partido_id']);
                         } else {
                             $resultsArray[] = PartidoPeer::retrieveByPK($match['id']);
                         }
                         break;
                     case 3:
                         if ($this->ext == "_tag") {
                             $this->propuestaCounts[$match['attrs']['propuesta_id']] = $match['attrs']['cnt'];
                             $resultsArray[] = PropuestaPeer::retrieveByPK($match['attrs']['propuesta_id']);
                         } else {
                             $resultsArray[] = PropuestaPeer::retrieveByPK($match['id']);
                         }
                         break;
                     case 101:
                         $resultsArray[] = InstitucionPeer::retrieveByPK($match['id']);
                         break;
                     case 102:
                         $resultsArray[] = SfGuardUserPeer::retrieveByPK($match['id']);
                         break;
                     case 103:
                         $resultsArray[] = ConvocatoriaPeer::retrieveByPK($match['id']);
                         break;
                 }
             }
         }
     }
     $this->results = $resultsArray;
     $this->title = sfContext::getInstance()->getI18N()->__('"%1%" en Voota', array('%1%' => $this->q));
     $descStr = "";
     foreach ($resultsArray as $idx => $result) {
         if ($idx < 3) {
             $descStr .= ($descStr ? ', ' : '') . $result;
         }
     }
     $this->response->addMeta('Description', sfContext::getInstance()->getI18N()->__('Resultados de la búsqueda "%1%" en Voota: %2%, ...', array('%1%' => $this->q, '%2%' => $descStr)));
     $this->response->setTitle($this->title);
 }
Exemplo n.º 4
0
 private function institucion($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $s3 = new S3Voota();
     $instituciones = InstitucionPeer::doSelect(new Criteria());
     foreach ($instituciones as $institucion) {
         if ($institucion->getImagen() != '') {
             echo "Creating " . $institucion->getImagen() . " ...\n";
             $s3->createInstitucionFromOri($institucion->getImagen());
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Get the associated Institucion object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Institucion The associated Institucion object.
  * @throws     PropelException
  */
 public function getInstitucion(PropelPDO $con = null)
 {
     if ($this->aInstitucion === null && $this->institucion_id !== null) {
         $this->aInstitucion = InstitucionPeer::retrieveByPk($this->institucion_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->aInstitucion->addPoliticoInstitucions($this);
         		 */
     }
     return $this->aInstitucion;
 }
Exemplo n.º 6
0
 protected function execute($arguments = array(), $options = array())
 {
     $sfContext = sfContext::createInstance($this->configuration);
     $controller = $sfContext->getController();
     $this->cultures = array('ca' => 'cat', 'es' => 'es');
     $culture = $options['culture'];
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     //foreach($this->cultures as $culture => $ext){
     $sfContext->getUser()->setCulture($culture);
     // **************** HOME **********************
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@homepage", true), $culture);
     // **************** Ultimas opiniones **********************
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_politicos_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_partidos_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_propuestas_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_otras_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_feed_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_politicos_feed_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_partidos_feed_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_propuestas_feed_{$culture}", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@ultimas_opiniones_otras_feed_{$culture}", true), $culture);
     // **************** varias **********************
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@about", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@rules", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@search", true), $culture);
     $this->writeToSitemap("voota-{$culture}", $controller->genUrl("@contact", true), $culture);
     // **************** Fichas POLITICOS **********************
     $c = new Criteria();
     //$c->setLimit(5);
     $politicos = PoliticoPeer::doSelect($c);
     foreach ($politicos as $politico) {
         $this->writeToSitemap("politico-{$culture}", $controller->genUrl("politico/show?id=" . $politico->getVanity(), true), $culture);
     }
     // **************** Fichas PARTIDOS **********************
     $c = new Criteria();
     $c->add(PartidoPeer::IS_ACTIVE, true);
     $partidos = PartidoPeer::doSelect($c);
     foreach ($partidos as $partido) {
         $this->writeToSitemap("partido-{$culture}", $controller->genUrl("partido/show?id=" . $partido->getAbreviatura(), true), $culture);
     }
     // **************** Fichas PROPUESTAS **********************
     $c = new Criteria();
     $c->add(PropuestaPeer::IS_ACTIVE, true);
     $c->add(PropuestaPeer::CULTURE, $culture);
     $propuestas = PropuestaPeer::doSelect($c);
     foreach ($propuestas as $propuesta) {
         $this->writeToSitemap("propuesta-{$culture}", $controller->genUrl("propuesta/show?id=" . $propuesta->getVanity(), true), $culture);
     }
     // **************** Fichas USUARIOS **********************
     $c = new Criteria();
     $c->add(SfGuardUserPeer::IS_ACTIVE, true);
     $usuarios = SfGuardUserPeer::doSelect($c);
     foreach ($usuarios as $usuario) {
         $this->writeToSitemap("usuario-{$culture}", $controller->genUrl("perfil/show?username="******"politico-feed-{$culture}", $controller->genUrl("politico/show?id=" . $politico->getVanity(), true), $culture);
     }
     // **************** feeds PARTIDOS **********************
     $c = new Criteria();
     $c->add(PartidoPeer::IS_ACTIVE, true);
     $partidos = PartidoPeer::doSelect($c);
     foreach ($partidos as $partido) {
         $this->writeToSitemap("partido-feed-{$culture}", $controller->genUrl("partido/feed?id=" . $partido->getAbreviatura(), true), $culture);
     }
     // **************** feeds PROPUESTAS **********************
     $c = new Criteria();
     $c->add(PropuestaPeer::IS_ACTIVE, true);
     $c->add(PropuestaPeer::CULTURE, $culture);
     $propuestas = PropuestaPeer::doSelect($c);
     foreach ($propuestas as $propuesta) {
         $this->writeToSitemap("propuesta-feed-{$culture}", $controller->genUrl("propuesta/feed?id=" . $propuesta->getVanity(), true), $culture);
     }
     // **************** feeds USUARIOS **********************
     $c = new Criteria();
     $c->add(SfGuardUserPeer::IS_ACTIVE, true);
     $usuarios = SfGuardUserPeer::doSelect($c);
     foreach ($usuarios as $usuario) {
         $this->writeToSitemap("usuario-feed-{$culture}", $controller->genUrl("perfil/feed?username="******"propuesta-ranking-{$culture}", $controller->genUrl("propuesta/ranking", true), $culture);
     $pager = EntityManager::getPropuestas($culture);
     $idx = 1;
     while ($idx < $pager->getLastPage()) {
         $idx++;
         $this->writeToSitemap("propuesta-ranking-{$culture}", $controller->genUrl("propuesta/ranking?page={$idx}", true), $culture);
     }
     // **************** ranking POLITICOS **********************
     $this->writeToSitemap("politico-ranking-{$culture}", $controller->genUrl("politico/ranking", true), $culture);
     $pager = EntityManager::getPoliticos(false, false, $culture);
     $idx = 1;
     while ($idx < $pager->getLastPage()) {
         $idx++;
         $this->writeToSitemap("politico-ranking-{$culture}", $controller->genUrl("politico/ranking?page={$idx}", true), $culture);
     }
     # ranking de polis filtrados por partido
     $c = new Criteria();
     $c->add(PartidoPeer::IS_ACTIVE, true);
     $partidos = PartidoPeer::doSelect($c);
     foreach ($partidos as $partido) {
         $this->writeToSitemap("politico-ranking-{$culture}", $controller->genUrl("politico/ranking?partido=" . $partido->getAbreviatura(), true), $culture);
         $pager = EntityManager::getPoliticos($partido->getAbreviatura(), false, $culture);
         $idx = 1;
         while ($idx < $pager->getLastPage()) {
             $idx++;
             $this->writeToSitemap("politico-ranking-{$culture}", $controller->genUrl("politico/ranking?partido=" . $partido->getAbreviatura() . "&page={$idx}", true), $culture);
         }
         # ranking de polis filtrados por partido e insti
         $c = new Criteria();
         $c->add(InstitucionPeer::IS_ACTIVE, true);
         $c->addJoin(PoliticoInstitucionPeer::INSTITUCION_ID, InstitucionPeer::ID);
         $c->addJoin(PoliticoPeer::ID, PoliticoInstitucionPeer::POLITICO_ID);
         $c->add(PoliticoPeer::PARTIDO_ID, $partido->getId());
         $instis = InstitucionPeer::doSelect($c);
         foreach ($instis as $insti) {
             $this->writeToSitemap("politico-ranking-{$culture}", $controller->genUrl("politico/ranking?partido=" . $partido->getAbreviatura() . "&institucion=" . $insti->getVanity(), true), $culture);
             $pager = EntityManager::getPoliticos($partido->getAbreviatura(), $insti->getVanity(), $culture);
             $idx = 1;
             while ($idx < $pager->getLastPage()) {
                 $idx++;
                 $this->writeToSitemap("politico-ranking-{$culture}", $controller->genUrl("politico/ranking?partido=" . $partido->getAbreviatura() . "&institucion=" . $insti->getVanity() . "&page={$idx}", true), $culture);
             }
         }
     }
     # ranking de polis filtrados por insti
     $c = new Criteria();
     $c->add(InstitucionPeer::IS_ACTIVE, true);
     $instis = InstitucionPeer::doSelect($c);
     foreach ($instis as $insti) {
         $this->writeToSitemap("politico-ranking-{$culture}", $controller->genUrl("politico/ranking?partido=all&institucion=" . $insti->getVanity(), true), $culture);
         $pager = EntityManager::getPoliticos(false, $insti->getVanity(), $culture);
         $idx = 1;
         while ($idx < $pager->getLastPage()) {
             $idx++;
             $this->writeToSitemap("politico-ranking-{$culture}", $controller->genUrl("politico/ranking?partido=all&institucion=" . $insti->getVanity() . "&page={$idx}", true), $culture);
         }
     }
     // **************** ranking PARTIDOS **********************
     $this->writeToSitemap("partido-ranking-{$culture}", $controller->genUrl("partido/ranking", true), $culture);
     $pager = EntityManager::getPartidos(false, $culture);
     $idx = 1;
     while ($idx < $pager->getLastPage()) {
         $idx++;
         $this->writeToSitemap("partido-ranking-{$culture}", $controller->genUrl("partido/ranking?page={$idx}", true), $culture);
     }
     $c = new Criteria();
     $c->add(InstitucionPeer::IS_ACTIVE, true);
     $instis = InstitucionPeer::doSelect($c);
     foreach ($instis as $insti) {
         $this->writeToSitemap("partido-ranking-{$culture}", $controller->genUrl("partido/ranking?institucion=" . $insti->getVanity(), true), $culture);
         $pager = EntityManager::getPartidos($insti->getVanity(), $culture);
         $idx = 1;
         while ($idx < $pager->getLastPage()) {
             $idx++;
             $this->writeToSitemap("partido-ranking-{$culture}", $controller->genUrl("partido/ranking?institucion=" . $insti->getVanity() . "&page={$idx}", true), $culture);
         }
     }
     // **************** elecciones **********************
     $c = new Criteria();
     $convocatorias = ConvocatoriaPeer::doSelect($c);
     foreach ($convocatorias as $convocatoria) {
         $this->writeToSitemap("elecciones-{$culture}", $controller->genUrl('eleccion/show?vanity=' . $convocatoria->getEleccion()->getVanity() . '&convocatoria=' . $convocatoria->getNombre(), true), $culture);
         $used = array();
         foreach ($convocatoria->getListasJoinCircunscripcion() as $geoLista) {
             if (!in_array($geoLista->getCircunscripcion()->getGeo(), $used)) {
                 $used[] = $geoLista->getCircunscripcion()->getGeo();
                 $this->writeToSitemap("elecciones-{$culture}", $controller->genUrl('eleccion/show?geo=' . $geoLista->getCircunscripcion()->getGeo()->getNombre() . '&vanity=' . $convocatoria->getEleccion()->getVanity() . '&convocatoria=' . $convocatoria->getNombre(), true), $culture);
             }
             $this->writeToSitemap("elecciones-{$culture}", $controller->genUrl('lista/show?partido=' . $geoLista->getPartido()->getAbreviatura() . '&geo=' . $geoLista->getCircunscripcion()->getGeo()->getNombre() . '&vanity=' . $convocatoria->getEleccion()->getVanity() . '&convocatoria=' . $convocatoria->getNombre(), true), $culture);
         }
     }
     //}
     $this->closeAll($culture);
 }
Exemplo n.º 7
0
 protected function institucion($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();
     $instituciones = InstitucionPeer::doSelect($c);
     foreach ($instituciones as $institucion) {
         if ($institucion->getVanity('es') == null || $institucion->getVanity('es') == '') {
             echo "Setting vanity to  " . $institucion->getId() . " ...\n";
             $vanityUrl = SfVoUtil::encodeVanity($institucion->getNombreCorto('es'));
             $c2 = new Criteria();
             $c2->addJoin(InstitucionPeer::ID, InstitucionI18nPeer::ID, Criteria::LEFT_JOIN);
             $c2->add(InstitucionI18nPeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
             $c2->add(InstitucionPeer::ID, $institucion->getId(), Criteria::NOT_EQUAL);
             $institucionesLikeMe = InstitucionPeer::doSelect($c2);
             $counter = 0;
             foreach ($institucionesLikeMe as $institucionLikeMe) {
                 $counter++;
             }
             $institucion->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"), 'es');
             $institucion->save();
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Selects a collection of InstitucionI18n objects pre-filled with all related objects.
  *
  * @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 InstitucionI18n objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     InstitucionI18nPeer::addSelectColumns($criteria);
     $startcol2 = InstitucionI18nPeer::NUM_COLUMNS - InstitucionI18nPeer::NUM_LAZY_LOAD_COLUMNS;
     InstitucionPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (InstitucionPeer::NUM_COLUMNS - InstitucionPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(InstitucionI18nPeer::ID, InstitucionPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BaseInstitucionI18nPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = InstitucionI18nPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = InstitucionI18nPeer::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 = InstitucionI18nPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             InstitucionI18nPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Institucion rows
         $key2 = InstitucionPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = InstitucionPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = InstitucionPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 InstitucionPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (InstitucionI18n) to the collection in $obj2 (Institucion)
             $obj2->addInstitucionI18n($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Exemplo n.º 9
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.º 10
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 = InstitucionPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setGeoId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setCreatedAt($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setDisabled($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setOrden($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setUrl($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setImagen($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setIsActive($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setIsMain($arr[$keys[8]]);
     }
 }
Exemplo n.º 11
0
 /**
  * Returns the number of related Institucion objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Institucion objects.
  * @throws     PropelException
  */
 public function countInstitucions(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(GeoPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collInstitucions === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(InstitucionPeer::GEO_ID, $this->id);
             $count = InstitucionPeer::doCount($criteria, false, $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 count of the collection.
             $criteria->add(InstitucionPeer::GEO_ID, $this->id);
             if (!isset($this->lastInstitucionCriteria) || !$this->lastInstitucionCriteria->equals($criteria)) {
                 $count = InstitucionPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collInstitucions);
             }
         } else {
             $count = count($this->collInstitucions);
         }
     }
     return $count;
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
0
function changeCulture($culture)
{
    $extensions = array('es' => 'es', 'ca' => 'cat');
    $sf_context = sfContext::getInstance();
    $request = $sf_context->getRequest();
    $module = $request->getParameter('module');
    $action = $request->getParameter('action');
    $parameters = $request->getParameterHolder()->getAll();
    $curCulture = $sf_context->getUser()->getCulture('es');
    $routeName = $sf_context->getRouting()->getCurrentRouteName();
    $routeName = preg_replace("/_{$curCulture}\$/", "_{$culture}", $routeName);
    $params = "";
    foreach ($parameters as $name => $value) {
        if ($name != 'module' && $name != 'action') {
            if ($name == 'institucion') {
                $c = new Criteria();
                $c->addJoin(InstitucionPeer::ID, InstitucionI18nPeer::ID);
                $c->addJoin(array(InstitucionPeer::ID, InstitucionI18nPeer::CULTURE), array(InstitucionI18nPeer::ID, "'{$curCulture}'"), Criteria::INNER_JOIN);
                $c->add(InstitucionI18nPeer::VANITY, $value);
                $aInstitucion = InstitucionPeer::doSelectOne($c);
                if ($aInstitucion) {
                    $value = $aInstitucion->getVanity($culture);
                }
            }
            if ($module == 'sfReviewFront' && $action == 'show' && $name == 'id') {
                $review = SfReviewPeer::retrieveByPk($request->getParameter('id'));
                $value = SfVoUtil::reviewPermalink($review, $culture);
            }
            $params .= ($params == "" ? '?' : '&') . "{$name}={$value}";
        }
    }
    $route = sfContext::getInstance()->getController()->genUrl("@{$routeName}{$params}");
    $host = preg_replace("/\\.[a-zA-Z]*\$/is", "." . $extensions[$culture], $_SERVER['HTTP_HOST']);
    return "http://{$host}{$route}";
}
Exemplo n.º 14
0
 /**
  * Selects a collection of {@link Institucion} objects with a {@link InstitucionI18n} translation populated.
  *
  * @param Criteria  $criteria
  * @param string    $culture
  * @param PropelPDO $con
  * @param string    $join_behavior
  *
  * @return array
  */
 public static function doSelectWithI18n(Criteria $criteria, $culture = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     if (null === $culture) {
         $culture = sfPropel::getDefaultCulture();
     }
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     InstitucionPeer::addSelectColumns($criteria);
     $startcol = InstitucionPeer::NUM_COLUMNS - InstitucionPeer::NUM_LAZY_LOAD_COLUMNS;
     InstitucionI18nPeer::addSelectColumns($criteria);
     $criteria->addJoin(InstitucionPeer::ID, InstitucionI18nPeer::ID, $join_behavior);
     $criteria->add(InstitucionI18nPeer::CULTURE, $culture);
     foreach (sfMixer::getCallables('BaseInstitucion:doSelectJoin:doSelectJoin') as $sf_hook) {
         call_user_func($sf_hook, 'Institucion', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = InstitucionPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = InstitucionPeer::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 = InstitucionPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             InstitucionPeer::addInstanceToPool($obj1, $key1);
         }
         // if $obj1 already loaded
         $key2 = InstitucionI18nPeer::getPrimaryKeyHashFromRow($row, $startcol);
         if ($key2 !== null) {
             $obj2 = InstitucionI18nPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = InstitucionI18nPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol);
                 InstitucionI18nPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 already loaded
             $obj1->setInstitucionI18nForCulture($obj2, $culture);
         }
         // if joined row was not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }