public static function countAssentiRibelliOpposizioneVotazioneMaggioranzaSalvata($votazione_id, $assente)
 {
     $c = new Criteria();
     $c->add(OppVotazioneHasCaricaPeer::VOTAZIONE_ID, $votazione_id);
     $c->add(OppVotazioneHasCaricaPeer::MAGGIORANZA_SOTTO_SALVA, 2);
     if ($assente == 1) {
         $c->add(OppVotazioneHasCaricaPeer::VOTO, 'Assente');
     } else {
         $c->add(OppVotazioneHasCaricaPeer::VOTO, 'Assente', Criteria::NOT_EQUAL);
     }
     return OppVotazioneHasCaricaPeer::doCount($c);
 }
<?php

define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
print "start script.\n";
if ($argv[1]) {
    print "elaborazione votazione: " . $argv[1] . "...\n";
    $c = new Criteria();
    $c->add(OppVotazionePeer::ID, $argv[1], Criteria::EQUAL);
    $votazione = OppVotazionePeer::doSelectOne($c);
    //$count = $votazione->getRibelliCount();
    $c = new Criteria();
    $c->add(OppVotazioneHasCaricaPeer::VOTAZIONE_ID, $votazione->getId());
    $c->add(OppVotazioneHasCaricaPeer::RIBELLE, 1);
    $count = OppVotazioneHasCaricaPeer::doCount($c);
    $votazione->setRibelli($count);
    $votazione->save();
} else {
    print "identificativo votazione non inserito";
}
print "done.\n";
 public static function doSelectPresenzePerGruppo($carica_id, $data_inizio, $data_fine)
 {
     $c = new Criteria();
     $c->addJoin(OppVotazioneHasCaricaPeer::VOTAZIONE_ID, OppVotazionePeer::ID, Criteria::LEFT_JOIN);
     $c->addJoin(OppVotazionePeer::SEDUTA_ID, OppSedutaPeer::ID, Criteria::LEFT_JOIN);
     $c->add(OppVotazioneHasCaricaPeer::CARICA_ID, $carica_id, Criteria::EQUAL);
     $c->add(OppSedutaPeer::DATA, $data_inizio, Criteria::GREATER_EQUAL);
     if ($data_fine != '') {
         $c->add(OppSedutaPeer::DATA, $data_fine, Criteria::LESS_EQUAL);
     }
     $cton1 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, sfConfig::get('app_voto_2'), Criteria::EQUAL);
     $cton2 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, sfConfig::get('app_voto_3'), Criteria::EQUAL);
     $cton1->addOr($cton2);
     $cton3 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, sfConfig::get('app_voto_4'), Criteria::EQUAL);
     $cton1->addOr($cton3);
     $cton4 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, sfConfig::get('app_voto_6'), Criteria::EQUAL);
     $cton1->addOr($cton4);
     $cton5 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, sfConfig::get('app_voto_7'), Criteria::EQUAL);
     $cton1->addOr($cton5);
     $cton6 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, sfConfig::get('app_voto_8'), Criteria::EQUAL);
     $cton1->addOr($cton6);
     $cton7 = $c->getNewCriterion(OppVotazioneHasCaricaPeer::VOTO, sfConfig::get('app_voto_9'), Criteria::EQUAL);
     $cton1->addOr($cton7);
     $c->add($cton1);
     return $totale = OppVotazioneHasCaricaPeer::doCount($c);
 }
    $c = new Criteria();
    $c->add(OppCaricaHasGruppoPeer::CARICA_ID, $carica->getId());
    $rs = OppCaricaHasGruppoPeer::doSelect($c);
    foreach ($rs as $r) {
        $c = new Criteria();
        $c->addJoin(OppVotazioneHasCaricaPeer::VOTAZIONE_ID, OppVotazionePeer::ID);
        $c->addJoin(OppVotazionePeer::SEDUTA_ID, OppSedutaPeer::ID);
        if ($r->getDataFine() !== NULL) {
            $crit0 = $c->getNewCriterion(OppSedutaPeer::DATA, $r->getDataInizio(), Criteria::GREATER_EQUAL);
            $crit1 = $c->getNewCriterion(OppSedutaPeer::DATA, $r->getDataFine(), Criteria::LESS_THAN);
            $crit0->addAnd($crit1);
            $c->add($crit0);
        } else {
            $c->add(OppSedutaPeer::DATA, $r->getDataInizio(), Criteria::GREATER_EQUAL);
        }
        $c->add(OppVotazioneHasCaricaPeer::CARICA_ID, $carica->getId());
        $c->add(OppVotazioneHasCaricaPeer::RIBELLE, 1);
        echo $n_ribelle = OppVotazioneHasCaricaPeer::doCount($c);
        echo "\n";
        $r->setRibelle($n_ribelle);
        $r->save();
    }
    $c = new Criteria();
    $c->add(OppVotazioneHasCaricaPeer::CARICA_ID, $carica->getId());
    $c->add(OppVotazioneHasCaricaPeer::RIBELLE, 1);
    $n_ribelle_tot = OppVotazioneHasCaricaPeer::doCount($c);
    $carica->setRibelle($n_ribelle_tot);
    $carica->save();
    echo $n_ribelle_tot . "\n---\n";
}
mail("*****@*****.**", "OK - Update Ribellioni", "aggiornamento a buon fine", "From: BatchOpp");
 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 getVotiCount()
 {
     $c = new Criteria();
     $c->addJoin(OppPoliticoPeer::ID, OppCaricaPeer::POLITICO_ID, Criteria::INNER_JOIN);
     $c->addJoin(OppCaricaPeer::ID, OppVotazioneHasCaricaPeer::CARICA_ID, Criteria::INNER_JOIN);
     $c->Add(OppPoliticoPeer::ID, $this->getId());
     return OppVotazioneHasCaricaPeer::doCount($c);
 }