You are here

function media_flickr_record_photoset in Media: Flickr 6

Record the photoset and all its photos.

Parameters

$id: Flickr's Photoset ID. @param $options Reserved for future use. Contains instanciated node information, etc.

1 call to media_flickr_record_photoset()
media_flickr_emfield_field_extra in ./media_flickr.module

File

./media_flickr.module, line 304
Embedded Video Field provider file for Flickr.com photosets.

Code

function media_flickr_record_photoset($id, $options = array()) {
  $instances = db_result(db_query("SELECT instances FROM {media_flickr_photoset_count} WHERE photoset = '%s'", $id));

  // @TODO: check for 0.
  if (!$instances) {
    $record = array(
      'photoset' => $id,
      'instances' => 1,
    );
    drupal_write_record('media_flickr_photoset_count', $record);
  }

  // Now we want to associate individual photos with their photoset.
  $photoset = media_flickr_photoset_load($id);
  if ($photoset) {

    // Remove already recorded photos from this array so we can record any not
    // already in place.
    $results = db_query("SELECT code FROM {media_flickr_sets} WHERE photoset = '%s'", $id);
    while ($result = db_fetch_array($results)) {
      unset($photoset['photoset']['photo'][$result['code']]);
    }

    // Now record any remaining photos that are not yet associated.
    foreach ($photoset['photoset']['photo'] as $code => $photo) {

      // This records the association between photoset & photo.
      $record = array(
        'photoset' => $id,
        'code' => $code,
      );
      drupal_write_record('media_flickr_sets', $record);

      // Now record the metadata associated with a photo.
      media_flickr_record_photo($code);
    }

    // @TODO: record each instance per node.
    // This is stored in the $options array, but not currently used.
  }
}