/**
  * 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;
 }