Ignore:
Timestamp:
May 25, 2010, 9:10:07 PM (11 years ago)
Author:
teymour
Message:
  • Ajout d'info sur le député dans la synthese
  • Ajout du format csv
  • Api pour les députés
Location:
cpc/trunk/project/apps/frontend
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • cpc/trunk/project/apps/frontend/config/routing.yml

    r1195 r1198  
    365365  url: /:slug/rss
    366366  param: {module: parlementaire, action: rss, Intervention: 1, QuestionEcrite: 1, Amendement: 1}
     367parlementaire_api_xml:
     368  url: /:slug/xml
     369  param: {module: api, action: parlementaire, type: xml}
     370parlementaire_api_json:
     371  url: /:slug/json
     372  param: {module: api, action: parlementaire, type: json}
     373parlementaire_api_csv:
     374  url: /:slug/csv
     375  param: {module: api, action: parlementaire, type: csv}
    367376parlementaire_interventions:
    368377  url: /:slug/interventions/:type
  • cpc/trunk/project/apps/frontend/modules/api/actions/actions.class.php

    r1195 r1198  
    2828    $this->forward404Unless(isset($top[$date]));
    2929
    30     $this->setLayout(false);
    3130    $this->res = array();
     31    $this->champs = array();
    3232    foreach(array_keys($top[$date]) as $id) {
    3333      $depute['id'] = $id;
     34      $this->champs['id'] = 1;
     35
    3436      foreach (array_keys($top[$date][$id]) as $k) {
    3537        $depute[$k] = $top[$date][$id][$k]['value'];
     38        $this->champs[$k] = 1;
    3639      }
    3740      $this->res["deputes"][] = array('depute' => $depute);
    3841    }
    39    
    40     $this->templatize($request->getParameter('type'));
     42
     43    for($i = 0 ; $i < count($this->res["deputes"]) ; $i++) {
     44      foreach(array_keys($this->champs) as $key) {
     45        if (!isset($this->res['deputes'][$i]['depute'][$key])) {
     46          $this->res['deputes'][$i]['depute'][$key] = 0;
     47        }
     48      }
     49    }
     50
     51    $this->breakline = 'depute';
     52    $this->templatize($request, $date.'_stats_deputes');
    4153  }
    42   private function templatize($type) {
    43     switch($type) {
     54
     55  protected function array2hash($array, $hashname) {
     56    if (!$array)
     57      return '';
     58    $hash = array();
     59    if (!isset($array[0])) {
     60      return $array;
     61    }
     62    foreach($array as $e) {
     63      if ($e)
     64        $hash[] = array($hashname => preg_replace('/\n/', ', ', $e));
     65    }
     66    return $hash;
     67  }
     68
     69  public function executeParlementaire(sfWebRequest $request)
     70  {
     71    $slug = $request->getParameter('slug');
     72    $this->forward404Unless($slug);
     73
     74    $depute = doctrine::getTable('Parlementaire')->findOneBySlug($slug);
     75    $this->res = array();
     76    $this->multi = array();
     77    $this->res['depute'] = array();
     78    $this->res['depute']['id'] = $depute->id;
     79    $this->res['depute']['nom'] = $depute->nom;
     80    $this->res['depute']['nom_de_famille'] = $depute->nom_de_famille;
     81    $this->res['depute']['groupe'] = $depute->getGroupe();
     82    $this->res['depute']['groupe_sigle'] = $depute->groupe_acronyme;
     83    $this->res['depute']['site_web'] = $depute->site_web;
     84    $this->res['depute']['url_an'] = 'http://www.assembleenationale.fr/13/tribun/fiches_id/'.$depute->id_an.'.asp';
     85    $this->res['depute']['emails'] = $this->array2hash(unserialize($depute->mails), 'email');
     86    $this->multi['email'] = 1;
     87    $this->res['depute']['adresses'] = $this->array2hash(unserialize($depute->adresses), 'adresse');
     88    $this->multi['adresse'] = 1;
     89    $this->res['depute']['autres_mandats'] = $this->array2hash(unserialize($depute->autres_mandats), 'mandat');
     90    $this->multi['mandat'] = 1;
     91    $this->res['depute']['responsabilites'] = $this->array2hash($depute->getResponsabilites(), 'responsabilite');
     92    $this->res['depute']['responsabilites_extra_parlementaires'] = $this->array2hash($depute->getExtras(), 'responsabilite');
     93    $this->multi['responsabilite'] = 1;
     94    $this->champ = 'depute';
     95    $this->breakline = '';
     96
     97    $this->templatize($request, 'nosdeputes.fr_'.$slug);
     98  }
     99
     100  private function templatize($request, $filename) {
     101    $this->setLayout(false);
     102    switch($request->getParameter('type')) {
    44103      case 'json':
    45104        $this->setTemplate('json');
    46         $this->getResponse()->setContentType('text/plain');
     105        if (!$request->getParameter('textplain')) {
     106          $this->getResponse()->setContentType('text/plain; charset=utf-8');
     107          $this->getResponse()->setHttpHeader('content-disposition', 'attachment; filename="'.$filename.'.json"');
     108        }
    47109        break;
    48110      case 'xml':
    49111        $this->setTemplate('xml');
    50         $this->getResponse()->setContentType('text/xml');
     112        if (!$request->getParameter('textplain')) {
     113          $this->getResponse()->setContentType('text/xml; charset=utf-8');
     114          //    $this->getResponse()->setHttpHeader('content-disposition', 'attachment; filename="'.$filename.'.xml"');
     115        }
     116        break;
     117      case 'csv':
     118        $this->setTemplate('csv');
     119        if (!$request->getParameter('textplain')) {
     120          $this->getResponse()->setContentType('application/csv; charset=utf-8');
     121          $this->getResponse()->setHttpHeader('content-disposition', 'attachment; filename="'.$filename.'.csv"');
     122        }
    51123        break;
    52124    default:
    53125      $this->forward404();
    54      
     126    }
     127    if ($request->getParameter('textplain')) {
     128      $this->getResponse()->setContentType('text/plain; charset=utf-8');
    55129    }
    56130  }
  • cpc/trunk/project/apps/frontend/modules/api/templates/xmlSuccess.php

    r1195 r1198  
    11<?
    2 
    3 function depile_assoc($asso) {
     2$alreadyline = 0;
     3function depile_assoc($asso, $breakline) {
     4  global $alreadyline;
    45  foreach (array_keys($asso) as $k) {
     6    if (!$alreadyline && $k == $breakline) {
     7      echo "\n";
     8      $alreadyline = 1;
     9    }
    510    echo "<$k>";
    6     echo depile($asso[$k]);
     11    echo depile($asso[$k], $breakline);
    712    echo "</$k>";
     13    if ($k == $breakline) {
     14      echo "\n";
     15    }
    816  }
    917}
    1018
    11 function depile($res) {
     19function depile($res, $breakline) {
    1220  if (is_array($res)) {
    1321    if (!isset($res[0])) {
    14       depile_assoc($res);
     22      depile_assoc($res, $breakline);
    1523    }else{
    1624      foreach($res as $r) {
    17         depile($r);
     25        depile($r, $breakline);
    1826      }
    1927    }
     
    2331}
    2432
    25 depile($res);
     33depile($res, $breakline);
Note: See TracChangeset for help on using the changeset viewer.