public function configure() { unset($this['politico_lista_list'], $this['partido_lista_list']); $this->widgetSchema['sf_lista_id'] = new sfWidgetFormChoice(array('choices' => array(), 'renderer_class' => 'sfWidgetFormPropelJQueryAutocompleter', 'renderer_options' => array('model' => 'Politico', 'url' => $this->getOption('url')))); $this->widgetSchema['convocatoria_id'] = new sfWidgetFormChoice(array('choices' => array(), 'renderer_class' => 'sfWidgetFormPropelJQueryAutocompleter', 'renderer_options' => array('model' => 'Convocatoria', 'url' => $this->getOption('url_co')))); $this->widgetSchema['circunscripcion_id'] = new sfWidgetFormChoice(array('choices' => array(), 'renderer_class' => 'sfWidgetFormPropelJQueryAutocompleter', 'renderer_options' => array('model' => 'Circunscripcion', 'url' => $this->getOption('url_ci')))); if (!$this->isNew()) { // embed all forms foreach ($this->getObject()->getPoliticoListas() as $politico) { $politicoForm = new PoliticoListaForm($politico); $politicoForm->setOption('url', $this->getOption('url')); $politicoForm->configure(); $this->embedForm('politico' . $politico->getPolitico()->getId(), $politicoForm); // set a custom label for the embedded form $this->widgetSchema['politico' . $politico->getPolitico()->getId()]->setLabel('Político ' . $politico->getPolitico()->getId()); } $listaPolitico = new PoliticoLista(); $listaPolitico->setListaId($this->getObject()->getId()); $politicoForm = new PoliticoListaForm($listaPolitico); $politicoForm->setOption('url', $this->getOption('url')); $politicoForm->configure(); $this->embedForm('politico', $politicoForm); // set a custom label for the embedded form $this->widgetSchema['politico']->setLabel('Nuevo político'); $c = new Criteria(); $c->add(PoliticoListaPeer::LISTA_ID, $this->getObject()->getId()); $c->addAscendingOrderByColumn(PoliticoListaPeer::ORDEN); $this->listaPoliticos = PoliticoListaPeer::doSelect($c); } }
/** * Gets an array of PoliticoLista objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this Politico has previously been saved, it will retrieve * related PoliticoListas from storage. If this Politico is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array PoliticoLista[] * @throws PropelException */ public function getPoliticoListas($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(PoliticoPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collPoliticoListas === null) { if ($this->isNew()) { $this->collPoliticoListas = array(); } else { $criteria->add(PoliticoListaPeer::POLITICO_ID, $this->id); PoliticoListaPeer::addSelectColumns($criteria); $this->collPoliticoListas = PoliticoListaPeer::doSelect($criteria, $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 the collection. $criteria->add(PoliticoListaPeer::POLITICO_ID, $this->id); PoliticoListaPeer::addSelectColumns($criteria); if (!isset($this->lastPoliticoListaCriteria) || !$this->lastPoliticoListaCriteria->equals($criteria)) { $this->collPoliticoListas = PoliticoListaPeer::doSelect($criteria, $con); } } } $this->lastPoliticoListaCriteria = $criteria; return $this->collPoliticoListas; }
/** * Retrieve object using using composite pkey values. * @param int $politico_id * @param int $lista_id * @param PropelPDO $con * @return PoliticoLista */ public static function retrieveByPK($politico_id, $lista_id, PropelPDO $con = null) { $key = serialize(array((string) $politico_id, (string) $lista_id)); if (null !== ($obj = PoliticoListaPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(PoliticoListaPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(PoliticoListaPeer::DATABASE_NAME); $criteria->add(PoliticoListaPeer::POLITICO_ID, $politico_id); $criteria->add(PoliticoListaPeer::LISTA_ID, $lista_id); $v = PoliticoListaPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
public function executeShow(sfWebRequest $request) { $vanity = $request->getParameter('id'); $s = $request->getParameter('s', 0); $f = $request->getParameter('f', 'none'); $F = $request->getParameter('F', 'none'); $culture = $this->getUser()->getCulture(); $c = new Criteria(); $c->add(PoliticoPeer::VANITY, $vanity, Criteria::EQUAL); $politico = PoliticoPeer::doSelectOne($c); $this->forward404Unless($politico); if ($f != 'none' || $F != 'none') { $this->redirect('politico/show?id=' . $politico->getVanity(), 301); } $this->partido = $request->getParameter("partido"); $this->institucion = $request->getParameter("institucion"); $this->rankingUrl = $this->generateRankingUrl($this->partido, $this->institucion); $this->politico = $politico; $id = $this->politico->getId(); $this->forward404Unless($this->politico); if ($this->politico->getVanity() != $vanity) { $this->redirect('politico/show?id=' . $this->politico->getVanity(), 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->politico->getImagen() != '') { $imageFileName = $this->politico->getImagen(); } else { $imageFileName = "p_unknown.png"; } $this->image = "bw_{$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; } $exclude = array(); $this->positives = SfReviewManager::getReviewsByEntityAndValue($request, 1, $id, 1, $resU); $this->negatives = SfReviewManager::getReviewsByEntityAndValue($request, 1, $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; } $this->title = sfContext::getInstance()->getI18N()->__('%1%, opiniones a favor y en contra en Voota', array('%1%' => $this->politico->getNombre() . ' ' . $this->politico->getApellidos())); $description = sfContext::getInstance()->getI18N()->__('Página de %1%', array('%1%' => $this->politico->getNombre() . ' ' . $this->politico->getApellidos())); if (count($this->politico->getPoliticoInstitucions()) > 0) { $description .= " ("; //instituciones foreach ($this->politico->getPoliticoInstitucions() as $idx => $politicoInstitucion) { if ($idx > 0) { $description .= ', '; } $description .= $politicoInstitucion->getInstitucion()->getNombre(); } $description .= ")"; } $description .= ", " . $this->politico->getPartido() . ", "; //partido $description .= sfContext::getInstance()->getI18N()->__('%1% votos a favor y %2% votos en contra.', array('%1%' => $positiveCount, '%2%' => $negativeCount)); $this->response->addMeta('Description', $description); $this->response->setTitle($this->title); // 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); if ($politico->getsfGuardUser()) { $c->add(EnlacePeer::SF_GUARD_USER_ID, $politico->getsfGuardUser()->getId()); } else { $c->add(EnlacePeer::POLITICO_ID, $id); } $c->add(EnlacePeer::URL, '', Criteria::NOT_EQUAL); $c->addAscendingOrderByColumn(EnlacePeer::ORDEN); $this->activeEnlaces = EnlacePeer::doSelect($c); if ($politico->getsfGuardUser() && count($this->activeEnlaces) == 0) { $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::POLITICO_ID, $id); $c->add(EnlacePeer::URL, '', Criteria::NOT_EQUAL); $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; } } /* paginador */ $this->politicosPager = EntityManager::getPager($this->politico); /* / paginador */ // Feed $request->setAttribute('rssTitle', $this->title . " Feed RSS"); $request->setAttribute('rssFeed', 'politico/feed?id=' . $this->politico->getVanity()); $this->listas = false; $c = new Criteria(); $c->add(PoliticoListaPeer::POLITICO_ID, $this->politico->getId()); $c->addJoin(PoliticoListaPeer::LISTA_ID, ListaPeer::ID); $c->addJoin(ConvocatoriaPeer::ID, ListaPeer::CONVOCATORIA_ID); $c->add(ConvocatoriaPeer::FECHA, time(), Criteria::GREATER_THAN); $this->listas = PoliticoListaPeer::doSelect($c); }