diff --git a/campaignion_csv.module b/campaignion_csv.module index 5c1a27a..4894099 100644 --- a/campaignion_csv.module +++ b/campaignion_csv.module @@ -11,6 +11,9 @@ use Drupal\campaignion_csv\Exporter\ContactExporter; use Drupal\campaignion_csv\Exporter\OptInExporter; use Drupal\campaignion_csv\Exporter\TargetStatsExporter; use Drupal\campaignion_csv\Exporter\TargetMessageExporter; +use Drupal\campaignion_csv\Exporter\WebformFormatted\DateFormatter; +use Drupal\campaignion_csv\Exporter\WebformFormatted\Exporter as WebformFormattedExporter; +use Drupal\campaignion_csv\Exporter\WebformFormatted\OptInChannelSelector; use Drupal\campaignion_csv\Exporter\WebformFormatted\SubmissionPropertySelector; use Drupal\campaignion_csv\Exporter\WebformGeneric\Exporter as WebformExporter; use Drupal\campaignion_csv\Files\ContactRangeFilePattern; @@ -43,6 +46,10 @@ function campaignion_csv_cron() { * Implements hook_campaignion_csv_info(). */ function campaignion_csv_campaignion_csv_info() { + $date_transformer = [ + 'class' => DateFormatter::class, + 'date_format' => '%d/%m/%Y - %H:%M', + ]; $export['actions_monthly'] = [ 'file_pattern' => [ 'class' => MonthlyFilePattern::class, @@ -56,6 +63,109 @@ function campaignion_csv_campaignion_csv_info() { 'donations' => FALSE, ], ]; + $export['actions_monthly_fixed'] = [ + 'file_pattern' => [ + 'class' => MonthlyFilePattern::class, + 'path' => 'actions/fixed_%Y-%m.csv', + 'retention_period' => new \DateInterval('P6M'), + 'refresh_interval' => new \DateInterval('PT23H30M'), + ], + 'exporter' => [ + 'class' => WebformFormattedExporter::class, + 'columns' => [ + 'NID' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'nid', + ], + 'SID' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'sid', + ], + 'Time' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'submitted', + 'transformers' => [$date_transformer], + ], + 'Completed Time' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'completed', + 'transformers' => [$date_transformer], + ], + 'Modified Time' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'modified', + 'transformers' => [$date_transformer], + ], + 'Draft' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'is_draft', + ], + 'Referer' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.referer', + ], + 'External Referer' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.external_referer', + ], + 'Form URL' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.form_url', + ], + 'Entry URL' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.entry_url', + ], + 'Referring SID' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.refsid', + ], + 'Source' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.source', + ], + 'Channel' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.medium', + ], + 'Version' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.version', + ], + 'Other' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.other', + ], + 'Country' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.country', + ], + 'Terms' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.term', + ], + 'Campaign' => [ + 'selector' => SubmissionPropertySelector::class, + 'property' => 'tracking.campaign', + ], + 'First name' => ['keys' => ['first_name']], + 'Last name' => ['keys' => ['last_name']], + 'E-mail address' => ['keys' => ['email']], + 'Postcode' => ['keys' => ['postcode']], + 'City' => ['keys' => ['city']], + 'Country' => ['keys' => ['country']], + 'Address line 1' => ['keys' => ['street_address']], + 'Address line 2' => ['keys' => ['street_address_2']], + 'City' => ['keys' => ['city']], + 'Comment' => ['keys' => ['comment']], + 'Email opt-in' => [ + 'selector' => OptInChannelSelector::class, + 'channel' => 'email', + ], + 'Phone number' => ['keys' => ['phone_number']], + ], + ], + ]; $export['donations_monthly'] = [ 'file_pattern' => [ 'class' => MonthlyFilePattern::class, diff --git a/src/Exporter/OptInExporter.php b/src/Exporter/OptInExporter.php index 33a68de..9458eb2 100644 --- a/src/Exporter/OptInExporter.php +++ b/src/Exporter/OptInExporter.php @@ -57,6 +57,10 @@ protected function buildQuery() { ->fields('ca', ['contact_id', 'created']); $q->innerJoin('campaignion_opt_in', 'o', 'o.activity_id=ca.activity_id'); $q->fields('o', ['id', 'channel', 'statement']); + $q->innerJoin('field_data_redhen_contact_email', 'ce', 'ce.entity_id=ca.contact_id'); + $q->fields('ce', ['redhen_contact_email_value']); + $q->innerJoin('campaignion_activity_webform', 'aw', 'aw.activity_id=ca.activity_id'); + $q->fields('aw', ['nid','sid']); $q->condition('ca.created', [$start, $end - 1], 'BETWEEN'); $q->condition('o.operation', $this->optIn ? 1 : 0); $q->orderBy('o.id'); @@ -71,8 +75,11 @@ public function writeTo(CsvFileInterface $file) { '#', 'Time', 'Contact ID', + 'Submission ID', + 'Node ID', 'Channel', 'Statement', + 'Email', ]; $file->writeRow($header); @@ -81,8 +88,11 @@ public function writeTo(CsvFileInterface $file) { $r->id, format_date($r->created, 'custom', $this->dateFormat), $r->contact_id, + $r->sid, + $r->nid, $r->channel, $r->statement, + $r->redhen_contact_email_value, ]; $file->writeRow($row); }