示例#1
0
 public function executeRanking(sfWebRequest $request)
 {
     $p = $request->getParameter("p");
     $i = $request->getParameter("i");
     $culture = $this->getUser()->getCulture("es");
     $partido = $request->getParameter("partido", false);
     $institucion = $request->getParameter("institucion", false);
     $redir = false;
     if ($institucion === ALL_FORM_VALUE) {
         $redir = true;
         $institucion = false;
     }
     $page = $request->getParameter("page", "");
     $order = $request->getParameter("o", "");
     $this->forward404Unless(!($order && $order != 'pd' && $order != 'pa' && $order != 'nd' && $order != 'na'));
     if ($order == 'pd' || $page == '1' || !$institucion && $partido == ALL_URL_STRING) {
         $qs = '';
         foreach ($request->getParameterHolder()->getAll() as $key => $value) {
             if ($key != 'module' && $key != 'action' && !($order == 'pd' && $key == 'o' || $page == '1' && $key == 'page') && ($key != 'partido' || ($institucion || $partido != ALL_URL_STRING))) {
                 $qs .= ($qs ? '&' : '?') . "{$key}={$value}";
             }
         }
         $this->redirect("politico/ranking{$qs}", 301);
     }
     $this->order = $order ? $order : 'pd';
     $page = $page ? $page : 1;
     if (!$partido) {
         $partido = ALL_FORM_VALUE;
     }
     if (!$institucion) {
         $institucion = ALL_FORM_VALUE;
     }
     $this->partido = ALL_FORM_VALUE;
     $this->institucion = ALL_FORM_VALUE;
     if ($p != '' || $i != '' || $redir) {
         $url = $this->generateRankingUrl($partido, $institucion, $p, $i, $page);
         $this->redirect($url);
     }
     $this->partidoAC = '';
     if ($partido && $partido != ALL_URL_STRING) {
         $this->partido = $partido;
         $aPartidoCriteria = new Criteria();
         $aPartidoCriteria->add(PartidoPeer::ABREVIATURA, $this->partido);
         $aaPartido = PartidoPeer::doSelectOne($aPartidoCriteria);
         $this->forward404Unless($aaPartido);
         $this->partidoAC = $aaPartido->getAbreviatura() . ', ' . $aaPartido->getNombre();
     } else {
         $this->partido = ALL_URL_STRING;
     }
     $this->institucionAC = '';
     if ($institucion && $institucion != ALL_URL_STRING) {
         $this->institucion = $institucion;
         $aInstitucionCriteria = new Criteria();
         $aInstitucionCriteria->addJoin(array(InstitucionPeer::ID, InstitucionI18nPeer::CULTURE), array(InstitucionI18nPeer::ID, "'{$culture}'"), Criteria::INNER_JOIN);
         $aInstitucionCriteria->add(InstitucionI18nPeer::VANITY, $this->institucion);
         $aInstitucion = InstitucionPeer::doSelectOne($aInstitucionCriteria);
         $this->forward404Unless($aInstitucion);
         if ($aInstitucion->getVanity() != $institucion) {
             $url = $this->generateRankingUrl($partido, $aInstitucion->getVanity());
             $params = $request->getParameterHolder()->getAll();
             foreach ($params as $key => $value) {
                 if ($key != 'module' && $key != 'action' && $key != 'partido' && $key != 'institucion') {
                     $url .= "&{$key}={$value}";
                 }
             }
             $this->redirect($url, 301);
         }
         $this->institucionAC = $aInstitucion->getNombre();
     }
     $filter = array('type' => 'politico', 'partido' => $partido, 'institucion' => $institucion, 'culture' => $culture, 'page' => $page, 'order' => $this->order);
     $this->getUser()->setAttribute("filter_" . Politico::NUM_ENTITY, $filter);
     $this->politicosPager = EntityManager::getPoliticos($partido, $institucion, $culture, $page, $this->order, EntityManager::PAGE_SIZE, &$totalUp, &$totalDown);
     $this->totalUp = $totalUp;
     $this->totalDown = $totalDown;
     $rule = sfContext::getInstance()->getRouting()->getCurrentRouteName();
     $params = "";
     foreach ($request->getParameterHolder()->getAll() as $name => $value) {
         if ($name != 'module' && $name != 'action' && $name != 'o' && $name != 'page') {
             if ($params === "") {
                 $params .= "?";
             } else {
                 $params .= "&";
             }
             $params .= "{$name}={$value}";
         }
     }
     $this->route = "politico/ranking{$params}";
     $this->pageTitle = sfContext::getInstance()->getI18N()->__('Ranking de políticos', array());
     $this->pageTitle .= $this->partido == 'all' ? '' : ', ' . $this->partido;
     $this->pageTitle .= $this->institucion == '0' ? '' : ", ";
     if (isset($aInstitucion)) {
         $this->pageTitle .= $aInstitucion->getNombre();
     }
     switch ($this->order) {
         case 'pa':
             $orderTxt = sfContext::getInstance()->getI18N()->__('votos positivos inverso');
             break;
         case 'nd':
             $orderTxt = sfContext::getInstance()->getI18N()->__('votos negativos');
             break;
         case 'na':
             $orderTxt = sfContext::getInstance()->getI18N()->__('votos negativos inverso');
             break;
         default:
             $orderTxt = sfContext::getInstance()->getI18N()->__('ordenado por votos positivos inverso');
     }
     if ($this->order != 'pd') {
         $this->pageTitle .= ", {$orderTxt}";
     }
     if ($page && $page != 1) {
         $this->pageTitle .= " " . sfContext::getInstance()->getI18N()->__('(Pág. %1%)', array('%1%' => $page));
     }
     $this->title = $this->pageTitle . ' - Voota';
     $description = sfContext::getInstance()->getI18N()->__('Ranking de políticos', array());
     if (isset($aaPartido)) {
         if ($this->partido != '0' && $aaPartido) {
             $description .= ", " . $aaPartido->getNombre();
         }
     } else {
         $description .= ", " . sfContext::getInstance()->getI18N()->__('todos los partidos');
     }
     if ($aInstitucion && $aInstitucion->getGeo() && $this->institucion != '0') {
         $description .= ", " . $aInstitucion->getNombre() . " (" . $aInstitucion->getGeo()->getNombre() . ", España)";
     }
     $description .= ", {$orderTxt}";
     if ($page && $page != 1) {
         $description .= " " . sfContext::getInstance()->getI18N()->__('(Pág. %1%)', array('%1%' => $page));
     }
     $this->response->addMeta('Description', $description);
     $this->response->setTitle($this->title);
 }
