Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Apr 14, 2024
1 parent 18f11f9 commit 1c3f183
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes for Campaign

## 3.1.0 - Unreleased

### Added

- Added one-click unsubscribe headers to sent emails ([#467](https://github.com/putyourlightson/craft-campaign/issues/467)).
- Added a new one-click unsubscribe controller action.
- Added an `addOneClickUnsubscribeHeaders` config setting that determines whether one-click unsubscribe headers should be added to emails, defaulting to `true`.

## 3.0.0 - 2024-04-08

> {warning} “Legacy” and “Template” segments are no longer available will be deleted in this update. They should be replaced with regular segments before updating, or they will be lost.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "putyourlightson/craft-campaign",
"description": "Send and manage email campaigns, contacts and mailing lists.",
"version": "3.0.0",
"version": "3.1.0",
"type": "craft-plugin",
"homepage": "https://putyourlightson.com/plugins/campaign",
"license": "proprietary",
Expand Down
27 changes: 14 additions & 13 deletions src/services/ReportsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use craft\db\ActiveRecord;
use craft\db\Query;
use craft\db\Table;
use craft\enums\CmsEdition;
use craft\helpers\DateTimeHelper;
use craft\helpers\Db;
use craft\helpers\Json;
Expand Down Expand Up @@ -56,12 +57,12 @@ public function getMaxIntervals(string $interval): int
/**
* Returns campaigns report data.
*/
public function getCampaignsReportData(Site|int|null $site = null): array
public function getCampaignsReportData(Site|null $site = null): array
{
// Get all sent campaigns
$campaigns = CampaignElement::find()
->status(CampaignElement::STATUS_SENT)
->orderBy('lastSent DESC')
->orderBy(['lastSent' => SORT_DESC])
->site($site)
->all();

Expand Down Expand Up @@ -432,7 +433,7 @@ public function getContactMailingListActivity(int $contactId, int $limit = null,
/**
* Returns mailing lists report data.
*/
public function getMailingListsReportData(Site|int|null $site = null): array
public function getMailingListsReportData(Site|null $site = null): array
{
// Get all mailing lists in all sites
$mailingLists = MailingListElement::find()
Expand Down Expand Up @@ -650,7 +651,7 @@ private function getChartData(string $recordClass, array $condition, array $inte
$fields = [];

foreach ($record->fields() as $field) {
$fields[] = 'MIN([[' . $field . ']]) AS ' . $field;
$fields[$field] = 'MIN([[' . $field . ']])';
}

// Get records within date range
Expand All @@ -659,7 +660,7 @@ private function getChartData(string $recordClass, array $condition, array $inte
->where($condition)
->andWhere(Db::parseDateParam('dateCreated', $endDateTime, '<'))
->orderBy(['dateCreated' => SORT_ASC])
->groupBy('contactId')
->groupBy(['contactId'])
->all();

// Get activity
Expand Down Expand Up @@ -737,7 +738,7 @@ private function getActivity(array $models, string $interaction = null, int $lim
$contactActivityModel->sourceUrl = UrlHelper::cpUrl('campaign/contacts/import/' . $model->source);
break;
case 'user':
$path = (Craft::$app->getEdition() === Craft::Pro && $model->source) ? 'users/' . $model->source : 'myaccount';
$path = (Craft::$app->edition !== CmsEdition::Solo && $model->source) ? 'users/' . $model->source : 'myaccount';
$contactActivityModel->sourceUrl = UrlHelper::cpUrl($path);
break;
default:
Expand Down Expand Up @@ -771,14 +772,14 @@ private function getLocations(string $recordClass, array $condition, int $total,

/** @var ActiveRecord $recordClass */
$query = ContactRecord::find()
->select(array_merge($fields, ['COUNT(*) AS count']))
->groupBy('country');
->select(array_merge($fields, ['count' => 'COUNT(*)']))
->groupBy(['country']);

if ($recordClass != ContactRecord::class) {
$contactIds = $recordClass::find()
->select('contactId')
->select(['contactId'])
->where($condition)
->groupBy('contactId')
->groupBy(['contactId'])
->column();

$query->andWhere([ContactRecord::tableName() . '.id' => $contactIds]);
Expand Down Expand Up @@ -839,15 +840,15 @@ private function getDevices(string $recordClass, array $condition, bool $detaile

/** @var ActiveRecord $recordClass */
$query = ContactRecord::find()
->select(array_merge($fields, ['COUNT(*) AS count']))
->select(array_merge($fields, ['count' => 'COUNT(*)']))
->where(['not', ['device' => null]])
->groupBy($fields);

if ($recordClass != ContactRecord::class) {
$contactIds = $recordClass::find()
->select('contactId')
->select(['contactId'])
->where($condition)
->groupBy('contactId')
->groupBy(['contactId'])
->column();

$query->andWhere([ContactRecord::tableName() . '.id' => $contactIds]);
Expand Down

0 comments on commit 1c3f183

Please sign in to comment.