Elgg\Database\Annotations::update PHP Method

update() public method

Update an annotation.
public update ( integer $annotation_id, string $name, string $value, string $value_type, integer $owner_guid, integer $access_id ) : boolean
$annotation_id integer Annotation ID
$name string Name of annotation
$value string Value of annotation
$value_type string Type of value
$owner_guid integer Owner of annotation
$access_id integer Access level of annotation
return boolean
    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;
    }