Skip to content

Commit 56816c6

Browse files
committed
Include computed data in members export
1 parent 354e54b commit 56816c6

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/Exporters/AbstractExporter.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ abstract public function contentType();
1111

1212
abstract public function export();
1313

14+
protected function getKeys()
15+
{
16+
return User::blueprint()
17+
->fields()
18+
->except(['id', 'groups', 'roles', 'password'])
19+
->all()
20+
->keys()
21+
->merge(['id', 'last_login'])
22+
->merge(User::getComputedCallbacks()->keys())
23+
->all();
24+
}
25+
1426
protected function getData()
1527
{
1628
return Member::query()->get()
1729
->map(function ($user) {
1830
$data = $user->data();
31+
$computedData = $user->computedData();
1932

20-
return User::blueprint()->fields()->all()->keys()->flip()
21-
->reject(function ($field, $key) {
22-
return in_array($key, ['id', 'groups', 'roles', 'password']);
23-
})
24-
->map(function ($field, $key) use ($data) {
25-
return $data[$key] ?? null;
33+
return collect($this->getKeys())
34+
->flip()
35+
->map(function ($field, $key) use ($data, $computedData) {
36+
return $data[$key] ?? $computedData[$key] ?? null;
2637
})
2738
->merge([
2839
'id' => $user->id(),

src/Exporters/CsvExporter.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use League\Csv\Writer;
66
use SplTempFileObject;
7-
use Statamic\Facades\User;
87

98
class CsvExporter extends AbstractExporter
109
{
@@ -22,23 +21,12 @@ public function contentType()
2221

2322
public function export()
2423
{
25-
$this->writer->insertOne($this->getHeaders());
24+
$this->writer->insertOne($this->getKeys());
2625
$this->writer->insertAll($this->getData());
2726

2827
return (string) $this->writer;
2928
}
3029

31-
protected function getHeaders()
32-
{
33-
return User::blueprint()
34-
->fields()
35-
->except(['id', 'groups', 'roles', 'password'])
36-
->all()
37-
->keys()
38-
->merge(['id', 'last_login'])
39-
->all();
40-
}
41-
4230
protected function getData()
4331
{
4432
return collect(parent::getData())

0 commit comments

Comments
 (0)