Project

General

Profile

« Previous | Next » 

Revision 97ff635c

Added by Andreas Kohlbecker almost 8 years ago

refactoring media_metadata function

View differences:

modules/cdm_dataportal/cdm_dataportal.module
2007 2007
  return $taxonRelationship->toTaxon->uuid == $focusedTaxon->uuid;
2008 2008
}
2009 2009

  
2010
/**
2011
 * Gets the metadata info such as title or artist of a media file.
2012
 *
2013
 * The function tries at first to get all the info from the file metadata
2014
 * and if it is not avaible look at the media file info stored at the database.
2015
 *
2016
 * @param mixed $media
2017
 *   The media file object for which to get the metadata.
2018
 *
2019
 * @return array
2020
 *   The array with the available specified metadata info.
2021
 * TODO rename to read_media_metadata() and move to *.module.
2022
 */
2023
function cdm_read_media_metadata($media) {
2024

  
2025
  $metadata_caption = array(
2026
    'title' => '',// Media_metadata and media.
2027
    'artist' => '',// Media_metadata and media.
2028
    'rights',// Media_metadata and media.
2029
    'location',// Media_metadata.
2030
    'filename' => '',// Media.
2031
    'mediacreated' => '',// Media.
2032
    'description' => '',
2033
  );// Media.
2034

  
2035
  // Getting the media metadata.
2036
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
2037
  $media_metadata_aux = (array) $media_metadata;
2038

  
2039
  // Filename.
2040
  if (!empty($media->representations[0]->parts[0]->uri)) {
2041
    $fileUri = $media->representations[0]->parts[0]->uri;
2042
    $filename = substr($fileUri, strrpos($fileUri, "/") + 1);
2043
    $metadata_caption['filename'] = $filename;
2044
  }
2045
  else {
2046
    $metadata_caption['filename'] = '';
2047
  }
2048

  
2049
  // Title.
2050
  if (!empty($media_metadata->ObjectName)) {
2051
    $metadata_caption['title'] = $media_metadata->ObjectName;
2052
  }
2053
  elseif (!empty($media_metadata_aux['Object Name'])) {
2054
    $metadata_caption['title'] = $media_metadata_aux['Object Name'];
2055
  }
2056
  elseif (!empty($media->title_L10n)) {
2057
    $metadata_caption['title'] = $media->title_L10n;
2058
  }
2059
  elseif (!empty($media->titleCache)) {
2060
    $metadata_caption['title'] = $media->titleCache;
2061
  }
2062

  
2063
  // Append description to title.
2064
  if (!empty($media->description_L10n)) {
2065
    $metadata_caption['title'] .= '<span class="media-description">' . $media->description_L10n . '<span>';
2066
  }
2067

  
2068
  // Artist.
2069
  if (!empty($media_metadata->Artist)) {
2070
    $metadata_caption['artist'] = '' . $media_metadata->Artist;
2071
  }
2072
  elseif (!empty($media->artist->titleCache)) {
2073
    $metadata_caption['artist'] = $media->artist->titleCache;
2074
  }
2075

  
2076
  // Copyright.
2077
  $metadata_caption['rights'] = array(
2078
    'copyright' => array('agentNames' => array()),
2079
    'license' => array(
2080
      'agentNames' => array(),
2081
      'types' => array(),
2082
      'abbreviatedTexts' => array(),
2083
      'uris' => array(),
2084
    ),
2085
  );
2086
  if (!empty($media_metadata->Copyright)) {
2087
    $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
2088
  }
2089
  elseif (isset($media->rights) && is_array($media->rights)) {
2090
    foreach ($media->rights as $right) {
2091
      if(isset($right->term)){
2092
        switch ($right->type->uuid) {
2093
          case UUID_RIGHTS_LICENCE:
2094
            $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? '' . $right->agent->firstname . ' ' . $right->agent->lastname : '');
2095
            $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? '' . $right->representation_L10n : '');
2096
            $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? '' . $right->abbreviatedText : '');
2097
            $metadata_caption['rights']['license']['uris'][] = ($right->uri ? '' . $right->uri : '');
2098
            break;
2099
          case UUID_RIGHTS_COPYRIGHT:
2100
            $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
2101
            break;
2102
        }
2103
      }
2104
    }
2105
  }
2106
  else {
2107
    $metadata_caption['rights']['agentNames'][] = '';
2108
  }
2109

  
2110
  // Filling the description (though there is no description in the db???).
2111
  // $metadata_caption['description'] = $media->description_L10n;
2112

  
2113
  // Location.
2114
  $metadata_caption['location'] = array();
2115
  $metadata_caption['location']['sublocation'] = !empty($media_metadata->Sublocation) ? $media_metadata->Sublocation : FALSE;
2116
  $metadata_caption['location']['city'] = !empty($media_metadata->City) ? $media_metadata->City : FALSE;
2117
  $metadata_caption['location']['province'] = !empty($media_metadata->Province) ? $media_metadata->Province : FALSE;
2118
  $metadata_caption['location']['country'] = !empty($media_metadata->Country)? $media_metadata->Country : FALSE;
2119

  
2120
  /*
2121
   // Creation date.
2122
   if($media_metadata["Modify Date"])
2123
   $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
2124
   else
2125
   $metadata_caption['mediacreated'] = $media->created;
2126
   */
2127

  
2128
  // Returned value.
2129
  return $metadata_caption;
2130
}
2131 2010

  
2132 2011
/**
2133 2012
 * Collects all the media from a list of description elements.

Also available in: Unified diff