public function executeVotazioni()
 {
     $c = new Criteria();
     $c->addJoin(OppVotazionePeer::ID, OppVotazioneHasEmendamentoPeer::VOTAZIONE_ID);
     $c->add(OppVotazioneHasEmendamentoPeer::EMENDAMENTO_ID, $this->emendamento->getId());
     $this->votazioni = OppVotazionePeer::doSelect($c);
     $this->limit = 2;
     $this->limit_count = 0;
     $this->votazioni_count = count($this->votazioni);
 }
 protected function setPage($page_name = null)
 {
     // Get page from request if not given as parameter (default behaviour)
     if (is_null($page_name)) {
         $page_name = $this->getRequestParameter('page', $this->startPage);
     }
     // Handle case insensitivity
     $page_name = strtolower($page_name);
     // Support default page if not specified in namespace
     if (substr($page_name, -1) == ':') {
         $page_name .= $this->startPage;
     }
     // Retrieve the page, or start a new one if cannot be found
     $this->page = nahoWikiPagePeer::retrieveByName($page_name);
     if (!$this->page) {
         return;
     }
     // Retrieve the revision
     $revision = $this->getRequestParameter('revision', $this->page->getLatestRevision());
     $this->revision = $this->page->getRevision($revision);
     if (!$this->revision) {
         $this->initNewRevision();
     }
     // Generate the URI parameters to keep trace of the requested page
     $this->uriParams = 'page=' . $this->page->getName();
     if ($this->revision->getRevision() != $this->page->getLatestRevision()) {
         $this->uriParams .= '&revision=' . $this->revision->getRevision();
     }
     // Permissions management
     $this->canView = $this->page->canView($this->getUser());
     $this->canEdit = $this->page->canEdit($this->getUser());
     // Retriev item name and type of item (tab and breadcrumbs)
     list($tipo, $id) = split("_", $this->page->getName());
     switch ($tipo) {
         case 'atto':
             $this->item = OppAttoPeer::retrieveByPK($id);
             $this->item_name = Text::denominazioneAttoShort($this->item);
             break;
         case 'votazione':
             $this->item = OppVotazionePeer::retrieveByPK($id);
             $this->item_name = $this->item->getTitolo();
             break;
         case 'emendamento':
             $this->item = OppEmendamentoPeer::retrieveByPK($id);
             $attoPortante = $this->item->getAttoPortante();
             $this->item_name = "Emendamento " . $this->item->getTitolo() . " relativo a " . Text::denominazioneAttoShort($attoPortante) . " - " . $attoPortante->getTitolo();
             break;
     }
     $this->item_type = $tipo;
 }
 public static function doSelectCountVotazioniPerPeriodo($data_inizio, $data_fine, $legislatura, $ramo)
 {
     $c = new Criteria();
     $c->addJoin(OppSedutaPeer::ID, OppVotazionePeer::SEDUTA_ID, Criteria::LEFT_JOIN);
     //$c->add(OppSedutaPeer::DATA, $data_inizio, Criteria::GREATER_EQUAL);
     $c->add(OppSedutaPeer::RAMO, $ramo, Criteria::EQUAL);
     $c->add(OppSedutaPeer::LEGISLATURA, $legislatura, Criteria::EQUAL);
     if ($data_inizio != '') {
         $c->add(OppSedutaPeer::DATA, $data_inizio, Criteria::GREATER_EQUAL);
     }
     if ($data_fine != '') {
         $c->add(OppSedutaPeer::DATA, $data_fine, Criteria::LESS_EQUAL);
     }
     return $count = OppVotazionePeer::doCount($c);
 }
