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