2 namespace Civi\ActionSchedule\Event
;
4 use Civi\ActionSchedule\MappingInterface
;
5 use Symfony\Component\EventDispatcher\Event
;
8 * Class MailingQueryEvent
9 * @package Civi\ActionSchedule\Event
11 * This event allows listeners to modify the query which generates mailing data.
12 * If you want to fetch extra mail-merge data as part of an initial query, then
13 * modify the mailing-query to add extra JOINs/SELECTs.
15 * The basic mailing query looks a bit like this (depending on configuration):
18 * SELECT reminder.id AS reminderID, reminder.contact_id as contactID, ...
19 * FROM `civicrm_action_log` reminder
20 * ... JOIN `target_entity` e ON e.id = reminder.entity_id ...
21 * WHERE reminder.action_schedule_id = #casActionScheduleId
24 * Listeners may modify the query. For example, suppose we want to load
25 * additional fields from the related 'foo' entity:
28 * $event->query->join('foo', '!casMailingJoinType civicrm_foo foo ON foo.myentity_id = e.id')
29 * ->select('foo.bar_value AS bar');
32 * There are several parameters pre-set for use in queries:
33 * - 'casActionScheduleId'
34 * - 'casEntityJoinExpr' - eg 'e.id = reminder.entity_id'
35 * - 'casMailingJoinType' - eg 'LEFT JOIN' or 'INNER JOIN' (depending on configuration)
37 * - 'casMappingEntity'
39 * (Note: When adding more JOINs, it seems typical to use !casMailingJoinType, although
40 * some hard-code a LEFT JOIN. Don't have an explanation for why.)
42 class MailingQueryEvent
extends Event
{
45 * The schedule record which produced this mailing.
47 * @var \CRM_Core_DAO_ActionSchedule
49 public $actionSchedule;
52 * The mapping record which produced this mailing.
54 * @var MappingInterface
59 * The alterable query. For details, see the class description.
60 * @var \CRM_Utils_SQL_Select
61 * @see MailingQueryEvent
66 * @param \CRM_Core_DAO_ActionSchedule $actionSchedule
67 * @param MappingInterface $mapping
68 * @param \CRM_Utils_SQL_Select $query
70 public function __construct($actionSchedule, $mapping, $query) {
71 $this->actionSchedule
= $actionSchedule;
72 $this->mapping
= $mapping;
73 $this->query
= $query;