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

updateAnnotation()

Description

Update (field bound) annotation and its tags, if applicable.
Text (comment) annotatins can't be updated (same as the comments logic for those with o perm).

Parameters

ColumnTypeDefaultDescription
$annotation array
$ctx: array
json_encode$annotation;
$ctx
string} array{k?: $ctx Environment context (e.g. external share)

Location

include/annotation_functions.php lines 457 to 528

Definition

 
function updateAnnotation(array $annotation, array $ctx): bool
{
    
debug(sprintf('[annotations][fct=updateAnnotation] Param $annotation = %s'json_encode($annotation)));
    if (!isset(
$annotation['ref']) || !annotationEditable($annotation$ctx)) {
        return 
false;
    }

    global 
$userref;

    
// ResourceSpace specific properties
    
$annotation_ref      $annotation['ref'];
    
$resource_type_field = (int) $annotation['resource_type_field'];
    
$resource            $annotation['resource'];
    
$page                = (isset($annotation['page']) && $annotation['page'] ? $annotation['page'] : null);
    
// Text (comment) annotations and tagging (bound) fields are mutually exclusive
    
$comment_text_mode $resource_type_field === 0;
    
$tags = !$comment_text_mode && isset($annotation['tags']) ? $annotation['tags'] : [];

    if (
$comment_text_mode) {
        
// Text (comment) annotations are not to be updated (same as the comments logic for those with o perm)
        
return false;
    }

    
// 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(
        
'UPDATE annotation SET resource_type_field = ?, user = ?, x = ?, y = ?, width = ?, height = ?, page = ? WHERE ref = ?',
        [
            
'i'$resource_type_field,
            
'i'$userref,
            
'd'$x,
            
'd'$y,
            
'd'$width,
            
'd'$height,
            
'i'$page,
            
'i'$annotation_ref,
        ]
    );

    
// Delete existing associations
    
$nodes_to_remove = array();
    foreach (
getAnnotationTags($annotation) as $tag) {
        
$nodes_to_remove[] = $tag['ref'];
    }

    
db_begin_transaction("updateAnnotation");

    if (
count($nodes_to_remove)) {
        
delete_resource_nodes($resource$nodes_to_remove);
    }

    
ps_query("DELETE FROM annotation_node WHERE annotation = ?", ['i'$annotation_ref]);

    
// Add any tags associated with this annotation
    
if (count($tags)) {
        
// Prepare tags before association by adding new nodes to
        // dynamic keywords list (if permissions allow it)
        
$prepared_tags prepareTags($tags);

        
// Add new associations
        
addAnnotationNodes($annotation_ref$prepared_tags);
        
add_resource_nodes($resourcearray_column($prepared_tags'ref'), false);
    }

    
db_end_transaction("updateAnnotation");

    return 
true;
}

This article was last updated 8th July 2025 07:35 Europe/London time based on the source file dated 4th July 2025 10:35 Europe/London time.