public function executeAttivitaGruppoArgomento()
 {
     // parametri obbligatori
     $this->ramo = $this->getRequestParameter('ramo');
     $gruppo_id = $this->getRequestParameter('gruppo_id');
     // parametri opzionali
     if ($this->hasRequestParameter('triple_value')) {
         $triple_value = $this->getRequestParameter('triple_value');
         $this->argomento = TagPeer::retrieveFirstByTripleValue($triple_value);
     }
     if ($this->hasRequestParameter('tag_name')) {
         $this->tag_name = $this->getRequestParameter('tag_name', '');
         $this->argomento = TagPeer::retrieveByTagName($this->tag_name);
     }
     if ($this->hasRequestParameter('tag_id')) {
         $this->tag_id = $this->getRequestParameter('tag_id', '');
         $this->argomento = TagPeer::retrieveByPK($this->tag_id);
     }
     $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')) {
         $this->data = $this->getRequestParameter('data');
     } else {
         $this->data = OppActHistoryCachePeer::fetchLastData();
     }
     $this->gruppo = OppGruppoPeer::retrieveByPK($gruppo_id);
     $this->forward404Unless($this->gruppo instanceof OppGruppo);
     $this->politici = OppCaricaPeer::getClassificaPoliticiSiOccupanoDiArgomenti(array($this->argomento->getId()), $this->ramo, $this->data, $limit, $gruppo_id, false);
 }
 /**
  * returns the groups in the given ramo (and for the given legislatura) and include the zero value, if given
  *
  * @param string $ramo 
  * @param int    $legislatura
  * @param string $include_zero 
  * @return an associative array, with id and name as key => value
  * @author Guglielmo Celata
  */
 public static function getAllGroups($ramo, $legislatura, $include_zero = false)
 {
     $c = new Criteria();
     if ($ramo == 'camera') {
         $c->add(OppCaricaPeer::TIPO_CARICA_ID, 1);
     } else {
         $c->add(OppCaricaPeer::TIPO_CARICA_ID, array(4, 5), Criteria::IN);
     }
     $c->addJoin(OppGruppoPeer::ID, OppCaricaHasGruppoPeer::GRUPPO_ID);
     $c->addJoin(OppCaricaPeer::ID, OppCaricaHasGruppoPeer::CARICA_ID);
     $c_or_leg = $c->getNewCriterion(OppCaricaPeer::LEGISLATURA, $legislatura);
     $c_or_leg->addOr($c->getNewCriterion(OppCaricaPeer::LEGISLATURA, null, Criteria::ISNULL));
     $c->add($c_or_leg);
     $c->clearSelectColumns();
     $c->addSelectColumn(OppGruppoPeer::ID);
     $c->addSelectColumn(OppGruppoPeer::NOME);
     $c->setDistinct();
     $rs = OppGruppoPeer::doSelectRS($c);
     if ($include_zero) {
         $all_groups = array('0' => $include_zero);
     } else {
         $all_groups = array();
     }
     while ($rs->next()) {
         $all_groups[$rs->getInt(1)] = $rs->getString(2);
     }
     return $all_groups;
 }
 public function getRibelliCount()
 {
     $risultati = OppVotazioneHasCaricaPeer::doSelectGroupByGruppo($this->getId());
     $n = 0;
     foreach ($risultati as $gruppo => $risultato) {
         if ($gruppo != 'Gruppo Misto') {
             $c = new Criteria();
             $c->add(OppGruppoPeer::NOME, $gruppo);
             $gruppo_id = OppGruppoPeer::doSelectOne($c);
             $c = new Criteria();
             $c->add(OppVotazioneHasGruppoPeer::VOTAZIONE_ID, $this->getId());
             $c->add(OppVotazioneHasGruppoPeer::GRUPPO_ID, $gruppo_id->getId());
             $voto_gruppo = OppVotazioneHasGruppoPeer::doSelectOne($c);
             if ($voto_gruppo) {
                 if ($voto_gruppo->getVoto() != 'nv') {
                     unset($risultato['Assente']);
                     unset($risultato['In missione']);
                     arsort($risultato);
                     array_shift($risultato);
                     $n += array_sum($risultato);
                 }
             }
         }
     }
     return $n;
 }
 /**
  * fornisce il gruppo cui la carica appartiene a una certa data
  * se la data non è passata, fornisce il gruppo corrente
  *
  * @param string $date 
  * @return OppGruppo
  * @author Guglielmo Celata
  */
 public function getGruppo($date = '')
 {
     $c = new Criteria();
     $c->addJoin(OppCaricaHasGruppoPeer::GRUPPO_ID, OppGruppoPeer::ID, Criteria::LEFT_JOIN);
     $c->add(OppCaricaHasGruppoPeer::CARICA_ID, $this->getId());
     if ($date == '') {
         $c->add(OppCaricaHasGruppoPeer::DATA_FINE, NULL, Criteria::ISNULL);
     } else {
         $c->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $date, Criteria::LESS_EQUAL);
         $cton0 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, null, Criteria::ISNULL);
         $cton1 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, $date, Criteria::GREATER_THAN);
         $cton0->addOr($cton1);
         $c->add($cton0);
     }
     return OppGruppoPeer::doSelectOne($c);
 }
/**
 * Calcola o ri-calcola i dati aggregati da cachare per i gruppi
 * Si può specificare:
 * - il ramo (camera, senato, governo, parlamento, tutti*)
 * - la data (da inizio legislatura a quella data)
 * Se sono passati degli ID (argomenti), sono interpretati come ID di gruppi e il calcolo è fatto solo per loro
 */
