entity_value); $selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status); $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['casContactTableAlias'] = NULL; $query['casDateField'] = str_replace('event_', 'r.', $schedule->start_action_date); $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())) { case 'participant_role': $query->where("e.role_id IN (#recipList)") ->param('recipList', \CRM_Utils_Array::explodePadded($schedule->recipient_listing)); break; default: break; } } // build where clause if (!empty($selectedValues)) { $valueField = ($this->id == \CRM_Core_ActionScheduleTmp::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('r.is_active = 1'); $query->where('r.is_template = 0'); // participant status criteria not to be implemented for additional recipients if (!empty($selectedStatuses)) { switch ($phase) { case RecipientBuilder::PHASE_RELATION_FIRST: case RecipientBuilder::PHASE_RELATION_REPEAT: $query->where("e.status_id IN (#selectedStatuses)") ->param('selectedStatuses', $selectedStatuses); break; } } 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; } }