} 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();
             }
         }
     }
 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;
 }