Skip to content

Commit

Permalink
Add back method that must have accidentally been removed during a reb…
Browse files Browse the repository at this point in the history
…ase/conflict merge into 3.x
  • Loading branch information
alanhartless committed Apr 14, 2020
1 parent e7a2df8 commit 38f7a58
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/bundles/CampaignBundle/Entity/CampaignRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,31 @@ public function getContactSingleSegmentByCampaign($contactId, $campaignId)
->execute()
->fetch();
}

/**
* @param int $segmentId
* @param array $campaignIds
*
* @return array
*/
public function getCampaignsSegmentShare($segmentId, $campaignIds = [])
{
$q = $this->getEntityManager()->getConnection()->createQueryBuilder();
$q->select('c.id, c.name, ROUND(IFNULL(COUNT(DISTINCT t.lead_id)/COUNT(DISTINCT cl.lead_id)*100, 0),1) segmentCampaignShare');
$q->from(MAUTIC_TABLE_PREFIX.'campaigns', 'c')
->leftJoin('c', MAUTIC_TABLE_PREFIX.'campaign_leads', 'cl', 'cl.campaign_id = c.id AND cl.manually_removed = 0')
->leftJoin('cl',
'(SELECT lll.lead_id AS ll, lll.lead_id FROM lead_lists_leads lll WHERE lll.leadlist_id = '.$segmentId
.' AND lll.manually_removed = 0)',
't',
't.lead_id = cl.lead_id'
);
$q->groupBy('c.id');

if (!empty($campaignIds)) {
$q->where($q->expr()->in('c.id', $campaignIds));
}

return $q->execute()->fetchAll();
}
}

0 comments on commit 38f7a58

Please sign in to comment.