Understanding parameter map code


(Nic Hubbard) #1

Hi guys,


I am wanting to add the parameter map functionality to a trigger that does not currently have it, so I figured it would be a good programing exercise.



Looking through other triggers the parameter map code is kind of inconsistent in how it is used, so I am having a really hard time understanding how to get it working. I want to add this to the Add Design action.



Currently I have the parameter map added, and it shows in the trigger action, but choosing one of the two options (Design ID and Asset id) does not save them.



Here is what I have done:



Added to top of file:

    require_once SQ_SYSTEM_ROOT.'/core/attributes/parameter_map/parameter_map.inc';


Added to getInterface function:
    $new_prefix = ereg_replace('\[', '_', ereg_replace('\]', '_', $prefix));
    hidden_field($prefix.'[new_prefix]', $new_prefix);
    $param_map_value = array_get_index($settings, 'value_map', serialize(Array()));
    $param_map_attr = new Asset_Attribute_Parameter_Map(0, $param_map_value);
    $param_map_attr->setParameter('asset_id', 'Asset ID');
    $param_map_attr->setParameter('design_id', 'Design');
    $settings['value_map'] = $param_map_attr->value;
    echo $param_map_attr->paint($new_prefix.'_parameter_map');


Added to execute function:
    $value_map = array_get_index($settings, 'value_map', serialize(Array()));
    $param_map_attr = new Asset_Attribute_Parameter_Map(0, $value_map);
    $param_map_design_id = $param_map_attr->getParameterValue('design_id');
    $param_map_asset_id = $param_map_attr->getParameterValue('asset_id');



Is there another trigger, asset or an example that can let me better understand how to get the parameter functionality working? Right now it is a little fuzzy.

Thanks.

(Ata) #2

Hi Nic,


You will have to put the following piece of codes to the processInterface() method so that parameter map values can be saved:


    $new_prefix = ereg_replace('\[', '_', ereg_replace('\]', '_', array_get_index($request_data, 'new_prefix', '')));
    if ($new_prefix != '') {
    	$atr_parameter_map = new Asset_Attribute_Parameter_Map();
    	$atr_parameter_map->process($new_prefix.'_parameter_map');
    	$settings['value_map'] = $atr_parameter_map->value;
    }

(Nic Hubbard) #3

[quote]

    $new_prefix = ereg_replace('\[', '_', ereg_replace('\]', '_', array_get_index($request_data, 'new_prefix', '')));
    if ($new_prefix != '') {
    	$atr_parameter_map = new Asset_Attribute_Parameter_Map();
    	$atr_parameter_map->process($new_prefix.'_parameter_map');
    	$settings['value_map'] = $atr_parameter_map->value;
    }

[/quote]



Thanks Anh!



That was what I needed, I have it working now. I think it is a really nice feature to have, so you can easily set the design of an asset by passing the ID of the design. I will submit the code as a new feature to the bug tracker. :slight_smile:


(Mark Brydon) #4

[quote]
I think it is a really nice feature to have, so you can easily set the design of an asset by passing the ID of the design. I will submit the code as a new feature to the bug tracker. :slight_smile:

[/quote]

For the benefit of all, Nic has submitted this to the Bug Tracker as promised. This will be assessed for inclusion in 3.24.2.

Cheers Nic :wink: