/**
  * estrae tutti gli atti presentati dal parlamentare nel corso della legislatura
  * sono considerate tutte le cariche ricoperte
  *
  * @return void
  * @author Guglielmo Celata
  */
 public function executeAttiPresentati()
 {
     $cariche_ids = $this->parlamentare->getCaricheCorrentiIds();
     if (count($cariche_ids) == 0) {
         $this->atti_presentati = array();
         return;
     }
     $cariche_ids_as_string = join($cariche_ids, ",");
     /* select raw 
        select ta.descrizione, ca.tipo, count(ta.id) 
         from opp_carica_has_atto ca, opp_atto a, opp_tipo_atto ta 
         where ca.atto_id=a.id and a.tipo_atto_id=ta.id and carica_id=$carica->getId() 
         group by ta.id, ca.tipo
         order by ta.id;
        */
     $connection = Propel::getConnection();
     $query = "SELECT %s AS tipo, %s AS tipo_id, %s AS firma, count(%s) AS cnt " . "FROM %s, %s, %s " . "WHERE %s=%s and %s=%s and %s in ({$cariche_ids_as_string})" . "GROUP BY %s, %s " . "ORDER BY %s";
     $query = sprintf($query, OppTipoAttoPeer::DESCRIZIONE, OppTipoAttoPeer::ID, OppCaricaHasAttoPeer::TIPO, OppTipoAttoPeer::ID, OppCaricaHasAttoPeer::TABLE_NAME, OppAttoPeer::TABLE_NAME, OppTipoAttoPeer::TABLE_NAME, OppCaricaHasAttoPeer::ATTO_ID, OppAttoPeer::ID, OppAttoPeer::TIPO_ATTO_ID, OppTipoAttoPeer::ID, OppCaricaHasAttoPeer::CARICA_ID, OppTipoAttoPeer::ID, OppCaricaHasAttoPeer::TIPO, OppTipoAttoPeer::ID);
     $statement = $connection->prepareStatement($query);
     $rs = $statement->executeQuery();
     $atti = array();
     while ($rs->next()) {
         $tipo = $rs->getString('tipo');
         $tipo_id = $rs->getString('tipo_id');
         if (!array_key_exists($tipo, $atti)) {
             $atti[$tipo] = array('id' => $tipo_id, 'C' => 0, 'P' => 0, 'R' => 0);
         }
         $firma = $rs->getString('firma');
         $cnt = $rs->getInt('cnt');
         $atti[$tipo][$firma] = $cnt;
     }
     $this->atti_presentati = $atti;
     for ($x = 0; $x < 2; $x++) {
         $c = new Criteria();
         $c->add(OppCaricaHasEmendamentoPeer::CARICA_ID, $cariche_ids, Criteria::IN);
         if ($x == 0) {
             $c->add(OppCaricaHasEmendamentoPeer::TIPO, 'P');
             $this->emen_primo = OppCaricaHasEmendamentoPeer::doCount($c);
         } else {
             $c->add(OppCaricaHasEmendamentoPeer::TIPO, 'C');
             $this->emen_co = OppCaricaHasEmendamentoPeer::doCount($c);
         }
     }
 }