Ejemplo 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);
 }
Ejemplo 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();
     $s3 = new S3Voota();
     $c = new Criteria();
     //$c->add(PoliticoPeer::ID, 1, Criteria::EQUAL);
     $politicos = PoliticoPeer::doSelect($c);
     foreach ($politicos as $politico) {
         $vanity = $politico->getVanity();
         # Los que acaban en -
         if (preg_match("/(.*)([\\-]+)\$/is", $vanity, $matches, PREG_OFFSET_CAPTURE)) {
             if ($matches[2][0] != '') {
                 #echo "politico:$vanity (".$matches[0][0].", ".$matches[1][0].", ".$matches[2][0].", ".$matches[3][0].")";
                 $vanityUrl = SfVoUtil::encodeVanity($matches[1][0]);
                 #echo "($vanityUrl)";
                 $c2 = new Criteria();
                 $c2->add(PoliticoPeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
                 $c2->add(PoliticoPeer::ID, $politico->getId(), Criteria::NOT_EQUAL);
                 $politicosLikeMe = PoliticoPeer::doSelect($c2);
                 $counter = 0;
                 foreach ($politicosLikeMe as $politicoLikeMe) {
                     $counter++;
                 }
                 //$profile->setVanity( "$vanityUrl". ($counter==0?'':"-$counter") );
                 #echo "->". "$vanityUrl". ($counter==0?'':"-$counter") ."\n";
                 //if ($counter != 0){
                 echo "politico:{$vanity} (" . $matches[0][0] . ", " . $matches[1][0] . ", " . $matches[2][0] . ")";
                 #echo "politico:$vanity (".$matches[0][0].", ".$matches[1][0].", ".$matches[2][0].", ".$matches[3][0].")";
                 echo "->" . "{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}") . "\n";
                 $politico->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"));
                 $politico->save();
                 //}
             }
         }
         # Los que acaban en --n
         if (preg_match("/(.*)--([0-9]*)\$/is", $vanity, $matches, PREG_OFFSET_CAPTURE)) {
             if ($matches[2][0] != '') {
                 #echo "politico:$vanity (".$matches[0][0].", ".$matches[1][0].", ".$matches[2][0].", ".$matches[3][0].")";
                 $vanityUrl = SfVoUtil::encodeVanity($matches[1][0]);
                 #echo "($vanityUrl)";
                 $c2 = new Criteria();
                 $c2->add(PoliticoPeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
                 $c2->add(PoliticoPeer::ID, $politico->getId(), Criteria::NOT_EQUAL);
                 $politicosLikeMe = PoliticoPeer::doSelect($c2);
                 $counter = 0;
                 foreach ($politicosLikeMe as $politicoLikeMe) {
                     if (preg_match("/(.*)-([0-9]*)\$/is", $politicoLikeMe->getVanity(), $m, PREG_OFFSET_CAPTURE)) {
                         if ($m[2][0] >= $counter) {
                             $counter = intval($m[2][0]) + 1;
                         }
                     } elseif ($counter == 0) {
                         $counter = 1;
                     }
                 }
                 //$profile->setVanity( "$vanityUrl". ($counter==0?'':"-$counter") );
                 #echo "->". "$vanityUrl". ($counter==0?'':"-$counter") ."\n";
                 echo "politico:{$vanity} (" . $matches[0][0] . ", " . $matches[1][0] . ", " . $matches[2][0] . ")";
                 #echo "politico:$vanity (".$matches[0][0].", ".$matches[1][0].", ".$matches[2][0].", ".$matches[3][0].")";
                 echo "->" . "{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}") . "\n";
                 $idx = 0;
                 $done = false;
                 while (!$done && $idx < 15) {
                     try {
                         $politico->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"));
                         $politico->save();
                         $done = true;
                     } catch (Exception $e) {
                         echo ".";
                         $done = false;
                         $counter++;
                         $idx++;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 3
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();
         }
     }
 }
Ejemplo n.º 4
0
 public function executeSignin($request)
 {
     $this->op = $request->getParameter('op');
     //echo $this->op;
     //die;
     $dialog = $request->getParameter('dialog', false);
     /* IF FB CONNECT */
     if ($this->op == 'fbc' && ($facebook_uid = VoFacebook::getUid())) {
         //echo "FBC";die;
         $c = new Criteria();
         $c->addJoin(SfGuardUserProfilePeer::USER_ID, SfGuardUserPeer::ID);
         $c->add(SfGuardUserProfilePeer::FACEBOOK_UID, $facebook_uid);
         $sfGuardUser = SfGuardUserPeer::doSelectOne($c);
         if (!$sfGuardUser instanceof sfGuardUser) {
             // Comprobación de que no existe ya el usuario con ese username (bug #734)
             $c = new Criteria();
             $c->add(sfGuardUserPeer::USERNAME, 'Facebook_' . $facebook_uid);
             $existingUser = sfGuardUserPeer::doSelectOne($c);
             if ($existingUser) {
                 $existingUser->setUsername('Facebook_' . $facebook_uid . '-' . time());
                 $existingUser->save();
             }
             $sfGuardUser = new sfGuardUser();
             $sfGuardUser->setUsername('Facebook_' . $facebook_uid);
             $sfGuardUser->save();
             $voProfile = $sfGuardUser->getProfile();
             $vanityUrl = SfVoUtil::encodeVanity('Facebook_' . $facebook_uid);
             $voProfile->setFacebookUid($facebook_uid);
             if (!$voProfile->getNombre()) {
                 $data = VoFacebook::getData($voProfile->getFacebookUid());
                 $voProfile->setNombre($data->first_name);
                 $voProfile->setApellidos($data->last_name);
             }
             $c2 = new Criteria();
             $c2->add(SfGuardUserProfilePeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
             $usuariosLikeMe = SfGuardUserProfilePeer::doSelect($c2);
             $counter = 0;
             foreach ($usuariosLikeMe as $usuarioLikeMe) {
                 if (preg_match("/^Facebook_{$facebook_uid}-([0-9]*)/i", $usuarioLikeMe->getVanity(), $matches)) {
                     $curIdx = $matches[1];
                     if ($curIdx > $counter) {
                         $counter = $curIdx + 1;
                     }
                 } else {
                     $counter++;
                 }
             }
             $voProfile->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"));
             $voProfile->setMailsComentarios(0);
             $voProfile->setMailsNoticias(0);
             $voProfile->setMailsContacto(0);
             $voProfile->setMailsSeguidor(0);
             $voProfile->save();
         }
         $this->getUser()->signin($sfGuardUser, false);
         $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $this->getUser()->getReferer('@homepage'));
         $this->redirect($signinUrl);
     }
     /* FI FB CONNECT */
     $this->registrationform = new RegistrationForm();
     $this->signinform = new SigninForm();
     if ($request->isMethod('post') && !$dialog) {
         // Register
         if ($this->op == 'r') {
             $this->registrationform = new RegistrationForm();
             $this->registrationform->bind($request->getParameter('registration'));
             if ($this->registrationform->isValid()) {
                 $user = new sfGuardUser();
                 $user->setUsername($this->registrationform->getValue('username'));
                 $user->setPassword($this->registrationform->getValue('password'));
                 $user->setIsActive(0);
                 $user->setCreatedAt(time());
                 $c = new Criteria();
                 $c->add(sfGuardUserPeer::USERNAME, $user->getUsername());
                 sfGuardUserPeer::doInsert($user);
                 $user = sfGuardUserPeer::doSelect($c);
                 if (count($user) == 1) {
                     $profile = $user[0]->getProfile();
                     $profile->setNombre($this->registrationform->getValue('nombre'));
                     $profile->setApellidos($this->registrationform->getValue('apellidos'));
                     $profile->setPresentacion($this->registrationform->getValue('presentacion'));
                     $profile->setAnonymous($this->registrationform->getValue('anonymous'));
                     $profile->setCodigo(util::generateUID());
                     /* Generar vanity */
                     if ($profile->getVanity() == '') {
                         $vanityUrl = SfVoUtil::encodeVanity($profile->getNombre() . "-" . $profile->getApellidos());
                         $c2 = new Criteria();
                         $c2->add(SfGuardUserProfilePeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
                         $c2->add(SfGuardUserProfilePeer::ID, $user[0]->getId(), Criteria::NOT_EQUAL);
                         $usuariosLikeMe = SfGuardUserProfilePeer::doSelect($c2);
                         $counter = 0;
                         foreach ($usuariosLikeMe as $usuarioLikeMe) {
                             $counter++;
                         }
                         $profile->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"));
                     }
                     /* Fin Generar vanity */
                     sfGuardUserProfilePeer::doInsert($profile);
                     $this->sendWelcome($user[0]);
                     $this->user = $user[0];
                     return "Registered";
                 }
             }
             /*
             else {
                   		$this->getUser()->setFlash('notice_type', 'error', false);
                   		$this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false);
             }
             */
         } else {
             $r = new SigninForm();
             $r->bind($request->getParameter('signin'));
             if ($r->isValid()) {
                 $r->addPostValidation();
                 $r->bind($request->getParameter('signin'));
                 if ($r->isValid()) {
                     $this->doSignin($request, $this->op);
                 }
             }
             /*
             	      else {
                   		$this->getUser()->setFlash('notice_type', 'error', false);
                   		$this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false);
             }
             */
             $this->signinform = $r;
         }
     }
     $this->title = sfContext::getInstance()->getI18N()->__('Acceso usuarios', array());
     $this->title .= ' - Voota';
     $this->response->setTitle($this->title);
     if ($this->op == 'fb') {
         return 'FB';
     }
 }
Ejemplo n.º 5
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();
     $c->add(InstitucionI18nPeer::NOMBRE, 'Ayuntamiento%', Criteria::LIKE);
     $c->add(InstitucionI18nPeer::CULTURE, 'es');
     $pager = new sfPropelPager('InstitucionI18n', 100);
     $pager->setCriteria($c);
     $pageNum = 0;
     do {
         $pageNum++;
         echo "\nBlock no. {$pageNum} \n";
         $pager->setPage($pageNum);
         $pager->init();
         $instituciones = $pager->getResults();
         foreach ($instituciones as $institucion) {
             $geo = GeoPeer::retrieveByPK($institucion->getInstitucion()->getGeoId());
             if ($geo) {
                 echo ".";
                 $nombreCorto = $geo->getNombre();
                 //$nombreCorto = $institucion->getInstitucion()->getGeo()->getNombre();
                 $vanityUrl = SfVoUtil::encodeVanity($nombreCorto);
                 $c2 = new Criteria();
                 $c2->add(EleccionPeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
                 //$c2->add(EleccionPeer::ID, $id, Criteria::NOT_EQUAL);
                 $eleccionesLikeMe = EleccionPeer::doSelect($c2);
                 $counter = 0;
                 foreach ($eleccionesLikeMe as $eleccionLikeMe) {
                     $counter++;
                 }
                 $vanity = "{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}");
                 $eleccion = new Eleccion();
                 $eleccion->setVanity($vanity);
                 $eleccion->save();
                 $ei = new EleccionInstitucion();
                 $ei->setEleccion($eleccion);
                 $ei->setInstitucion($institucion->getInstitucion());
                 $ei->save();
                 $eleccion_i18n = new EleccionI18n();
                 $eleccion_i18n->setCulture('es');
                 $eleccion_i18n->setNombreCorto($nombreCorto);
                 $eleccion_i18n->setNombre("Elecciones al Ayuntamiento de {$nombreCorto}");
                 $eleccion_i18n->setEleccion($eleccion);
                 $eleccion_i18n->save();
                 $eleccion_i18n = new EleccionI18n();
                 $eleccion_i18n->setCulture('ca');
                 $eleccion_i18n->setNombreCorto($nombreCorto);
                 $eleccion_i18n->setNombre("Eleccions al Ajuntament de {$nombreCorto}");
                 $eleccion_i18n->setEleccion($eleccion);
                 $eleccion_i18n->save();
                 $convocatoria = new Convocatoria();
                 $convocatoria->setEleccion($eleccion);
                 $convocatoria->setNombre('2011');
                 $convocatoria->setFecha('2011/05/22');
                 $convocatoria->save();
                 $convocatoria_i18n = new ConvocatoriaI18n();
                 $convocatoria_i18n->setConvocatoria($convocatoria);
                 $convocatoria_i18n->setCulture('es');
                 $convocatoria_i18n->setDescripcion("Las listas y candidatos que se presentan a las elecciones de mayo. Vota y elige al alcalde y a los concejales de {$nombreCorto}. Compara las listas cerradas de los partidos con las listas abiertas de Voota, la lista oficial contra lo que dice la calle.");
                 $convocatoria_i18n->save();
                 $convocatoria_i18n = new ConvocatoriaI18n();
                 $convocatoria_i18n->setConvocatoria($convocatoria);
                 $convocatoria_i18n->setCulture('ca');
                 $convocatoria_i18n->setDescripcion("Las listas y candidatos que se presentan a las elecciones de mayo. Vota y elige al alcalde y a los concejales de {$nombreCorto}. Compara las listas cerradas de los partidos con las listas abiertas de Voota, la lista oficial contra lo que dice la calle.");
                 $convocatoria_i18n->save();
                 $circu = new Circunscripcion();
                 $circu->setGeo($geo);
                 $criteria = new Criteria();
                 $criteria->add(PoliticoInstitucionPeer::INSTITUCION_ID, $institucion->getId());
                 $count = PoliticoInstitucionPeer::doCount($criteria);
                 $circu->setEscanyos($count);
                 $circu->save();
             }
         }
     } while (!$pager->isLastPage());
 }