define('SF_ENVIRONMENT', 'prod');
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();
require_once "batch/get_args_options.php";
$args = arguments($argv);
$argv = $args['input'];
$argc = count($argv);
# controllo sintassi
if ($argc != 2) {
    print "sintassi: php batch/updateVotiRibelliVotazione votazione_id\n";
    exit;
}
echo $votazione_id = $argv[1];
echo "\n";
$votazione = OppVotazionePeer::retrieveByPK($votazione_id);
$data_votazione = $votazione->getOppSeduta()->getData();
$c = new Criteria();
/*
$c->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $data_votazione, Criteria::LESS_EQUAL);
$cton = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, $data_votazione, Criteria::GREATER_EQUAL);
$cton->addOr($c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, null, Criteria::ISNULL));
$c->add($cton);
*/
$c->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $data_votazione, Criteria::LESS_EQUAL);
$cton4 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, $data_votazione, Criteria::GREATER_THAN);
$cton5 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, null, Criteria::ISNULL);
$cton4->addOr($cton5);
$c->add($cton4);
$cariche = $votazione->getOppVotazioneHasCaricas();
$ncariche = count($cariche);
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 "Fetching data... \n";
$c = new Criteria();
$c->setOffset(3013213);
$c->setLimit(600000);
$votazioni = OppVotazioneHasPoliticoPeer::doSelect($c);
foreach ($votazioni as $votazione) {
    echo "votazione: " . $votazione->getVotazioneId() . " politico: " . $votazione->getPoliticoId() . "\n";
    $c1 = new Criteria();
    $c1->add(OppVotazionePeer::ID, $votazione->getVotazioneId(), Criteria::EQUAL);
    $vot = OppVotazionePeer::doSelectOne($c1);
    $c2 = new Criteria();
    $c2->add(OppSedutaPeer::ID, $vot->getSedutaId(), Criteria::EQUAL);
    $seduta = OppSedutaPeer::doSelectOne($c2);
    $senatori_a_vita = array("1529", "1606", "1719", "1519", "1682", "1456", "1524");
    $c3 = new Criteria();
    $c3->add(OppCaricaPeer::POLITICO_ID, $votazione->getPoliticoId());
    if (!in_array($votazione->getPoliticoId(), $senatori_a_vita)) {
        $c3->add(OppCaricaPeer::LEGISLATURA, $seduta->getLegislatura());
    }
    $carica = OppCaricaPeer::doSelectOne($c3);
    $votazioneCarica = new OppVotazioneHasCarica();
    $votazioneCarica->setVotazioneId($votazione->getVotazioneId());
    $votazioneCarica->setCaricaId($carica->getId());
    $votazioneCarica->setVoto($votazione->getVoto());
    $votazioneCarica->save();
    ?>
			   <b><?php 
    echo OppVotazionePeer::doSelectCountVotazioniPerPeriodo('', '', '16', 'C');
    ?>
 votazioni elettroniche d'aula finora svolte (ultima votazione del <?php 
    echo format_date(OppVotazionePeer::doSelectDataUltimaVotazione('', '', '16', 'C'), 'dd/MM/yyyy');
    ?>
).</b>
			<?php 
} else {
    ?>
			   <b><?php 
    echo OppVotazionePeer::doSelectCountVotazioniPerPeriodo('', '', '16', 'S');
    ?>
 votazioni elettroniche d'aula finora svolte (ultima votazione del <?php 
    echo format_date(OppVotazionePeer::doSelectDataUltimaVotazione('', '', '16', 'S'), 'dd/MM/yyyy');
    ?>
).</b>
			<?php 
}
?>
<br />
			Esplorando l'immagine si scopre come i <?php 
echo $tipo == "votes_16_C" ? 'deputati' : 'senatori';
?>
 si distribuiscono nello spazio in base ai loro voti. Si possono notare le distanze tra
			le nuvole di colore omogeneo ognuna delle quali corrisponde ad un gruppo parlamentare diverso ma anche verificare all'interno della stessa nuvola (gruppo) le prossimit&agrave; e le lontananze di voto tra
			un parlamentare e l'altro.<br />
			Prende forma in questo modo uno spazio politico inedito in cui &egrave; possibile confrontare e verificare,
			con <?php 
