Esempio n. 1
0
 /**
  * Returns the number of related Propuesta objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Propuesta objects.
  * @throws     PropelException
  */
 public function countPropuestas(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(sfGuardUserPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collPropuestas === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(PropuestaPeer::SF_GUARD_USER_ID, $this->id);
             $count = PropuestaPeer::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(PropuestaPeer::SF_GUARD_USER_ID, $this->id);
             if (!isset($this->lastPropuestaCriteria) || !$this->lastPropuestaCriteria->equals($criteria)) {
                 $count = PropuestaPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collPropuestas);
             }
         } else {
             $count = count($this->collPropuestas);
         }
     }
     return $count;
 }
Esempio n. 2
0
 public function executeEdit(sfWebRequest $request)
 {
     $this->hasDeepUpdates = false;
     $c = new Criteria();
     $c->add(PropuestaPeer::IS_ACTIVE, true);
     $this->propuestasCount = PropuestaPeer::doCount($c);
     $this->isCanonicalVootaUser = SfVoUtil::isCanonicalVootaUser($this->getUser()->getGuardUser());
     if ($this->getUser()->isAuthenticated()) {
         $this->lastReview = SfReviewManager::getLastReviewByUserId($this->getUser()->getGuardUser()->getId());
         $this->lastReviewOnReview = SfReviewManager::getLastReviewOnReviewByUserId($this->getUser()->getGuardUser()->getId());
     }
     $this->redirectUnless($this->getUser()->isAuthenticated(), "@sf_guard_signin");
     $formData = sfGuardUserPeer::retrieveByPk($this->getUser()->getGuardUser()->getId());
     if (!SfVoUtil::isEmail($formData->getUsername())) {
         $formData->setUsername('');
     }
     $this->profileEditForm = new ProfileEditForm($formData);
     $this->politico = false;
     $politicos = $this->getUser()->getGuardUser()->getPoliticos();
     if ($politicos && count($politicos) != 0) {
         $this->politico = $politicos[0];
         unset($this->profileEditForm['nombre'], $this->profileEditForm['apellidos']);
     }
     $imagenOri = $formData->getProfile()->getImagen();
     $criteria = new Criteria();
     $criteria->add(SfReviewPeer::IS_ACTIVE, true);
     $criteria->add(SfReviewPeer::SF_GUARD_USER_ID, $this->getUser()->getGuardUser()->getId());
     $this->numReviews = SfReviewPeer::doCount($criteria);
     if ($request->isMethod('post')) {
         $this->profileEditForm->bind($request->getParameter('profile'), $request->getFiles('profile'));
         if ($this->profileEditForm->isValid()) {
             /*if ($this->politico){
             		  	$cacheManager = $this->getContext()->getViewCacheManager();
             		  	if ($cacheManager != null) {
             		  		$politico = $this->getRoute()->getObject();
             		    	$cacheManager->remove("politico/show?id=".$politico->getVanity()."");
             		  	}				
             		}*/
             $profile = $request->getParameter('profile');
             $this->hasDeepUpdates = $profile['presentacion'] != $formData->getProfile()->getPresentacion();
             if ($this->profileEditForm->getValue('imagen_delete') != "") {
                 // Si se elimina la imagen, hay que recargar el formulario para que se refresque
                 $formData->getProfile()->setImagen("");
                 //$formData->getProfile()->save();
                 $this->profileEditForm->setImageSrc("");
                 $this->profileEditForm->resetImageWidget();
                 //$this->profileEditForm = new ProfileEditForm( $formData );
             } else {
                 $imageOri = $this->profileEditForm->getObject()->getProfile()->getImagen();
                 $imagen = $this->profileEditForm->getValue('imagen');
                 $this->profileEditForm->save();
                 if ($imagen) {
                     $arr = array_reverse(explode(".", $imagen->getOriginalName()));
                     $ext = strtolower($arr[0]);
                     if (!$ext || $ext == "") {
                         $ext = "png";
                     }
                     $imageName = $this->profileEditForm->getValue('nombre') ? $this->profileEditForm->getValue('nombre') : $arr[1];
                     if ($this->profileEditForm->getValue('apellidos') != '') {
                         $imageName .= "-" . $this->profileEditForm->getValue('apellidos');
                     }
                     $imageName .= "-" . sprintf("%04d", rand(0, 999));
                     $imageName .= ".{$ext}";
                     $imagen->save(sfConfig::get('sf_upload_dir') . '/usuarios/' . $imageName);
                     $this->profileEditForm->getObject()->getProfile()->setImagen($imageName);
                     $this->profileEditForm->setImageSrc($imageName);
                     $this->profileEditForm->resetImageWidget();
                     $this->hasDeepUpdates = true;
                 } else {
                     $this->profileEditForm->getObject()->getProfile()->setImagen($imagenOri);
                     $this->profileEditForm->setImageSrc($imagenOri);
                 }
             }
             if ($profile['passwordNew'] != '') {
                 // Check old password
                 if ($this->getUser()->checkPassword($profile['passwordOld'])) {
                     $this->getUser()->setPassword($profile['passwordNew']);
                 } else {
                     $this->getUser()->setFlash('notice_type', 'error', false);
                     $this->getUser()->setFlash('notice', sfVoForm::getMissingPasswordMessage(), false);
                     return;
                 }
             }
             $this->getUser()->setFlash('notice_type', 'notice', false);
             $this->getUser()->setFlash('notice', sfVoForm::getFormSavesMessage(), false);
             $this->profileEditForm->save();
             $profile = $this->profileEditForm->getObject()->getProfile();
             $profile->save();
             $aText = utf8_decode($this->profileEditForm->getValue('presentacion'));
             $aText = strip_tags(substr($aText, 0, 280));
             $aText = utf8_encode($aText);
             $profile->setPresentacion($aText);
             $profile->save();
             if ($profile->isColumnModified(SfGuardUserProfileI18nPeer::PRESENTACION)) {
                 $this->hasDeepUpdates = true;
             }
             $this->presentacionValue = $aText;
         } else {
             $this->getUser()->setFlash('notice_type', 'error', false);
             $this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false);
         }
     }
     if (!$this->presentacionValue) {
         $this->presentacionValue = $politicos = $this->getUser()->getGuardUser()->getProfile()->getPresentacion();
     }
 }
