예제 #1
0
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     $taintedValues['abreviatura'] = SfVoUtil::fixVanityChars($taintedValues['abreviatura']);
     if (!$this->isNew()) {
         if (is_null($taintedValues['enlace']['url']) || strlen($taintedValues['enlace']['url']) === 0) {
             unset($this->embeddedForms['enlace'], $taintedValues['enlace']);
             $this->validatorSchema['enlace'] = new sfValidatorPass();
         } else {
             $this->embeddedForms['enlace']->getObject()->setPartido($this->getObject());
         }
     }
     parent::bind($taintedValues, $taintedFiles);
 }
예제 #2
0
 public function bind(array $taintedValues = null, array $taintedFiles = null, $img = false)
 {
     // remove the embedded new form if the name field was not provided
     $taintedValues['vanity'] = SfVoUtil::fixVanityChars($taintedValues['vanity']);
     for ($idx = 1; $idx <= 5; $idx++) {
         if (is_null($taintedValues["enlace_n{$idx}"]['url'])) {
             unset($this->embeddedForms["enlace_n{$idx}"], $taintedValues["enlace_n{$idx}"]);
             $this->validatorSchema["enlace_n{$idx}"]['url'] = new sfValidatorUrl(array('required' => false));
         } else {
             $this->validatorSchema["enlace_n{$idx}"]['url'] = new sfVoValidatorUrl(array('required' => false), sfVoForm::getUrlMessages());
             $this->embeddedForms["enlace_n{$idx}"]->getObject()->setSfGuardUser($this->getObject());
         }
     }
     // call parent bind method
     parent::bind($taintedValues, $taintedFiles);
 }
예제 #3
0
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     $vanity = isset($taintedValues['vanity']) ? $taintedValues['vanity'] : false;
     $titulo = isset($taintedValues['titulo']) ? $taintedValues['titulo'] : false;
     $descripcion = isset($taintedValues['descripcion']) ? $taintedValues['descripcion'] : false;
     $id = isset($taintedValues['id']) ? $taintedValues['id'] : false;
     if ($titulo) {
         $taintedValues['titulo'] = SfVoUtil::cutToLength($taintedValues['titulo'], 80);
     }
     if ($descripcion) {
         $taintedValues['descripcion'] = SfVoUtil::cutToLength($taintedValues['descripcion'], 600);
     }
     if ($vanity) {
         $taintedValues['vanity'] = SfVoUtil::fixVanityChars($vanity);
     } else {
         if (!$id) {
             $taintedValues['vanity'] = SfVoUtil::fixVanityChars($taintedValues['titulo']);
         }
     }
     if (!$this->isNew()) {
         if (isset($taintedValues['enlace'])) {
             if (is_null($taintedValues['enlace']['url']) || strlen($taintedValues['enlace']['url']) === 0) {
                 unset($this->embeddedForms['enlace'], $taintedValues['enlace']);
                 $this->validatorSchema['enlace'] = new sfValidatorPass();
             } else {
                 $this->embeddedForms['enlace']->getObject()->setPropuesta($this->getObject());
             }
         }
         if (isset($taintedValues['institucion'])) {
             if (is_null($taintedValues['institucion']['institucion_id']) || strlen($taintedValues['institucion']['institucion_id']) === 0) {
                 unset($this->embeddedForms['institucion'], $taintedValues['institucion']);
                 $this->validatorSchema['institucion'] = new sfValidatorPass();
             } else {
                 $this->embeddedForms['institucion']->getObject()->setPropuesta($this->getObject());
             }
         }
     }
     parent::bind($taintedValues, $taintedFiles);
 }
예제 #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();
     $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";
         }
     }
 }
예제 #5
0
파일: newPreview.php 프로젝트: voota/voota
',
							'href': '<?php 
echo url_for('propuesta/show?id=' . SfVoUtil::fixVanityChars($form['titulo']->getValue()), true);
?>
',
						  'media': [{
				  			'type': 'image',
				  			'src': '<?php 
echo S3Voota::getImagesUrl();
?>
/propuestas/cc_s_<?php 
echo $form['imagen']->getValue();
?>
',
						  	'href': '<?php 
echo url_for('propuesta/show?id=' . SfVoUtil::fixVanityChars($form['titulo']->getValue()), true);
?>
'
						  }]
						};
					  try {
					    publishFaceBook("<?php 
echo __('He dejado una nueva propuesta en Voota: \\"%1\\"', array('%1' => $form['titulo']->getValue()));
?>
", attachment, [{'text':'<?php 
echo __('Ir a Voota');
?>
', 'href':'http://voota.es'}], '<?php 
echo __('Vamos a publicar esto en Facebook, ¿que te parece?');
?>
');
예제 #6
0
 public function executeNew(sfWebRequest $request)
 {
     $this->redirectUnless($this->getUser()->isAuthenticated(), "@sf_guard_signin");
     $op = $request->getParameter("op", "n");
     $this->title = sfContext::getInstance()->getI18N()->__('Añadir una nueva propuesta - Voota ', array());
     $this->response->setTitle($this->title);
     if ($op == 'c') {
         $this->form = new PreviewPropuestaForm();
     } else {
         $this->form = new NuevaPropuestaForm();
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('propuesta'), $request->getFiles('propuesta'));
         if ($this->form->isValid()) {
             if ($op == 'r') {
                 $imagen = $this->form->getValue('imagen');
                 if ($imagen) {
                     $arr = array_reverse(explode(".", $imagen->getOriginalName()));
                     $ext = strtolower($arr[0]);
                     if (!$ext || $ext == "") {
                         $ext = "png";
                     }
                     $imageName = SfVoUtil::fixVanityChars($arr[1]);
                     $imageName .= "-" . sprintf("%04d", rand(0, 999));
                     $imageName .= ".{$ext}";
                     $imagen->save(sfConfig::get('sf_upload_dir') . '/propuestas/' . $imageName);
                     $this->form->getObject()->setImagen($imageName);
                 }
                 $doc = $this->form->getValue('doc');
                 if ($doc) {
                     $arr = array_reverse(explode(".", $doc->getOriginalName()));
                     $ext = strtolower($arr[0]);
                     if (!$ext || $ext == "") {
                         $ext = "png";
                     }
                     $docName = SfVoUtil::fixVanityChars($arr[1]);
                     $docName .= "-" . sprintf("%04d", rand(0, 999));
                     $docName .= ".{$ext}";
                     $doc->save(sfConfig::get('sf_upload_dir') . '/docs/' . $docName);
                     $this->form->getObject()->setDoc($docName);
                 }
                 $this->form = new PreviewPropuestaForm();
                 $this->form->bind($request->getParameter('propuesta'), array(), isset($imageName) ? $imageName : false, isset($docName) ? $docName : false);
                 return 'Preview';
             } elseif ($op == 'c') {
                 $this->form->save();
                 $this->propuesta = $this->form->getObject();
                 if ($this->propuesta->getDoc()) {
                     $s = new S3Voota();
                     $this->propuesta->setDocSize($s->getSize('docs/' . $this->propuesta->getDoc()));
                     $this->propuesta->save();
                 }
                 $this->redirect("propuesta/show?id=" . $this->propuesta->getVanity());
             }
         }
     }
 }