PHP Class Elgg\Database\MetadataTable

Since: 1.10.0
Inheritance: use trait Elgg\TimeUsing
Show file Open project: elgg/elgg Class Usage Examples

Protected Properties

Property Type Description
$cache Elgg\Cache\MetadataCache
$db Elgg\Database
$entityTable EntityTable
$events Elgg\EventsService
$independents array
$session ElggSession
$table string

Public Methods

Method Description
__construct ( MetadataCache $cache, Database $db, EntityTable $entityTable, EventsService $events, ElggSession $session ) Constructor
create ( integer $entity_guid, string $name, string $value, string $value_type = '', integer $owner_guid, integer $access_id = ACCESS_PRIVATE, boolean $allow_multiple = false ) : integer | false Create a new metadata object, or update an existing one.
createFromArray ( integer $entity_guid, array $name_and_values, string $value_type, integer $owner_guid, integer $access_id = ACCESS_PRIVATE, boolean $allow_multiple = false ) : boolean This function creates metadata from an associative array of "key => value" pairs.
delete ( integer $id ) : boolean Deletes metadata using its ID.
deleteAll ( array $options ) : boolean | null Deletes metadata based on $options.
disableAll ( array $options ) : boolean | null Disables metadata based on $options.
enableAll ( array $options ) : boolean | null Enables metadata based on $options.
get ( integer $id ) : ElggMetadata | false Get a specific metadata object by its id.
getAll ( array $options = [] ) : ElggMetadata[] | mixed Returns metadata. Accepts all elgg_get_entities() options for entity restraints.
getEntities ( array $options = [] ) : ElggEntity[] | mixed Returns entities based upon metadata. Also accepts all options available to elgg_get_entities(). Supports the singular option shortcut.
getEntityMetadataWhereSql ( string $e_table, string $n_table, array | null $names = null, array | null $values = null, array | null $pairs = null, string $pair_operator = 'AND', boolean $case_sensitive = true, array | null $order_by_metadata = null, array | null $owner_guids = null ) : false | array Returns metadata name and value SQL where for entities.
getUrl ( integer $id ) : mixed Get the URL for this metadata
handleUpdate ( string $event, string $object_type, ElggEntity $object ) : true When an entity is updated, resets the access ID on all of its child metadata
isMetadataIndependent ( string $type, string $subtype ) : boolean Determines whether entities of a given type and subtype should not change their metadata in line with their parent entity
registerMetadataAsIndependent ( string $type, string $subtype = '*' ) : void Mark entities with a particular type and subtype as having access permissions that can be changed independently from their parent entity
update ( integer $id, string $name, string $value, string $value_type, integer $owner_guid, integer $access_id ) : boolean Update a specific piece of metadata.

Method Details

__construct() public method

Constructor
public __construct ( MetadataCache $cache, Database $db, EntityTable $entityTable, EventsService $events, ElggSession $session )
$cache Elgg\Cache\MetadataCache A cache for this table
$db Elgg\Database The Elgg database
$entityTable EntityTable The entities table
$events Elgg\EventsService The events registry
$session ElggSession The session

create() public method

Metadata can be an array by setting allow_multiple to true, but it is an indexed array with no control over the indexing.
public create ( integer $entity_guid, string $name, string $value, string $value_type = '', integer $owner_guid, integer $access_id = ACCESS_PRIVATE, boolean $allow_multiple = false ) : integer | false
$entity_guid integer The entity to attach the metadata to
$name string Name of the metadata
$value string Value of the metadata
$value_type string 'text', 'integer', or '' for automatic detection
$owner_guid integer GUID of entity that owns the metadata. Default is logged in user.
$access_id integer Default is ACCESS_PRIVATE
$allow_multiple boolean Allow multiple values for one key. Default is false
return integer | false id of metadata or false if failure

createFromArray() public method

To achieve an array for a single key, pass in the same key multiple times with allow_multiple set to true. This creates an indexed array. It does not support associative arrays and there is no guarantee on the ordering in the array.
public createFromArray ( integer $entity_guid, array $name_and_values, string $value_type, integer $owner_guid, integer $access_id = ACCESS_PRIVATE, boolean $allow_multiple = false ) : boolean
$entity_guid integer The entity to attach the metadata to
$name_and_values array Associative array - a value can be a string, number, bool
$value_type string 'text', 'integer', or '' for automatic detection
$owner_guid integer GUID of entity that owns the metadata
$access_id integer Default is ACCESS_PRIVATE
$allow_multiple boolean Allow multiple values for one key. Default is false
return boolean

delete() public method

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

deleteAll() public method

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

disableAll() public method

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

enableAll() public method

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

get() public method

If you want multiple metadata objects, use {@link elgg_get_metadata()}.
public get ( integer $id ) : ElggMetadata | false
$id integer The id of the metadata object being retrieved.
return ElggMetadata | false false if not found

