public function executeIndex(sfWebRequest $request) { $culture = $this->getUser()->getCulture(); $cpos = new Criteria(); $cpos->add(SfReviewPeer::VALUE, 1); $cpos->add(SfReviewPeer::IS_ACTIVE, 1); //$cpos->add(SfReviewPeer::CULTURE, $culture); $this->totalUpReviews = SfReviewPeer::doCount($cpos); $cneg = new Criteria(); $cneg->add(SfReviewPeer::VALUE, -1); $cneg->add(SfReviewPeer::IS_ACTIVE, 1); //$cneg->add(SfReviewPeer::CULTURE, $culture); $this->totalDownReviews = SfReviewPeer::doCount($cneg); $exclude = ""; $this->reviewables = EntityManager::getTopEntities(6, $exclude, "WebEntity", true); $c = new Criteria(); $c->addDescendingOrderByColumn(PoliticoPeer::SUMU); $c->addAscendingOrderByColumn(PoliticoPeer::SUMD); $c->setLimit(5); $this->topPoliticos = PoliticoPeer::doSelect($c); $c = new Criteria(); $c->addDescendingOrderByColumn(PartidoPeer::SUMU); $c->addAscendingOrderByColumn(PartidoPeer::SUMD); $c->setLimit(5); $c->add(PartidoPeer::IS_ACTIVE, true); $this->partidosMasVotados = PartidoPeer::doSelect($c); $c = new Criteria(); $c->addDescendingOrderByColumn(PropuestaPeer::SUMU); $c->addAscendingOrderByColumn(PropuestaPeer::SUMD); $c->setLimit(5); $c->add(PropuestaPeer::IS_ACTIVE, true); $c->add(PropuestaPeer::CULTURE, $culture); $this->propuestasMasVotadas = PropuestaPeer::doSelect($c); //Totales /* $c = new Criteria(); $this->totalPoliticos = PoliticoPeer::doCount($c); $c = new Criteria(); $c->add(PartidoPeer::IS_ACTIVE, true); $this->totalPartidos = PartidoPeer::doCount($c); $c = new Criteria(); $c->add(PropuestaPeer::IS_ACTIVE, true); $c->add(PropuestaPeer::CULTURE, $culture); $this->totalPropuestas = PropuestaPeer::doCount($c); */ $this->response->addMeta('Description', sfContext::getInstance()->getI18N()->__('Comparte opiniones sobre políticos y partidos de España. Ranking de los políticos y partidos más votados.')); // Ultimos comentarios $filter = array(); $filter['culture'] = $culture; //$this->topReviews = SfReviewManager::getReviews($filter, 1, 5); $this->activities = SfReviewManager::getActivities($filter, 1, 5); // elecciones destacadas $convocatoriaActiva = sfConfig::get('sf_convocatoria_activa'); $this->convocatoria = ConvocatoriaPeer::retrieveByPk($convocatoriaActiva); }
public function executeUsuarioResult() { $this->quote = ''; if (SfVoUtil::matches($this->obj->getProfile()->getNombre(), $this->q)) { } else { if (SfVoUtil::matches($this->obj->getProfile()->getApellidos(), $this->q)) { } else { if (SfVoUtil::matches($this->obj->getProfile()->getPresentacion(), $this->q)) { $this->quote = $this->obj->getProfile()->getPresentacion(); } } } $c = new Criteria(); $c->add(SfReviewPeer::SF_GUARD_USER_ID, $this->obj->getId()); $c->add(SfReviewPeer::IS_ACTIVE, true); $this->numReviews = SfReviewPeer::doCount($c); $this->quote = SfVoUtil::highlightWords($this->quote, $this->q); }
/** * Returns the number of related SfReview objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related SfReview objects. * @throws PropelException */ public function countSfReviews(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->collSfReviews === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(SfReviewPeer::SF_GUARD_USER_ID, $this->id); $count = SfReviewPeer::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(SfReviewPeer::SF_GUARD_USER_ID, $this->id); if (!isset($this->lastSfReviewCriteria) || !$this->lastSfReviewCriteria->equals($criteria)) { $count = SfReviewPeer::doCount($criteria, false, $con); } else { $count = count($this->collSfReviews); } } else { $count = count($this->collSfReviews); } } return $count; }
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(); } }
public static function countReviews() { $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false; if ($cache) { $key = md5("reviews_counter"); $data = unserialize($cache->get($key)); } else { $data = false; } if (!$data) { //$user = sfContext::getInstance()->getUser(); //$culture = $user->getCulture(); $cpos = new Criteria(); $cpos->add(SfReviewPeer::IS_ACTIVE, 1); //$cpos->add(SfReviewPeer::CULTURE, $culture); $data = SfReviewPeer::doCount($cpos); if ($cache) { $cache->set($key, serialize($data), 360); } } return $data; }
public static function getReviewsCount($filter, $page = 1, $numberOfResults = BaseSfReviewManager::NUM_REVIEWS) { return SfReviewPeer::doCount(self::getReviewsCriteria($filter)); }