function run_opp_build_cache_gruppi($task, $args, $options)
{
    static $loaded;
    // load application context
    if (!$loaded) {
        task_loader();
        $loaded = true;
    }
    echo "memory usage: " . memory_get_usage() . "\n";
    $msg = sprintf("start time: %s\n", date('H:i:s'));
    echo $msg;
    $data = '';
    $ramo_esteso = 'parlamento';
    $verbose = false;
    if (array_key_exists('data', $options)) {
        $data = $options['data'];
    }
    if (array_key_exists('ramo', $options)) {
        $ramo_esteso = $options['ramo'];
    }
    if (array_key_exists('verbose', $options)) {
        $verbose = true;
    }
    // definisce la data fino alla quale vanno fatti i calcoli
    // data_lookup serve per controllare se i record già esistono
    if ($data != '') {
        $legislatura_corrente = OppLegislaturaPeer::getCurrent($data);
        $data_lookup = $data;
    } else {
        $legislatura_corrente = OppLegislaturaPeer::getCurrent();
        $data = date('Y-m-d');
        $data_lookup = OppPoliticianHistoryCachePeer::fetchLastData('G');
    }
    // costruisce array di rami a partire da ramo esteso
    switch ($ramo_esteso) {
        case 'parlamento':
        case 'tutti':
            $rami = array('C', 'S');
            break;
        case 'camera':
            $rami = array('C');
            break;
        case 'senato':
            $rami = array('S');
            break;
        default:
            $rami = array();
            break;
    }
    foreach ($rami as $ramo) {
        $msg = sprintf("calcolo aggregazione per gruppi - data: %s, ramo: %s\n", $data, $ramo);
        echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
        if (count($args) > 0) {
            try {
                $gruppi_rs = OppGruppoPeer::getRSFromIDArray($args);
            } catch (Exception $e) {
                throw new Exception("Specificare degli ID validi. \n" . $e);
            }
        } else {
            $gruppi_rs = OppGruppoPeer::getGruppiRamoDataRS($ramo, $data);
        }
        $cnt = 0;
        while ($gruppi_rs->next()) {
            $cnt++;
            $g = $gruppi_rs->getRow();
            $nome = $g['nome'];
            $acronimo = $g['acronimo'];
            $id = $g['id'];
            printf("%4d) %30s (%10s) [%6d] ... ", $cnt, $nome, $acronimo, $id);
            $numero = OppPoliticianHistoryCachePeer::countRecordsGruppoRamoData($id, $ramo, $data);
            if ($numero > 0) {
                $dati = OppPoliticianHistoryCachePeer::aggregaDatiGruppoRamoData($id, $ramo, $data);
                // inserimento o aggiornamento del valore in opp_politician_history_cache
                $cache_record = OppPoliticianHistoryCachePeer::retrieveByDataChiTipoChiIdRamo($data_lookup, 'G', $id, $ramo);
                if (!$cache_record) {
                    $cache_record = new OppPoliticianHistoryCache();
                }
                $cache_record->setLegislatura($legislatura_corrente);
                $cache_record->setChiTipo('G');
                $cache_record->setChiId($id);
                $cache_record->setRamo($ramo);
                $cache_record->setGruppoId($id);
                // ridondante, ma ok
                $cache_record->setIndice($dati['indice']);
                $cache_record->setPresenze($dati['presenze']);
                $cache_record->setAssenze($dati['assenze']);
                $cache_record->setMissioni($dati['missioni']);
                $cache_record->setRibellioni($dati['ribellioni']);
                $cache_record->setData($data);
                $cache_record->setNumero($numero);
                // serve per ricostruire la somma aggregata
                $cache_record->setUpdatedAt(date('Y-m-d H:i'));
                // forza riscrittura updated_at, per tenere traccia esecuzioni
                $cache_record->save();
                unset($cache_record);
                $msg = sprintf("i: %7.2f  p:%7.2f  a:%7.2f  m:%7.2f   r:%7.2f (su %d membri)", $dati['indice'], $dati['presenze'], $dati['assenze'], $dati['missioni'], $dati['ribellioni'], $numero);
                echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
            } else {
                $msg = sprintf("nessun dato da aggregare!");
                echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
            }
            echo "\n";
        }
    }
    $msg = sprintf("end time: %s\n", date('H:i:s'));
    echo $msg;
    $msg = sprintf("memory usage: %10d\n", memory_get_usage());
    echo pakeColor::colorize($msg, array('fg' => 'red', 'bold' => false));
}
<?php

