Working …
This value you provided is not a number. Please try again.
This value you provided is not an integer. Please try again.
The value entered is not a valid Vanderbilt Medical Record Number (i.e. 4- to 9-digit number, excluding leading zeros). Please try again.
The value you provided must be within the suggested range
The value you provided is outside the suggested range
This value is admissible, but you may wish to double check it.
The value entered must be a time value in the following format HH:MM within the range 00:00-23:59 (e.g., 04:32 or 23:19).
This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please re-enter it now.
This field must be a 10 digit U.S. phone number (like 415 555 1212). Please re-enter it now.
This field must be a valid email address (like joe@user.com). Please re-enter it now.
The value you provided could not be validated because it does not follow the expected format. Please try again.
Required format:
REDCap Logo
Plugins, Hooks, & External Modules
Developer methods for
Plugins, Hooks, & External Modules
Hook functions

REDCap Developer Tools:
Documentation for Plugins, Hooks, & External Modules

REDCap Version 14.9.1
REDCap::getEventNames
(REDCap >= 5.5.0)
REDCap::getEventNames — Returns a list of event names (or unique event names) for all events defined in the current project (longitudinal projects only)
Description
mixed REDCap::getEventNames ( [ bool $unique_names = FALSE [, bool $append_arm_name = FALSE [, int $event_id = NULL ]]] )
Returns a list of event names (or unique event names) for all events defined in the current project. If $event_id is specified for a single event, it will return only the event name for that event.
Parameters
unique_names
Set this to TRUE to return the unique event names for the events, else it will return the normal event names (i.e. event labels). By default, FALSE is used.
append_arm_name
Determines if the arm number and arm name should be appended to the event name if the current project contains multiple arms. If the project does not contain multiple arms, FALSE is used. If unique_names is set to TRUE, append_arm_name is set to FALSE.
event_id
Event_id of a single event defined in the current project. If provided, it will return the event name (as a string) for only that event. By default, NULL is used, in which it will return an array of all event names in the current project. If event_id is invalid, returns FALSE.
Return Values
Returns array of event names with their corresponding event_id's as array keys. Returns FALSE if project is not longitidinal. The events are ordered in the order in which they are specified in the project.
Restrictions
This method can ONLY be used in a project context (i.e. when "pid" parameter is in the query string of the plugin URL) or else a fatal error is produced.
Examples
Example #1:
This example shows how to simply display the event name of all events in a project.
// Check if project is longitdudinal first
if (!REDCap::isLongitudinal()) exit("Cannot get event names because this project is not longitudinal.");

// Print out the names of all events in the project (append the arm name if multiple arms exist)
$events = REDCap::getEventNames(false, true);
foreach ($events as $event_name) {
    // Print this event name
    print $event_name . ",\n";
}
Example #2:
This example illustrates how to determine the first event's event_id in a project and export all data for only that one event.
// Check if project is longitdudinal first
if (!REDCap::isLongitudinal()) exit("Cannot get event names because this project is not longitudinal.");

// Obtain array of all events in the project
$events = REDCap::getEventNames(false, true);

// Get event_id of the first event in the project (obtain from first array key in $events)
$first_event_id = array_shift(array_keys($events));

// Export data in CSV format for all records for that first event
$csv_data = REDCap::getData('csv', null, null, $first_event_id);

// Display all the CSV data on the page
print $csv_data;
REDCap 14.9.1 - © 2024 Vanderbilt University