Xataface 2.0
Xataface Application Framework
actions/export_json.php
Go to the documentation of this file.
00001 <?php
00134 class dataface_actions_export_json {
00135         function handle(&$params){
00136                 $app =& Dataface_Application::getInstance();
00137                 $query =& $app->getQuery();
00138                 
00139                 $records = df_get_selected_records($query);
00140                 if ( !$records ){
00141                         if ( $query['-mode'] == 'list' ){
00142                                 $records = df_get_records_array($query['-table'], $query);
00143                         } else {
00144                                 $records = array( $app->getRecord() );
00145                         }
00146                 }
00147                 
00148                 $displayMethod = 'val';
00149                 if ( @$query['--displayMethod'] == 'display' ){
00150                         $displayMethod = 'display';
00151                 } else if ( @$query['--displayMethod'] == 'htmlValue' ){
00152                         $displayMethod = 'htmlValue';
00153                 }
00154                 
00155                 $out = array();
00156                 if ( isset( $query['--fields'] ) ){
00157                         $fields = explode(' ', $query['--fields']);
00158                 } else {
00159                         $fields = null;
00160                 }
00161                 
00162                 foreach ($records as $record){
00163                         if ( !$record->checkPermission('export_json')  ){
00164                                 continue;
00165                         }
00166                         
00167                         if ( is_array($fields) ){
00168                                 $allowed_fields = array();
00169                                 foreach ($fields as $field ){
00170                                         if ( !$record->checkPermission('export_json', array('field'=>$field) ) ){
00171                                                 continue;
00172                                         }
00173                                         $allowed_fields[] = $field;
00174                                 }
00175                         } else {
00176                                 $allowed_fields = array_keys($record->table()->fields(false,true));
00177                         }
00178                         $row = array();
00179                         foreach ( $allowed_fields as $fld ){
00180                                 $row[$fld] = $record->$displayMethod($fld);
00181                         }
00182                         $out[] = $row;
00183                 }
00184                 
00185                 import('Services/JSON.php');
00186                 $json = new Services_JSON;
00187                 $enc_out = $json->encode($out);
00188                 header('Content-type: application/json; charset='.$app->_conf['oe']);
00189                 header('Connection: close');
00190                 echo $enc_out;
00191                 exit;
00192         }
00193 }
 All Data Structures Namespaces Files Functions Variables Enumerations