示例#2
0
 public function executeRanking(sfWebRequest $request)
 {
     $culture = sfContext::getInstance()->getUser()->getCulture('es');
     $institucion = $request->getParameter("institucion");
     $i = $request->getParameter("i");
     $page = $request->getParameter("page", "");
     $order = $request->getParameter("o", "");
     if ($order == 'pd' || $page == '1') {
         $qs = '';
         foreach ($request->getParameterHolder()->getAll() as $key => $value) {
             if ($key != 'module' && $key != 'action' && !($order == 'pd' && $key == 'o' || $page == '1' && $key == 'page')) {
                 $qs .= ($qs ? '&' : '?') . "{$key}={$value}";
             }
         }
         $this->redirect("politico/ranking{$qs}", 301);
     }
     if ($i != '') {
         $url = $this->generateRankingUrl($institucion, $i);
         $this->redirect($url);
     }
     $this->order = $order ? $order : 'pd';
     $page = $page ? $page : 1;
     $filter = array('type' => 'partido', 'partido' => false, 'institucion' => $institucion, 'culture' => $culture, 'page' => $page, 'order' => $this->order);
     $this->getUser()->setAttribute("filter_" . Partido::NUM_ENTITY, $filter);
     $this->partidosPager = EntityManager::getPartidos($institucion, $culture, $page, $this->order, EntityManager::PAGE_SIZE, &$totalUp, &$totalDown);
     $this->totalUp = $totalUp;
     $this->totalDown = $totalDown;
     $this->institucion = $institucion;
     $this->institucionAC = '';
     if ($institucion) {
         $aInstitucionCriteria = new Criteria();
         $aInstitucionCriteria->addJoin(array(InstitucionPeer::ID, InstitucionI18nPeer::CULTURE), array(InstitucionI18nPeer::ID, "'{$culture}'"), Criteria::INNER_JOIN);
         $aInstitucionCriteria->add(InstitucionI18nPeer::VANITY, $this->institucion);
         $aInstitucion = InstitucionPeer::doSelectOne($aInstitucionCriteria);
         $this->forward404Unless($aInstitucion);
         if ($aInstitucion->getVanity() != $institucion) {
             $url = $this->generateRankingUrl($aInstitucion->getVanity());
             $params = $request->getParameterHolder()->getAll();
             foreach ($params as $key => $value) {
                 if ($key != 'module' && $key != 'action' && $key != 'partido' && $key != 'institucion') {
                     $url .= "&{$key}={$value}";
                 }
             }
             $this->redirect($url, 301);
         }
         $this->institucionAC = $aInstitucion->getNombre();
     }
     /* Lista de instituciones 
       	$c = new Criteria();
       	$c->addAscendingOrderByColumn(InstitucionPeer::ORDEN);
       	$c->add(InstitucionPeer::IS_MAIN, true);
       	$this->instituciones = InstitucionPeer::doSelect($c);
       	  Fin Lista de instituciones */
     //$rule = sfContext::getInstance()->getRouting()->getCurrentRouteName();
     $params = "";
     foreach ($request->getParameterHolder()->getAll() as $name => $value) {
         if ($name != 'module' && $name != 'action' && $name != 'o' && $name != 'page') {
             if ($params === "") {
                 $params .= "?";
             } else {
                 $params .= "&";
             }
             $params .= "{$name}={$value}";
         }
     }
     $this->route = "partido/ranking{$params}";
     $this->pageTitle = sfContext::getInstance()->getI18N()->__('Ranking de partidos', array());
     $this->pageTitle .= !$this->institucion || $this->institucion == '0' || !isset($aInstitucion) ? '' : ", " . $aInstitucion->getNombre();
     if ($this->order && $this->order != 'pd') {
         switch ($this->order) {
             case 'pa':
                 $orderTxt = sfContext::getInstance()->getI18N()->__('votos positivos inverso');
                 break;
             case 'nd':
                 $orderTxt = sfContext::getInstance()->getI18N()->__('votos negativos');
                 break;
             case 'na':
                 $orderTxt = sfContext::getInstance()->getI18N()->__('votos negativos inverso');
                 break;
         }
         $this->pageTitle .= ", {$orderTxt}";
     }
     if ($page && $page != 1) {
         $this->pageTitle .= " " . sfContext::getInstance()->getI18N()->__('(Pág. %1%)', array('%1%' => $page));
     }
     $this->title = $this->pageTitle . ' - Voota';
     $this->response->addMeta('Title', $this->title);
     $description = sfContext::getInstance()->getI18N()->__('Los partidos más votados en Voota');
     $description .= !$this->institucion || $this->institucion == '0' || !isset($aInstitucion) ? '' : ", " . $aInstitucion->getNombre();
     $description .= ': ';
     if ($this->partidosPager->getNbResults() > 0) {
         foreach ($this->partidosPager->getResults() as $idx => $partido) {
             if ($idx < 5) {
                 $description .= ($idx == 0 ? "" : ", ") . $partido->getAbreviatura();
             }
         }
     }
     if ($this->partidosPager->getNbResults() > 5) {
         $description .= ', ...';
     }
     if ($this->order != 'pd') {
         $description .= ", {$orderTxt}";
     }
     if ($page && $page != 1) {
         $description .= " " . sfContext::getInstance()->getI18N()->__('(Pág. %1%)', array('%1%' => $page));
     }
     $this->response->addMeta('Description', $description);
 }
