public function executeFeed(sfWebRequest $request) { $vanity = $request->getParameter('id'); $s = $request->getParameter('s', 0); $culture = $this->getUser()->getCulture(); $c = new Criteria(); $c->add(PropuestaPeer::VANITY, $vanity); $entity = PropuestaPeer::doSelectOne($c); $this->forward404Unless($entity); if ($entity->getCulture() != $culture) { $this->redirect("@homepage"); } $filter = array(); $filter['type_id'] = Propuesta::NUM_ENTITY; $filter['entity_id'] = $entity->getId(); $reviews = SfReviewManager::getReviews($filter); $title = sfContext::getInstance()->getI18N()->__('%1% en Voota.es', array('%1%' => $entity)); $description = sfContext::getInstance()->getI18N()->__('Opiniones sobre %1%, %2% votos a favor y %3% votos en contra', array('%1%' => $entity, '%2%' => $entity->getSumu(), '%3%' => $entity->getSumd())); $feed = new sfRssFeed(); $feed->setTitle($title); $feed->setLanguage($culture); $feed->setSubtitle($description); $feed->setDescription($description); $feed->setLink('propuesta/show?id=' . $entity->getVanity()); $domainExt = $culture == 'ca' ? "cat" : $culture; $feed->setAuthorName("Voota.{$domainExt}"); $feedImage = new sfFeedImage(); $feedImage->setLink('propuesta/show?id=' . $entity->getVanity()); $feedImage->setImage(S3Voota::getImagesUrl() . '/' . $entity->getImagePath() . '/cc_' . $entity->getImagen()); $feedImage->setTitle($entity); $feed->setImage($feedImage); foreach ($reviews as $review) { $item = new sfFeedItem(); $item->setTitle(sfContext::getInstance()->getI18N()->__('%1%, voota %2%.', array('%1%' => $review->getSfGuardUser(), '%2%' => $review->getValue() == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor')))); $item->setLink('sfReviewFront/show?id=' . SfVoUtil::reviewPermalink($review)); $item->setAuthorName($review->getSfGuardUser()); $item->setPubdate($review->getCreatedAt('U')); $item->setUniqueId($review->getId()); $avatar = S3Voota::getImagesUrl() . '/usuarios/cc_s_' . $review->getSfGuardUser()->getProfile()->getImagen(); $text = $culture == $review->getCulture() || !$review->getCulture() ? $review->getText() : ''; $img = $review->getSfGuardUser()->getProfile()->getImagen() ? "<img src=\"{$avatar}\" alt =\"" . $review->getSfGuardUser() . "\" /> " : ""; $content = "{$text}"; $item->setDescription($content); $feed->addItem($item); } $this->feed = $feed; }
public function executeActivities() { $this->page = $this->page ? $this->page : 1; sfContext::getInstance()->getRequest()->setAttribute('page', $this->page); $filter = array(); if (isset($this->sfReviewType)) { $filter['type_id'] = $this->sfReviewType; } if (isset($this->entityId)) { $filter['entity_id'] = $this->entityId; } if (isset($this->value)) { $filter['value'] = $this->value; } if (isset($this->filter)) { $filter['textFilter'] = $this->filter; } if (isset($this->userId)) { $filter['userId'] = $this->userId; } if (isset($this->culture)) { $filter['culture'] = $this->culture; } $sfr_status = sfContext::getInstance()->getRequest()->getAttribute('sfr_status', false); $this->count = SfReviewManager::getActivitiesCount($filter); $this->activities = SfReviewManager::getActivities($filter, $this->page, 20 * ($sfr_status && !$sfr_status['t'] ? $sfr_status['pag'] : 1)); }
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 executeDelete(sfWebRequest $request) { $id = $request->getParameter('id'); SfReviewManager::deleteReview(1, $id); $criteria = new Criteria(); $criteria->add(PartidoInstitucionPeer::PARTIDO_ID, $id); PartidoInstitucionPeer::doDelete($criteria); $criteria = new Criteria(); $criteria->add(EnlacePeer::PARTIDO_ID, $id); EnlacePeer::doDelete($criteria); parent::executeDelete($request); }
public function executeSubreviews() { if (!isset($this->showCount)) { $this->showCount = SfReviewManager::NUM_REVIEWS; } /* $this->reviewLastList = SfReviewManager::getLastReviewsByEntityAndValue(false, $this->type_id, $this->id, null, SfReviewManager::NUM_LAST_REVIEWS); $exclude = array(); foreach ($this->reviewLastList->getResults() as $result){ $exclude[] = $result->getId(); } */ $this->reviewList = SfReviewManager::getReviewsByEntityAndValue(false, $this->type_id, $this->id, null, $this->showCount); //$this->positiveCount = SfReviewManager::getTotalReviewsByEntityAndValue('', $this->id, 1); //$this->negativeCount = SfReviewManager::getTotalReviewsByEntityAndValue('', $this->id, -1); $this->total = $this->reviewList->getNbResults(); // + $this->reviewList->getNbResults(); $this->seeMoreCount = 0; if ($this->total > $this->showCount) { $this->seeMoreCount = $this->total - $this->showCount > 10 ? $this->showCount + 10 : $this->total; } $this->review_c = $this->getUser()->getAttribute('review_c'); }
public function executeQuickvote(sfWebRequest $request) { $typeId = $request->getParameter("t", false); $entityId = $request->getParameter("e", false); $value = $request->getParameter("v", false); $rm = $request->getParameter("rm", false); $this->review = false; $type = SfReviewTypePeer::retrieveByPk($typeId); if ($type) { $peer = $type->getModel() . 'Peer'; $this->entity = $peer::retrieveByPK($entityId); } try { $this->review = SfReviewManager::postReview($this->getUser()->getGuardUser()->getId(), $typeId, $entityId, $value, false, $this->entity, $rm, 0, 'quick'); } catch (Exception $e) { echo "fail:" . $e->getMessage(); } }
public function getNegatives() { return SfReviewManager::getTotalReviewsByEntityAndValue(Politico::NUM_ENTITY, $this->getId(), -1); }
public function executeMore(sfWebRequest $request) { $vanity = $request->getParameter('username'); $culture = $this->getUser()->getCulture(); $this->page = $request->getParameter("page"); if ($this->page) { $this->page += 1; } else { $this->page = 1; } $c = new Criteria(); $c->add(SfGuardUserProfilePeer::VANITY, $vanity, Criteria::EQUAL); $userProfile = SfGuardUserProfilePeer::doSelectOne($c); $this->forward404Unless($userProfile); $this->user = $userProfile->getsfGuardUser(); /* $criteria = new Criteria(); $criteria->add(SfReviewPeer::IS_ACTIVE, true); //$criteria->add(SfReviewPeer::CULTURE, $culture); $criteria->add(SfReviewPeer::SF_GUARD_USER_ID , $this->user->getId()); $criteria->addDescendingOrderByColumn("IFNULL(".SfReviewPeer::MODIFIED_AT.",".SfReviewPeer::CREATED_AT.")"); $this->reviews = new sfPropelPager('SfReview', BaseSfReviewManager::NUM_REVIEWS); $this->reviews->setCriteria($criteria); if ($this->page) { $this->page += 1; $this->reviews->setPage( $this->page ); } else { $this->page = 1; } $this->reviews->init(); */ $this->reviews = SfReviewManager::getReviewsByUser($this->user->getId(), $this->f, $this->page ? $this->page : 1); }
private function post_review($data) { try { $userId = oauthSecurityManager::checkAuthorized(); } catch (Exception $e) { throw new NotAuthorizedException($e->getMessage()); } $entityId = $this->getRequestParameter("entity"); $value = $this->getRequestParameter("value"); $text = $this->getRequestParameter("text", false); $type = $this->getRequestParameter("type"); $key = oauthSecurityManager::getConsummerKey(); if (!$entityId || !$value || !$type) { throw new BadRequestException("Not enough parameters."); } if ($value != -1 && $value != 1) { throw new BadRequestException("Invalid data for 'value'."); } $typeId = -1; switch ($type) { case 'politician': $typeId = Politico::NUM_ENTITY; $entity = PoliticoPeer::retrieveByPK($entityId); break; case 'party': $typeId = Partido::NUM_ENTITY; $entity = PartidoPeer::retrieveByPK($entityId); break; case 'proposal': $typeId = Propuesta::NUM_ENTITY; $entity = PropuestaPeer::retrieveByPK($entityId); break; default: throw new BadRequestException('Invalid type.'); } try { $this->review = SfReviewManager::postReview($userId, $typeId, $entityId, $value, $text, $entity, false, 0, $key); } catch (Exception $e) { throw new Exception($e->getMessage()); } return "saved."; }
public function executeFeed(sfWebRequest $request) { $this->page = $request->getParameter("page", "1"); $this->entityId = $request->getParameter("entityId", false); $this->value = $request->getParameter("value", false); $this->sfReviewType = $request->getParameter("type_id", false); $this->text = $request->getParameter("t", false); $this->entity = false; $this->filter = false; $culture = $this->getUser()->getCulture(); $filter = array(); //$filter['culture'] = $culture; if ($this->sfReviewType) { $filter['type_id'] = $this->sfReviewType; } if ($this->text) { $filter['textFilter'] = 'text'; } $reviewsPager = SfReviewManager::getReviews($filter); $str = ''; switch ($this->sfReviewType) { case 1: $str = sfContext::getInstance()->getI18N()->__("políticos"); break; case 2: $str = sfContext::getInstance()->getI18N()->__("partidos"); break; case 3: $str = sfContext::getInstance()->getI18N()->__("propuestas"); break; case "null": $str = sfContext::getInstance()->getI18N()->__("respuestas a otros comentarios"); break; } $title = sfContext::getInstance()->getI18N()->__("Últimas opiniones%1% en Voota.", array('%1%' => $str ? " " . sfContext::getInstance()->getI18N()->__("sobre") . " {$str}" : "")); $reviews = $reviewsPager->getResults(); $description = ($reviews[0]->getAnonymous() ? sfContext::getInstance()->getI18N()->__('anónimo') : (trim($reviews[0]->getSfGuardUser()) ? $reviews[0]->getSfGuardUser() : $reviews[0]->getSfGuardUser()->getProfile())) . " (" . ago(strtotime($reviews[0]->getModifiedAt() ? $reviews[0]->getModifiedAt() : $reviews[0]->getCreatedAt())) . "), " . ($reviews[1]->getAnonymous() ? sfContext::getInstance()->getI18N()->__('anónimo') : (trim($reviews[1]->getSfGuardUser()) ? $reviews[1]->getSfGuardUser() : $reviews[1]->getSfGuardUser()->getProfile())) . " (" . ago(strtotime($reviews[1]->getModifiedAt() ? $reviews[1]->getModifiedAt() : $reviews[1]->getCreatedAt())) . "), " . ($reviews[2]->getAnonymous() ? sfContext::getInstance()->getI18N()->__('anónimo') : (trim($reviews[2]->getSfGuardUser()) ? $reviews[2]->getSfGuardUser() : $reviews[2]->getSfGuardUser()->getProfile())) . " (" . ago(strtotime($reviews[2]->getModifiedAt() ? $reviews[2]->getModifiedAt() : $reviews[2]->getCreatedAt())) . "), " . "..."; $feed = new sfRssFeed(); $feed->setTitle($title); $feed->setLanguage($culture); $feed->setSubtitle($description); $feed->setDescription($description); $params = ""; if ($this->sfReviewType) { $params .= ($params ? '&' : '?') . 'type_id=' . $this->sfReviewType; } if ($this->text) { $params .= ($params ? '&' : '?') . 't=' . $this->text; } $feed->setLink("sfReviewFront/feed{$params}"); $domainExt = $culture == 'ca' ? "cat" : $culture; $feed->setAuthorName("Voota.{$domainExt}"); foreach ($reviews as $review) { $item = new sfFeedItem(); $entityText = ""; if (!$review->getSfReviewType()) { $tmpReview = $review->getSfReviewRelatedBySfReviewId(); $entityText = sfContext::getInstance()->getI18N()->__('otra opinión sobre') . ' '; } else { $tmpReview = $review; } $sfReviewType = SfReviewTypePeer::retrieveByPk($tmpReview->getSfReviewTypeId()); $peer = $sfReviewType->getModel() . 'Peer'; $entity = $peer::retrieveByPk($tmpReview->getEntityId()); $entityText .= $entity; $item->setTitle(sfContext::getInstance()->getI18N()->__('%1%, voota %2% de %3%.', array('%1%' => $review->getAnonymous() ? sfContext::getInstance()->getI18N()->__('anónimo') : $review->getSfGuardUser(), '%2%' => $review->getValue() == -1 ? sfContext::getInstance()->getI18N()->__('en contra') : sfContext::getInstance()->getI18N()->__('a favor'), '%3%' => $entityText))); $item->setLink('sfReviewFront/show?id=' . SfVoUtil::reviewPermalink($review)); if (!$review->getAnonymous()) { $item->setAuthorName($review->getSfGuardUser()); } $item->setPubdate($review->getCreatedAt('U')); $item->setUniqueId($review->getId()); if (!$review->getAnonymous()) { $avatar = S3Voota::getImagesUrl() . '/usuarios/cc_s_' . $review->getSfGuardUser()->getProfile()->getImagen(); } $text = $culture == $review->getCulture() || !$review->getCulture() ? $review->getText() : ''; if (!$review->getAnonymous()) { $img = $review->getSfGuardUser()->getProfile()->getImagen() ? "<img src=\"{$avatar}\" alt =\"" . $review->getSfGuardUser() . "\" /> " : ""; } $content = "{$text}"; $item->setDescription($content); $feed->addItem($item); } $this->feed = $feed; }
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 postReview($userId, $typeId, $entityId, $value, $text = false, $entity = false, $rm = false, $fb = '?', $source = '', $anonymous = '?', $tw = '?') { $prevValue = false; $guessAnonymous = $anonymous && $anonymous == '?' ? true : false; $guessFB = $fb && $fb == '?' ? true : false; $guessTW = $tw && $tw == '?' ? true : false; if ($guessAnonymous) { $user = sfGuardUserPeer::retrieveByPK($userId); if ($user) { $anonymous = $user->getProfile()->getAnonymous(); } } if (!$entityId || !$value) { throw new Exception("Not enough parameters."); } if ($value != -1 && $value != 1) { throw new Exception("Invalid data for 'value'."); } // Check if already exists $c = new Criteria(); if (!$typeId) { $c->add(SfReviewPeer::SF_REVIEW_ID, $entityId); } else { $c->add(SfReviewPeer::ENTITY_ID, $entityId); } $c->add(SfReviewPeer::SF_GUARD_USER_ID, $userId); $c->add(SfReviewPeer::SF_REVIEW_TYPE_ID, $typeId ? $typeId : null); $review = SfReviewPeer::doSelectOne($c); if (!$review) { $review = new SfReview(); if (!$typeId) { $review->setSfReviewId($entityId); } else { $review->setEntityId($entityId); } $review->setSfReviewTypeId($typeId ? $typeId : null); $review->setSfGuardUserId($userId); $review->setCreatedAt(new DateTime()); $review->setSource($source); } else { if ($rm && $value == $review->getValue() && $review->getIsActive()) { $review->setIsActive(false); } else { $review->setIsActive(true); } $review->setModifiedAt(new DateTime()); } $review->setValue($value); if ($text) { $aText = SfVoUtil::cutToLength($text, self::MAX_LENGTH, ''); $aText = strip_tags($aText); $review->setText($aText); } $review->setSfReviewStatusId(1); $review->setIpAddress($_SERVER['REMOTE_ADDR']); $review->setCookie(sfContext::getInstance()->getRequest()->getCookie('symfony')); $review->setCulture(sfContext::getInstance()->getUser()->getCulture()); if (!$guessFB) { $review->setToFb($fb); } if (!$guessTW) { $review->setToTw($tw); } if (!$guessAnonymous || $review->isNew()) { $review->setAnonymous($anonymous); } try { $review->save(); if (!$typeId) { $parentReview = SfReviewPeer::retrieveByPk($entityId); $parentReview->setBalance(SfReviewManager::getBalanceByReviewId($entityId)); $parentReview->save(); } if (!$entity) { if (!$typeId) { $aEntityId = $parentReview->getEntityId(); $aTypeId = $parentReview->getSfReviewTypeId(); } else { $aTypeId = $typeId; $aEntityId = $entityId; } $reviewType = SfReviewTypePeer::retrieveByPK($aTypeId); $peer = $reviewType->getModel() . 'Peer'; $entity = $peer::retrieveByPK($aEntityId); } $entity->updateCalcs(); $entity->save(); } catch (Exception $e) { throw new Exception('Error writing review.'); } return $review->getIsActive() ? $review : false; }