echo link_to('approssimazione affidabile', '/static/faq#11a');
<?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";
 $c = new Criteria();
 $c->add(OppSedutaPeer::ID, $votazione->getSedutaId(), Criteria::EQUAL);
 $seduta = OppSedutaPeer::doSelectOne($c);
 $c = new Criteria();
 $crit0 = $c->getNewCriterion(OppGruppoRamoPeer::RAMO, $seduta->getRamo());
 $crit1 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_INIZIO, $seduta->getData(), Criteria::LESS_EQUAL);
 $crit2 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_FINE, $seduta->getData(), Criteria::GREATER_THAN);
 $crit3 = $c->getNewCriterion(OppGruppoRamoPeer::DATA_FINE, NULL, Criteria::ISNULL);
 $crit2->addOr($crit3);
 $crit0->addAnd($crit1);
 $crit0->addAnd($crit2);
 $c->add($crit0);
 $gruppi_votazione = OppGruppoRamoPeer::doSelect($c);
 foreach ($gruppi_votazione as $gruppo) {
     $gr = OppGruppoPeer::retrieveByPk($gruppo->getGruppoId());
     $voto_gruppo = OppVotazionePeer::doSelectVotoGruppo($votazione->getId(), $gr->getNome());
     $c = new Criteria();
     $c->add(OppVotazioneHasGruppoPeer::VOTAZIONE_ID, $votazione->getId());
     $c->add(OppVotazioneHasGruppoPeer::GRUPPO_ID, $gr->getId());
     $result = OppVotazioneHasGruppoPeer::doSelectOne($c);
     if ($result) {
         $result->setVoto($voto_gruppo);
         $result->save();
         print $gr->getNome() . ": " . $voto_gruppo . "\n";
     } else {
         $insert = new OppVotazioneHasGruppo();
         $insert->setVotazioneId($votazione->getId());
         $insert->setGruppoId($gr->getId());
         $insert->setVoto($voto_gruppo);
         $insert->save();
         print "++++++++++++++++ " . $gr->getNome() . ": " . $voto_gruppo . "\n";
<?php

/*
Controlla le votazioni, e mette 1 al campo ìs_maggioranza_sotto nel caso nella votazione la maggioranza sia stata battuta.
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();
$votazioni = OppVotazionePeer::doSelect(OppVotazionePeer::maggioranzaSottoCriteria($argv[1], $argv[2]));
if (count($votazioni) > 0) {
    foreach ($votazioni as $v) {
        //if (OppVotazionePeer::isMaggioranzaUnitaSuVotazione($v->getId()))
        //{
        $v->setIsMaggioranzaSottoSalva(1);
        $v->save();
        echo $v->getId() . "\n";
        //}
    }
}
mail("*****@*****.**", "UP MAGG. SOTTO", "controllo magg sotto", "From: 1_lista_ddl_new");
 /**
  * torna array contenente il dettaglio del comportamento dei gruppi
  * - Gruppo Misto
  *   - favorevole  => N
  *   - contrario   => N
  *   - astenuto    => N
  *   - assente     => N
  *   - in missione => N
  *
  * @param integer $votazione_id 
  * @return complex hash
  * @author Guglielmo Celata
  */
 public static function doSelectGroupByGruppo($votazione_id, $data = null)
 {
     if (is_null($data)) {
         $votazione = OppVotazionePeer::retrieveByPK($votazione_id);
         $data = $votazione->getOppSeduta()->getData('Y-m-d');
     }
     $risultato = array();
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addSelectColumn(OppGruppoPeer::NOME);
     $c->addSelectColumn(OppVotazioneHasCaricaPeer::VOTO);
     $c->addSelectColumn(OppGruppoPeer::ID);
     $c->addAsColumn('CONT', 'COUNT(*)');
     $c->addJoin(OppVotazioneHasCaricaPeer::CARICA_ID, OppCaricaPeer::ID, Criteria::INNER_JOIN);
     $c->addJoin(OppVotazioneHasCaricaPeer::CARICA_ID, OppCaricaHasGruppoPeer::CARICA_ID, Criteria::INNER_JOIN);
     $c->addJoin(OppCaricaHasGruppoPeer::GRUPPO_ID, OppGruppoPeer::ID, Criteria::INNER_JOIN);
     $c->add(OppVotazioneHasCaricaPeer::VOTAZIONE_ID, $votazione_id);
     $c->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $data, Criteria::LESS_EQUAL);
     $cton1 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, $data, Criteria::GREATER_EQUAL);
     $cton2 = $c->getNewCriterion(OppCaricaHasGruppoPeer::DATA_FINE, null, Criteria::ISNULL);
     $cton1->addOr($cton2);
     $c->add($cton1);
     $c->addGroupByColumn(OppGruppoPeer::NOME);
     $c->addGroupByColumn(OppVotazioneHasCaricaPeer::VOTO);
     $rs = OppVotazioneHasCaricaPeer::doSelectRS($c);
     while ($rs->next()) {
         if (!isset($risultato[$rs->getString(1)])) {
             $risultato[$rs->getString(1)] = array('id' => $rs->getInt(3), 'Favorevole' => 0, 'Contrario' => 0, 'Astenuto' => 0, 'Assente' => 0, 'In missione' => 0);
         }
         if (isset($risultato[$rs->getString(1)][$rs->getString(2)])) {
             $risultato[$rs->getString(1)][$rs->getString(2)] = $rs->getInt(4);
         }
     }
     return $risultato;
 }
- 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::getVotazioniMaggioranzaSalva($argv[1]));
} else {
    $c = new Criteria();
    $c->add(OppVotazionePeer::ID, $argv[2]);
    $c->add(OppVotazionePeer::IS_MAGGIORANZA_SOTTO_SALVA, 2, Criteria::EQUAL);
    $votazioni = OppVotazionePeer::doSelect($c);
}
echo count($votazioni) . "\n\n";
if (count($votazioni) > 0) {
    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);
