You are here

function feeds_tamper_conditional_callback in Feeds Tamper Conditional 7

Callback for plugin.

1 string reference to 'feeds_tamper_conditional_callback'
feeds_tamper_conditional.inc in plugins/feeds_tamper_conditional.inc

File

plugins/feeds_tamper_conditional.inc, line 150

Code

function feeds_tamper_conditional_callback(&$result, $item_key, $element_key, &$field, $settings, $source) {
  $condition_met = FALSE;

  // The value of the field that should be checked for the condition.
  $conditional_field_value = $result->items[$item_key][$settings['conditional_field']];
  switch ($settings['operator']) {
    case 'equals':
      $condition_met = $conditional_field_value == $settings['value'] ? TRUE : FALSE;
      break;
    case 'begins':
      if (!isset($settings['negate']) || $settings['negate'] == 0) {
        $condition_met = feeds_tamper_conditional_begins_with($conditional_field_value, $settings['value']);
      }
      else {
        $condition_met = !feeds_tamper_conditional_begins_with($conditional_field_value, $settings['value']);
      }
      break;
    case 'ends':
      if (!isset($settings['negate']) || $settings['negate'] == 0) {
        $condition_met = feeds_tamper_conditional_ends_with($conditional_field_value, $settings['value']);
      }
      else {
        $condition_met = !feeds_tamper_conditional_ends_with($conditional_field_value, $settings['value']);
      }
      break;
    case 'not_equals':
      $condition_met = $conditional_field_value != $settings['value'] ? TRUE : FALSE;
      break;
    case 'greater':
      $condition_met = $conditional_field_value > $settings['value'] ? TRUE : FALSE;
      break;
    case 'greater_equal':
      $condition_met = $conditional_field_value >= $settings['value'] ? TRUE : FALSE;
      break;
    case 'less':
      $condition_met = $conditional_field_value < $settings['value'] ? TRUE : FALSE;
      break;
    case 'less_equal':
      $condition_met = $conditional_field_value <= $settings['value'] ? TRUE : FALSE;
      break;
    case 'contains':
      $condition_met = is_int(stripos($conditional_field_value, $settings['value'])) ? TRUE : FALSE;
      break;
    case 'not_contains':
      $condition_met = is_int(stripos($conditional_field_value, $settings['value'])) ? FALSE : TRUE;
      break;
    case 'empty':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? empty($conditional_field_value) : !empty($conditional_field_value);
      break;
    case 'set':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? isset($conditional_field_value) : !isset($conditional_field_value);
      break;
    case 'null':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? is_null($conditional_field_value) : !is_null($conditional_field_value);
      break;
    case 'array':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? is_array($conditional_field_value) : !is_array($conditional_field_value);
      break;
    case 'bool':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? is_bool($conditional_field_value) : !is_bool($conditional_field_value);
      break;
    case 'int':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? is_int($conditional_field_value) : !is_int($conditional_field_value);
      break;
    case 'float':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? is_float($conditional_field_value) : !is_float($conditional_field_value);
      break;
    case 'numeric':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? is_numeric($conditional_field_value) : !is_numeric($conditional_field_value);
      break;
    case 'string':
      $condition_met = !isset($settings['negate']) || $settings['negate'] == 0 ? is_string($conditional_field_value) : !is_string($conditional_field_value);
      break;
  }
  if (!$condition_met) {
    unset($result->items[$item_key][$element_key]);
  }
}