示例#3
0
function changeCulture($culture)
{
    $extensions = array('es' => 'es', 'ca' => 'cat');
    $sf_context = sfContext::getInstance();
    $request = $sf_context->getRequest();
    $module = $request->getParameter('module');
    $action = $request->getParameter('action');
    $parameters = $request->getParameterHolder()->getAll();
    $curCulture = $sf_context->getUser()->getCulture('es');
    $routeName = $sf_context->getRouting()->getCurrentRouteName();
    $routeName = preg_replace("/_{$curCulture}\$/", "_{$culture}", $routeName);
    $params = "";
    foreach ($parameters as $name => $value) {
        if ($name != 'module' && $name != 'action') {
            if ($name == 'institucion') {
                $c = new Criteria();
                $c->addJoin(InstitucionPeer::ID, InstitucionI18nPeer::ID);
                $c->addJoin(array(InstitucionPeer::ID, InstitucionI18nPeer::CULTURE), array(InstitucionI18nPeer::ID, "'{$curCulture}'"), Criteria::INNER_JOIN);
                $c->add(InstitucionI18nPeer::VANITY, $value);
                $aInstitucion = InstitucionPeer::doSelectOne($c);
                if ($aInstitucion) {
                    $value = $aInstitucion->getVanity($culture);
                }
            }
            if ($module == 'sfReviewFront' && $action == 'show' && $name == 'id') {
                $review = SfReviewPeer::retrieveByPk($request->getParameter('id'));
                $value = SfVoUtil::reviewPermalink($review, $culture);
            }
            $params .= ($params == "" ? '?' : '&') . "{$name}={$value}";
        }
    }
    $route = sfContext::getInstance()->getController()->genUrl("@{$routeName}{$params}");
    $host = preg_replace("/\\.[a-zA-Z]*\$/is", "." . $extensions[$culture], $_SERVER['HTTP_HOST']);
    return "http://{$host}{$route}";
}