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; }
/** * Executes index action * */ public function executeIndex() { $votazione_id = $this->getRequestParameter('id'); $this->votazione = OppVotazionePeer::retrieveByPK($votazione_id); $this->forward404Unless($this->votazione); $this->ramo = $this->votazione->getOppSeduta()->getRamo() == 'C' ? 'Camera' : 'Senato'; $data = $this->votazione->getOppSeduta()->getData('Y-m-d'); $this->risultati = $this->votazione->getVotoGruppi($data); $this->ribelli = $this->votazione->getVotoRibelli($data); $this->getResponse()->setTitle('Votazione ' . $this->ramo . ' ' . $this->votazione->getTitolo() . ' - ' . sfConfig::get('app_main_title')); $this->response->addMeta('description', 'Come hanno votato i gruppi, che voto hanno espresso i singoli parlamentari e quali sono stati ribelli al proprio gruppo parlamentare per la votazione ' . $this->ramo . ' ' . $this->votazione->getTitolo(), true); $this->processSort(); $this->votanti = OppVotazioneHasCaricaPeer::getRSAllVotanti($votazione_id, $data); $this->votantiComponent = OppVotazioneHasCaricaPeer::getRSAllVotanti($votazione_id, $data); $c = new Criteria(); $c->add(OppVotazioneHasGruppoPeer::VOTAZIONE_ID, $votazione_id); $this->voto_gruppi = OppVotazioneHasGruppoPeer::doSelect($c); $c = new Criteria(); $c->add(OppVotazioneHasAttoPeer::VOTAZIONE_ID, $votazione_id); $this->voto_atti = OppVotazioneHasAttoPeer::doSelect($c); $c = new Criteria(); $c->add(OppVotazioneHasEmendamentoPeer::VOTAZIONE_ID, $votazione_id); $this->voto_ems = OppVotazioneHasEmendamentoPeer::doSelect($c); }
$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);
/** * 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; }
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);
/** * API (protetta da una API key) * torna flusso xml con i dati di una singola votazione * 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> * <votazione> * <riferimenti> * <atto xlink:href="http://parlamento.openpolis.it/votazione/32288"></atto> * ... * </riferimenti> * <sorgente xlink:href="http://leg16.camera.it/resoconti/resoconto_votazioni.asp?idSeduta=313&resoconto=indice_votazioni" /> * <titolo>1 Titulo</titolo> * <descrizione_wiki>La descrizione ...</descrizione_wiki> * <data>28/04/2010</data> * <ramo>Camera</ramo> * <num_seduta>313</num_seduta> * <dettagli_voto> * <esito>respinto</esito> * <favorevoli n="225" perc="50.1" /> * <contrari n="224" perc="49.9" /> * <astenuti n="0" perc="0.0" /> * <scarto n="1"> * <presenti n="449" perc="71.3" /> * <assenti n="103" perc="16.3" /> * <in_missione n="76" perc="12.1" /> * <voto_ribelli n_voti="3"> * <parlamentare> * <nome>Giancarlo</nome> * <cognome>ABELLI</cognome> * <acronimo_gruppo>PDL</acronimo_gruppo> * <voto>Contrario</voto> * <voto_gruppo>Favorevole</voto_gruppo> * </parlamentare> * ... * </voto_ribelli> * <voto_gruppi> * <gruppo> * <nome>Gruppo misto</nome> * <favorevoli n="11" /> * <contrari n="1"> * <astenuti n="0"> * <assenti n="13"> * <in_missione n="6"> * </gruppo> * ... * </voto_gruppi> * <voto_parlamentari> * <parlamentare xlink:href="/parlamentari/4573.xml"> * <nome>Giancarlo</nome> * <cognome>ABELLI</cognome> * <acronimo_gruppo>PDL</acronimo_gruppo> * <voto>Contrario</voto> * </parlamentare> * ... * </voto_parlamentari> * </dettagli_voto> * </votazione> * </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 executeVotazione() { $key = $this->getRequestParameter('key'); $id = $this->getRequestParameter('id'); $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) { // estrazione informazioni $votazione = OppVotazionePeer::retrieveByPK($id); $seduta = $votazione->getOppSeduta(); $data = $seduta->getData('Y-m-d'); $titulo = $votazione->getTitoloAggiuntivo() ? $votazione->getTitoloAggiuntivo() : $votazione->getTitolo(); $favorevoli = $votazione->getFavorevoli(); $contrari = $votazione->getContrari(); $astenuti = $votazione->getAstenuti(); $votanti = $votazione->getVotanti(); $presenti = $votazione->getPresenti(); $ribelli = $votazione->getRibelli(); $favorevoli_perc = sprintf("%4.1f", 100.0 * $favorevoli / $votanti); $contrari_perc = sprintf("%4.1f", 100.0 * $contrari / $votanti); $astenuti_perc = sprintf("%4.1f", 100.0 * $astenuti / $votanti); $voto_gruppi = $votazione->getVotoGruppi($data); $voto_ribelli = $votazione->getVotoRibelli($data); $voto_parlamentari = $votazione->getVotoParlamentari($data); // produzione xml $content_node = $resp_node->addChild('op:content', null, $this->op_ns); $votazione_node = $content_node->addChild('votazione', null, $this->opkw_ns); $dettagli_node = $votazione_node->addChild('dettagli_voto', null, $this->opkw_ns); $dettagli_node->addChild('data', $seduta->getData('d/m/Y')); $dettagli_node->addChild('ramo', $seduta->getRamo() == 'C' ? 'Camera' : 'Senato'); $dettagli_node->addChild('n_votazione', $votazione->getNumeroVotazione()); $dettagli_node->addChild('n_seduta', $seduta->getNumero()); $dettagli_node->addChild('titolo', $titulo); $dettagli_node->addChild('esito', ucfirst(strtolower($votazione->getEsito()))); $favorevoli_node = $dettagli_node->addChild('favorevoli', null); $favorevoli_node->addAttribute('n', $favorevoli); $favorevoli_node->addAttribute('perc', $favorevoli_perc); $contrari_node = $dettagli_node->addChild('contrari', null); $contrari_node->addAttribute('n', $contrari); $contrari_node->addAttribute('perc', $contrari_perc); $astenuti_node = $dettagli_node->addChild('astenuti', null); $astenuti_node->addAttribute('n', $astenuti); $astenuti_node->addAttribute('perc', $astenuti_perc); $presenti_node = $dettagli_node->addChild('presenti', null); $presenti_node->addAttribute('n', $presenti); $votanti_node = $dettagli_node->addChild('votanti', null); $votanti_node->addAttribute('n', $votanti); $ribelli_node = $dettagli_node->addChild('ribelli', null); $ribelli_node->addAttribute('n', $ribelli); // dettaglio voto dei gruppi $gruppi_node = $votazione_node->addChild('voto_gruppi', null, $this->opkw_ns); foreach ($voto_gruppi as $nome => $detail) { $gruppo_node = $gruppi_node->addChild('gruppo', null, $this->opkw_ns); $gruppo_node->addChild('nome', $nome, $this->opkw_ns); foreach ($detail as $key => $value) { $gruppo_node->addChild(strtolower(str_replace(' ', '_', $key)), $value, $this->opkw_ns); } } // dettaglio voto dei ribelli $ribelli_node = $votazione_node->addChild('voto_ribelli', null, $this->opkw_ns); $ribelli_node->addAttribute('n_voti', $votazione->getRibelli()); foreach ($voto_ribelli as $cognome => $ribelle) { $parlamentare_node = $ribelli_node->addChild('parlamentare', null, $this->opkw_ns); $parlamentare_node->addAttribute('xlink:href', sprintf("/parlamentari/%d.xml", $ribelle['politico_id']), $this->xlink_ns); $parlamentare_node->addAttribute('id', $ribelle['politico_id']); $parlamentare_node->addChild('nome', $ribelle['politico_nome'], $this->opkw_ns); $parlamentare_node->addChild('cognome', $ribelle['politico_cognome'], $this->opkw_ns); $parlamentare_node->addChild('acronimo_gruppo', $ribelle['gruppo_acronimo'], $this->opkw_ns); $parlamentare_node->addChild('voto', $ribelle['voto']); $parlamentare_node->addChild('voto_gruppo', $ribelle['voto_gruppo']); } // dettaglio voto dei parlamentari $parlamentari_node = $votazione_node->addChild('voto_parlamentari', null, $this->opkw_ns); foreach ($voto_parlamentari as $p) { $parlamentare_node = $parlamentari_node->addChild('parlamentare', null, $this->opkw_ns); $parlamentare_node->addAttribute('xlink:href', sprintf("/parlamentari/%d.xml", $p['id']), $this->xlink_ns); $parlamentare_node->addAttribute('id', $p['id']); $parlamentare_node->addChild('nome', $p['nome'], $this->opkw_ns); $parlamentare_node->addChild('cognome', $p['cognome'], $this->opkw_ns); $parlamentare_node->addChild('nome_gruppo', $p['nome_gruppo'], $this->opkw_ns); $parlamentare_node->addChild('acronimo_gruppo', $p['acronimo_gruppo'], $this->opkw_ns); $parlamentare_node->addChild('voto', $p['voto']); $parlamentare_node->addChild('circoscrizione', $p['circoscrizione'], $this->opkw_ns); } } 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; }