$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);
        }
        $parlamentare = OppVotazioneHasCaricaPeer::doSelect($c);
        foreach ($parlamentare as $p) {
            $p->setMaggioranzaSottoSalva(2);
            $p->save();
        }
    }
}
mail("*****@*****.**", "UP PARL. SALVA", "ctrl parl salva", "From: 1_lista_ddl_new");
 public function executeKeyvoteComparati()
 {
     $lanci = array();
     $c = new Criteria();
     $c->add(sfLaunchingPeer::OBJECT_MODEL, 'OppVotazione');
     $c->add(sfLaunchingPeer::LAUNCH_NAMESPACE, 'key_vote');
     $c->addDescendingOrderByColumn(sfLaunchingPeer::PRIORITY);
     $evidences = sfLaunchingPeer::doSelect($c);
     foreach ($evidences as $evidence) {
         $c1 = new Criteria();
         $c1->addJoin(OppCaricaPeer::ID, OppVotazioneHasCaricaPeer::CARICA_ID);
         $c1->add(OppVotazioneHasCaricaPeer::CARICA_ID, array($this->parlamentare1->getId(), $this->parlamentare2->getId()), Criteria::IN);
         $c1->add(OppVotazioneHasCaricaPeer::VOTAZIONE_ID, $evidence->getObjectId());
         $results = OppVotazioneHasCaricaPeer::doSelect($c1);
         if (count($results) == 2) {
             if ($results[0]->getCaricaId() == $this->parlamentare1->getId()) {
                 $left = 0;
                 $right = 1;
             } else {
                 $left = 1;
                 $right = 0;
             }
             $lanci[] = array($results[1]->getOppVotazione(), $evidence->getObjectModel(), $results[$left]->getVoto(), $results[$right]->getVoto());
         }
     }
     $this->lanci = $lanci;
 }
