/**
  * 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 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;
 }
 public function executeKeyvotes()
 {
     $this->votazioni = OppVotazionePeer::getKeyVotes($this->limit, $this->type);
 }