define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', true);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
print "Fetching data... \n";
$cariche = OppCaricaPeer::doSelect(new Criteria());
foreach ($cariche as $carica) {
    $c = new Criteria();
    $c->add(OppGruppoPeer::NOME, $carica->getGruppo(), Criteria::EQUAL);
    $gruppo = OppGruppoPeer::doSelectOne($c);
    if ($gruppo != null) {
        $carica_gruppo = new OppCaricaHasGruppo();
        $carica_gruppo->setCaricaId($carica->getId());
        $carica_gruppo->setGruppoId($gruppo->getId());
        $carica_gruppo->setDataInizio($carica->getDataInizio());
        $carica_gruppo->setDataFine($carica->getDataFine());
        $carica_gruppo->save();
    } else {
        echo "carica {$carica->getId}() gruppo non trovato\n";
    }
}
print "done.\n";
 if ($votazione) {
     $c = new Criteria();
     $c->add(OppSedutaPeer::ID, $votazione->getSedutaId(), Criteria::EQUAL);
     $seduta = OppSedutaPeer::doSelectOne($c);
     $c = new Criteria();
     $crit0 = $c->getNewCriterion(OppGruppoRamoPeer::RAMO, $seduta->getRamo());
     $crit1 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_INIZIO, $seduta->getData(), Criteria::LESS_EQUAL);
     $crit2 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_FINE, $seduta->getData(), Criteria::GREATER_THAN);
     $crit3 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_FINE, NULL, Criteria::ISNULL);
     $crit2->addOr($crit3);
     $crit0->addAnd($crit1);
     $crit0->addAnd($crit2);
     $c->add($crit0);
     $gruppi_votazione = OppGruppoRamoPeer::doSelect($c);
     foreach ($gruppi_votazione as $gruppo) {
         $gr = OppGruppoPeer::retrieveByPk($gruppo->getGruppoId());
         $voto_gruppo = OppVotazionePeer::doSelectVotoGruppo($votazione->getId(), $gr->getNome());
         $c = new Criteria();
         $c->add(OppVotazioneHasGruppoPeer::VOTAZIONE_ID, $votazione->getId());
         $c->add(OppVotazioneHasGruppoPeer::GRUPPO_ID, $gr->getId());
         $result = OppVotazioneHasGruppoPeer::doSelectOne($c);
         if ($result) {
             $result->setVoto($voto_gruppo);
             $result->save();
             print $gr->getNome() . ": " . $voto_gruppo . "\n";
         } else {
             $insert = new OppVotazioneHasGruppo();
             $insert->setVotazioneId($votazione->getId());
             $insert->setGruppoId($gr->getId());
             $insert->setVoto($voto_gruppo);
             $insert->save();
    $num_totale = $num_totale + $gruppo;
}
$perc_grafico = "50,";
$label_grafico = "|";
$color_grafico = "FFFFFF|";
foreach ($perc_magg as $k => $perc) {
    $perc_grafico = $perc_grafico . number_format($perc * 100 / $num_totale / 2, 2) . ",";
    $label_grafico = $label_grafico . OppGruppoPeer::retrieveByPk($k)->getAcronimo() . " [" . $perc . "]|";
}
foreach ($perc_neutral as $k => $perc) {
    $perc_grafico = $perc_grafico . number_format($perc * 100 / $num_totale / 2, 2) . ",";
    $label_grafico = $label_grafico . OppGruppoPeer::retrieveByPk($k)->getAcronimo() . " [" . $perc . "]|";
}
foreach ($perc_min as $k => $perc) {
    $perc_grafico = $perc_grafico . number_format($perc * 100 / $num_totale / 2, 2) . ",";
    $label_grafico = $label_grafico . OppGruppoPeer::retrieveByPk($k)->getAcronimo() . " [" . $perc . "]|";
}
for ($x = 0; $x < count($perc_magg); $x++) {
    switch ($x) {
        case 0:
            $color_grafico = $color_grafico . "022468|";
            break;
        case 1:
            $color_grafico = $color_grafico . "063cab|";
            break;
        case 2:
            $color_grafico = $color_grafico . "0b50dc|";
            break;
        case 3:
            $color_grafico = $color_grafico . "105dfb|";
            break;
 public static function maggioranzaSalva($leg = 17, $votazione_id = 0)
 {
     $maggioranza_salva = array();
     $c = new Criteria();
     $c->addJoin(OppVotazionePeer::SEDUTA_ID, OppSedutaPeer::ID);
     $c->add(OppVotazionePeer::IS_MAGGIORANZA_SOTTO_SALVA, 1, Criteria::NOT_EQUAL);
     $crit0 = $c->getNewCriterion(OppVotazionePeer::ESITO, 'Appr.');
     $crit1 = $c->getNewCriterion(OppVotazionePeer::ESITO, 'Resp.');
     $crit0->addOr($crit1);
     $c->add($crit0);
     $c->add(OppSedutaPeer::LEGISLATURA, $leg, Criteria::EQUAL);
     $c->add(OppVotazionePeer::TITOLO, '%annullata%', Criteria::NOT_LIKE);
     // Prendi solo votazioni durante il Governo Renzi
     $c->add(OppSedutaPeer::DATA, '2014-02-22', Criteria::GREATER_EQUAL);
     $c->addDescendingOrderByColumn(OppSedutaPeer::DATA);
     if ($votazione_id > 0) {
         $c->add(OppVotazionePeer::ID, $votazione_id);
     }
     $votazioni_magg_su = OppVotazionePeer::doSelect($c);
     foreach ($votazioni_magg_su as $votazione) {
         //echo $votazione->getId();
         if ($votazione->getOppSeduta()->getRamo() == 'C') {
             $ramo = 'camera';
         } else {
             $ramo = 'senato';
         }
         $arr_opposizione = array();
         $c = new Criteria();
         $c->addJoin(OppGruppoPeer::ID, OppGruppoRamoPeer::GRUPPO_ID);
         $c->add(OppGruppoRamoPeer::DATA_INIZIO, $votazione->getOppSeduta()->getData(), Criteria::LESS_EQUAL);
         $crit0 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_FINE, NULL, Criteria::ISNULL);
         $crit1 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_FINE, $votazione->getOppSeduta()->getData(), Criteria::GREATER_EQUAL);
         $crit0->addOr($crit1);
         $c->add($crit0);
         $c->add(OppGruppoRamoPeer::RAMO, $votazione->getOppSeduta()->getRamo());
         $gruppi = OppGruppoPeer::doSelect($c);
         foreach ($gruppi as $g) {
             if (!OppGruppoIsMaggioranzaPeer::isGruppoMaggioranza($g->getId(), $votazione->getOppSeduta()->getData()) && $g->getNome() != 'Gruppo Misto') {
                 $voto_gruppo = OppVotazioneHasGruppoPeer::getVotoGruppoVotazione($g->getId(), $votazione->getId());
                 if ($votazione->getEsito() == 'APPROVATA' && $voto_gruppo == 'Contrario' && $ramo == 'camera' || $votazione->getEsito() == 'RESPINTA' && $voto_gruppo == 'Favorevole' && $ramo == 'camera' || $votazione->getEsito() == 'APPROVATA' && ($voto_gruppo == 'Contrario' || $voto_gruppo == 'Astenuto') && $ramo == 'senato' || $votazione->getEsito() == 'RESPINTA' && $voto_gruppo == 'Favorevole' && $ramo == 'senato') {
                     //echo "\n".$votazione->getEsito()."-".$voto_gruppo."- $ramo\n";
                     //echo "\n".$g->getId()."\n\n";
                     $c = new Criteria();
                     $c->add(OppCaricaHasGruppoPeer::GRUPPO_ID, $g->getId());
                     $c->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $votazione->getOppSeduta()->getData(), Criteria::LESS_EQUAL);
                     $crit0 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, NULL, Criteria::ISNULL);
                     $crit1 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, $votazione->getOppSeduta()->getData(), Criteria::GREATER_EQUAL);
                     $crit0->addOr($crit1);
                     $c->add($crit0);
                     $parlamentari = OppCaricaHasGruppoPeer::doSelect($c);
                     //$parlamentari = OppCaricaHasGruppoPeer::getParlamentariGruppoData($g->getId(),$votazione->getOppSeduta()->getData());
                     foreach ($parlamentari as $p) {
                         $arr_opposizione[] = $p->getCaricaId();
                     }
                 }
             }
         }
         $c = new Criteria();
         $c->add(OppVotazioneHasCaricaPeer::VOTAZIONE_ID, $votazione->getId());
         $c->add(OppVotazioneHasCaricaPeer::CARICA_ID, $arr_opposizione, Criteria::IN);
         if ($votazione->getEsito() == 'APPROVATA' && $votazione->getOppSeduta()->getRamo() == 'C') {
             $crit0 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, 'Assente');
             $crit1 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, 'Favorevole');
             $crit2 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, 'Astenuto');
             $crit0->addOr($crit1);
             $crit0->addOr($crit2);
             $c->add($crit0);
         } elseif ($votazione->getEsito() == 'RESPINTA') {
             $crit0 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, 'Assente');
             $crit1 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, 'Contrario');
             $crit2 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, 'Astenuto');
             $crit0->addOr($crit1);
             $crit0->addOr($crit2);
             $c->add($crit0);
         } elseif ($votazione->getEsito() == 'APPROVATA' && $votazione->getOppSeduta()->getRamo() == 'S') {
             $crit0 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, 'Assente');
             $crit1 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, 'Favorevole');
             $crit0->addOr($crit1);
             $c->add($crit0);
         }
         $cn = OppVotazioneHasCaricaPeer::doCount($c);
         if ($cn >= $votazione->getMargine()) {
             //echo "!!!!!!!$cn  ".$votazione->getId()."\n";
             $maggioranza_salva[] = $votazione;
         }
     }
     return $maggioranza_salva;
 }
 public function executeGruppiParlamentari()
 {
     if ($this->ramo == 1) {
         $this->tipo_carica = array(1);
     } else {
         $this->tipo_carica = array(4, 5);
     }
     $array_diff = array();
     $gruppo_in = array();
     $gruppo_out = array();
     $gruppo_now = array();
     $parlamentari_change = array();
     $c1 = new Criteria();
     $gruppi = OppGruppoPeer::doSelect($c1);
     foreach ($gruppi as $gruppo) {
         if (!array_key_exists($gruppo->getId(), $gruppo_in)) {
             $gruppo_in[$gruppo->getId()] = 0;
         }
         if (!array_key_exists($gruppo->getId(), $gruppo_out)) {
             $gruppo_out[$gruppo->getId()] = 0;
         }
         if (!array_key_exists($gruppo->getId(), $gruppo_now)) {
             $gruppo_now[$gruppo->getId()] = 0;
         }
         $c = new Criteria();
         $c->add(OppCaricaPeer::TIPO_CARICA_ID, $this->tipo_carica, Criteria::IN);
         $c->addJoin(OppCaricaPeer::ID, OppCaricaHasGruppoPeer::CARICA_ID);
         if (!in_array(5, $this->tipo_carica)) {
             $c->add(OppCaricaPeer::LEGISLATURA, $this->leg);
         }
         $c->add(OppCaricaPeer::DATA_FINE, NULL, Criteria::ISNULL);
         $c->add(OppCaricaHasGruppoPeer::GRUPPO_ID, $gruppo->getId());
         $rs = OppCaricaHasGruppoPeer::doSelect($c);
         foreach ($rs as $r) {
             if ($r->getDataFine() == NULL) {
                 $gruppo_now[$gruppo->getId()] = $gruppo_now[$gruppo->getId()] + 1;
             } else {
                 if (!in_array($r->getCaricaId(), $parlamentari_change)) {
                     $parlamentari_change[] = $r->getCaricaId();
                 }
                 $gruppo_out[$gruppo->getId()] = $gruppo_out[$gruppo->getId()] + 1;
                 $c2 = new Criteria();
                 $c2->add(OppCaricaHasGruppoPeer::CARICA_ID, $r->getCaricaId());
                 $c2->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $r->getDataFine());
                 $diff = OppCaricaHasGruppoPeer::doSelectOne($c2);
                 if ($diff) {
                     if (array_key_exists($diff->getGruppoId(), $gruppo_in)) {
                         $gruppo_in[$diff->getGruppoId()] = $gruppo_in[$diff->getGruppoId()] + 1;
                     } else {
                         $gruppo_in[$diff->getGruppoId()] = 1;
                     }
                     if (isset($array_diff[$diff->getGruppoId()][$gruppo->getId()])) {
                         $array_diff[$diff->getGruppoId()][$gruppo->getId()] = $array_diff[$diff->getGruppoId()][$gruppo->getId()] + 1;
                     } else {
                         $array_diff[$diff->getGruppoId()][$gruppo->getId()] = 1;
                     }
                     if (isset($array_diff[$gruppo->getId()][$diff->getGruppoId()])) {
                         $array_diff[$gruppo->getId()][$diff->getGruppoId()] = $array_diff[$gruppo->getId()][$diff->getGruppoId()] - 1;
                     } else {
                         $array_diff[$gruppo->getId()][$diff->getGruppoId()] = -1;
                     }
                 }
             }
         }
     }
     $this->gruppo_in = $gruppo_in;
     $this->gruppo_out = $gruppo_out;
     $this->gruppo_now = $gruppo_now;
     $this->array_diff = $array_diff;
     $this->parlamentari_change = $parlamentari_change;
 }
 public function executeGetIndexChartsTopPoliticians()
 {
     # check query string parameters and validate to avoid SQL injection
     $this->forward404Unless($this->hasRequestParameter('ramo'));
     $ramo = $this->getRequestParameter('ramo', '');
     $this->forward404Unless(in_array($ramo, array('C', 'S')));
     //$this->forward404Unless($this->hasRequestParameter('data'));
     $data = $this->getRequestParameter('data', '');
     if ($data != '') {
         $this->forward404Unless(strtotime($data));
     }
     $this->forward404Unless($this->hasRequestParameter('limit'));
     $limit = (int) $this->getRequestParameter('limit', '');
     $this->forward404Unless(is_integer($limit));
     $group_acr = $this->getRequestParameter('group', '');
     $group_id = null;
     if ($group_acr != '') {
         $c = new Criteria();
         $c->add(OppGruppoPeer::ACRONIMO, $group_acr);
         $group = OppGruppoPeer::doSelectOne($c);
         $this->forward404If(is_null($group));
         $group_id = $group->getId();
     }
     foreach ($this->regioni as $reg) {
         sfContext::getInstance()->getLogger()->info($reg);
     }
     $constituency = $this->getRequestParameter('circoscrizione', '');
     if ($constituency != '') {
         $constituency_is_valid = in_array(strtolower($constituency), $this->regioni);
         $this->forward404Unless($constituency_is_valid);
     }
     if ($data != '') {
         $items = OppPoliticianHistoryCachePeer::getIndexChartsTopPoliticians($ramo, $data, $limit, $group_id, $constituency);
     } else {
         $items = OppCaricaPeer::getIndexChartsTopPoliticiansRealTime($ramo, $data, $limit, $group_id, $constituency);
     }
     $this->_send_json_output(json_encode($items));
     return sfView::NONE;
 }
 protected function addSortCriteria(&$c)
 {
     if ($sort_column = $this->getUser()->getAttribute('sort', NULL, 'opp_votazione/sort')) {
         switch ($this->getUser()->getAttribute('sort', NULL, 'opp_votazione/sort')) {
             case 'parlamentare':
                 $sort_column = OppPoliticoPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
                 break;
             case 'gruppo':
                 $sort_column = 'nome';
                 $sort_column = OppGruppoPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
                 break;
             case 'circoscrizione':
                 $sort_column = OppCaricaPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
                 break;
             case 'voto':
                 $sort_column = OppVotazioneHasCaricaPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
                 break;
         }
         if ($this->getUser()->getAttribute('type', NULL, 'opp_votazione/sort') == 'asc') {
             $c->addAscendingOrderByColumn($sort_column);
         } else {
             $c->addDescendingOrderByColumn($sort_column);
         }
     }
 }
 public function getGruppoCorrente()
 {
     $c = new Criteria();
     $c->add(OppCaricaPeer::TIPO_CARICA_ID, array(1, 4, 5), Criteria::IN);
     $c->add(OppCaricaHasGruppoPeer::DATA_FINE, null, Criteria::ISNULL);
     // dava errore per i senatori a vita
     // $c->add(OppCaricaPeer::LEGISLATURA, 16);
     $c->add(OppCaricaPeer::POLITICO_ID, $this->getId());
     $c->addJoin(OppCaricaPeer::ID, OppCaricaHasGruppoPeer::CARICA_ID);
     $c->addJoin(OppCaricaHasGruppoPeer::GRUPPO_ID, OppGruppoPeer::ID);
     return OppGruppoPeer::doSelectOne($c);
 }
 public function executeList()
 {
     $this->session = $this->getUser();
     $ramo = $this->getRequestParameter('ramo', 'camera');
     // estrae i gruppi del ramo
     $this->all_groups = OppGruppoPeer::getAllGroups($ramo, 17, 'tutti');
     // estrae le circoscrizioni, compreso il valore 0
     $this->all_constituencies = OppCaricaPeer::getAllConstituencies($ramo, 'tutte');
     // reset dei filtri se richiesto esplicitamente
     if ($this->getRequestParameter('reset_filters', 'false') == 'true') {
         $this->getRequest()->getParameterHolder()->set('filter_group', '0');
         $this->getRequest()->getParameterHolder()->set('filter_const', '0');
     }
     //estrazione parlamentari
     $this->processFilters(array('group', 'const'), $ramo);
     // if all filters were reset, then restart
     if ($this->getRequestParameter('filter_group') == '0' && $this->getRequestParameter('filter_const') == '0') {
         $this->redirect('@parlamentari?ramo=' . $ramo);
     }
     $this->processSort();
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addSelectColumn(OppCaricaPeer::ID);
     $c->addSelectColumn(OppPoliticoPeer::ID);
     $c->addSelectColumn(OppPoliticoPeer::COGNOME);
     $c->addSelectColumn(OppPoliticoPeer::NOME);
     $c->addSelectColumn(OppCaricaPeer::CIRCOSCRIZIONE);
     $c->addSelectColumn(OppCaricaPeer::PRESENZE);
     $c->addSelectColumn(OppCaricaPeer::ASSENZE);
     $c->addSelectColumn(OppCaricaPeer::MISSIONI);
     $c->addSelectColumn(OppCaricaPeer::INDICE);
     $c->addSelectColumn(OppCaricaPeer::POSIZIONE);
     $c->addSelectColumn(OppCaricaPeer::MEDIA);
     $c->addSelectColumn(OppCaricaPeer::RIBELLE);
     $c->addSelectColumn(OppPoliticoPeer::N_MONITORING_USERS);
     $c->addSelectColumn(OppCaricaPeer::DATA_INIZIO);
     $c->addSelectColumn(OppCaricaPeer::DATA_FINE);
     $c->addJoin(OppCaricaPeer::POLITICO_ID, OppPoliticoPeer::ID, Criteria::INNER_JOIN);
     if ($ramo == 'camera') {
         $this->getResponse()->setTitle('elenco dei deputati - ' . sfConfig::get('app_main_title'));
         $this->response->addMeta('description', 'Elenco dei deputati della legislatura con assenze, indice di produttivit&agrave; e voti ribelli', true);
         $c->add(OppCaricaPeer::LEGISLATURA, '17', Criteria::EQUAL);
         $c->add(OppCaricaPeer::TIPO_CARICA_ID, '1', Criteria::EQUAL);
         //conteggio numero deputati
         $c1 = new Criteria();
         $c1->add(OppCaricaPeer::LEGISLATURA, '17', Criteria::EQUAL);
         $c1->add(OppCaricaPeer::TIPO_CARICA_ID, '1', Criteria::EQUAL);
         $c1->add(OppCaricaPeer::DATA_FINE, null, Criteria::EQUAL);
         $this->numero_parlamentari = OppCaricaPeer::doCount($c1);
     } else {
         $this->getResponse()->setTitle('elenco dei senatori - ' . sfConfig::get('app_main_title'));
         $this->response->addMeta('description', 'Elenco dei senatori della legislatura con assenze, indice di produttivit&agrave; e voti ribelli', true);
         $cton = $c->getNewCriterion(OppCaricaPeer::LEGISLATURA, '17', Criteria::EQUAL);
         //in questo modo considero i senatori a vita
         $cton1 = $c->getNewCriterion(OppCaricaPeer::LEGISLATURA, null, Criteria::EQUAL);
         $cton->addOr($cton1);
         $c->add($cton);
         $cton = $c->getNewCriterion(OppCaricaPeer::TIPO_CARICA_ID, '4', Criteria::EQUAL);
         $cton1 = $c->getNewCriterion(OppCaricaPeer::TIPO_CARICA_ID, '5', Criteria::EQUAL);
         $cton->addOr($cton1);
         $c->add($cton);
         //conteggio numero senatori
         $c1 = new Criteria();
         $c1->add(OppCaricaPeer::LEGISLATURA, '17', Criteria::EQUAL);
         $c1->add(OppCaricaPeer::TIPO_CARICA_ID, '4', Criteria::EQUAL);
         $c1->add(OppCaricaPeer::DATA_FINE, null, Criteria::EQUAL);
         $numero_senatori = OppCaricaPeer::doCount($c1);
         //conteggio numero senatori a vita
         $c2 = new Criteria();
         $c2->add(OppCaricaPeer::TIPO_CARICA_ID, '5', Criteria::EQUAL);
         $numero_senatori_a_vita = OppCaricaPeer::doCount($c2);
         $this->numero_parlamentari = $numero_senatori + $numero_senatori_a_vita;
     }
     $this->addSortCriteria($c);
     $this->addFiltersCriteria($c);
     $c->add(OppCaricaPeer::DATA_FINE, null, Criteria::EQUAL);
     $this->parlamentari = OppCaricaPeer::doSelectRS($c);
     $this->n_parlamentari = OppCaricaPeer::doCount($c);
     //estrazione parlamentari decaduti
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addSelectColumn(OppCaricaPeer::ID);
     $c->addSelectColumn(OppPoliticoPeer::ID);
     $c->addSelectColumn(OppPoliticoPeer::COGNOME);
     $c->addSelectColumn(OppPoliticoPeer::NOME);
     $c->addSelectColumn(OppCaricaPeer::CIRCOSCRIZIONE);
     $c->addSelectColumn(OppCaricaPeer::PRESENZE);
     $c->addSelectColumn(OppCaricaPeer::ASSENZE);
     $c->addSelectColumn(OppCaricaPeer::MISSIONI);
     $c->addSelectColumn(OppCaricaPeer::INDICE);
     $c->addSelectColumn(OppCaricaPeer::POSIZIONE);
     $c->addSelectColumn(OppCaricaPeer::MEDIA);
     $c->addSelectColumn(OppCaricaPeer::RIBELLE);
     $c->addSelectColumn(OppPoliticoPeer::N_MONITORING_USERS);
     $c->addSelectColumn(OppCaricaPeer::DATA_INIZIO);
     $c->addSelectColumn(OppCaricaPeer::DATA_FINE);
     $c->addJoin(OppCaricaPeer::POLITICO_ID, OppPoliticoPeer::ID, Criteria::INNER_JOIN);
     if ($ramo == 'camera') {
         $c->add(OppCaricaPeer::TIPO_CARICA_ID, '1', Criteria::EQUAL);
     } else {
         $c->add(OppCaricaPeer::TIPO_CARICA_ID, '4', Criteria::EQUAL);
     }
     $c->add(OppCaricaPeer::LEGISLATURA, '17', Criteria::EQUAL);
     $c->add(OppCaricaPeer::DATA_FINE, 'NULL', Criteria::NOT_EQUAL);
     $this->parlamentari_decaduti = OppCaricaPeer::doSelectRS($c);
 }
      <td>
      <span class="small">il <?php 
        echo date('d/m/Y', strtotime($parlamentari->getString(5)));
        ?>
 ha aderito al gruppo</span><br/><strong><?php 
        echo $parlamentari->getString(4);
        ?>
