You are here

function scheduler_feeds_set_target in Scheduler 7

Same name and namespace in other branches
  1. 8 scheduler.module \scheduler_feeds_set_target()
  2. 2.x scheduler.module \scheduler_feeds_set_target()

Mapping callback for the Feeds module.

1 string reference to 'scheduler_feeds_set_target'
scheduler_feeds_processor_targets_alter in ./scheduler.module
Implements hook_feeds_processor_targets_alter().

File

./scheduler.module, line 870
Scheduler publishes and unpublishes nodes on dates specified by the user.

Code

function scheduler_feeds_set_target($source, $entity, $target, $value, $mapping) {

  // We expect a string or integer, but can accomodate an array, by taking the
  // first item. Use trim() so that a string of blanks is reduced to empty.
  $value = is_array($value) ? trim(reset($value)) : trim($value);

  // Convert input from parser to timestamp form. If $value is empty or blank
  // then strtotime() must not be used, otherwise it returns the current time.
  if (!empty($value) && !is_numeric($value)) {
    if (!($timestamp = strtotime($value))) {

      // Throw an exception if the date format was not recognized.
      throw new FeedsValidationException("Value {$value} for {$mapping['source']} could not be converted to a valid Scheduler {$target} date.");
    }
  }
  else {
    $timestamp = $value;
  }

  // If the timestamp is valid then use it to set the target field in the node.
  if (is_numeric($timestamp) && $timestamp > 0) {
    $entity->{$target} = $timestamp;
  }
}