/**
* Update an annotation.
*
* @param int $annotation_id Annotation ID
* @param string $name Name of annotation
* @param string $value Value of annotation
* @param string $value_type Type of value
* @param int $owner_guid Owner of annotation
* @param int $access_id Access level of annotation
*
* @return bool
*/
function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
{
$annotation_id = (int) $annotation_id;
$annotation = $this->get($annotation_id);
if (!$annotation) {
return false;
}
if (!$annotation->canEdit()) {
return false;
}
$name = trim($name);
$value_type = detect_extender_valuetype($value, $value_type);
$owner_guid = (int) $owner_guid;
if ($owner_guid == 0) {
$owner_guid = $this->session->getLoggedInUserGuid();
}
$access_id = (int) $access_id;
$sql = "UPDATE {$this->db->prefix}annotations\n\t\t\t(name, value, value_type, access_id, owner_guid)\n\t\t\tVALUES\n\t\t\t(:name, :value, :value_type, :access_id, :owner_guid)\n\t\t\tWHERE id = :annotation_id";
$result = $this->db->updateData($sql, false, [':name' => $name, ':value' => $value, ':value_type' => $value_type, ':access_id' => $access_id, ':owner_guid' => $owner_guid, ':annotation_id' => $annotation_id]);
if ($result !== false) {
// @todo add plugin hook that sends old and new annotation information before db access
$obj = $this->get($annotation_id);
$this->events->trigger('update', 'annotation', $obj);
}
return $result;
}