</div>

 
<?php 
slot('breadcrumbs');
?>
  <?php 
echo link_to("home", "@homepage");
?>
 /
  <?php 
echo link_to('votazioni', '@votazioni');
?>
    /
  <?php 
$votazione = OppVotazionePeer::retrieveByPk($sf_params->get('id'));
?>
  <?php 
echo $votazione->getTitolo();
end_slot();
?>

<script type="text/javascript" charset="utf-8">
  jQuery.noConflict();
   jQuery(document).ready(function($) { 
     $("#complete-chart").tablesorter({
       sortList: [[0, 0]], 
       widgets: ['zebra']
     }); 
   });  
 </script>
 /**
  * Executes Ddl index action
  *
  */
 public function executeDdlIndex()
 {
     $c = new Criteria();
     $c->add(OppAttoPeer::ID, $this->getRequestParameter('id'), Criteria::EQUAL);
     $this->ddl = OppAttoPeer::doSelectOne($c);
     $this->forward404Unless($this->ddl);
     $pred = '';
     $pred_1 = '';
     if ($this->ddl->getPred()) {
         $pred = $this->getPrimoPred($this->ddl->getPred());
         $pred_1 = $this->ddl->getId();
     } else {
         $pred = $this->ddl->getId();
         $pred_1 = $this->ddl->getId();
     }
     $this->primi_firmatari = OppAttoPeer::doSelectPrimiFirmatari($pred);
     $this->co_firmatari = OppAttoPeer::doSelectCoFirmatari($pred);
     $this->relatori = OppAttoPeer::doSelectRelatori($pred_1);
     $this->commissioni = $this->ddl->getCommissioni();
     $this->status = $this->ddl->getStatus();
     $this->iter_completo = $this->ddl->getIterCompleto();
     $this->tesei = OppAttoPeer::doSelectTeseo($pred);
     $this->lettura_parlamentare_precedente = null;
     $leggi = $this->ddl->getOppLegges();
     if (count($leggi) > 0) {
         $this->legge = $leggi[0];
     } else {
         $this->legge = "";
     }
     /*
     $quale_atto=$this->getTuttiSucc($this->ddl->getId());
     if (count($quale_atto)==0) $leggi=$this->ddl->getOppLegges();
     else $leggi=$quale_atto[count($quale_atto)-1]->getOppLegges();
     	
     if (count($leggi)>0) $this->legge=$leggi[0];
     else $this->legge="";
     */
     if ($this->ddl->getPred()) {
         $c = new Criteria();
         $c->add(OppAttoPeer::ID, $this->ddl->getPred(), Criteria::EQUAL);
         $this->lettura_parlamentare_precedente = OppAttoPeer::doSelectOne($c);
     }
     $this->lettura_parlamentare_successiva = null;
     if ($this->ddl->getSucc()) {
         $c = new Criteria();
         $c->add(OppAttoPeer::ID, $this->ddl->getSucc(), Criteria::EQUAL);
         $this->lettura_parlamentare_successiva = OppAttoPeer::doSelectOne($c);
     }
     $c = new Criteria();
     $c->add(OppVotazionePeer::ID, $this->ddl->getIdVotazioni(), Criteria::IN);
     $c->addDescendingOrderByColumn(OppSedutaPeer::DATA);
     $c->addDescendingOrderByColumn(OppVotazionePeer::FINALE);
     $this->votazioni = OppVotazionePeer::doSelectJoinOppSeduta($c);
     $this->interventi = $this->ddl->getInterventi();
 }
<?php

