public function executeInteressi()
 {
     $this->session = $this->getUser();
     $this->ramo = $this->getRequestParameter('ramo', 'C');
     if ($this->hasRequestParameter('triple_value')) {
         $triple_value = $this->getRequestParameter('triple_value');
         $this->tags_ids = TagPeer::getIdsFromTagsValues($triple_value);
         //array(TagPeer::retrieveFirstByTripleValue($triple_value));
     } else {
         $this->tags = trim(strip_tags($this->getRequestParameter('tag_search', '')), " ,");
         sfContext::getInstance()->getLogger()->info('{interessi}' . $this->tags);
         $this->tags_ids = TagPeer::getIdsFromTagsValues($this->tags);
     }
     $limit = null;
     if ($this->hasRequestParameter('limit')) {
         $limit = $this->getRequestParameter('limit');
     }
     // la data è passata come parametro o viene estratta l'ultima nella cache (per dati di tipo 'A', singoli atti)
     if ($this->hasRequestParameter('data')) {
         $data = $this->getRequestParameter('data');
     } else {
         $data = OppActHistoryCachePeer::fetchLastData();
     }
     if (is_array($this->tags_ids) && count($this->tags_ids)) {
         $this->politici = OppCaricaPeer::getClassificaPoliticiSiOccupanoDiArgomenti($this->tags_ids, $this->ramo, $data, $limit);
     }
 }
 protected function impactFactorCSV($ramo)
 {
     sfLoader::loadHelpers(array('Number'));
     $this->opp_user = OppUserPeer::retrieveByPK($this->getUser()->getId());
     $this->forward404Unless($this->getUser()->hasCredential('adhoc'));
     // get user's monitored tags
     $this->tags_ids = $this->opp_user->getMonitoredPks('Tag');
     $limit = sfConfig::get('app_limit_classifica_parlamentari_sioccupanodi', 15);
     $data_inizio = OppLegislaturaPeer::$legislature[OppLegislaturaPeer::getCurrent()]['data_inizio'];
     $data_fine = OppActHistoryCachePeer::fetchLastData();
     $date = array_reverse(Util::buildCacheDatesArray($data_inizio, $data_fine));
     $politici_csv = array();
     if (count($this->tags_ids)) {
         $this->group_filter = $this->getRequestParameter('group_filter');
         if (is_array($this->group_filter)) {
             $c = new Criteria();
             $c->add(OppGruppoPeer::ID, $this->group_filter, Criteria::IN);
         } else {
             $this->group_filter = array();
         }
         // estrazione classifica dei politici che più si interessano degli argomenti monitorati
         $politici = OppCaricaPeer::getClassificaPoliticiSiOccupanoDiArgomenti($this->tags_ids, $ramo, $data_fine, $limit, $this->group_filter);
         // costruzione delle serie storiche per ogni politico (da inizio legislatura)
         foreach ($politici as $carica_id => $politico) {
             // genero il label
             $label = sprintf("%s %s (%s)", $politico['nome'], $politico['cognome'], $politico['acronimo']);
             // arrotonda l'array dei valori storici a due cifre decimali (max)
             $storico = OppCaricaPeer::getStoricoInteressePoliticoArgomenti($carica_id, $this->tags_ids);
             // calcola la posizione del politico
             $posizione = OppCaricaPeer::getPosizionePoliticoOggettiVotatiPerArgomenti($carica_id, $this->tags_ids, $this->getUser()->getId());
             $posizione = format_number(round($posizione, 2), 'it_IT');
             // primi campi (dati fissi)
             $csv_row = "{$carica_id},\"{$label}\",\"{$posizione}\",";
             foreach ($date as $cnt => $data) {
                 if (array_key_exists($data, $storico)) {
                     $storico[$data] = format_number(round($storico[$data], 2), 'it_IT');
                 } else {
                     $storico[$data] = 0;
                 }
                 $csv_row .= '"' . $storico[$data] . '"';
                 if ($cnt < count($date) - 1) {
                     $csv_row .= ",";
                 }
             }
             $politici_csv[] = $csv_row;
         }
     }
     $this->date_csv = "carica_id,politico,posizione," . implode(",", $date);
     $this->politici_csv = $politici_csv;
     $this->setLayout(false);
     $this->setTemplate('impactFactorCSV');
     $this->response->setContentType('text/csv');
 }
 public function executeListClassificaActionAid()
 {
     $this->ramo = $this->getRequestParameter('ramo');
     $this->argomentis = array('aiuti umanitari' => 6729, 'cooperazione allo sviluppo' => 4653);
     $this->forward404Unless(in_array($this->ramo, array('C', 'S')));
     if ($this->ramo == 'C') {
         $this->tipo_politici = 'dep';
     } else {
         $this->tipo_politici = 'sen';
     }
     if ($this->hasRequestParameter('limit')) {
         $limit = $this->getRequestParameter('limit');
     }
     // la data è passata come parametro o viene estratta l'ultima nella cache (per dati di tipo 'A', singoli atti)
     if ($this->hasRequestParameter('data')) {
         $data = $this->getRequestParameter('data');
     } else {
         $data = OppActHistoryCachePeer::fetchLastData();
     }
     $this->politici = OppCaricaPeer::getClassificaPoliticiSiOccupanoDiArgomenti(array_values($this->argomentis), $this->ramo, $data);
 }