Skip to content
Permalink
Browse files

feat: add newsletter subscriber export

  • Loading branch information...
themightychris committed Jun 19, 2019
1 parent f993b3f commit 0bc3a1a98d163958c8a4599e8c7920bf4ebc9cea
Showing with 55 additions and 0 deletions.
  1. +55 −0 data-exporters/newsletter.php
@@ -0,0 +1,55 @@
<?php
return [
'title' => 'Newsletter Subscribers',
'description' => 'Each row represents a registered user who has not opted out from the newsletter',
'filename' => 'subscribers',
'headers' => [
'Created' => 'Joined',
'Email',
'FirstName' => 'First Name',
'LastName' => 'Last Name'
],
'readQuery' => function (array $input) {
$query = [];
return $query;
},
'buildRows' => function (array $query = [], array $config = []) {
// build rows
try {
$result = DB::query(
'
SELECT Person.*
FROM `%s` Person
WHERE Email IS NOT NULL
AND Newsletter
ORDER BY Created DESC
',
[
Person::$tableName
]
);
while ($record = $result->fetch_assoc()) {
$Person = Person::instantiateRecord($record);
yield [
'Created' => date('Y-m-d H:i:s', $Person->Created),
'Email' => $Person->Email,
'FirstName' => $Person->FirstName,
'LastName' => $Person->LastName
];
}
} finally {
unset($record);
unset($Person);
if ($result) {
$result->free();
}
unset($result);
}
}
];

0 comments on commit 0bc3a1a

Please sign in to comment.
You can’t perform that action at this time.