Elgg  Version 1.11
Public Member Functions | List of all members
Elgg\Database\MetadataTable Class Reference

Public Member Functions

 __construct (Cache $cache, Database $db, EntityTable $entityTable, Events $events, MetastringsTable $metastringsTable, Session $session)
 Constructor. More...
 
 get ($id)
 Get a specific metadata object by its id. More...
 
 delete ($id)
 Deletes metadata using its ID. More...
 
 create ($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE, $allow_multiple=false)
 Create a new metadata object, or update an existing one. More...
 
 update ($id, $name, $value, $value_type, $owner_guid, $access_id)
 Update a specific piece of metadata. More...
 
 createFromArray ($entity_guid, array $name_and_values, $value_type, $owner_guid, $access_id=ACCESS_PRIVATE, $allow_multiple=false)
 This function creates metadata from an associative array of "key => value" pairs. More...
 
 getAll (array $options=array())
 Returns metadata. More...
 
 deleteAll (array $options)
 Deletes metadata based on $options. More...
 
 disableAll (array $options)
 Disables metadata based on $options. More...
 
 enableAll (array $options)
 Enables metadata based on $options. More...
 
 getEntities (array $options=array())
 Returns entities based upon metadata. More...
 
 getEntityMetadataWhereSql ($e_table, $n_table, $names=null, $values=null, $pairs=null, $pair_operator= 'AND', $case_sensitive=true, $order_by_metadata=null, $owner_guids=null)
 Returns metadata name and value SQL where for entities. More...
 
 getUrl ($id)
 Get the URL for this metadata. More...
 
 registerMetadataAsIndependent ($type, $subtype= '*')
 Mark entities with a particular type and subtype as having access permissions that can be changed independently from their parent entity. More...
 
 isMetadataIndependent ($type, $subtype)
 Determines whether entities of a given type and subtype should not change their metadata in line with their parent entity. More...
 
 handleUpdate ($event, $object_type, $object)
 When an entity is updated, resets the access ID on all of its child metadata. More...
 

Detailed Description

Definition at line 21 of file MetadataTable.php.

Constructor & Destructor Documentation

Elgg\Database\MetadataTable::__construct ( Cache  $cache,
Database  $db,
EntityTable  $entityTable,
Events  $events,
MetastringsTable  $metastringsTable,
Session  $session 
)

Constructor.

Parameters
Cache$cacheA cache for this table
Database$dbThe Elgg database
EntityTable$entityTableThe entities table
Events$eventsThe events registry
MetastringsTable$metastringsTableThe metastrings table
Session$sessionThe session

Definition at line 56 of file MetadataTable.php.

Member Function Documentation

Elgg\Database\MetadataTable::create (   $entity_guid,
  $name,
  $value,
  $value_type = '',
  $owner_guid = 0,
  $access_id = ACCESS_PRIVATE,
  $allow_multiple = false 
)

Create a new metadata object, or update an existing one.

Metadata can be an array by setting allow_multiple to true, but it is an indexed array with no control over the indexing.

Parameters
int$entity_guidThe entity to attach the metadata to
string$nameName of the metadata
string$valueValue of the metadata
string$value_type'text', 'integer', or '' for automatic detection
int$owner_guidGUID of entity that owns the metadata. Default is logged in user.
int$access_idDefault is ACCESS_PRIVATE
bool$allow_multipleAllow multiple values for one key. Default is false
Returns
int|false id of metadata or false if failure

Definition at line 113 of file MetadataTable.php.

Elgg\Database\MetadataTable::createFromArray (   $entity_guid,
array  $name_and_values,
  $value_type,
  $owner_guid,
  $access_id = ACCESS_PRIVATE,
  $allow_multiple = false 
)

This function creates metadata from an associative array of "key => value" pairs.

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.

Parameters
int$entity_guidThe entity to attach the metadata to
array$name_and_valuesAssociative array - a value can be a string, number, bool
string$value_type'text', 'integer', or '' for automatic detection
int$owner_guidGUID of entity that owns the metadata
int$access_idDefault is ACCESS_PRIVATE
bool$allow_multipleAllow multiple values for one key. Default is false
Returns
bool

Definition at line 277 of file MetadataTable.php.

Elgg\Database\MetadataTable::delete (   $id)

Deletes metadata using its ID.

Parameters
int$idThe metadata ID to delete.
Returns
bool

Definition at line 91 of file MetadataTable.php.

Elgg\Database\MetadataTable::deleteAll ( array  $options)

Deletes metadata based on $options.

Warning
Unlike elgg_get_metadata() this will not accept an empty options array! This requires at least one constraint: metadata_owner_guid(s), metadata_name(s), metadata_value(s), or guid(s) must be set.
Parameters
array$optionsAn options array. elgg_get_metadata()
Returns
bool|null true on success, false on failure, null if no metadata to delete.

Definition at line 342 of file MetadataTable.php.

Elgg\Database\MetadataTable::disableAll ( array  $options)

Disables metadata based on $options.

Warning
Unlike elgg_get_metadata() this will not accept an empty options array!
Parameters
array$optionsAn options array. elgg_get_metadata()
Returns
bool|null true on success, false on failure, null if no metadata disabled.

