You are here

public function AvailabilityCalendarICalFeedsProcessor::setTargetElement in Availability Calendars 7.5

Set a concrete target element. Invoked from FeedsProcessor::map().

Parameters

\FeedsSource $source:

object $target_item:

string $target_element:

mixed $value:

Throws

\Exception

1 call to AvailabilityCalendarICalFeedsProcessor::setTargetElement()
AvailabilityCalendarICalFeedsProcessor::map in ./AvailabilityCalendarICalFeedsProcessor.inc
Execute mapping on an item.

File

./AvailabilityCalendarICalFeedsProcessor.inc, line 175

Class

AvailabilityCalendarICalFeedsProcessor
@class ICalendar processor for availability calendars.

Code

public function setTargetElement(FeedsSource $source, $target_item, $target_element, $value) {
  $calendarField = $target_item->{$target_element};
  $calendar = reset(reset($calendarField));
  $field_info = field_info_field($target_element);
  $defaultState = $field_info['settings']['default_state'];
  $newState = $this->config['availability_calendar_state'];
  $cid = $calendar['cid'];
  $updated = 0;
  $skipped = 0;
  foreach ($value as $vevent) {
    if ($this
      ->update1Period($cid, $newState, $vevent->start, $vevent->end, $defaultState)) {
      $updated++;
    }
    else {
      $skipped++;
    }
  }
  $eids = entity_extract_ids($this
    ->entityType(), $target_item);
  $entity_id = $eids[0];
  $message = t('Imported iCal feed for @entity_type %entity_id (cid = %cid): updated %updated periods; skipped %skipped periods', array(
    '@entity_type' => $this
      ->entityType(),
    '%entity_id' => $entity_id,
    '%cid' => $cid,
    '%updated' => $updated,
    '%skipped' => $skipped,
  ));
  $source
    ->log('import', $message, array(), WATCHDOG_INFO);
}