public function executeSendStmt() { if ($this->reviewType == Politico::NUM_ENTITY) { $this->politico = PoliticoPeer::retrieveByPK($this->reviewEntityId); } else { if ($this->reviewType == Partido::NUM_ENTITY) { $this->partido = PartidoPeer::retrieveByPK($this->reviewEntityId); } else { if ($this->reviewType != null) { $type = SfReviewTypePeer::retrieveByPk($this->reviewType); $peer = $type->getModel() . 'Peer'; $this->entity = $peer::retrieveByPK($this->reviewEntityId); } else { if ($this->reviewType == null) { $review_ = SfReviewPeer::retrieveByPK($this->reviewEntityId); if ($review_) { $this->review = $review_; if ($this->review->getSfReviewTypeId() == Politico::NUM_ENTITY) { $this->politico = PoliticoPeer::retrieveByPK($this->review->getEntityId()); } else { if ($this->review->getSfReviewTypeId() == Partido::NUM_ENTITY) { $this->partido = PartidoPeer::retrieveByPK($this->review->getEntityId()); } else { $type = SfReviewTypePeer::retrieveByPk($this->review->getSfReviewTypeId()); $peer = $type->getModel() . 'Peer'; $this->entity = $peer::retrieveByPK($this->review->getEntityId()); } } } } } } } }
public function executeIndex(sfWebRequest $request) { $culture = $this->getUser()->getCulture(); $cpos = new Criteria(); $cpos->add(SfReviewPeer::VALUE, 1); $cpos->add(SfReviewPeer::IS_ACTIVE, 1); //$cpos->add(SfReviewPeer::CULTURE, $culture); $this->totalUpReviews = SfReviewPeer::doCount($cpos); $cneg = new Criteria(); $cneg->add(SfReviewPeer::VALUE, -1); $cneg->add(SfReviewPeer::IS_ACTIVE, 1); //$cneg->add(SfReviewPeer::CULTURE, $culture); $this->totalDownReviews = SfReviewPeer::doCount($cneg); $exclude = ""; $this->reviewables = EntityManager::getTopEntities(6, $exclude, "WebEntity", true); $c = new Criteria(); $c->addDescendingOrderByColumn(PoliticoPeer::SUMU); $c->addAscendingOrderByColumn(PoliticoPeer::SUMD); $c->setLimit(5); $this->topPoliticos = PoliticoPeer::doSelect($c); $c = new Criteria(); $c->addDescendingOrderByColumn(PartidoPeer::SUMU); $c->addAscendingOrderByColumn(PartidoPeer::SUMD); $c->setLimit(5); $c->add(PartidoPeer::IS_ACTIVE, true); $this->partidosMasVotados = PartidoPeer::doSelect($c); $c = new Criteria(); $c->addDescendingOrderByColumn(PropuestaPeer::SUMU); $c->addAscendingOrderByColumn(PropuestaPeer::SUMD); $c->setLimit(5); $c->add(PropuestaPeer::IS_ACTIVE, true); $c->add(PropuestaPeer::CULTURE, $culture); $this->propuestasMasVotadas = PropuestaPeer::doSelect($c); //Totales /* $c = new Criteria(); $this->totalPoliticos = PoliticoPeer::doCount($c); $c = new Criteria(); $c->add(PartidoPeer::IS_ACTIVE, true); $this->totalPartidos = PartidoPeer::doCount($c); $c = new Criteria(); $c->add(PropuestaPeer::IS_ACTIVE, true); $c->add(PropuestaPeer::CULTURE, $culture); $this->totalPropuestas = PropuestaPeer::doCount($c); */ $this->response->addMeta('Description', sfContext::getInstance()->getI18N()->__('Comparte opiniones sobre políticos y partidos de España. Ranking de los políticos y partidos más votados.')); // Ultimos comentarios $filter = array(); $filter['culture'] = $culture; //$this->topReviews = SfReviewManager::getReviews($filter, 1, 5); $this->activities = SfReviewManager::getActivities($filter, 1, 5); // elecciones destacadas $convocatoriaActiva = sfConfig::get('sf_convocatoria_activa'); $this->convocatoria = ConvocatoriaPeer::retrieveByPk($convocatoriaActiva); }
private function partido($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(); $c = new Criteria(); $c->add(PartidoPeer::ID, $options['minid'], Criteria::GREATER_EQUAL); $partidos = PartidoPeer::doSelect($c); foreach ($partidos as $partido) { if ($partido->getImagen() != '') { echo "Creating " . $partido->getImagen() . " ...\n"; $s3->createPartidoFromOri($partido->getImagen()); } } }
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(); $s3 = new S3Voota(); $c = new Criteria(); //$c->add(PoliticoPeer::ID, 1, Criteria::EQUAL); $politicos = PoliticoPeer::doSelect($c); foreach ($politicos as $politico) { $vanity = $politico->getVanity(); if ($vanity != ($new = SfVoUtil::fixVanityChars($vanity))) { while (preg_match("/(.*)-\$/is", $new, $m, PREG_OFFSET_CAPTURE)) { $new = $m[1][0]; } $c2 = new Criteria(); $c2->add(PoliticoPeer::VANITY, "{$new}%", Criteria::LIKE); $c2->add(PoliticoPeer::ID, $politico->getId(), Criteria::NOT_EQUAL); $politicosLikeMe = PoliticoPeer::doSelect($c2); $counter = 0; foreach ($politicosLikeMe as $politicoLikeMe) { $aVanity = str_replace("-", "\\-", $new); if (preg_match(SfVoUtil::voDecode("/^{$new}\\-([0-9]*)\$/is"), SfVoUtil::voDecode($politicoLikeMe->getVanity()), $matches)) { if ($counter < 1 + $matches[1]) { $counter = 1 + $matches[1]; } else { $counter++; } } else { $counter++; } } $new = "{$new}" . ($counter == 0 ? '' : "-{$counter}"); echo "politico:{$vanity} "; echo "cambia a:{$new}\n"; $politico->setVanity($new); $politico->save(); } } $usuarios = SfGuardUserPeer::doSelect($c); foreach ($usuarios as $usuario) { $vanity = $usuario->getProfile()->getVanity(); if ($vanity != SfVoUtil::fixVanityChars($vanity)) { echo "usuario:{$vanity} ({$usuario})\n"; $usuario->getProfile()->setVanity(SfVoUtil::fixVanityChars($vanity)); $usuario->getProfile()->save(); } } $partidos = PartidoPeer::doSelect($c); foreach ($partidos as $partido) { $vanity = $partido->getAbreviatura(); if ($vanity != SfVoUtil::fixVanityChars($vanity)) { echo "partido:{$vanity}\n"; } } // Instituciones $instituciones = InstitucionI18nPeer::doSelect($c); foreach ($instituciones as $institucion) { $vanity = $institucion->getVanity(); if ($vanity != ($new = SfVoUtil::fixVanityChars($vanity))) { echo "institucion:{$vanity}\n"; $institucion->setVanity($new); $institucion->save(); echo "cambia a:{$new}\n"; } } }
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); }
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); }
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); }
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; }
/** * Get the associated Partido object * * @param PropelPDO Optional Connection object. * @return Partido The associated Partido object. * @throws PropelException */ public function getPartido(PropelPDO $con = null) { if ($this->aPartido === null && $this->partido_id !== null) { $this->aPartido = PartidoPeer::retrieveByPk($this->partido_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->aPartido->addEtiquetaPartidos($this); */ } return $this->aPartido; }
private function post_review($data) { try { $userId = oauthSecurityManager::checkAuthorized(); } catch (Exception $e) { throw new NotAuthorizedException($e->getMessage()); } $entityId = $this->getRequestParameter("entity"); $value = $this->getRequestParameter("value"); $text = $this->getRequestParameter("text", false); $type = $this->getRequestParameter("type"); $key = oauthSecurityManager::getConsummerKey(); if (!$entityId || !$value || !$type) { throw new BadRequestException("Not enough parameters."); } if ($value != -1 && $value != 1) { throw new BadRequestException("Invalid data for 'value'."); } $typeId = -1; switch ($type) { case 'politician': $typeId = Politico::NUM_ENTITY; $entity = PoliticoPeer::retrieveByPK($entityId); break; case 'party': $typeId = Partido::NUM_ENTITY; $entity = PartidoPeer::retrieveByPK($entityId); break; case 'proposal': $typeId = Propuesta::NUM_ENTITY; $entity = PropuestaPeer::retrieveByPK($entityId); break; default: throw new BadRequestException('Invalid type.'); } try { $this->review = SfReviewManager::postReview($userId, $typeId, $entityId, $value, $text, $entity, false, 0, $key); } catch (Exception $e) { throw new Exception($e->getMessage()); } return "saved."; }
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; }
private function updateSums(sfWebRequest $request) { // Actualizar cache y puntos en politicos if ($request->getParameter("t") == Politico::NUM_ENTITY) { $this->politico = PoliticoPeer::retrieveByPk($request->getParameter('e')); $this->politico->setSumu($this->politico->getPositives()); $this->politico->setSumd($this->politico->getNegatives()); if ($this->politico->isModified()) { PoliticoPeer::doUpdate($this->politico); } $this->clearCache($this->politico); } else { if ($request->getParameter("t") == Partido::NUM_ENTITY) { $this->partido = PartidoPeer::retrieveByPk($request->getParameter('e')); $this->partido->setSumu($this->partido->getPositives()); $this->partido->setSumd($this->partido->getNegatives()); if ($this->partido->isModified()) { PartidoPeer::doUpdate($this->partido); } $this->clearCachePartido($this->partido); } else { if ($request->getParameter("t") == '') { $review = SfReviewPeer::retrieveByPk($request->getParameter('e')); if ($review->getSfReviewType()->getId() == Politico::NUM_ENTITY) { $politico = PoliticoPeer::retrieveByPk($review->getEntityId()); $this->clearCache($politico); } else { if ($review->getSfReviewType()->getId() == Partido::NUM_ENTITY) { $partido = PartidoPeer::retrieveByPk($review->getEntityId()); $this->clearCachePartido($partido); } } } } } }
public static function countPartidosReviewed() { $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false; if ($cache) { $key = md5("partidos_reviewed_counter"); $data = unserialize($cache->get($key)); } else { $data = false; } if (!$data) { $cpar = new Criteria(); $cpar->addJoin(PartidoPeer::ID, SfReviewPeer::ENTITY_ID, Criteria::INNER_JOIN); $cpar->add(SfReviewPeer::SF_REVIEW_TYPE_ID, Partido::NUM_ENTITY); $cpar->add(SfReviewPeer::IS_ACTIVE, TRUE); $cpar->add(PartidoPeer::IS_ACTIVE, TRUE); //$cpar->add(SfReviewPeer::CULTURE, $culture); $cpar->setDistinct(); $data = PartidoPeer::doCount($cpar); if ($cache) { $cache->set($key, serialize($data), 360); } } return $data; }
/** * Selects a collection of {@link Partido} objects with a {@link PartidoI18n} 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); } PartidoPeer::addSelectColumns($criteria); $startcol = PartidoPeer::NUM_COLUMNS - PartidoPeer::NUM_LAZY_LOAD_COLUMNS; PartidoI18nPeer::addSelectColumns($criteria); $criteria->addJoin(PartidoPeer::ID, PartidoI18nPeer::ID, $join_behavior); $criteria->add(PartidoI18nPeer::CULTURE, $culture); foreach (sfMixer::getCallables('BasePartido:doSelectJoin:doSelectJoin') as $sf_hook) { call_user_func($sf_hook, 'Partido', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = PartidoPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = PartidoPeer::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 = PartidoPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); PartidoPeer::addInstanceToPool($obj1, $key1); } // if $obj1 already loaded $key2 = PartidoI18nPeer::getPrimaryKeyHashFromRow($row, $startcol); if ($key2 !== null) { $obj2 = PartidoI18nPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = PartidoI18nPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol); PartidoI18nPeer::addInstanceToPool($obj2, $key2); } // if obj2 already loaded $obj1->setPartidoI18nForCulture($obj2, $culture); } // if joined row was not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
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); }
public function executeRmtag(sfWebRequest $request) { $e = $request->getParameter('e', false); $id = $request->getParameter('id', false); $type = $request->getParameter('type', false); TagManager::removeTag($id, $e, $type); switch ($type) { case Politico::NUM_ENTITY: $this->entity = PoliticoPeer::retrieveByPK($e); break; case Partido::NUM_ENTITY: $this->entity = PartidoPeer::retrieveByPK($e); break; case Propuesta::NUM_ENTITY: $this->entity = PropuestaPeer::retrieveByPK($e); break; } }
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 EtiquetaPartido objects pre-filled with all related objects except sfGuardUser. * * @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 EtiquetaPartido objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptsfGuardUser(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); } EtiquetaPartidoPeer::addSelectColumns($criteria); $startcol2 = EtiquetaPartidoPeer::NUM_COLUMNS - EtiquetaPartidoPeer::NUM_LAZY_LOAD_COLUMNS; EtiquetaPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (EtiquetaPeer::NUM_COLUMNS - EtiquetaPeer::NUM_LAZY_LOAD_COLUMNS); PartidoPeer::addSelectColumns($criteria); $startcol4 = $startcol3 + (PartidoPeer::NUM_COLUMNS - PartidoPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(EtiquetaPartidoPeer::ETIQUETA_ID, EtiquetaPeer::ID, $join_behavior); $criteria->addJoin(EtiquetaPartidoPeer::PARTIDO_ID, PartidoPeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BaseEtiquetaPartidoPeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = EtiquetaPartidoPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = EtiquetaPartidoPeer::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 = EtiquetaPartidoPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); EtiquetaPartidoPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Etiqueta rows $key2 = EtiquetaPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = EtiquetaPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = EtiquetaPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); EtiquetaPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (EtiquetaPartido) to the collection in $obj2 (Etiqueta) $obj2->addEtiquetaPartido($obj1); } // if joined row is not null // Add objects for joined Partido rows $key3 = PartidoPeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = PartidoPeer::getInstanceFromPool($key3); if (!$obj3) { $cls = PartidoPeer::getOMClass(false); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); PartidoPeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (EtiquetaPartido) to the collection in $obj3 (Partido) $obj3->addEtiquetaPartido($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Returns the number of related Partido objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Partido objects. * @throws PropelException */ public function countPartidosRelatedByPartidoId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(PartidoPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collPartidosRelatedByPartidoId === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(PartidoPeer::PARTIDO_ID, $this->id); $count = PartidoPeer::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(PartidoPeer::PARTIDO_ID, $this->id); if (!isset($this->lastPartidoRelatedByPartidoIdCriteria) || !$this->lastPartidoRelatedByPartidoIdCriteria->equals($criteria)) { $count = PartidoPeer::doCount($criteria, false, $con); } else { $count = count($this->collPartidosRelatedByPartidoId); } } else { $count = count($this->collPartidosRelatedByPartidoId); } } return $count; }