Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 317 to 374

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 17th November 2024 15:35 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.