PHP Class Elgg\Database\Annotations

Since: 1.10.0
Show file Open project: elgg/elgg

Protected Properties

Property Type Description
$db Elgg\Database
$events Elgg\EventsService
$session ElggSession

Public Methods

Method Description
__construct ( Database $db, ElggSession $session, EventsService $events ) Constructor
create ( integer $entity_guid, string $name, string $value, string $value_type = '', integer $owner_guid, integer $access_id = ACCESS_PRIVATE ) : integer | boolean Create a new annotation.
delete ( integer $id ) : boolean Deletes an annotation using its ID.
deleteAll ( array $options ) : boolean | null Deletes annotations based on $options.
disableAll ( array $options ) : boolean | null Disables annotations based on $options.
enableAll ( array $options ) : boolean | null Enables annotations based on $options.
exists ( integer $entity_guid, string $annotation_type, integer $owner_guid = null ) : boolean Check to see if a user has already created an annotation on an object
find ( array $options = [] ) : ElggAnnotation[] | mixed Returns annotations. Accepts all elgg_get_entities() options for entity restraints.
get ( integer $id ) : ElggAnnotation | false Get a specific annotation by its id.
getEntities ( array $options = [] ) : mixed Returns entities based upon annotations. Also accepts all options available to elgg_get_entities() and elgg_get_entities_from_metadata().
getEntitiesFromCalculation ( array $options ) : ElggEntity[] | integer Get entities ordered by a mathematical calculation on annotation values
update ( integer $annotation_id, string $name, string $value, string $value_type, integer $owner_guid, integer $access_id ) : boolean Update an annotation.

Method Details

__construct() public method

Constructor
public __construct ( Database $db, ElggSession $session, EventsService $events )
$db Elgg\Database Database
$session ElggSession Session
$events Elgg\EventsService Events

create() public method

Create a new annotation.
public create ( integer $entity_guid, string $name, string $value, string $value_type = '', integer $owner_guid, integer $access_id = ACCESS_PRIVATE ) : integer | boolean
$entity_guid integer GUID of entity to be annotated
$name string Name of annotation
$value string Value of annotation
$value_type string Type of value (default is auto detection)
$owner_guid integer Owner of annotation (default is logged in user)
$access_id integer Access level of annotation
return integer | boolean id on success or false on failure

delete() public method

Deletes an annotation using its ID.
public delete ( integer $id ) : boolean
$id integer The annotation ID to delete.
return boolean

deleteAll() public method

Deletes annotations based on $options.
public deleteAll ( array $options ) : boolean | null
$options array An options array. {@link elgg_get_annotations()}
return boolean | null true on success, false on failure, null if no annotations to delete.

disableAll() public method

Disables annotations based on $options.
public disableAll ( array $options ) : boolean | null
$options array An options array. {@link elgg_get_annotations()}
return boolean | null true on success, false on failure, null if no annotations disabled.

enableAll() public method

Enables annotations based on $options.
public enableAll ( array $options ) : boolean | null
$options array An options array. {@link elgg_get_annotations()}
return boolean | null true on success, false on failure, null if no metadata enabled.

exists() public method

Check to see if a user has already created an annotation on an object
public exists ( integer $entity_guid, string $annotation_type, integer $owner_guid = null ) : boolean
$entity_guid integer Entity guid
$annotation_type string Type of annotation
$owner_guid integer Defaults to logged in user.
return boolean

find() public method

Returns annotations. Accepts all elgg_get_entities() options for entity restraints.
See also: elgg_get_entities
public find ( array $options = [] ) : ElggAnnotation[] | mixed
$options array Array in format: annotation_names => null|ARR Annotation names annotation_values => null|ARR Annotation values annotation_ids => null|ARR annotation ids annotation_case_sensitive => BOOL Overall Case sensitive annotation_owner_guids => null|ARR guids for annotation owners annotation_created_time_lower => INT Lower limit for created time. annotation_created_time_upper => INT Upper limit for created time. annotation_calculation => STR Perform the MySQL function on the annotation values returned. Do not confuse this "annotation_calculation" option with the "calculation" option to elgg_get_entities_from_annotation_calculation(). The "annotation_calculation" option causes this function to return the result of performing a mathematical calculation on all annotations that match the query instead of \ElggAnnotation objects. See the docs for elgg_get_entities_from_annotation_calculation() for the proper use of the "calculation" option.
return ElggAnnotation[] | mixed

get() public method

If you want multiple annotation objects, use {@link elgg_get_annotations()}.
public get ( integer $id ) : ElggAnnotation | false
$id integer The id of the annotation object being retrieved.
return ElggAnnotation | false

getEntities() public method

Returns entities based upon annotations. Also accepts all options available to elgg_get_entities() and elgg_get_entities_from_metadata().
See also: elgg_get_entities
See also: elgg_get_entities_from_metadata
public getEntities ( array $options = [] ) : mixed
$options array Array in format: annotation_names => null|ARR annotations names annotation_values => null|ARR annotations values annotation_name_value_pairs => null|ARR (name = 'name', value => 'value', 'operator' => '=', 'case_sensitive' => true) entries. Currently if multiple values are sent via an array (value => array('value1', 'value2') the pair's operator will be forced to "IN". annotation_name_value_pairs_operator => null|STR The operator to use for combining (name = value) OPERATOR (name = value); default AND annotation_case_sensitive => BOOL Overall Case sensitive order_by_annotation => null|ARR (array('name' => 'annotation_text1', 'direction' => ASC|DESC, 'as' => text|integer), Also supports array('name' => 'annotation_text1') annotation_owner_guids => null|ARR guids for annotaiton owners
return mixed If count, int. If not count, array. false on errors.

getEntitiesFromCalculation() public method

Get entities ordered by a mathematical calculation on annotation values
See also: elgg_get_annotations()
See also: elgg_get_entities_from_annotations()
public getEntitiesFromCalculation ( array $options ) : ElggEntity[] | integer
$options array An options array: 'calculation' => The calculation to use. Must be a valid MySQL function. Defaults to sum. Result selected as 'annotation_calculation'. Don't confuse this "calculation" option with the "annotation_calculation" option to elgg_get_annotations(). This "calculation" option is applied to each entity's set of annotations and is selected as annotation_calculation for that row. See the docs for elgg_get_annotations() for proper use of the "annotation_calculation" option. 'order_by' => The order for the sorting. Defaults to 'annotation_calculation desc'. 'annotation_names' => The names of annotations on the entity. 'annotation_values' => The values of annotations on the entity. 'metadata_names' => The name of metadata on the entity. 'metadata_values' => The value of metadata on the entitiy. 'callback' => Callback function to pass each row through. @tip This function is different from other ege* functions, as it uses a metastring-based getter function { @link elgg_get_annotations() }, therefore the callback function should be a derivative of { @link entity_row_to_elggstar() } and not of { @link row_to_annotation() }
return ElggEntity[] | integer An array or a count of entities

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

Property Details

$db protected property

protected Database,Elgg $db
return Elgg\Database

$events protected property

protected EventsService,Elgg $events
return Elgg\EventsService

$session protected property

protected ElggSession $session
return ElggSession