Collections functions
General functions
Render functions
Theme permission functions
Resource functions

createAnnotation()

Description

Create new annotations based on Annotorious annotation

NOTE: Annotorious annotation shape is an array but at the moment they use only the first shape found

Parameters

ColumnTypeDefaultDescription
$annotation array

Return

boolean|integer Returns false on failure OR the ref of the newly created annotation

Location

include/annotation_functions.php lines 319 to 376

Definition

 
function createAnnotation(array $annotation)
    {
    
debug(sprintf('[annotations][fct=createAnnotation] Param $annotation = %s'json_encode($annotation)));
    global 
$userref;

    if(!
annotationEditable($annotation))
        {
        
debug('[annotations][fct=createAnnotation][warn] annotation not editable');
        return 
false;
        }
    
debug('[annotations][fct=createAnnotation] attempting to create annotation...');

    
// ResourceSpace specific properties
    
$resource            $annotation['resource'];
    
$resource_type_field $annotation['resource_type_field'];
    
$page                = (isset($annotation['page']) && $annotation['page'] ? $annotation['page'] : null);
    
$tags                $annotation['tags'] ?? [];

    
// Annotorious annotation
    
$x      $annotation['shapes'][0]['geometry']['x'];
    
$y      $annotation['shapes'][0]['geometry']['y'];
    
$width  $annotation['shapes'][0]['geometry']['width'];
    
$height $annotation['shapes'][0]['geometry']['height'];

    
ps_query(
        
'INSERT INTO annotation (resource, resource_type_field, user, x, y, width, height, page) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
        [
            
'i'$resource,
            
'i'$resource_type_field,
            
'i'$userref,
            
'd'$x,
            
'd'$y,
            
'd'$width,
            
'd'$height,
            
'i'$page,
        ]
    );
    
$annotation_ref sql_insert_id();
    
debug('[annotations][fct=createAnnotation] annotation_ref = ' json_encode($annotation_ref));

    if(
== $annotation_ref)
        {
        
debug('[annotations][fct=createAnnotation][warn] Unable to create annotation');
        return 
false;
        }

    
// Prepare tags before association by adding new nodes to dynamic keywords list (if permissions allow it)
    
$prepared_tags prepareTags($tags);

    
// Add any tags associated with it
    
if(count($tags))
        {
        
addAnnotationNodes($annotation_ref$prepared_tags);
        
add_resource_nodes($resourcearray_column($prepared_tags'ref'), false);
        }

    return 
$annotation_ref;
    }

This article was last updated 20th May 2022 07:05 Europe/London time based on the source file dated 1st February 2022 16:00 Europe/London time.