Creating a centralised list

A centralised list is a dataset field type that uses a list that has its values stored on the system. The example below will enable you to generate a list of regions and filter them by country ID. 

A module needs to have a public static function that returns an array of regions for each country.

public static function getRegionsByCountry($mode, $value = false) {
switch ($mode) {
case ZENARIO_CENTRALISED_LIST_MODE_INFO:
return array(
'filter_label' => 'Country ID:',
'can_filter' => true);

case ZENARIO_CENTRALISED_LIST_MODE_LIST:
return getRowsArray(
ZENARIO_COUNTRY_MANAGER_PREFIX. 'country_manager_regions',
'name',
array(),
'name');

case ZENARIO_CENTRALISED_LIST_MODE_FILTERED_LIST:
return getRowsArray(
ZENARIO_COUNTRY_MANAGER_PREFIX. 'country_manager_regions',
'name',
array('country_id' => $value),
'name');
}
}

A static method for a centralised list accepts the parameters $mode and $value (defaults to false). The function should return an array of values based on the mode and value passed to it.

The mode variable can have three possible values:

1) ZENARIO_CENTRALISED_LIST_MODE_INFO: (this must be included in the switch statement) will return an array with can_filter set to true.

If you want to be able to filter a dataset field, you have to use filter_label which is used to name the field "Country ID" shown below. Otherwise it can just return the whole region list using array('can_filter' => false);

floating admin box

 

2) ZENARIO_CENTRALISED_LIST_MODE_LIST (must be included) will return the full unfiltered list of regions.

3) ZENARIO_CENTRALISED_LIST_MODE_FILTERED_LIST (optional) will return the list filtered by the value of what's entered into the filter box above e.g. US returns only US regions.

In an Organizer yaml file, use the following code to add it into the select list:

zenario_custom_field:
tabs:
details:
fields:
values_source:
values: 
'zenario_country_manager::getRegionsByCountry': 'Regions'

You can now access it in the drop down of centralised lists and depending on whether can_filter is true, choose to filter it.