Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

updateAnnotation()

Description

Update annotation and its tags if needed

Parameters

ColumnTypeDefaultDescription
$annotation array

Return

boolean

Location

include/annotation_functions.php lines 374 to 439

Definition

 
function updateAnnotation(array $annotation)
    {
    if(!isset(
$annotation['ref']) || !annotationEditable($annotation))
        {
        return 
false;
        }

    global 
$userref;

    
// 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
    
$annotation_ref      escape_check($annotation['ref']);
    
$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');

    
$update_query "
        UPDATE annotation
           SET
               resource_type_field = '
{$resource_type_field}',
               user = '
{$userref}',
               x = '
{$x}',
               y = '
{$y}',
               width = '
{$width}',
               height = '
{$height}',
               page = 
{$page}
         WHERE ref = '
{$annotation_ref}'";
    
sql_query($update_query);

    
// 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);
        }
    
sql_query("DELETE FROM annotation_node WHERE annotation = '{$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 10th July 2020 00:05 Europe/London time based on the source file dated 17th January 2020 16:11 Europe/London time.