/**
  * @param \Civi\ActionSchedule\MappingInterface $mapping
  * @param \CRM_Core_DAO_ActionSchedule $actionSchedule
  * @return string
  */
 protected static function prepareMailingQuery($mapping, $actionSchedule)
 {
     $select = CRM_Utils_SQL_Select::from('civicrm_action_log reminder')->select("reminder.id as reminderID, reminder.contact_id as contactID, reminder.entity_table as entityTable, reminder.*, e.id AS entityID")->join('e', "!casMailingJoinType !casMappingEntity e ON !casEntityJoinExpr")->select("e.id as entityID, e.*")->where("reminder.action_schedule_id = #casActionScheduleId")->where("reminder.action_date_time IS NULL")->param(array('casActionScheduleId' => $actionSchedule->id, 'casMailingJoinType' => $actionSchedule->limit_to == 0 ? 'LEFT JOIN' : 'INNER JOIN', 'casMappingId' => $mapping->getId(), 'casMappingEntity' => $mapping->getEntity(), 'casEntityJoinExpr' => 'e.id = reminder.entity_id'));
     if ($actionSchedule->limit_to == 0) {
         $select->where("e.id = reminder.entity_id OR reminder.entity_table = 'civicrm_contact'");
     }
     \Civi\Core\Container::singleton()->get('dispatcher')->dispatch(\Civi\ActionSchedule\Events::MAILING_QUERY, new \Civi\ActionSchedule\Event\MailingQueryEvent($actionSchedule, $mapping, $select));
     return $select->toSQL();
 }
 /**
  * Register a new mapping.
  *
  * @param MappingInterface $mapping
  *   The new mapping.
  * @return $this
  */
 public function register(MappingInterface $mapping)
 {
     $this->mappings[$mapping->getId()] = $mapping;
     return $this;
 }