public function getVotoParlamentari($data = null) { if (is_null($data)) { $data = $this > getOppSeduta()->getData('Y-m-d'); } return OppVotazioneHasCaricaPeer::getVotoParlamentari($this->getId(), $data); }
/** * 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; }
$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");
$c = new Criteria(); $c->clearSelectColumns(); $c->addSelectColumn(OppVotazioneHasCaricaPeer::VOTAZIONE_ID); $c->addSelectColumn(OppVotazioneHasCaricaPeer::VOTO); $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, $argv[1], Criteria::EQUAL); if ($df != '') { $cton1 = $c->getNewCriterion(OppSedutaPeer::DATA, $di, Criteria::GREATER_EQUAL); $cton2 = $c->getNewCriterion(OppSedutaPeer::DATA, $df, Criteria::LESS_EQUAL); $cton1->addAnd($cton2); $c->add($cton1); } else { $c->add(OppSedutaPeer::DATA, $di, Criteria::GREATER_EQUAL); } $rs = OppVotazioneHasCaricaPeer::doSelectRS($c); $voto_carica = array(); while ($rs->next()) { $voto_carica[$rs->getInt(1)] = $rs->getString(2); } $cont = 0; foreach ($voto_gruppo as $indice => $voto) { if (isset($voto_carica[$indice]) && ($voto == 'Favorevole' || $voto == 'Astenuto' || $voto == 'Contrario') && $voto != $voto_carica[$indice]) { if ($voto_carica[$indice] == 'Favorevole' || $voto_carica[$indice] == 'Astenuto' || $voto_carica[$indice] == 'Contrario') { $cont = $cont + 1; echo "votazione: " . $indice . " voto gruppo: " . $voto . " voto carica: " . $voto_carica[$indice] . "\n"; } } } /* $c = new Criteria();
<?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";
/** * Calcola o ri-calcola i dati da cachare per i politici * - presenze, assenze, missioni * - indice di attivitร (nuovo) * - ribellioni * Si puรฒ specificare: * - il ramo (camera, senato, governo, parlamento, tutti*) * - la data (da inizio legislatura a quella data) * Se sono passati degli ID (argomenti), sono interpretati come ID di politici e il calcolo รจ fatto solo per loro * L'opzione --verbose, permette di visualizzare il dettaglio dei calcoli svolti */ function run_opp_build_cache_politici($task, $args, $options) { static $loaded; // load application context if (!$loaded) { task_loader(); $loaded = true; } echo "memory usage: " . memory_get_usage() . "\n"; $msg = sprintf("start time: %s\n", date('H:i:s')); echo $msg; $data = ''; $ramo = 'tutti'; $tipo = 'P'; $verbose = false; $dry_run = false; if (array_key_exists('data', $options)) { $data = $options['data']; } if (array_key_exists('ramo', $options)) { $ramo = strtoupper($options['ramo'][0]); } if (array_key_exists('verbose', $options)) { $verbose = true; } if (array_key_exists('dry_run', $options)) { $dry_run = true; } // restrizione su un subset di atti/emendamenti per eventuale debug $atti_ids = array(); if (array_key_exists('atti', $options)) { $atti_ids = explode(",", $options['atti']); } $emendamenti_ids = array(); if (array_key_exists('emendamenti', $options)) { $emendamenti_ids = explode(",", $options['emendamenti']); } // definisce la data fino alla quale vanno fatti i calcoli // data_lookup serve per controllare se i record giร esistono if ($data != '') { $legislatura_corrente = OppLegislaturaPeer::getCurrent($data); $data_lookup = $data; } else { $legislatura_corrente = OppLegislaturaPeer::getCurrent(); $data = date('Y-m-d'); if ($ramo == 'tutti') { $data_lookup = OppPoliticianHistoryCachePeer::fetchLastData('P'); } else { $data_lookup = OppPoliticianHistoryCachePeer::fetchLastData('P', $ramo); } } $msg = sprintf("calcolo cache per politici data: %10s, ramo: %10s\n", $data ? $data : '-', $ramo); echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true)); if (count($args) > 0) { try { $parlamentari_rs = OppCaricaPeer::getRSFromIDArray($args); } catch (Exception $e) { throw new Exception("Specificare degli ID validi. \n" . $e); } } else { $parlamentari_rs = OppCaricaPeer::getParlamentariRamoDataRS($ramo, $legislatura_corrente, $data); } echo "memory usage: " . memory_get_usage() . "\n"; $start_time = time(); $cnt = 0; $indice_ar = array(); $presenze_ar = array(); $missioni_ar = array(); $assenze_ar = array(); while ($parlamentari_rs->next()) { $cnt++; $p = $parlamentari_rs->getRow(); $nome = $p['nome']; $cognome = $p['cognome']; $tipo_carica_id = $p['tipo_carica_id']; $id = $p['id']; list($mio_ramo, $prefisso) = OppTipoCaricaPeer::getRamoPrefisso($tipo_carica_id); $gruppo = OppCaricaPeer::getGruppo($id, $data); $politico_stringa = sprintf("%s %s %s", $prefisso, $nome, strtoupper($cognome)); printf("%4d) %40s %7s [%06d] ... ", $cnt, $politico_stringa, "(" . $gruppo['acronimo'] . ")", $id); $indice = OppIndiceAttivitaPeer::calcola_indice_politico($id, $legislatura_corrente, $data, $verbose, $atti_ids); list($presenze, $assenze, $missioni) = OppVotazioneHasCaricaPeer::getDatiPresenzaCaricaData($id, $legislatura_corrente, $data); $ribellioni = OppVotazioneHasCaricaPeer::countRibellioniCaricaData($id, $legislatura_corrente, $data); // inserimento o aggiornamento del valore in opp_politician_history_cache if (!$dry_run) { $cache_record = OppPoliticianHistoryCachePeer::retrieveByDataChiTipoChiIdRamo($data_lookup, 'P', $id, $mio_ramo); if (!$cache_record) { $cache_record = new OppPoliticianHistoryCache(); } $cache_record->setLegislatura($legislatura_corrente); $cache_record->setChiTipo('P'); $cache_record->setChiId($id); $cache_record->setRamo($mio_ramo); $cache_record->setGruppoId($gruppo['id']); $cache_record->setIndice($indice); $cache_record->setPresenze($presenze); $cache_record->setAssenze($assenze); $cache_record->setMissioni($missioni); $cache_record->setRibellioni($ribellioni); $cache_record->setData($data); $cache_record->setNumero(1); // il dato riguarda un solo soggetto $cache_record->setUpdatedAt(date('Y-m-d H:i')); // forza riscrittura updated_at, per tenere traccia esecuzioni $cache_record->save(); unset($cache_record); } $msg = sprintf("i: %7.2f p:%4d a:%4d m:%4d, r:%4d", $indice, $presenze, $assenze, $missioni, $ribellioni); echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true)); $msg = sprintf(" [%4d sec] [%10d bytes]\n", time() - $start_time, memory_get_usage()); echo pakeColor::colorize($msg, array('fg' => 'red', 'bold' => false)); } $msg = sprintf("end time: %s\n", date('H:i:s')); echo $msg; $msg = sprintf("memory usage: %10d\n", memory_get_usage()); echo pakeColor::colorize($msg, array('fg' => 'red', 'bold' => false)); $msg = sprintf("%d parlamentari elaborati\n", $cnt); echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true)); }
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); }
<?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(); } }
$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 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; }
protected function addSortCriteria(&$c) { if ($sort_column = $this->getUser()->getAttribute('sort', NULL, 'opp_votazione/sort')) { switch ($this->getUser()->getAttribute('sort', NULL, 'opp_votazione/sort')) { case 'parlamentare': $sort_column = OppPoliticoPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); break; case 'gruppo': $sort_column = 'nome'; $sort_column = OppGruppoPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); break; case 'circoscrizione': $sort_column = OppCaricaPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); break; case 'voto': $sort_column = OppVotazioneHasCaricaPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); break; } if ($this->getUser()->getAttribute('type', NULL, 'opp_votazione/sort') == 'asc') { $c->addAscendingOrderByColumn($sort_column); } else { $c->addDescendingOrderByColumn($sort_column); } } }
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); }
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à 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'); } } }