</strong>
      <?php 
        $gruppo = OppCaricaHasGruppoPeer::getGruppoPerParlamentareAllaData($parlamentari->getInt(8), date('Y-m-d', strtotime($parlamentari->getString(5)) - 1));
        ?>
      <?php 
        if (count($gruppo) == 1) {
            ?>
        <br/><span class="small"> abbandonando il gruppo</span><br/><?php 
            echo OppGruppoPeer::retrieveByPk($gruppo['gruppo_id'])->getNome();
            ?>
      <?php 
        }
        ?>
      </td>              
    </tr>
  <?php 
    }
    ?>
  
<?php 
}
?>
<tr>
  <td>&nbsp;</td>
 public function executeDdl2legge()
 {
     if ($this->gruppo != NULL) {
         $c = new Criteria();
         $c->add(OppGruppoPeer::ACRONIMO, $this->gruppo);
         $gruppo = OppGruppoPeer::doSelectOne($c);
         $cariche = OppCaricaHasGruppoPeer::getCarichePerGruppo($gruppo->getId(), 1);
         foreach ($cariche as $carica) {
             $componenti_gruppo[] = $carica->getCaricaId();
         }
     }
     if ($this->gruppo != NULL) {
         $c = new Criteria();
         $c->add(OppGruppoPeer::ACRONIMO, $this->gruppo);
         $gruppo = OppGruppoPeer::doSelectOne($c);
         $cariche = OppCaricaHasGruppoPeer::getCaricheGovernoPerGruppo($gruppo->getId(), 1);
         foreach ($cariche as $carica) {
             $componenti_gruppo[] = $carica;
         }
     }
     $arrs = array();
     $arr_alls = array();
     foreach (array(1, 2, 4) as $i) {
         $c = new Criteria();
         if ($this->gruppo != NULL) {
             $c->addJoin(OppAttoPeer::ID, OppCaricaHasAttoPeer::ATTO_ID);
             $c->add(OppCaricaHasAttoPeer::CARICA_ID, $componenti_gruppo, Criteria::IN);
             $c->add(OppCaricaHasAttoPeer::TIPO, 'P');
         }
         $c->add(OppAttoPeer::TIPO_ATTO_ID, 1);
         $c->add(OppAttoPeer::LEGISLATURA, $this->leg);
         $c->add(OppAttoPeer::INIZIATIVA, $i);
         $c->setDistinct(OppAttoPeer::ID);
         $atti = OppAttoPeer::doSelect($c);
         $c = new Criteria();
         if ($this->gruppo != NULL) {
             $c->addJoin(OppAttoPeer::ID, OppCaricaHasAttoPeer::ATTO_ID);
             $c->add(OppCaricaHasAttoPeer::CARICA_ID, $componenti_gruppo, Criteria::IN);
             $c->add(OppCaricaHasAttoPeer::TIPO, 'P');
         }
         $c->addJoin(OppAttoPeer::ID, OppAttoHasIterPeer::ATTO_ID);
         $c->add(OppAttoPeer::TIPO_ATTO_ID, 1);
         $c->add(OppAttoPeer::LEGISLATURA, $this->leg);
         $c->add(OppAttoPeer::INIZIATIVA, $i);
         $c->add(OppAttoHasIterPeer::ITER_ID, 16);
         $c->setDistinct(OppAttoPeer::ID);
         $leggi = OppAttoHasIterPeer::doSelect($c);
         $tempo_medio = 0;
         foreach ($leggi as $legge) {
             $ddl = $legge->getOppAtto();
             while ($ddl->getPred() != NULL) {
                 $ddl = OppAttoPeer::retrieveByPk($ddl->getPred());
             }
             //$this->data_pres=$ddl->getDataPres();
             //$this->data_appr=$legge->getData();
             $data_pres = strtotime($ddl->getDataPres());
             $data_appr = strtotime($legge->getData());
             $tempo_medio = $tempo_medio + ($data_appr - $data_pres) / 86400;
             $arr_alls[] = array($legge->getOppAtto(), ($data_appr - $data_pres) / 86400);
         }
         if (count($leggi) > 0) {
             $tempo_medio = intval($tempo_medio / count($leggi));
         } else {
             $tempo_medio = $tempo_medio;
         }
         $arrs[] = array(count($atti), count($leggi), $tempo_medio);
     }
     $this->arrs = $arrs;
     function cmp($a, $b)
     {
         if ($a[1] == $b[1]) {
             return 0;
         }
         return $a[1] < $b[1] ? -1 : 1;
     }
     usort($arr_alls, "cmp");
     $this->arr_alls = $arr_alls;
 }
