Rename the plugin's vendor/namespace from experiential/Program to mt3s/MT3SMarketingProgram (composer: mt3s/mautic-marketing-program-bundle): - ProgramBundle -> MT3SMarketingProgramBundle; extension, integration, config support, permissions, events and twig extension renamed likewise - Initiative* -> Program*: controller (InitiativeController -> ProgramController), model, entities, repositories, form types and views (new _tabs/_task_table/_tab_table_filter partials, details page) - Settings config form theme -> _config_mt3smarketingprogramconfig_widget; routes and translations re-prefixed (mt3s_marketing_program_*) - Assets: icon.svg -> mt3s-mp-icon.svg; program.js -> mt3s-mp-program.js (OnLoad hooks renamed mt3sMpProgram*) - Add Command/RefreshStatsCommand; Migrations/Version_0_17_0.php renames the tables to mt3s_mp_program_*
91 lines
2.9 KiB
PHP
91 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Entity;
|
|
|
|
use Doctrine\DBAL\Connection;
|
|
use Mautic\CoreBundle\Entity\CommonRepository;
|
|
|
|
/**
|
|
* @extends CommonRepository<Audience>
|
|
*/
|
|
class AudienceRepository extends CommonRepository
|
|
{
|
|
public function getTableAlias(): string
|
|
{
|
|
return 'pa';
|
|
}
|
|
|
|
/**
|
|
* The contact count of one segment: lead_lists_leads rows with manually_removed = 0.
|
|
*/
|
|
public function getSegmentContactCount(int $leadlistId): int
|
|
{
|
|
$count = $this->getEntityManager()->getConnection()->fetchOne(
|
|
'SELECT COUNT(ll.lead_id) FROM lead_lists_leads ll WHERE ll.leadlist_id = :leadlistId AND ll.manually_removed = 0',
|
|
['leadlistId' => $leadlistId]
|
|
);
|
|
|
|
return (int) $count;
|
|
}
|
|
|
|
/**
|
|
* Contact counts (lead_lists_leads rows with manually_removed = 0) for the segments of one
|
|
* audience, keyed by segment id. Used by the list view to show "Segment (123)".
|
|
*
|
|
* @return array<int, int> leadlist_id => contact count
|
|
*/
|
|
public function getSegmentContactCounts(int $audienceId): array
|
|
{
|
|
$rows = $this->getEntityManager()->getConnection()->fetchAllAssociative(
|
|
'SELECT s.leadlist_id, COUNT(ll.lead_id) AS cnt
|
|
FROM mt3s_mp_program_audiences_segments s
|
|
JOIN lead_lists_leads ll ON ll.leadlist_id = s.leadlist_id AND ll.manually_removed = 0
|
|
WHERE s.audience_id = :audienceId
|
|
GROUP BY s.leadlist_id',
|
|
['audienceId' => $audienceId]
|
|
);
|
|
|
|
$counts = [];
|
|
foreach ($rows as $row) {
|
|
$counts[(int) $row['leadlist_id']] = (int) $row['cnt'];
|
|
}
|
|
|
|
return $counts;
|
|
}
|
|
|
|
/**
|
|
* Contact counts for the segments of every audience in the list view, keyed by audience id then
|
|
* segment id. One query for the whole page.
|
|
*
|
|
* @param list<int> $audienceIds
|
|
*
|
|
* @return array<int, array<int, int>> audience_id => (leadlist_id => contact count)
|
|
*/
|
|
public function getSegmentContactCountsForAudiences(array $audienceIds): array
|
|
{
|
|
if ([] === $audienceIds) {
|
|
return [];
|
|
}
|
|
|
|
$connection = $this->getEntityManager()->getConnection();
|
|
$rows = $connection->fetchAllAssociative(
|
|
'SELECT s.audience_id, s.leadlist_id, COUNT(ll.lead_id) AS cnt
|
|
FROM mt3s_mp_program_audiences_segments s
|
|
JOIN lead_lists_leads ll ON ll.leadlist_id = s.leadlist_id AND ll.manually_removed = 0
|
|
WHERE s.audience_id IN (:audienceIds)
|
|
GROUP BY s.audience_id, s.leadlist_id',
|
|
['audienceIds' => $audienceIds],
|
|
['audienceIds' => Connection::PARAM_INT_ARRAY]
|
|
);
|
|
|
|
$counts = [];
|
|
foreach ($rows as $row) {
|
|
$counts[(int) $row['audience_id']][(int) $row['leadlist_id']] = (int) $row['cnt'];
|
|
}
|
|
|
|
return $counts;
|
|
}
|
|
}
|