Esempio n. 3
0
 public function executeShow(sfWebRequest $request)
 {
     $vanity = $request->getParameter('id');
     $s = $request->getParameter('s', 0);
     $culture = $this->getUser()->getCulture();
     $c = new Criteria();
     $c->add(PropuestaPeer::VANITY, $vanity);
     $this->propuesta = PropuestaPeer::doSelectOne($c);
     $this->forward404Unless($this->propuesta);
     if ($this->propuesta->getCulture() != $culture) {
         $this->redirect("@homepage");
     }
     if ($this->propuesta->getVanity() != $vanity) {
         $this->redirect('propuesta/show?id=' . $this->propuesta->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;
     }
     $exclude = array();
     $this->positives = SfReviewManager::getReviewsByEntityAndValue($request, Propuesta::NUM_ENTITY, $this->propuesta->getId(), 1);
     $this->negatives = SfReviewManager::getReviewsByEntityAndValue($request, Propuesta::NUM_ENTITY, $this->propuesta->getId(), -1);
     $positiveCount = $this->positives->getNbResults();
     $negativeCount = $this->negatives->getNbResults();
     $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->propuesta->getTitulo()));
     $description = sfContext::getInstance()->getI18N()->__('Página de %1%', array('%1%' => $this->propuesta->getTitulo()));
     $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
     $this->activeEnlaces = $this->getEnlaces($this->propuesta);
     $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->propuestasPager = EntityManager::getPager($this->propuesta);
     /* / paginador */
     $c = new Criteria();
     $c->add(PropuestaPeer::IS_ACTIVE, true);
     $c->add(PropuestaPeer::CULTURE, $culture);
     $this->propuestasCount = PropuestaPeer::doCount($c);
     // Feed
     $request->setAttribute('rssTitle', $this->title . " Feed RSS");
     $request->setAttribute('rssFeed', 'propuesta/feed?id=' . $this->propuesta->getVanity());
 }
Esempio n. 4
0
 public static function countPropuestasReviewed()
 {
     $user = sfContext::getInstance()->getUser();
     $culture = $user->getCulture();
     $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false;
     if ($cache) {
         $key = md5("propuestas_reviewes_counter_{$culture}");
         $data = unserialize($cache->get($key));
     } else {
         $data = false;
     }
     if (!$data) {
         $user = sfContext::getInstance()->getUser();
         $culture = $user->getCulture();
         $cpro = new Criteria();
         $cpro->addJoin(PropuestaPeer::ID, SfReviewPeer::ENTITY_ID, Criteria::INNER_JOIN);
         $cpro->add(SfReviewPeer::SF_REVIEW_TYPE_ID, Propuesta::NUM_ENTITY);
         $cpro->add(SfReviewPeer::IS_ACTIVE, TRUE);
         $cpro->add(PropuestaPeer::IS_ACTIVE, TRUE);
         //$cpro->add(SfReviewPeer::CULTURE, $culture);
         $cpro->add(PropuestaPeer::CULTURE, $culture);
         $cpro->setDistinct();
         $data = PropuestaPeer::doCount($cpro);
         if ($cache) {
             $cache->set($key, serialize($data), 360);
         }
     }
     return $data;
 }