getAll() public method

Returns metadata. Accepts all elgg_get_entities() options for entity restraints.
See also: elgg_get_entities
public getAll ( array $options = [] ) : ElggMetadata[] | mixed
$options array Array in format: metadata_names => null|ARR metadata names metadata_values => null|ARR metadata values metadata_ids => null|ARR metadata ids metadata_case_sensitive => BOOL Overall Case sensitive metadata_owner_guids => null|ARR guids for metadata owners metadata_created_time_lower => INT Lower limit for created time. metadata_created_time_upper => INT Upper limit for created time. metadata_calculation => STR Perform the MySQL function on the metadata values returned. The "metadata_calculation" option causes this function to return the result of performing a mathematical calculation on all metadata that match the query instead of returning \ElggMetadata objects.
return ElggMetadata[] | mixed

getEntities() public method

Returns entities based upon metadata. Also accepts all options available to elgg_get_entities(). Supports the singular option shortcut.
See also: elgg_get_entities
public getEntities ( array $options = [] ) : ElggEntity[] | mixed
$options array Array in format: metadata_names => null|ARR metadata names metadata_values => null|ARR metadata values metadata_name_value_pairs => null|ARR ( name => 'name', value => 'value', 'operand' => '=', 'case_sensitive' => true ) Currently if multiple values are sent via an array (value => array('value1', 'value2') the pair's operand will be forced to "IN". If passing "IN" as the operand and a string as the value, the value must be a properly quoted and escaped string. metadata_name_value_pairs_operator => null|STR The operator to use for combining (name = value) OPERATOR (name = value); default AND metadata_case_sensitive => BOOL Overall Case sensitive order_by_metadata => null|ARR array( 'name' => 'metadata_text1', 'direction' => ASC|DESC, 'as' => text|integer ) Also supports array('name' => 'metadata_text1') metadata_owner_guids => null|ARR guids for metadata owners
return ElggEntity[] | mixed If count, int. If not count, array. false on errors.

getEntityMetadataWhereSql() public method

NB: $names and $values are not paired. Use $pairs for this. Pairs default to '=' operand. This function is reused for annotations because the tables are exactly the same.
public getEntityMetadataWhereSql ( string $e_table, string $n_table, array | null $names = null, array | null $values = null, array | null $pairs = null, string $pair_operator = 'AND', boolean $case_sensitive = true, array | null $order_by_metadata = null, array | null $owner_guids = null ) : false | array
$e_table string Entities table name
$n_table string Normalized metastrings table name (Where entities, values, and names are joined. annotations / metadata)
$names array | null Array of names
$values array | null Array of values
$pairs array | null Array of names / values / operands
$pair_operator string ("AND" or "OR") Operator to use to join the where clauses for pairs
$case_sensitive boolean Case sensitive metadata names?
$order_by_metadata array | null Array of names / direction
$owner_guids array | null Array of owner GUIDs
return false | array False on fail, array('joins', 'wheres')

getUrl() public method

By default this links to the export handler in the current view.
public getUrl ( integer $id ) : mixed
$id integer Metadata ID
return mixed

handleUpdate() public method

When an entity is updated, resets the access ID on all of its child metadata
public handleUpdate ( string $event, string $object_type, ElggEntity $object ) : true
$event string The name of the event
$object_type string The type of object
$object ElggEntity The entity itself
return true

isMetadataIndependent() public method

Determines whether entities of a given type and subtype should not change their metadata in line with their parent entity
public isMetadataIndependent ( string $type, string $subtype ) : boolean
$type string The type - object, user, etc
$subtype string The entity subtype
return boolean

registerMetadataAsIndependent() public method

Mark entities with a particular type and subtype as having access permissions that can be changed independently from their parent entity
public registerMetadataAsIndependent ( string $type, string $subtype = '*' ) : void
$type string The type - object, user, etc
$subtype string The subtype; all subtypes by default
return void

update() public method

Update a specific piece of metadata.
public update ( integer $id, string $name, string $value, string $value_type, integer $owner_guid, integer $access_id ) : boolean
$id integer ID of the metadata to update
$name string Metadata name
$value string Metadata value
$value_type string Value type
$owner_guid integer Owner guid
$access_id integer Access ID
return boolean

Property Details

$cache protected property

protected MetadataCache,Elgg\Cache $cache
return Elgg\Cache\MetadataCache

$db protected property

protected Database,Elgg $db
return Elgg\Database

$entityTable protected property

protected EntityTable,Elgg\Database $entityTable
return EntityTable

$events protected property

protected EventsService,Elgg $events
return Elgg\EventsService

$independents protected property

protected array $independents
return array

$session protected property

protected ElggSession $session
return ElggSession

$table protected property

protected string $table
return string