<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
+ | CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
*/
class CRM_Event_ActionMapping extends \Civi\ActionSchedule\Mapping {
+ /**
+ * The value for civicrm_action_schedule.mapping_id which identifies the
+ * "Event Type" mapping.
+ *
+ * Note: This value is chosen to match legacy DB IDs.
+ */
+ const EVENT_TYPE_MAPPING_ID = 2;
+ const EVENT_NAME_MAPPING_ID = 3;
+ const EVENT_TPL_MAPPING_ID = 5;
+
+ /**
+ * Register CiviEvent-related action mappings.
+ *
+ * @param \Civi\ActionSchedule\Event\MappingRegisterEvent $registrations
+ */
+ public static function onRegisterActionMappings(\Civi\ActionSchedule\Event\MappingRegisterEvent $registrations) {
+ $registrations->register(CRM_Event_ActionMapping::create(array(
+ 'id' => CRM_Event_ActionMapping::EVENT_TYPE_MAPPING_ID,
+ 'entity' => 'civicrm_participant',
+ 'entity_label' => ts('Event Type'),
+ 'entity_value' => 'event_type',
+ 'entity_value_label' => ts('Event Type'),
+ 'entity_status' => 'civicrm_participant_status_type',
+ 'entity_status_label' => ts('Participant Status'),
+ 'entity_date_start' => 'event_start_date',
+ 'entity_date_end' => 'event_end_date',
+ )));
+ $registrations->register(CRM_Event_ActionMapping::create(array(
+ 'id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID,
+ 'entity' => 'civicrm_participant',
+ 'entity_label' => ts('Event Name'),
+ 'entity_value' => 'civicrm_event',
+ 'entity_value_label' => ts('Event Name'),
+ 'entity_status' => 'civicrm_participant_status_type',
+ 'entity_status_label' => ts('Participant Status'),
+ 'entity_date_start' => 'event_start_date',
+ 'entity_date_end' => 'event_end_date',
+ )));
+ $registrations->register(CRM_Event_ActionMapping::create(array(
+ 'id' => CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID,
+ 'entity' => 'civicrm_participant',
+ 'entity_label' => ts('Event Template'),
+ 'entity_value' => 'event_template',
+ 'entity_value_label' => ts('Event Template'),
+ 'entity_status' => 'civicrm_participant_status_type',
+ 'entity_status_label' => ts('Participant Status'),
+ 'entity_date_start' => 'event_start_date',
+ 'entity_date_end' => 'event_end_date',
+ )));
+ }
+
+ /**
+ * Get a list of recipient types.
+ *
+ * Note: A single schedule may filter on *zero* or *one* recipient types.
+ * When an admin chooses a value, it's stored in $schedule->recipient.
+ *
+ * @return array
+ * array(string $value => string $label).
+ * Ex: array('assignee' => 'Activity Assignee').
+ */
+ public function getRecipientTypes() {
+ return \CRM_Core_OptionGroup::values('event_contacts', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
+ }
+
+ /**
+ * Get a list of recipients which match the given type.
+ *
+ * Note: A single schedule may filter on *multiple* recipients.
+ * When an admin chooses value(s), it's stored in $schedule->recipient_listing.
+ *
+ * @param string $recipientType
+ * Ex: 'participant_role'.
+ * @return array
+ * Array(mixed $name => string $label).
+ * Ex: array(1 => 'Attendee', 2 => 'Volunteer').
+ * @see getRecipientTypes
+ */
+ public function getRecipientListing($recipientType) {
+ switch ($recipientType) {
+ case 'participant_role':
+ return \CRM_Event_PseudoConstant::participantRole();
+
+ default:
+ return array();
+ }
+ }
+
/**
* Generate a query to locate recipients who match the given
* schedule.
* The schedule as configured by the administrator.
* @param string $phase
* See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
+ * @param array $defaultParams
+ *
* @return \CRM_Utils_SQL_Select
* @see RecipientBuilder
*/
- public function createQuery($schedule, $phase) {
+ public function createQuery($schedule, $phase, $defaultParams) {
$selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
$selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
- $query = \CRM_Utils_SQL_Select::from("{$this->entity} e");
+ $query = \CRM_Utils_SQL_Select::from("{$this->entity} e")->param($defaultParams);;
$query['casAddlCheckFrom'] = 'civicrm_event r';
$query['casContactIdField'] = 'e.contact_id';
$query['casEntityIdField'] = 'e.id';
$query->join('r', 'INNER JOIN civicrm_event r ON e.event_id = r.id');
if ($schedule->recipient_listing && $schedule->limit_to) {
- switch (\CRM_Utils_Array::value($schedule->recipient, $this->getRecipientOptions())) {
+ switch ($schedule->recipient) {
case 'participant_role':
$query->where("e.role_id IN (#recipList)")
->param('recipList', \CRM_Utils_Array::explodePadded($schedule->recipient_listing));
// build where clause
if (!empty($selectedValues)) {
- $valueField = ($this->id == \CRM_Core_ActionScheduleTmp::EVENT_TYPE_MAPPING_ID) ? 'event_type_id' : 'id';
+ $valueField = ($this->id == \CRM_Event_ActionMapping::EVENT_TYPE_MAPPING_ID) ? 'event_type_id' : 'id';
$query->where("r.{$valueField} IN (@selectedValues)")
->param('selectedValues', $selectedValues);
}
else {
- $query->where(($this->id == \CRM_Core_ActionScheduleTmp::EVENT_TYPE_MAPPING_ID) ? "r.event_type_id IS NULL" : "r.id IS NULL");
+ $query->where(($this->id == \CRM_Event_ActionMapping::EVENT_TYPE_MAPPING_ID) ? "r.event_type_id IS NULL" : "r.id IS NULL");
}
$query->where('r.is_active = 1');
$query->where('r.is_template = 0');
// participant status criteria not to be implemented for additional recipients
+ // ... why not?
if (!empty($selectedStatuses)) {
switch ($phase) {
case RecipientBuilder::PHASE_RELATION_FIRST:
return $query;
}
- /**
- * FIXME: Seems to duplicate getRecipientTypes?
- * @return array|null
- */
- public function getRecipientOptions() {
- $recipientOptions = NULL;
- if (!\CRM_Utils_System::isNull($this->entity_recipient)) {
- if ($this->entity_recipient == 'event_contacts') {
- $recipientOptions = \CRM_Core_OptionGroup::values($this->entity_recipient, FALSE, FALSE, FALSE, NULL, 'name', TRUE, FALSE, 'name');
- }
- else {
- $recipientOptions = \CRM_Core_OptionGroup::values($this->entity_recipient, FALSE, FALSE, FALSE, NULL, 'name');
- }
- }
- return $recipientOptions;
- }
-
}