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 annotation and its tags if needed

Parameters

ColumnTypeDefaultDescription
$annotation array

Return

boolean

Location

include/annotation_functions.php lines 392 to 460

Definition

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

    global 
$userref;

    
// ResourceSpace specific properties
    
$annotation_ref      $annotation['ref'];
    
$resource_type_field $annotation['resource_type_field'];
    
$resource            $annotation['resource'];
    
$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(
        
'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 5th December 2024 06:35 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.