/*
Controlla le votazioni, e mette 2 al campo ìs_maggioranza_sotto nel caso nella votazione la maggioranza sia stata battuta.
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();
$votazioni = OppVotazionePeer::maggioranzaSalva($argv[1], $argv[2]);
if (count($votazioni) > 0) {
    foreach ($votazioni as $v) {
        //if (OppVotazionePeer::isMaggioranzaUnitaSuVotazione($v->getId()))
        //{
        //$v->setIsMaggioranzaSottoSalva(2);
        //$v->save();
        echo $v->getId() . "\n";
        //}
    }
}
mail("*****@*****.**", "UP MAGG. SALVA", "ctrl magg salva", "From: 1_lista_ddl_new");
 public function executeMaggioranzaSalva()
 {
     $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 salvata dai voti dell\'opposizione - ' . sfConfig::get('app_main_title'));
     $this->response->addMeta('description', 'Il dettaglio delle votazioni elettroniche di Camera e Senato in cui la maggioranza &egrave; stata salvata dai voti e dalle assenze dei parlamentari di opposizione.', 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/maggioranzaSalva');
     }
     $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::getVotazioniMaggioranzaSalva();
     $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();
 }
 public function getRibelleReport($carica_id, $ramo, $gruppo, $data_inizio, $data_fine)
 {
     $esiti_gruppo = array();
     $count = 0;
     //determinazione voto esito gruppo nel periodo considerato
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addSelectColumn(OppVotazionePeer::ID);
     $c->addSelectColumn(OppSedutaPeer::DATA);
     $c->addSelectColumn(OppVotazioneHasCaricaPeer::VOTO);
     $c->addAsColumn('CONT', 'COUNT(*)');
     $c->addJoin(OppVotazionePeer::SEDUTA_ID, OppSedutaPeer::ID, Criteria::INNER_JOIN);
     $c->addJoin(OppVotazionePeer::ID, OppVotazioneHasCaricaPeer::VOTAZIONE_ID, Criteria::INNER_JOIN);
     $c->addJoin(OppVotazioneHasCaricaPeer::CARICA_ID, OppCaricaHasGruppoPeer::CARICA_ID, Criteria::INNER_JOIN);
     $c->addJoin(OppCaricaHasGruppoPeer::GRUPPO_ID, OppGruppoPeer::ID, Criteria::INNER_JOIN);
     $c->add(OppSedutaPeer::RAMO, $ramo, Criteria::EQUAL);
     $c->add(OppSedutaPeer::DATA, $data_inizio, Criteria::GREATER_EQUAL);
     if ($data_fine != '') {
         $c->add(OppSedutaPeer::DATA, $data_fine, Criteria::LESS_EQUAL);
     }
     $c->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $data_inizio, Criteria::GREATER_EQUAL);
     if ($data_fine != '') {
         $c->add(OppCaricaHasGruppoPeer::DATA_FINE, $data_fine, Criteria::LESS_EQUAL);
     }
     $c->add(OppGruppoPeer::NOME, $gruppo, Criteria::EQUAL);
     $c->addGroupByColumn(OppVotazionePeer::ID);
     $c->addGroupByColumn(OppVotazioneHasCaricaPeer::VOTO);
     $c->addAscendingOrderByColumn(OppVotazionePeer::ID);
     $c->addDescendingOrderByColumn('CONT');
     $rs = OppVotazionePeer::doSelectRS($c);
     while ($rs->next()) {
         if (!isset($esiti_gruppo[$rs->getInt(1)])) {
             $esiti_gruppo[$rs->getInt(1)] = $rs->getString(3);
         }
     }
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addSelectColumn(OppVotazionePeer::ID);
     $c->addSelectColumn(OppVotazioneHasCaricaPeer::VOTO);
     $c->addJoin(OppVotazionePeer::SEDUTA_ID, OppSedutaPeer::ID, Criteria::INNER_JOIN);
     $c->addJoin(OppVotazionePeer::ID, OppVotazioneHasCaricaPeer::VOTAZIONE_ID, Criteria::INNER_JOIN);
     $c->addJoin(OppVotazioneHasCaricaPeer::CARICA_ID, OppCaricaHasGruppoPeer::CARICA_ID, Criteria::INNER_JOIN);
     $c->add(OppSedutaPeer::RAMO, $ramo, Criteria::EQUAL);
     $c->add(OppVotazioneHasCaricaPeer::CARICA_ID, $carica_id, Criteria::EQUAL);
     $c->add(OppCaricaHasGruppoPeer::DATA_INIZIO, $data_inizio, Criteria::GREATER_EQUAL);
     $c->add(OppSedutaPeer::DATA, $data_inizio, Criteria::GREATER_EQUAL);
     if ($data_fine != '') {
         $c->add(OppSedutaPeer::DATA, $data_fine, Criteria::LESS_EQUAL);
     }
     if ($data_fine != '') {
         $c->add(OppCaricaHasGruppoPeer::DATA_FINE, $data_fine, Criteria::LESS_EQUAL);
     }
     $c->addAscendingOrderByColumn(OppVotazionePeer::ID);
     $rs1 = OppVotazionePeer::doSelectRS($c);
     while ($rs1->next()) {
         if ($rs1->getString(2) == 'Astenuto' || $rs1->getString(2) == 'Contrario' || $rs1->getString(2) == 'Favorevole') {
             if ($esiti_gruppo[$rs1->getInt(1)] != '' && $rs1->getString(2) != $esiti_gruppo[$rs1->getInt(1)]) {
                 $count++;
             }
         }
     }
     return $count;
 }
 protected function addVotiSortCriteria($c)
 {
     if ($sort_column = $this->session->getAttribute('sort', 'data', 'opp_parlamentare_voti/sort')) {
         if ($sort_column == 'data') {
             $sort_column = OppSedutaPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
         } else {
             $sort_column = OppVotazionePeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
         }
         if ($this->session->getAttribute('type', null, 'opp_parlamentare_voti/sort') == 'asc') {
             $c->addAscendingOrderByColumn($sort_column);
         } else {
             $c->addDescendingOrderByColumn($sort_column);
         }
     }
 }
$voto['Favorevole'] = 'FAV';
$voto['Contrario'] = 'CON';
$voto['Astenuto'] = 'AST';
$voto['Assente'] = 'NA';
$voto['In missione'] = 'NA';
$voto['Presidente di turno'] = 'NA';
$voto['Richiedente la votazione e non votante'] = 'NA';
$voto['Voto segreto'] = 'SKIP';
$voto['Partecipante votazione non valida'] = 'SKIP';
//calcola il numro totale di votazioni per ramp per escludere i parl. con poche votazioni
$c = new Criteria();
$c->addJoin(OppSedutaPeer::ID, OppVotazionePeer::SEDUTA_ID);
$c->add(OppSedutaPeer::LEGISLATURA, $legislatura);
//$c->add(OppCaricaPeer::IS_IMPORTED,1);
$c->add(OppSedutaPeer::RAMO, $ramo);
$num_votazioni = OppVotazionePeer::doCount($c);
$min_presenze = intval($num_votazioni * 50 / 100);
// estrae le cariche (attuali) per ramo e legislatura,
$c = new Criteria();
$c->add(OppCaricaPeer::LEGISLATURA, $legislatura);
$c->add(OppCaricaPeer::DATA_FINE, null, Criteria::ISNULL);
if ($ramo == 'C') {
    $c->add(OppCaricaPeer::TIPO_CARICA_ID, 1);
} else {
    $c->add(OppCaricaPeer::TIPO_CARICA_ID, array(4, 5), Criteria::IN);
}
//selezione dei parlamentari con il 50% minimo di presenze al voto
$c->add(OppCaricaPeer::PRESENZE, $min_presenze, Criteria::GREATER_THAN);
$cariche = OppCaricaPeer::doSelect($c);
unset($c);
$ncariche = count($cariche);
 public function executeVotiInEvidenza()
 {
     $namespace = 'key';
     if ($this->hasRequestParameter('namespace')) {
         $namespace = $this->getRequestParameter('namespace');
     }
     $base_href = 'openparlamento';
     if ($this->hasRequestParameter('base_href')) {
         $base_href = $this->getRequestParameter('base_href');
     }
     setlocale(LC_TIME, 'it_IT');
     sfLoader::loadHelpers(array('Tag', 'Url', 'DeppNews'));
     if ($base_href == 'espresso') {
         $site_link = "http://www.openpolitix.it";
         $site_url = "http://espresso.repubblica.it/dal_parlamento/voti-chiave";
     } else {
         $site_link = url_for('@homepage', true);
         $site_url = 'http://' . sfConfig::get('sf_site_url');
     }
     $feed = new sfRss2ExtendedFeed();
     $feed->initialize(array('title' => 'Voti in evidenza', 'link' => $site_link, 'feedUrl' => $this->getRequest()->getURI(), 'siteUrl' => $site_url, 'image' => 'http://' . sfConfig::get('sf_site_url') . '/images/logo-openparlamento.png', 'language' => 'it', 'authorEmail' => '*****@*****.**', 'authorName' => 'Openparlamento', 'description' => "Openparlamento.it - il progetto Openpolis per la trasparenza del Parlamento", 'sy_updatePeriod' => 'daily', 'sy_updateFrequency' => '1', 'sy_updateBase' => '2000-01-01T12:00+00:00'));
     $voti = OppVotazionePeer::getKeyVotes(20, $namespace);
     foreach ($voti as $voto) {
         $description = sprintf("%s, seduta n. %s. Esito: %s. Scarto: %d. Ribelli: %d", $voto->getOppSeduta()->getRamo() == 'C' ? 'Camera' : 'Senato', $voto->getOppSeduta()->getNumero(), $voto->getEsito(), $voto->getMargine(), $voto->getRibelli());
         $item = new sfRss2ExtendedItem();
         if ($base_href == 'espresso') {
             $item_link = sprintf("http://espresso.repubblica.it/dal_parlamento/votazioni/%d", $voto->getId());
         } else {
             $item_link = url_for('@votazione?' . $voto->getUrlParams(), true);
         }
         $aggiuntivo_only = true;
         $item->initialize(array('title' => $voto->getTitoloAggiuntivo() ? $voto->getTitoloAggiuntivo() : $voto->getTitolo(), 'link' => $item_link, 'permalink' => $item_link, 'pubDate' => $voto->getOppSeduta()->getData('U'), 'uniqueId' => $voto->getId(), 'description' => $description, 'authorEmail' => '*****@*****.**', 'authorName' => 'Openparlamento'));
         $feed->addItem($item);
     }
     $this->_send_output($feed);
     return sfView::NONE;
 }
sfContext::getInstance();
$t = new lime_test(16, new lime_output_color());
$t->diag('unit test to verify the mechanisms of wiki descriptions automatic creation and removal');
$t->diag('Tests beginning');
// clean the database
$t->diag('Cleaning previously created test records');
$c = new Criteria();
$c->add(OppAttoPeer::PARLAMENTO_ID, 999999);
$existing_records = OppAttoPeer::doSelect($c);
foreach ($existing_records as $rec) {
    $t->diag('Cleaning record ' . get_class($rec) . "(" . $rec->getId() . ")");
    $rec->delete();
}
$c = new Criteria();
$c->add(OppVotazionePeer::NUMERO_VOTAZIONE, 999999);
$existing_records = OppVotazionePeer::doSelect($c);
foreach ($existing_records as $rec) {
    $t->diag('Cleaning record ' . get_class($rec) . "(" . $rec->getId() . ")");
    $rec->delete();
}
$t->diag('Create the act object');
$obj_atto = new OppAtto();
$obj_atto->setTipoAttoId(1);
$obj_atto->setParlamentoId(999999);
$obj_atto->setDataPres('2008-11-01');
$obj_atto->setDescrizione("Un'atto di test");
$obj_atto->save();
$prefix = sfConfig::get(sprintf('propel_behavior_wikifiableBehavior_%s_prefix', get_class($obj_atto)));
$t->ok($prefix == 'atto', 'The prefix was correctly read from the behavior configuration');
$wiki_page = nahoWikiPagePeer::retrieveByName($prefix . "_" . $obj_atto->getId());
$t->ok($wiki_page instanceof nahoWikiPage, 'a wiki page was just created for this object');
$t->diag('Create the test act object');
$obj = new OppAtto();
$obj->setTipoAttoId(1);
$obj->setParlamentoId(999999);
$obj->setRamo('S');
$obj->setNumFase(914);
$obj->setDataPres('2008-11-01');
$obj->setDescrizione("Una descrizione di prova");
$obj->save();
$related_news = getRelatedNews($obj);
$n_related_news = count($related_news);
$first_news = $related_news[0];
$t->ok($n_related_news == 1, 'One news related to the act was generated');
dumpNews($t, "news related to the act", $related_news);
$t->diag('Create a non-final votation: two more news expected (group and detail)');
$vot = OppVotazionePeer::retrieveByPK(9900);
$vot_att = new OppVotazioneHasAtto();
$vot_att->setOppVotazione($vot);
$vot_att->setOppAtto($obj);
$vot_att->save();
$related_news = getRelatedNews($obj);
$n_related_news = count($related_news);
$t->ok($n_related_news == 3, 'Now there are two more news related to the act');
dumpNews($t, "news related to the act", $related_news);
$t->diag('Create a document');
$doc = new OppDocumento();
$doc->setData('2008-11-20');
$doc->setTitolo('Titolo di prova');
$doc->setOppAtto($obj);
$doc->save();
$related_news = getRelatedNews($obj);
		<?php 
echo include_partial('secondLevelVotiMaggioranzaSalva', array('current' => 'lista'));
?>
		
	</div>
</div>

<div class="row">
	<div class="ninecol">
		
		<p style="padding:10px 0 5px 0; font-size:16px;">
	        In questa legislatura la maggioranza che sostiene il Governo &egrave; stata salvata in <?php 
echo number_format($pager->getNbResults(), 0, ',', '.');
?>
 votazioni (su un totale di <?php 
echo number_format(OppVotazionePeer::doSelectCountVotazioniPerPeriodo('', '', 16, 'C') + OppVotazionePeer::doSelectCountVotazioniPerPeriodo('', '', 16, 'S'), 0, ',', '.');
?>
 voti) dai voti e dalle assenze dei parlamentari di opposizione.<br/>
	        <?php 
include_partial('wikiMaggioranzaSalva');
?>
  
	      </p>		

	      <?php 
include_partial('filter', array('tags_categories' => $all_tags_categories, 'active' => deppFiltersAndSortVariablesManager::arrayHasNonzeroValue(array_values($filters)), 'selected_type' => array_key_exists('type', $filters) ? $filters['type'] : 0, 'selected_tags_category' => array_key_exists('tags_category', $filters) ? $filters['tags_category'] : 0, 'selected_ramo' => array_key_exists('ramo', $filters) ? $filters['ramo'] : 0, 'selected_esito' => array_key_exists('esito', $filters) ? $filters['esito'] : 0));
?>



	      <?php 
 /**
  * API (protetta da una API key)
  * torna flusso xml con i voti chiave
  * progetto op_kw
  *
  *  <opkw xmlns="http://www.openpolis.it/2010/opkw"
  *         xmlns:op="http://www.openpolis.it/2010/op"
  *         xmlns:op_location="http://www.openpolis.it/2010/op_location"
  *         xmlns:op_politician="http://www.openpolis.it/2010/op_politician"
  *         xmlns:xlink="http://www.w3.org/1999/xlink">
  *    <op:content> 
  *      <voti_chiave n_voti="50">
  *        <voto xlink:href="/votazioni/32288.xml">
  *          <titolo>Titolo</titolo>
  *          <data>28/04/2010</data>
  *          <ramo>Camera</ramo>
  *          <num_seduta>313</num_seduta>
  *          <esito>respinto</esito>
  *          <n_ribelli>34</n_ribelli>
  *        </voto>
  *        ...
  *      </voti_chiave>
  *    </op:content>
  *  </opkw>
  *
  *       
  * Return error in case something's wrong
  * <opkw xlmns="http://www.openpolis.it/2010/opkw"
  *       xmlns:op="http://www.openpolis.it/2010/op"
  *       xlmns:op_location="http://www.openpolis.it/2010/op_location"
  *       xmlns:op_politician="http://www.openpolis.it/2010/op_politician">
  *   <op:error>Messaggio di errore</op:error>
  * </opkw>
  * @return String
  * @author Guglielmo Celata
  **/
 public function executeElencoVotiChiave()
 {
     $key = $this->getRequestParameter('key');
     $home = $this->getRequestParameter('home') == 'true' ? true : false;
     $is_valid_key = deppApiKeysPeer::isValidKey($key);
     $resp_node = new SimpleXMLElement('<opkw xmlns="' . $this->opkw_ns . '" ' . ' xmlns:op="' . $this->op_ns . '" ' . ' xmlns:xlink="' . $this->xlink_ns . '" >' . '</opkw>');
     if ($is_valid_key) {
         // start producing xml
         $content_node = $resp_node->addChild('op:content', null, $this->op_ns);
         if ($home) {
             $votazioni = OppVotazionePeer::getLastTwoKeyVotes('relevant');
         } else {
             $votazioni = OppVotazionePeer::getKeyVotes(0, 'relevant');
         }
         // voti chiave
         $voti_node = $content_node->addChild('voti_chiave', null, $this->opkw_ns);
         $voti_node->addAttribute('n_voti', count($votazioni));
         foreach ($votazioni as $votazione) {
             $data = $votazione->getOppSeduta()->getData('d/m/Y');
             $ramo = $votazione->getOppSeduta()->getRamo() == 'C' ? 'Camera' : 'Senato';
             $n_seduta = $votazione->getOppSeduta()->getNumero();
             $href = sprintf("/votazioni/%s.xml", $votazione->getId());
             $titulo = $votazione->getTitoloAggiuntivo() ? $votazione->getTitoloAggiuntivo() : $votazione->getTitolo();
             $esito = $votazione->getEsito();
             $n_ribelli = $votazione->getRibelli();
             $voto_node = $voti_node->addChild('voto', null, $this->opkw_ns);
             $voto_node->addAttribute('xlink:href', $href, $this->xlink_ns);
             $voto_node->addAttribute('id', $votazione->getId());
             $voto_node->addChild('data', $data);
             $voto_node->addChild('ramo', $ramo);
             $voto_node->addChild('n_seduta', $n_seduta);
             $voto_node->addChild('titolo', $titulo);
             $voto_node->addChild('esito', ucfirst(strtolower($esito)));
             $voto_node->addChild('n_ribelli', $n_ribelli);
             if ($home) {
                 $voto_node->addChild('link', $href);
             }
         }
     } else {
         $resp_node->addChild('op:error', 'Chiave di accesso non valida', $this->op_ns);
     }
     $xmlContent = $resp_node->asXML();
     $this->_send_output($xmlContent);
     return sfView::NONE;
 }
 public function executeKeyvotes()
 {
     $this->votazioni = OppVotazionePeer::getKeyVotes($this->limit, $this->type);
 }