Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get all media for a node #2

Closed
mjordan opened this issue Nov 21, 2018 · 3 comments
Closed

Add function to get all media for a node #2

mjordan opened this issue Nov 21, 2018 · 3 comments

Comments

@mjordan
Copy link
Owner

mjordan commented Nov 21, 2018

This will be used to generate the media-level report described in #1.

@mjordan
Copy link
Owner Author

mjordan commented Nov 21, 2018

The Manage Media view bundled with the Islandora module provides a REST API to get all media attached to a node using requests like curl -v -u admin:islandora http://localhost:8000/node/266/media?_format=json. This snippet will pick out all the URLs for the media attached to node 1:

// $json is the JSON returned by the above URL.
$array = json_decode($json, true);

$media_fields = array(
  'field_media_file',
  'field_media_image',
  'field_media_audio_file',
  'field_media_video_file',
);

$media_use_tags = array();
foreach ($array as $media) {
  foreach ($media_fields as $media_field) {
    if (array_key_exists($media_field, $media)) {
      if (!in_array($media['field_media_use'][0]['url'], $media_use_tags)) {
        $tag_url = $media['field_media_use'][0]['url'];
      }
      $media_use_tags[$tag_url][] = $media[$media_field][0]['url'];
    }
  }
}

print_r($media_use_tags);

This will parse out URLs to the media files and group them by media use (Preservation Master, Original File, etc.);

Array
(
    [/taxonomy/term/15] => Array
        (
            [0] => http://localhost:8000/_flysystem/fedora/2018-11/iCamp%20CA%20-%20mjordan%20-%20taxi%20receipt.png
        )

    [/taxonomy/term/19] => Array
        (
            [0] => http://localhost:8000/_flysystem/fedora/2018-11/iCamp%20CA%20-%20mjordan%20-%20hotel%20receipt.pdf
            [1] => http://localhost:8000/_flysystem/fedora/2018-11/VP_academic_conference_fund_2019_islandora_conference.pdf
        )

    [/taxonomy/term/16] => Array
        (
            [0] => http://localhost:8000/_flysystem/fedora/2018-11/sample.mp3
            [1] => http://localhost:8000/_flysystem/fedora/2018-11/sample.mp4
        )

)

These Drupal URLs will need to be converted to Fedora URLs (via Gemini) if Riprap is polling Fedora.

@mjordan
Copy link
Owner Author

mjordan commented Nov 22, 2018

To get the taxonomy term name, use:

$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
$name = $term->getName();

mjordan added a commit that referenced this issue Nov 22, 2018
@mjordan
Copy link
Owner Author

mjordan commented Nov 22, 2018

Closed with 683cab0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant