You are here

public function MediaFeedsLibraryProvider::__construct in Media Feeds 7.2

Same name and namespace in other branches
  1. 7 includes/MediaFeedsLibraryProvider.inc \MediaFeedsLibraryProvider::__construct()

Constructor of MediaFeedsProvider.

Parameters

$value: The value to save.

$config: An associative array of configuration options.

Overrides MediaFeedsProvider::__construct

File

includes/MediaFeedsLibraryProvider.inc, line 14
Map existing files from the library.

Class

MediaFeedsLibraryProvider
Class for mapping values using existing files from the media library.

Code

public function __construct($value, $config = array()) {

  // Query existing files.
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'file');
  switch (file_uri_scheme($value)) {

    // No URI scheme given. Use as a file name.
    case FALSE:

      // By exact match or without file extension.
      if (empty($config['no_file_extensions'])) {
        $query
          ->propertyCondition('filename', $value);
      }
      else {
        $query
          ->propertyCondition('filename', $value . '.', 'STARTS_WITH');
      }
      break;

    // Query by URI.
    default:
      $query
        ->propertyCondition('uri', $value);
      break;
  }

  // Get the result.
  $result = $query
    ->execute();
  if (!empty($result)) {
    $this->file = reset(file_load_multiple(array_keys($result['file'])));
  }
}