?>
%)|da 5 a 10 anni di incarichi: <?php 
echo $stat[1] . ' (' . round($stat[1] * 100 / array_sum($stat), 2);
?>
%)|con+meno di 5 anni di incarichi: <?php 
echo $stat[0] . ' (' . round($stat[0] * 100 / array_sum($stat), 2);
?>
%)&chd=t:<?php 
echo "{$stat['4']},{$stat['3']},{$stat['2']},{$stat['1']},{$stat['0']}";
?>
&chco=FF0000,FFFF10">
	  <?php 
foreach ($stat_gruppi as $k => $sg) {
    ?>
	    <h5 class="subsection"><?php 
    echo OppGruppoPeer::retrieveByPk($k)->getNome();
    ?>
</h2>
	    <img src="https://chart.googleapis.com/chart?cht=p3&chd=s:Uf9a&chs=400x130&chdl=con oltre 20 anni di incarichi: <?php 
    echo $sg[4] . ' (' . round($sg[4] * 100 / array_sum($sg), 2);
    ?>
%)|da 15 a 20 anni di incarichi: <?php 
    echo $sg[3] . ' (' . round($sg[3] * 100 / array_sum($sg), 2);
    ?>
%)|da 10 a 15 anni di incarichi: <?php 
    echo $sg[2] . ' (' . round($sg[2] * 100 / array_sum($sg), 2);
    ?>
