function create($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE)
{
$result = false;
$entity_guid = (int) $entity_guid;
$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;
// @todo we don't check that the entity is loaded which means the user may
// not have access to the entity
$entity = get_entity($entity_guid);
if ($this->events->trigger('annotate', $entity->type, $entity)) {
$sql = "INSERT INTO {$this->db->prefix}annotations\n\t\t\t\t(entity_guid, name, value, value_type, owner_guid, time_created, access_id)\n\t\t\t\tVALUES\n\t\t\t\t(:entity_guid, :name, :value, :value_type, :owner_guid, :time_created, :access_id)";
$result = $this->db->insertData($sql, [':entity_guid' => $entity_guid, ':name' => $name, ':value' => $value, ':value_type' => $value_type, ':owner_guid' => $owner_guid, ':time_created' => $this->getCurrentTime()->getTimestamp(), ':access_id' => $access_id]);
if ($result !== false) {
$obj = elgg_get_annotation_from_id($result);
if ($this->events->trigger('create', 'annotation', $obj)) {
return $result;
} else {
// plugin returned false to reject annotation
elgg_delete_annotation_by_id($result);
return false;
}
}
}
return $result;
}