Definition at line 364 of file MetadataTable.php.

Elgg\Database\MetadataTable::enableAll ( array  $options)

Enables metadata based on $options.

Warning
Unlike elgg_get_metadata() this will not accept an empty options array!
In order to enable metadata, you must first use access_show_hidden_entities().
Parameters
array$optionsAn options array. elgg_get_metadata()
Returns
bool|null true on success, false on failure, null if no metadata enabled.

Definition at line 390 of file MetadataTable.php.

Elgg\Database\MetadataTable::get (   $id)

Get a specific metadata object by its id.

If you want multiple metadata objects, use elgg_get_metadata().

Parameters
int$idThe id of the metadata object being retrieved.
Returns
|false false if not found

Definition at line 81 of file MetadataTable.php.

Elgg\Database\MetadataTable::getAll ( array  $options = array())

Returns metadata.

Accepts all elgg_get_entities() options for entity restraints.

See also
elgg_get_entities
Warning
1.7's find_metadata() didn't support limits and returned all metadata. This function defaults to a limit of 25. There is probably not a reason for you to return all metadata unless you're exporting an entity, have other restraints in place, or are doing something horribly wrong in your code.
Parameters
array$optionsArray 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 objects.

Returns
[]|mixed

Definition at line 319 of file MetadataTable.php.

Elgg\Database\MetadataTable::getEntities ( array  $options = array())

Returns entities based upon metadata.

Also accepts all options available to elgg_get_entities(). Supports the singular option shortcut.

Note
Using metadata_names and metadata_values results in a "names IN (...) AND values IN (...)" clause. This is subtly differently than default multiple metadata_name_value_pairs, which use "(name = value) AND (name = value)" clauses.

When in doubt, use name_value_pairs.

To ask for entities that do not have a metadata value, use a custom where clause like this:

$options['wheres'][] = "NOT EXISTS (
    SELECT 1 FROM {$dbprefix}metadata md
    WHERE md.entity_guid = e.guid
        AND md.name_id = $name_metastring_id
        AND md.value_id = $value_metastring_id)";

Note the metadata name and value has been denormalized in the above example.

See also
elgg_get_entities
Parameters
array$optionsArray 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

Returns
[]|mixed If count, int. If not count, array. false on errors.

Definition at line 460 of file MetadataTable.php.

Elgg\Database\MetadataTable::getEntityMetadataWhereSql (   $e_table,
  $n_table,
  $names = null,
  $values = null,
  $pairs = null,
  $pair_operator = 'AND',
  $case_sensitive = true,
  $order_by_metadata = null,
  $owner_guids = null 
)

Returns metadata name and value SQL where for entities.

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.

Parameters
string$e_tableEntities table name
string$n_tableNormalized metastrings table name (Where entities, values, and names are joined. annotations / metadata)
array | null$namesArray of names
array | null$valuesArray of values
array | null$pairsArray of names / values / operands
string$pair_operator("AND" or "OR") Operator to use to join the where clauses for pairs
bool$case_sensitiveCase sensitive metadata names?
array | null$order_by_metadataArray of names / direction
array | null$owner_guidsArray of owner GUIDs
Returns
false|array False on fail, array('joins', 'wheres') private

Definition at line 509 of file MetadataTable.php.

Elgg\Database\MetadataTable::getUrl (   $id)

Get the URL for this metadata.

By default this links to the export handler in the current view.

Parameters
int$idMetadata ID
Returns
mixed

Definition at line 763 of file MetadataTable.php.

Elgg\Database\MetadataTable::handleUpdate (   $event,
  $object_type,
  $object 
)

When an entity is updated, resets the access ID on all of its child metadata.

Parameters
string$eventThe name of the event
string$object_typeThe type of object
\ElggEntity$objectThe entity itself
Returns
true private Set as private in 1.9.0

Definition at line 814 of file MetadataTable.php.

Elgg\Database\MetadataTable::isMetadataIndependent (   $type,
  $subtype 
)

Determines whether entities of a given type and subtype should not change their metadata in line with their parent entity.

Parameters
string$typeThe type - object, user, etc
string$subtypeThe entity subtype
Returns
bool

Definition at line 795 of file MetadataTable.php.

Elgg\Database\MetadataTable::registerMetadataAsIndependent (   $type,
  $subtype = '*' 
)

Mark entities with a particular type and subtype as having access permissions that can be changed independently from their parent entity.

Parameters
string$typeThe type - object, user, etc
string$subtypeThe subtype; all subtypes by default
Returns
void

Definition at line 778 of file MetadataTable.php.

Elgg\Database\MetadataTable::update (   $id,
  $name,
  $value,
  $value_type,
  $owner_guid,
  $access_id 
)

Update a specific piece of metadata.

Parameters
int$idID of the metadata to update
string$nameMetadata name
string$valueMetadata value
string$value_typeValue type
int$owner_guidOwner guid
int$access_idAccess ID
Returns
bool

Definition at line 196 of file MetadataTable.php.


The documentation for this class was generated from the following file: