private function getExtendedFieldValuesMultiple(
        $extendedFieldList = [],
        $leadIds = []
    ) {
        /** @var EntityManager $em */
        $em = $this->getEntityManager();

        $leadIdsStr = "'".implode("','", $leadIds)."'";

        $selects = [];
        foreach (['string', 'float', 'boolean', 'date', 'datetime', 'time', 'text'] as $data_type) {
            foreach (['', '_secure'] as $secure) {
                $xrefTable = MAUTIC_TABLE_PREFIX."lead_fields_leads_{$data_type}{$secure}_xref";

                $selects[] = <<<EOSQL
SELECT lead_id, lead_field_id, value, '{$data_type}' AS data_type 
FROM  {$xrefTable}
WHERE lead_id IN ({$leadIdsStr})
EOSQL;
            }
        }
        $xrefQuery = implode("\nUNION\n", $selects);

        $leadsTable      = $em->getRepository('MauticLeadBundle:Lead')->getTableName();
        $lt              = $em->getRepository('MauticLeadBundle:Lead')->getTableAlias();
        $leadFieldsTable = $em->getRepository('MauticLeadBundle:LeadField')->getTableName();
        $lft             = $em->getRepository('MauticLeadBundle:LeadField')->getTableAlias();

        $where = "{$lft}.object IN ('extendedField','extendedFieldSecure') ";
        if (!empty($extendedFieldList)) {
            $ids             = array_map(
                function ($e) {
                    return $e['id'];
                },
                $extendedFieldList
            );
            $leadFiieldIdStr = "'".implode("','", $ids)."'";
            $where           = "{$lft}.id IN ({$leadFiieldIdStr}) ";
        }

        $sql = <<<EOSQL
SELECT x.lead_id, x.alias, v.value, v.data_type
FROM
(
    SELECT {$lt}.id AS lead_id,
    {$lft}.id as lead_field_id,
    {$lft}.alias
    FROM {$leadsTable} {$lt} CROSS JOIN {$leadFieldsTable} {$lft}
    WHERE {$where}
    AND {$lt}.id  IN ({$leadIdsStr})
) x
LEFT JOIN
(
    {$xrefQuery}
) v USING (lead_id, lead_field_id)
EOSQL;

        $query = $em->getConnection()->prepare($sql);
        $query->execute();
        $results = $query->fetchAll();

        // Group results by leadId.
        $leads = [];
        foreach ($results as $row => $result) {
            $leads[$result['lead_id']][$result['alias']] = $result['value'];
            unset($results[$row]);
        }

        return $leads;
    }