Collections functions
Encryption functions
General 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 312 to 356

Definition

 
function createAnnotation(array $annotation)
    {
    global 
$userref;

    if(!
annotationEditable($annotation))
        {
        return 
false;
        }

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

    
// ResourceSpace specific properties
    
$resource            escape_check($annotation['resource']);
    
$resource_type_field escape_check($annotation['resource_type_field']);
    
$tags                = (isset($annotation['tags']) ? $annotation['tags'] : array());
    
$page                = (isset($annotation['page']) && $annotation['page'] ? '\'' escape_check($annotation['page']) . '\'' 'NULL');

    
$query "INSERT INTO annotation (resource, resource_type_field, user, x, y, width, height, page)
                   VALUES ('
{$resource}', '{$resource_type_field}', '{$userref}', '{$x}', '{$y}', '{$width}', '{$height}', {$page})";
    
sql_query($query);

    
$annotation_ref sql_insert_id();

    if(
== $annotation_ref)
        {
        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 11th July 2020 01:05 Europe/London time based on the source file dated 17th January 2020 16:11 Europe/London time.