Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

extractFitsMetadata()

Description

Extract FITS metadata from a file for a specific resource.

Parameters

ColumnTypeDefaultDescription
$file_path string Path to the file from which you will extract FITS metadata
$resource integer|array Resource ID or resource array (as returned by get_resource_data())

Return

boolean

Location

include/metadata_functions.php lines 112 to 178

Definition

 
function extractFitsMetadata($file_path$resource)
    {
    if(
get_utility_path('fits') === false)
        {
        return 
false;
        }

    if(!
file_exists($file_path))
        {
        return 
false;
        }

    if(!
is_array($resource) && !is_numeric($resource))
        {
        return 
false;
        }

    if(!
is_array($resource) && is_numeric($resource) && $resource)
        {
        
$resource get_resource_data($resource);
        }

    
$resource_type $resource['resource_type'];

    
// Get a list of all the fields that have a FITS field set
    
$allfields get_resource_type_fields($resource_type);
    
$rs_fields_to_read_for array_filter($allfields,function($field){return trim((string)$field["fits_field"]) != "";});

    if(
=== count($rs_fields_to_read_for))
        {
        return 
false;
        }

    
// Run FITS and extract metadata
    
$fits_xml            runFitsForFile($file_path);
    if(!
$fits_xml)
        {
        return 
false;
        }
    
$fits_updated_fields = array();

    foreach(
$rs_fields_to_read_for as $rs_field)
        {
        
$fits_fields explode(',', (string)$rs_field['fits_field']);

        foreach(
$fits_fields as $fits_field)
            {
            
$fits_field_value getFitsMetadataFieldValue($fits_xml$fits_field);

            if(
'' == $fits_field_value)
                {
                continue;
                }

            
update_field($resource['ref'], $rs_field['ref'], $fits_field_value);

            
$fits_updated_fields[] = $rs_field['ref'];
            }
        }

    if(
count($fits_updated_fields))
        {
        return 
true;
        }

    return 
false;
    }

This article was last updated 22nd May 2024 15:05 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.