Commit | Line | Data |
---|---|---|
f9ec2da6 TO |
1 | <?php |
2 | namespace Civi\ActionSchedule\Event; | |
3 | ||
4 | use Civi\ActionSchedule\MappingInterface; | |
5 | use Symfony\Component\EventDispatcher\Event; | |
6 | ||
7 | /** | |
8 | * Class MailingQueryEvent | |
9 | * @package Civi\ActionSchedule\Event | |
10 | * | |
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. | |
14 | * | |
15 | * The basic mailing query looks a bit like this (depending on configuration): | |
16 | * | |
17 | * @code | |
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 | |
22 | * @endcode | |
23 | * | |
24 | * Listeners may modify the query. For example, suppose we want to load | |
25 | * additional fields from the related 'foo' entity: | |
26 | * | |
27 | * @code | |
28 | * $event->query->join('foo', '!casMailingJoinType civicrm_foo foo ON foo.myentity_id = e.id') | |
29 | * ->select('foo.bar_value AS bar'); | |
30 | * @endcode | |
31 | * | |
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) | |
36 | * - 'casMappingId' | |
37 | * - 'casMappingEntity' | |
38 | * | |
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.) | |
41 | */ | |
42 | class MailingQueryEvent extends Event { | |
43 | ||
44 | /** | |
45 | * The schedule record which produced this mailing. | |
46 | * | |
47 | * @var \CRM_Core_DAO_ActionSchedule | |
48 | */ | |
49 | public $actionSchedule; | |
50 | ||
51 | /** | |
52 | * The mapping record which produced this mailing. | |
53 | * | |
54 | * @var MappingInterface | |
55 | */ | |
56 | public $mapping; | |
57 | ||
58 | /** | |
59 | * The alterable query. For details, see the class description. | |
60 | * @var \CRM_Utils_SQL_Select | |
61 | * @see MailingQueryEvent | |
62 | */ | |
63 | public $query; | |
64 | ||
65 | /** | |
66 | * @param \CRM_Core_DAO_ActionSchedule $actionSchedule | |
67 | * @param MappingInterface $mapping | |
68 | * @param \CRM_Utils_SQL_Select $query | |
69 | */ | |
70 | public function __construct($actionSchedule, $mapping, $query) { | |
71 | $this->actionSchedule = $actionSchedule; | |
72 | $this->mapping = $mapping; | |
73 | $this->query = $query; | |
74 | } | |
75 | ||
76 | } |