Changeset 12186

Show
Ignore:
Timestamp:
09/12/07 22:01:38 (1 year ago)
Author:
bergie
Message:

Some bulletproofing and downloadable reports

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/fi.mik.lentopaikkakisa/handler/download.php

    r3414 r12186  
    2828        $_MIDCOM->header("Content-type: text/xml; charset=UTF-8"); 
    2929         
    30         $qb = fi_mik_lentopaikkakisa_report_dba::new_query_builder(); 
     30        $qb = fi_mik_flight_dba::new_query_builder(); 
    3131        $qb->add_order('created', 'DESC'); 
    3232        $this->_request_data['all'] = $qb->execute(); 
     
    3737    function _show_xml($handler_id, &$data) 
    3838    { 
     39        $_MIDCOM->load_library('midcom.helper.xml'); 
    3940        echo "<reports>\n"; 
    4041        $mapper = new midcom_helper_xml_objectmapper(); 
     
    5051        $_MIDCOM->auth->require_valid_user(); 
    5152        $_MIDCOM->skip_page_style = true; 
    52         $_MIDCOM->header('Content-Type: text/plain;charset=UTF-8'); 
     53        $_MIDCOM->cache->content->content_type('application/csv'); 
     54        $_MIDCOM->header('Content-Type: application/csv;charset=UTF-8'); 
    5355         
    54         $qb = fi_mik_lentopaikkakisa_report_dba::new_query_builder(); 
     56        $qb = fi_mik_flight_dba::new_query_builder(); 
    5557        $qb->add_order('created', 'DESC'); 
    5658        $this->_request_data['all'] = $qb->execute(); 
     
    6163    function _show_csv($handler_id, &$data) 
    6264    { 
     65        $pilots = array(); 
     66        $organizations = array(); 
     67        $aircraft = array(); 
     68        echo "date,firstname,lastname,username,operator,aircraft,origin,destination,score_origin,score_destination\n"; 
    6369        foreach ($this->_request_data['all'] as $report) 
    6470        { 
    6571            // FIXME: Use DM2 CSV output system 
    66             echo date('Y-m-d', $report->date).",{$report->organization},{$report->aerodrome},{$report->plane},".str_replace(',','.',$report->score).",{$report->sendername}\n"; 
     72            if (!isset($pilots[$report->pilot])) 
     73            { 
     74                $pilots[$report->pilot] = new midcom_db_person($report->pilot); 
     75            } 
     76            if (!isset($organizations[$report->operator])) 
     77            { 
     78                $organizations[$report->operator] = new midcom_db_group($report->operator); 
     79            } 
     80            if (!isset($aircraft[$report->aircraft])) 
     81            { 
     82                $aircraft[$report->aircraft] = new org_openpsa_calendar_resource_dba($report->aircraft); 
     83            } 
     84            echo date('Y-m-d', $report->end).",{$pilots[$report->pilot]->firstname},{$pilots[$report->pilot]->lastname},{$pilots[$report->pilot]->username},{$organizations[$report->operator]->official},{$aircraft[$report->aircraft]->title},{$report->origin},{$report->destination},".str_replace(',','.',$report->scoreorigin).",".str_replace(',','.',$report->scoredestination)."\n"; 
    6785        } 
    6886    }   
  • trunk/midcom/fi.mik.lentopaikkakisa/handler/score.php

    r5578 r12186  
    5555        { 
    5656            $owner = new $report_class($score->parentguid); 
    57             $data['scores'][$owner->$report_label] = $score->value; 
    58             $data['total'] += $score->value; 
     57            $data['scores']["{$owner->$report_label} ({$score->parentguid}"] = (int) $score->value; 
     58            $data['total'] += (int) $score->value; 
    5959        } 
     60         
     61        arsort($data['scores']); 
    6062        return true; 
    6163    } 
  • trunk/midcom/fi.mik.lentopaikkakisa/viewer.php

    r5572 r12186  
    4848            'fixed_args' => Array('score', 'pilot'), 
    4949        ); 
     50 
     51        // Match /flights.xml 
     52        $this->_request_switch['xml'] = Array 
     53        ( 
     54            'handler' => Array('fi_mik_lentopaikkakisa_handler_download', 'xml'), 
     55            'fixed_args' => Array('flights.xml'), 
     56        ); 
     57        
     58        // Match /flights.csv 
     59        $this->_request_switch['csv'] = Array 
     60        ( 
     61            'handler' => Array('fi_mik_lentopaikkakisa_handler_download', 'csv'), 
     62            'fixed_args' => Array('flights.csv'), 
     63        ); 
    5064    } 
    5165