17 require_once dirname(dirname(__FILE__)).
'/trigger_condition_asset_type/trigger_condition_asset_type.inc';
63 public static function evaluate($settings, &$state)
65 if (empty($settings[
'asset_type']))
return FALSE;
66 if (empty($settings[
'attribute']))
return FALSE;
68 if ((!$settings[
'inherit']) && (array_get_index($state,
'asset_type') != $settings[
'asset_type'])) {
73 if (empty($state[
'asset'])) {
74 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
77 if (!isset($state[
'asset_type'])) {
78 $state[
'asset_type'] = $state[
'asset']->type();
81 $changed_attr = $state[
'event'][
'data'];
83 if ($settings[
'inherit']) {
84 if ($state[
'asset'] instanceof $settings[
'asset_type']) {
85 return isset($changed_attr[$settings[
'attribute']]);
88 if ($state[
'asset_type'] == $settings[
'asset_type']) {
89 return isset($changed_attr[$settings[
'attribute']]);
107 public static function getInterface($settings, $prefix, $write_access=FALSE)
109 $selected_type = array_get_index($settings,
'asset_type',
'page');
110 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
115 asset_type_chooser($prefix.
'[type_code]', FALSE, Array(
'type_code' => $selected_type), NULL, TRUE, FALSE);
117 check_box($prefix.
'[inherit]', 1, array_get_index($settings,
'inherit'),
'',
'id="'.$prefix.
'_inherit" style="margin: 0px"');
119 label(translate(
'or_inherited_types'), $prefix.
'_inherit');
122 echo
'<b>'.$selected_type.
'</b>';
123 if (array_get_index($settings,
'inherit')) {
124 echo
' '.translate(
'or_inherited_types').
' ';
127 $asset_type_component = ob_get_contents();
132 $attribute = array_get_index($settings,
'attribute',
'');
133 if ($selected_type ==
'') {
134 echo
'<b>['.translate(
'asset_type_not_selected').
']</b>';
136 $attrs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeAttributes($selected_type, Array(
'name'));
138 echo
'<b>['.translate(
'asset_type_no_attributes_found').
']</b>';
141 $attr_options = Array(
'' =>
'');
142 foreach ($attrs as $attr_name) {
143 $attr_options[$attr_name] = $attr_name;
145 combo_box($prefix.
'[attribute]', $attr_options, FALSE, $attribute);
147 echo
'<b>'.$attribute.
'</b>';
151 $attribute_component = ob_get_contents();
154 return translate(
'trigger_attribute_changed', $asset_type_component, $attribute_component);
171 if (empty($request_data)) {
172 return translate(
'trigger_input_data_error');
175 $asset_type = array_get_index($request_data,
'type_code', FALSE);
177 return translate(
'trigger_type_code_not_supplied');
180 $settings[
'asset_type'] = $asset_type;
181 $settings[
'inherit'] = !empty($request_data[
'inherit']);
182 $settings[
'attribute'] = array_get_index($request_data,
'attribute', FALSE);