Project

General

Profile

« Previous | Next » 

Revision 97ff635c

Added by Andreas Kohlbecker almost 8 years ago

refactoring media_metadata function

View differences:

modules/cdm_dataportal/includes/media.inc
111 111
 */
112 112
function media_feature_icon($feature, $media_url = NULL) {
113 113
  return font_awesome_icon_markup('fa-book', array('alt' => $feature->representation_L10n));
114
}
114
}
115

  
116
/**
117
 * Gets the metadata info such as title or artist of a media file.
118
 *
119
 * The function tries at first to get all the info from the file metadata
120
 * and if it is not available look at the media file info stored at the database.
121
 *
122
 * @param mixed $media
123
 *   The media file object for which to get the metadata.
124
 *
125
 * @return array
126
 *   The array with the available specified metadata info.
127
 */
128
function read_media_metadata($media) {
129

  
130
  $metadata_caption = array(
131
    'title' => '',// Media_metadata and media.
132
    'artist' => '',// Media_metadata and media.
133
    'rights',// Media_metadata and media.
134
    'location',// Media_metadata.
135
    'filename' => '',// Media.
136
    'mediacreated' => '',// Media.
137
    'description' => '',
138
  );// Media.
139

  
140
  // Getting the media metadata.
141
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
142
  $media_metadata_aux = (array) $media_metadata;
143

  
144
  // Filename.
145
  if (!empty($media->representations[0]->parts[0]->uri)) {
146
    $fileUri = $media->representations[0]->parts[0]->uri;
147
    $filename = substr($fileUri, strrpos($fileUri, "/") + 1);
148
    $metadata_caption['filename'] = $filename;
149
  }
150
  else {
151
    $metadata_caption['filename'] = '';
152
  }
153

  
154
  // Title.
155
  if (!empty($media_metadata->ObjectName)) {
156
    $metadata_caption['title'] = $media_metadata->ObjectName;
157
  }
158
  elseif (!empty($media_metadata_aux['Object Name'])) {
159
    $metadata_caption['title'] = $media_metadata_aux['Object Name'];
160
  }
161
  elseif (!empty($media->title_L10n)) {
162
    $metadata_caption['title'] = $media->title_L10n;
163
  }
164
  elseif (!empty($media->titleCache)) {
165
    $metadata_caption['title'] = $media->titleCache;
166
  }
167

  
168
  // Append description to title.
169
  if (!empty($media->description_L10n)) {
170
    $metadata_caption['title'] .= '<span class="media-description">' . $media->description_L10n . '<span>';
171
  }
172

  
173
  // Artist.
174
  if (!empty($media_metadata->Artist)) {
175
    $metadata_caption['artist'] = '' . $media_metadata->Artist;
176
  }
177
  elseif (!empty($media->artist->titleCache)) {
178
    $metadata_caption['artist'] = $media->artist->titleCache;
179
  }
180

  
181
  // Copyright.
182
  $metadata_caption['rights'] = array(
183
    'copyright' => array('agentNames' => array()),
184
    'license' => array(
185
      'agentNames' => array(),
186
      'types' => array(),
187
      'abbreviatedTexts' => array(),
188
      'uris' => array(),
189
    ),
190
  );
191
  if (!empty($media_metadata->Copyright)) {
192
    $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
193
  }
194
  elseif (isset($media->rights) && is_array($media->rights)) {
195
    foreach ($media->rights as $right) {
196
      if(isset($right->term)){
197
        switch ($right->type->uuid) {
198
          case UUID_RIGHTS_LICENCE:
199
            $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? '' . $right->agent->firstname . ' ' . $right->agent->lastname : '');
200
            $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? '' . $right->representation_L10n : '');
201
            $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? '' . $right->abbreviatedText : '');
202
            $metadata_caption['rights']['license']['uris'][] = ($right->uri ? '' . $right->uri : '');
203
            break;
204
          case UUID_RIGHTS_COPYRIGHT:
205
            $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
206
            break;
207
        }
208
      }
209
    }
210
  }
211
  else {
212
    $metadata_caption['rights']['agentNames'][] = '';
213
  }
214

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

  
218
  // Location.
219
  $metadata_caption['location'] = array();
220
  $metadata_caption['location']['sublocation'] = !empty($media_metadata->Sublocation) ? $media_metadata->Sublocation : FALSE;
221
  $metadata_caption['location']['city'] = !empty($media_metadata->City) ? $media_metadata->City : FALSE;
222
  $metadata_caption['location']['province'] = !empty($media_metadata->Province) ? $media_metadata->Province : FALSE;
223
  $metadata_caption['location']['country'] = !empty($media_metadata->Country)? $media_metadata->Country : FALSE;
224

  
225
  /*
226
   // Creation date.
227
   if($media_metadata["Modify Date"])
228
   $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
229
   else
230
   $metadata_caption['mediacreated'] = $media->created;
231
   */
232

  
233
  // Returned value.
234
  return $metadata_caption;
235
}

Also available in: Unified diff