<?php

/*
Controlla le votazioni, e mette 1 al campo maggioranza_sotto in opp_votazione_has_carica nel caso nella votazione il parlamentare abbia mandato giù la maggioranza.
in input:
- numero della legislatuta
- 0 ctrl tutte le votazioni, id_votazione ctrl solo una votazione 
*/
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();
if ($argv[2] == 0) {
    $votazioni = OppVotazionePeer::doSelect(OppVotazionePeer::getVotazioniMaggioranzaSotto($argv[1]));
} else {
    $c = new Criteria();
    $c->add(OppVotazionePeer::ID, $argv[2]);
    $c->add(OppVotazionePeer::IS_MAGGIORANZA_SOTTO_SALVA, 1);
    $votazioni = OppVotazionePeer::doSelect($c);
}
echo count($votazioni) . "\n\n";
if (count($votazioni) > 0) {
    foreach ($votazioni as $v) {
        echo $v->getOppSeduta()->getRamo() . $v->getOppSeduta()->getData() . "\n\n";
        //controlla come ha votato la PD (gruppo id=71)
        $c = new Criteria();
        $c->add(OppVotazioneHasGruppoPeer::GRUPPO_ID, 71);
        $c->add(OppVotazioneHasGruppoPeer::VOTAZIONE_ID, $v->getId());
        $voto_magg = OppVotazioneHasGruppoPeer::doSelectOne($c);
 public function executeMaggioranzaSotto()
 {
     $this->session = $this->getUser();
     $this->query = $this->getRequestParameter('query', '');
     $this->getResponse()->setTitle('I voti di Camera e Senato in cui la maggioranza di governo e\' stata sconfitta - ' . sfConfig::get('app_main_title'));
     $this->response->addMeta('description', 'Il dettaglio delle votazioni elettroniche di Camera e Senato in cui la maggioranza &egrave; stata sconfitta. I parlamentari di maggioranza assenti e i ribelli al proprio gruppo di appartenenza', true);
     // estrae tutte le macrocategorie, per costruire la select
     $this->all_tags_categories = OppTeseottPeer::doSelect(new Criteria());
     // reset dei filtri se richiesto esplicitamente
     if ($this->getRequestParameter('reset_filters', 'false') == 'true') {
         $this->getRequest()->getParameterHolder()->set('filter_tags_category', '0');
         $this->getRequest()->getParameterHolder()->set('filter_type', '0');
         $this->getRequest()->getParameterHolder()->set('filter_ramo', '0');
         $this->getRequest()->getParameterHolder()->set('filter_esito', '0');
     }
     $this->processFilters(array('tags_category', 'type', 'ramo', 'esito'));
     // if all filters were reset, then restart
     if ($this->getRequestParameter('filter_tags_category') == '0' && $this->getRequestParameter('filter_type') == '0' && $this->getRequestParameter('filter_ramo') == '0' && $this->getRequestParameter('filter_esito') == '0') {
         $this->redirect('/votazioni/maggioranzaSotto');
     }
     $this->processListSort();
     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);
     //$c = OppVotazionePeer::maggioranzaSottoCriteria(17);
     $c = OppVotazionePeer::getVotazioniMaggioranzaSotto();
     $this->addListSortCriteria($c);
     $this->addFiltersCriteria($c);
     $this->pager->setCriteria($c);
     $this->pager->setPage($this->getRequestParameter('page', 1));
     $this->pager->setPeerMethod('doSelectJoinOppSeduta');
     $this->pager->setPeerCountMethod('doCountJoinOppSeduta');
     $this->pager->init();
 }