<?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();
$c = new Criteria();
$c->addJoin(OppSedutaPeer::ID, OppVotazionePeer::SEDUTA_ID);
$c->add(OppVotazionePeer::TITOLO, 'Votazione annullata');
$c->add(OppSedutaPeer::RAMO, 'C');
$votazioni = OppVotazionePeer::doSelect($c);
echo count($votazioni);
foreach ($votazioni as $votazione) {
    $c1 = new Criteria();
    $c1->add(OppVotazioneHasCaricaPeer::VOTAZIONE_ID, $votazione->getId());
    $voti = OppVotazioneHasCaricaPeer::doSelect($c1);
    foreach ($voti as $voto) {
        $voto->setVoto('Votazione annullata');
        $voto->save();
    }
}
 public function executeComparaDeputati()
 {
     if ($this->hasRequestParameter('id1') && $this->hasRequestParameter('id2') && $this->hasRequestParameter('ramo')) {
         $this->ramo = $this->getRequestParameter('ramo');
         if ($this->getRequestParameter('id1') != 0 && $this->getRequestParameter('id2') != 0) {
             $this->session = $this->getUser();
             $this->query = $this->getRequestParameter('query', '');
             if ($this->hasRequestParameter('itemsperpage')) {
                 $this->getUser()->setAttribute('itemsperpage', $this->getRequestParameter('itemsperpage'));
             }
             $itemsperpage = $this->getUser()->getAttribute('itemsperpage', sfConfig::get('app_pagination_limit'));
             $this->pager = new sfPropelPager('OppVotazione', $itemsperpage);
             // estrae le cariche dei due parlamentari
             $politico = OppPoliticoPeer::retrieveByPk($this->getRequestParameter('id1'));
             $carica1 = $politico->getCaricaDepSenCorrente();
             $politico = OppPoliticoPeer::retrieveByPk($this->getRequestParameter('id2'));
             $carica2 = $politico->getCaricaDepSenCorrente();
             $c1 = new Criteria();
             $c1->add(OppVotazioneHasCaricaPeer::VOTO, array('Favorevole', 'Contrario', 'Astenuto'), Criteria::IN);
             $c1->add(OppVotazioneHasCaricaPeer::CARICA_ID, array($carica1->getId(), $carica2->getId()), Criteria::IN);
             $results = OppVotazioneHasCaricaPeer::doSelect($c1);
             $arr1 = array();
             $arr2 = array();
             foreach ($results as $result) {
                 if ($result->getCaricaId() == $carica1->getId()) {
                     $arr1[$result->getVotazioneId()] = $result->getVoto();
                 } else {
                     $arr2[$result->getVotazioneId()] = $result->getVoto();
                 }
             }
             $this->compare = count(array_intersect_assoc($arr1, $arr2));
             $this->compare_voti = array_keys(array_intersect_key($arr1, $arr2));
             $this->numero_voti = count($this->compare_voti);
             $c = new Criteria();
             $c->add(OppVotazionePeer::ID, $this->compare_voti, Criteria::IN);
             $this->pager->setCriteria($c);
             $this->pager->setPage($this->getRequestParameter('page', 1));
             $this->pager->setPeerMethod('doSelect');
             $this->pager->init($c);
             $this->arr1 = $arr1;
             $this->arr2 = $arr2;
             $this->parlamentare1 = $carica1;
             $this->assenze1 = round($carica1->getAssenze() * 100 / ($carica1->getPresenze() + $carica1->getAssenze() + $carica1->getMissioni()), 1);
             $this->parlamentare2 = $carica2;
             $this->assenze2 = round($carica2->getAssenze() * 100 / ($carica2->getPresenze() + $carica2->getAssenze() + $carica2->getMissioni()), 1);
             $this->compara_ok = '1';
             // da quanti giorni รจ parlamentare da openpolis
             $xml = simplexml_load_file("http://politici.openpolis.it/api/parlamentareHowDays?id=" . $carica1->getOppPolitico()->getId());
             $this->giorni = array();
             if ($xml) {
                 $giorni = $xml->xpath("//days");
             }
             if ($giorni[0] / 365 >= 2) {
                 $durata = intval($giorni[0] / 365) . ' anni e ';
             } elseif ($giorni[0] / 365 >= 1) {
                 $durata = 'un anno e ';
             } else {
                 $durata = "";
             }
             if ($giorni[0] % 365 > 0) {
                 $durata = $durata . $giorni[0] % 365 . " giorni";
             }
             $this->durata1 = $durata;
             $xml = simplexml_load_file("http://politici.openpolis.it/api/parlamentareHowDays?id=" . $carica2->getOppPolitico()->getId());
             $this->giorni = array();
             if ($xml) {
                 $giorni = $xml->xpath("//days");
             }
             if ($giorni[0] / 365 >= 2) {
                 $durata = intval($giorni[0] / 365) . ' anni e ';
             } elseif ($giorni[0] / 365 >= 1) {
                 $durata = 'un anno e ';
             } else {
                 $durata = "";
             }
             if ($giorni[0] % 365 > 0) {
                 $durata = $durata . $giorni[0] % 365 . " giorni";
             }
             $this->durata2 = $durata;
             $this->getResponse()->setTitle(($this->ramo == 1 ? 'Deputati ' : 'Senatori ') . 'a confronto:' . $carica1->getOppPolitico()->getCognome() . ' vs ' . $carica2->getOppPolitico()->getCognome() . ' - ' . sfConfig::get('app_main_title'));
             $this->response->addMeta('description', 'Confronto tra le attivit&agrave; parlamentari di ' . $carica1->getOppPolitico()->getCognome() . ' e ' . $carica2->getOppPolitico()->getCognome(), true);
         } else {
             $this->compara_ok = '0';
             $this->parlamentare1 = null;
             $this->getResponse()->setTitle(($this->ramo == 1 ? 'Deputati ' : 'Senatori ') . 'a confronto - ' . sfConfig::get('app_main_title'));
         }
     }
     if ($this->getRequest()->getMethod() != sfRequest::POST) {
         // Display the form
         return sfView::SUCCESS;
     } else {
         // Handle the form submission
         $parlamentare1 = $this->getRequestParameter('parlamentare1');
         $parlamentare2 = $this->getRequestParameter('parlamentare2');
         $ramo = $this->getRequestParameter('ramo');
         if ($ramo == 1) {
             $this->redirect('/parlamentare/comparaDeputati/?id1=' . $parlamentare1 . '&id2=' . $parlamentare2 . '&ramo=1');
         } else {
             $this->redirect('/parlamentare/comparaDeputati/?id1=' . $parlamentare1 . '&id2=' . $parlamentare2 . '&ramo=2');
         }
     }
 }