chg: [API] further work on the new CSV export

pull/3608/head
iglocska 2018-08-14 23:38:01 +02:00
parent 1d5ff2f146
commit 006a922e9f
3 changed files with 18 additions and 9 deletions

View File

@ -2695,8 +2695,6 @@ class EventsController extends AppController
if ($user === false) {
return $exception;
}
App::uses('CsvExport', 'Export');
$export = new CsvExport();
// if it's a search, grab the attributeIDList from the session and get the IDs from it. Use those as the condition
// We don't need to look out for permissions since that's filtered by the search itself
// We just want all the attributes found by the search
@ -2775,11 +2773,13 @@ class EventsController extends AppController
'requested_attributes' => $requested_attributes,
'includeContext' => $includeContext
);
App::uses('CsvExport', 'Export');
$export = new CsvExport();
$final = $export->header($options);
while ($continue) {
$attributes = $this->Event->csv($user, $params, false, $continue);
$params['page'] += 1;
$final .= $export->handler($attributes, $final);
$final .= $export->handler($attributes, $final, $options);
$final .= $export->separator($attributes, $final);
}
$export->footer();

View File

@ -16,6 +16,7 @@ class CsvExport
public function handler($attributes, $final, $options = array())
{
$result = array();
foreach ($attributes as $attribute) {
$line1 = '';
$line2 = '';
@ -29,7 +30,7 @@ class CsvExport
$line2 = rtrim($line2, ",");
$line = $line1 . ',' . $line2;
$line = rtrim($line, ",");
if ($includeContext) {
if (!empty($options['includeContext'])) {
foreach ($this->Event->csv_event_context_fields_to_fetch as $header => $field) {
if ($field['object']) {
$line .= ',' . $attribute['Event'][$field['object']][$field['var']];
@ -38,9 +39,10 @@ class CsvExport
}
}
}
$final .= $line;
$result[] = $line;
}
return $final;
$result = implode(PHP_EOL, $result);
return $result;
}
public function header($options = array())
@ -60,7 +62,7 @@ class CsvExport
$headers[$k] = 'date';
}
}
$headers = implode(',', $headers);
$headers = implode(',', $headers) . PHP_EOL;
return $headers;
}

View File

@ -2837,10 +2837,14 @@ class Attribute extends AppModel
$continue = false;
continue;
}
} else {
$continue = false;
}
$results = $this->find('all', $params);
if (!$loop) {
if (!empty($params['limit']) && count($results) < $params['limit']) {
$continue = false;
}
$break = true;
}
// return false if we're paginating
if (isset($options['limit']) && empty($results)) {
return array();
@ -2869,6 +2873,9 @@ class Attribute extends AppModel
}
$attributes[] = $results[$key];
}
if ($break) {
break;
}
}
return $attributes;
}