Example #1
0
 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);
     }
 }
Example #2
0
 public function savePoliticoListaList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['politico_lista_list'])) {
         // somebody has unset this widget
         return;
     }
     if (null === $con) {
         $con = $this->getConnection();
     }
     $c = new Criteria();
     $c->add(PoliticoListaPeer::LISTA_ID, $this->object->getPrimaryKey());
     PoliticoListaPeer::doDelete($c, $con);
     $values = $this->getValue('politico_lista_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new PoliticoLista();
             $obj->setListaId($this->object->getPrimaryKey());
             $obj->setPoliticoId($value);
             $obj->save();
         }
     }
 }
Example #3
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Politico is new, it will return
  * an empty collection; or if this Politico has previously
  * been saved, it will retrieve related PoliticoListas from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Politico.
  */
 public function getPoliticoListasJoinLista($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     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);
             $this->collPoliticoListas = PoliticoListaPeer::doSelectJoinLista($criteria, $con, $join_behavior);
         }
     } else {
         // 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);
         if (!isset($this->lastPoliticoListaCriteria) || !$this->lastPoliticoListaCriteria->equals($criteria)) {
             $this->collPoliticoListas = PoliticoListaPeer::doSelectJoinLista($criteria, $con, $join_behavior);
         }
     }
     $this->lastPoliticoListaCriteria = $criteria;
     return $this->collPoliticoListas;
 }
Example #4
0
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $handle = fopen("php://stdin", "r");
     $line = fgets($handle);
     while ($line = fgets($handle)) {
         $data = explode(";", "{$line}");
         $c = new Criteria();
         $c->add(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);
 }
Example #5
0
 public function executeDeleteInstitucion(sfWebRequest $request)
 {
     $politico = PoliticoListaPeer::retrieveByPK($request->getParameter('idi'), $request->getParameter('idm'));
     $politico->delete();
     $this->redirect('@lista_edit?id=' . $politico->getListaId());
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $handle = fopen("php://stdin", "r");
     $line = fgets($handle);
     while ($line = fgets($handle)) {
         $data = explode(";", "{$line}");
         $c = new Criteria();
         $c->add(GeoPeer::NOMBRE, $data[3]);
         $geos = GeoPeer::doSelect($c);
         $aGeo = false;
         foreach ($geos as $geo) {
             if ($geo->getGeoRelatedByGeoId() != null && $geo->getGeoRelatedByGeoId()->getCodigo() && $geo->getGeoRelatedByGeoId()->getCodigo() != '') {
                 //echo 'geo: ' . $geo->getNombre() . "\n";
                 $aGeo = $geo;
             }
         }
         if (!$aGeo) {
             echo 'Geo not found: (' . $data[3] . ")\n";
             continue;
         }
         $c = new Criteria();
         $c->add(PartidoPeer::ABREVIATURA, $data[5]);
         $partido = PartidoPeer::doSelectOne($c);
         if (!$partido) {
             $partido = new Partido();
             $partido->setAbreviatura($data[5]);
             $partido->setIsActive(true);
             $partido->setNombre($data[5], 'es');
             $partido->setNombre($data[5], 'ca');
             $partido->save();
             echo "Created partido ({$partido})\n";
         }
         $c = new Criteria();
         $c->add(CircunscripcionPeer::GEO_ID, $aGeo->getId());
         $circu = CircunscripcionPeer::doSelectOne($c);
         $c = new Criteria();
         $c->addJoin(ConvocatoriaPeer::ELECCION_ID, EleccionPeer::ID);
         $c->addJoin(EleccionInstitucionPeer::ELECCION_ID, EleccionPeer::ID);
         $c->addJoin(InstitucionPeer::ID, EleccionInstitucionPeer::INSTITUCION_ID);
         $c->add(InstitucionPeer::GEO_ID, $aGeo->getId());
         $convocatoria = ConvocatoriaPeer::doSelectOne($c);
         if (!$convocatoria) {
             echo "Convocatoria not found: ({$geo})\n";
             continue;
         }
         $c = new Criteria();
         $c->add(ListaPeer::CONVOCATORIA_ID, $convocatoria->getId());
         $c->add(ListaPeer::CIRCUNSCRIPCION_ID, $circu->getId());
         $c->add(ListaPeer::PARTIDO_ID, $partido->getId());
         $lista = ListaPeer::doSelectOne($c);
         if (!$lista) {
             $lista = new Lista();
             $lista->setPartido($partido);
             $lista->setCircunscripcion($circu);
             $lista->setConvocatoria($convocatoria);
             $lista->save();
             echo "Created lista ({$partido}, {$circu})\n";
         }
         $politicos = false;
         $c = new Criteria();
         $c->add("concat(nombre, ' ', apellidos)", trim($data[2]));
         //$c->add('fullname', utf8_encode( trim($data[2]) ), Criteria::EQUAL);
         $politicos = PoliticoPeer::doSelect($c);
         if (count($politicos) != 0) {
             echo "(ASIGNADO) " . $data[2] . "\n";
             $politico = $politicos[0];
         } else {
             echo "(NUEVO) " . $data[2] . "\n";
             $politico = new Politico();
             $nombreApellidos = explode(" ", $data[2]);
             $nombre = array_shift($nombreApellidos);
             $apellidos = implode(" ", $nombreApellidos);
             $politico->setNombre($nombre);
             $politico->setApellidos($apellidos);
             if ($data[7] != '1') {
                 if (trim($data[10]) != '') {
                     $c = new Criteria();
                     $c->add(PartidoPeer::ABREVIATURA, $data[5]);
                     $partido = PartidoPeer::doSelectOne($c);
                     if ($partido) {
                         $politico->setPartido($partido);
                     }
                 } else {
                     $politico->setPartido($lista->getPartido());
                 }
             }
             $politico->setSexo($data[1] == "hombre" ? 'H' : 'M');
             $politico->save();
             $politicoI18n = new PoliticoI18n();
             $politicoI18n->setPolitico($politico);
             $politicoI18n->setCulture('es');
             $politicoI18n->save();
             $politicoI18n = new PoliticoI18n();
             $politicoI18n->setPolitico($politico);
             $politicoI18n->setCulture('ca');
             $politicoI18n->save();
         }
         $c = new Criteria();
         $c->add(PoliticoListaPeer::LISTA_ID, $lista->getId());
         $c->add(PoliticoListaPeer::POLITICO_ID, $politico->getId());
         $pl = PoliticoListaPeer::doSelectOne($c);
         if (!$pl) {
             $pl = new PoliticoLista();
             $pl->setLista($lista);
             $pl->setPolitico($politico);
         } else {
             echo "Ya estaba.\n";
         }
         $pl->setOrden($data[0]);
         $pl->save();
     }
     fclose($handle);
 }
Example #8
0
 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);
 }
Example #9
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 = PoliticoListaPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setPoliticoId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setListaId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setOrden($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setCreatedAt($arr[$keys[3]]);
     }
 }