You are here

function dfp_targeting_trim in Doubleclick for Publishers (DFP) 7.2

Same name and namespace in other branches
  1. 7 dfp.admin.inc \dfp_targeting_trim()

Helper function that takes a form_state['values'] and removes empty targets.

1 call to dfp_targeting_trim()
dfp_targeting_form_validate in ./dfp.admin.inc
Validation function used by the targeting form.

File

./dfp.admin.inc, line 351
Admin forms and functinality for DFP ads.

Code

function dfp_targeting_trim(&$values, $parent = 'targeting') {
  foreach ($values as $key => &$val) {
    if ($key === $parent) {

      // We found the targeting values.
      foreach ($val as $k => $v) {
        if (empty($val[$k]['target']) && empty($val[$k]['value'])) {
          unset($val[$k]);
        }
      }

      // Reset the array indexes to prevent wierd behavior caused by a target
      // being removed in the middle of the array.
      $val = array_values($val);
      break;
    }
    elseif (is_array($val)) {
      dfp_targeting_trim($val, $parent);
    }
  }
}