%)|da 5 a 10 anni di incarichi: <?php 
    echo $sg[1] . ' (' . round($sg[1] * 100 / array_sum($sg), 2);
    ?>
%)|con+meno di 5 anni di incarichi: <?php 
            $politico = OppCaricaPeer::retrieveByPk($k[0])->getOppPolitico();
            ?>
          <?php 
            echo image_tag(OppPoliticoPeer::getThumbUrl($politico->getId()), array('width' => '40', 'height' => '53'));
            ?>
                               <?php 
            echo link_to((OppSedePeer::retrieveByPk($sede_id)->getRamo() == 'CS' ? OppCaricaPeer::retrieveByPk($k[0])->getTipoCaricaId() == 1 ? 'On. ' : 'Sen. ' : '') . $politico->getNome() . " " . $politico->getCognome(), '@parlamentare?' . $politico->getUrlParams());
            ?>
        <?php 
            echo $k[1] != "componente" ? " (" . ucfirst($k[1]) . ")" : "";
            ?>
        </p>
        </th>
        <td>
          <?php 
            echo OppGruppoPeer::retrieveByPk($g)->getAcronimo();
            ?>
        </td>
        <td>
          <?php 
            echo OppCaricaPeer::retrieveByPk($k[0])->getCircoscrizione();
            ?>
        </td>
    <?php 
        }
        ?>
  <?php 
    }
}
?>
 foreach ($votazioni as $votazione) {
     if ($votazione->getOppSeduta()->getRamo() == 'C') {
         $ramo = 'camera';
     } else {
         $ramo = 'senato';
     }
     $arr_opposizione = array();
     $c = new Criteria();
     $c->addJoin(OppGruppoPeer::ID, OppGruppoRamoPeer::GRUPPO_ID);
     $c->add(OppGruppoRamoPeer::DATA_INIZIO, $votazione->getOppSeduta()->getData(), Criteria::LESS_EQUAL);
     $crit0 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_FINE, NULL, Criteria::ISNULL);
     $crit1 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_FINE, $votazione->getOppSeduta()->getData(), Criteria::GREATER_EQUAL);
     $crit0->addOr($crit1);
     $c->add($crit0);
     $c->add(OppGruppoRamoPeer::RAMO, $votazione->getOppSeduta()->getRamo());
     $gruppi = OppGruppoPeer::doSelect($c);
     foreach ($gruppi as $g) {
         if (!OppGruppoIsMaggioranzaPeer::isGruppoMaggioranza($g->getId(), $votazione->getOppSeduta()->getData()) and $g->getNome() != 'Gruppo Misto') {
             $voto_gruppo = OppVotazioneHasGruppoPeer::getVotoGruppoVotazione($g->getId(), $votazione->getId());
             if ($votazione->getEsito() == 'APPROVATA' && $voto_gruppo == 'Contrario' && $ramo == 'camera' || $votazione->getEsito() == 'RESPINTA' && $voto_gruppo == 'Favorevole' && $ramo == 'camera' || $votazione->getEsito() == 'APPROVATA' && ($voto_gruppo == 'Contrario' || $voto_gruppo == 'Astenuto') && $ramo == 'senato' || $votazione->getEsito() == 'RESPINTA' && $voto_gruppo == 'Favorevole' && $ramo == 'senato') {
                 $c = new Criteria();
                 $c->add(OppCaricaHasGruppoPeer::GRUPPO_ID, $g->getId());
                 $c->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $votazione->getOppSeduta()->getData(), Criteria::LESS_EQUAL);
                 $crit0 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, NULL, Criteria::ISNULL);
                 $crit1 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, $votazione->getOppSeduta()->getData(), Criteria::GREATER_EQUAL);
                 $crit0->addOr($crit1);
                 $c->add($crit0);
                 $parlamentari = OppCaricaHasGruppoPeer::doSelect($c);
                 //$parlamentari = OppCaricaHasGruppoPeer::getParlamentariGruppoData($g->getId(),$votazione->getOppSeduta()->getData());
                 foreach ($parlamentari as $p) {
                     $arr_opposizione[] = $p->getCaricaId();
<?php

define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', true);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
print "Fetching data... \n";
$xml = simplexml_load_file('http://www.openpolis.it/api/gruppi');
foreach ($xml->gruppi->gruppo as $gruppo) {
    $gruppo_esistente = OppGruppoPeer::RetrieveByPk($gruppo->id);
    if ($gruppo_esistente == null) {
        $gruppo_nuovo = new OppGruppo();
        $gruppo_nuovo->setId($gruppo->id);
        $gruppo_nuovo->setNome($gruppo->nome);
        $gruppo_nuovo->setAcronimo($gruppo->acronimo);
        $gruppo_nuovo->save();
        echo "inserito {$gruppo->nome}\n";
    } else {
        echo "{$gruppo->nome} gia esistente\n";
    }
}
print "done.\n";
$pol->save();
$t->diag('Add a new charge');
$car = new OppCarica();
$car->setId(999999);
$car->setOppPolitico($pol);
$car->setTipoCaricaId(2);
$car->setCarica('Ministro dell\'abolizione dei beni Inutili');
$car->setDataInizio('2008-10-10');
$car->save();
$pol_related_news = getRelatedNews($pol);
$n_pol_related_news = count($pol_related_news);
$t->diag("related_news: " . $n_pol_related_news);
$t->ok($n_pol_related_news == 1, 'One news related to the politician');
dumpNews($t, "news related to the politician", $pol_related_news);
$t->diag('Add a group to the charge');
$gruppo = OppGruppoPeer::retrieveByPK(1);
$car_gruppo = new OppCaricaHasGruppo();
$car_gruppo->setOppCarica($car);
$car_gruppo->setOppGruppo($gruppo);
$car_gruppo->setDataInizio('2008-08-20');
$car_gruppo->save();
$pol_related_news = getRelatedNews($pol);
$n_pol_related_news = count($pol_related_news);
$t->ok($n_pol_related_news == 2, 'Two news related to the politician');
dumpNews($t, "news related to the politician", $pol_related_news);
$t->diag('Add a first-signer, at the presentation date');
$firma = new OppCaricaHasAtto();
$firma->setTipo('P');
$firma->setOppCarica($car);
$firma->setOppAtto($obj);
$firma->setData($obj->getDataPres());
            if ($parlamentari->getString(9) != NULL) {
                ?>
	                      <?php 
                echo "<span style='background-color:yellow;'>in carica fino al " . format_date($parlamentari->getString(9), 'dd/MM/yyyy') . "</span>";
                ?>
	                    <?php 
            }
            ?>
	                  <?php 
            foreach ($gruppi as $g) {
                ?>
	                    <?php 
                if ($g['data_fine'] != null) {
                    ?>
	                      <?php 
                    $gruppo = OppGruppoPeer::retrieveByPk($g['gruppo_id']);
                    ?>
	                      <?php 
                    echo ", " . $gruppo->getAcronimo() . " dal " . format_date($g['data_inizio'], 'dd/MM/yyyy') . " al " . format_date($g['data_fine'], 'dd/MM/yyyy');
                    ?>
	                    <?php 
                }
                ?>
	                  <?php 
            }
            ?>
	                  </span>
	                <?php 
        }
        ?>
	                )
 /**
  * restituisce il gruppo corrente per la carica
  *
  * @param integer $carica_id 
  * @return void
  * @author Ettore Di Cesare
  */
 public static function getGruppoCorrentePerCarica($carica_id)
 {
     $c = new Criteria();
     $c->addJoin(OppCaricaHasGruppoPeer::GRUPPO_ID, OppGruppoPeer::ID);
     $c->add(OppCaricaHasGruppoPeer::CARICA_ID, $carica_id, Criteria::EQUAL);
     $c->add(OppCaricaHasGruppoPeer::DATA_FINE, NULL, Criteria::ISNULL);
     $rs = OppGruppoPeer::doSelectOne($c);
     if ($rs) {
         return $rs;
     } else {
         return NULL;
     }
 }
 public function executeChartRibelli()
 {
     $ribelli = $this->ribelli;
     $label = "";
     $valore = "";
     $ribelli_gruppi = array();
     foreach ($ribelli as $cognome => $ribelle) {
         $c1 = new Criteria();
         $c1->add(OppGruppoPeer::NOME, $ribelle['gruppo_nome']);
         $obj_gruppo = OppGruppoPeer::doSelectOne($c1);
         $gruppo_acr = $obj_gruppo->getAcronimo();
         if (!array_key_exists($gruppo_acr, $ribelli_gruppi)) {
             $ribelli_gruppi[$gruppo_acr] = 0;
         }
         $ribelli_gruppi[$gruppo_acr] += 1;
     }
     foreach ($ribelli_gruppi as $gruppo1 => $numvoto) {
         if ($numvoto > 0) {
             if ($valore == "") {
                 $valore = round($numvoto * 100 / $this->votazione->getRibelli(), 0);
             } else {
                 $valore = $valore . "," . round($numvoto * 100 / $this->votazione->getRibelli(), 0);
             }
             if ($label == "") {
                 $label = $gruppo1 . " " . $numvoto . " (" . round($numvoto * 100 / $this->votazione->getRibelli(), 0) . "%)";
             } else {
                 $label = $label . "|" . $gruppo1 . " " . $numvoto . " (" . round($numvoto * 100 / $this->votazione->getRibelli(), 0) . "%)";
             }
         }
     }
     $gchartRibelli = "http://chart.apis.google.com/chart?chs=350x130&chd=t:" . $valore . "&cht=p&chl=" . $label . "&chdlp=bv";
     $this->gchartRibelli = $gchartRibelli;
 }