Exemplo n.º 1
0
 /**
  * Export this class's data
  * 
  * @param string $type (csv, json, xml, sql)
  * @param array $display
  * @param string $filename
  * @param string $action (return, download)
  * @return bool
  */
 public function Export($type, $display = NULL, $filename = NULL, $action = 'return')
 {
     // Create the export object
     $myExport = new Export();
     // Set the filename
     $myExport->SetFilename($filename != NULL ? $filename : get_class($this));
     // Reset all data going in
     $data = array();
     $i = 0;
     // If display array, reorganize
     if (is_array($display)) {
         // Add the first row titles if CSV
         if ($type == 'csv') {
             // Grab the labels
             foreach ($display as $field) {
                 if ($this->IsField($field)) {
                     $data[$i][$field] = $this->GetLabel($field);
                 } else {
                     $data[$i][$field] = $field;
                 }
             }
         }
     } else {
         // Default display is all the fields
         $display = $this->GetFields();
     }
     // Grab the data in order of display
     foreach ($this->results as $key => $row) {
         $i++;
         foreach ($display as $field) {
             $data[$i][$field] = stripslashes($row[$field]);
         }
     }
     // Set the display
     if ($type != 'csv') {
         $myExport->SetDisplay($display);
     }
     // Set the data
     $myExport->SetData($data);
     // Do requested action
     if ($action == 'return') {
         return $myExport->Retrieve($type);
     } else {
         $myExport->Download($type);
     }
     return false;
 }