Elgg  Version 2.3
metadata.php
Go to the documentation of this file.
1 <?php
19  if (!($row instanceof \stdClass)) {
20  return $row;
21  }
22 
23  return new \ElggMetadata($row);
24 }
25 
36  return _elgg_services()->metadataTable->get($id);
37 }
38 
46  return _elgg_services()->metadataTable->delete($id);
47 }
48 
66 function create_metadata($entity_guid, $name, $value, $value_type = '', $owner_guid = 0,
67  $access_id = null, $allow_multiple = false) {
68 
69  if ($access_id === null) {
70  $access_id = ACCESS_PRIVATE;
71  } elseif ($access_id != ACCESS_PUBLIC) {
72  elgg_deprecated_notice('Setting $access_id to a value other than ACCESS_PUBLIC is deprecated. '
73  . 'All metadata will be public in 3.0.', '2.3');
74  }
75 
76  return _elgg_services()->metadataTable->create($entity_guid, $name, $value,
77  $value_type, $owner_guid, $access_id, $allow_multiple);
78 }
79 
93 function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id) {
94  if ($access_id != ACCESS_PUBLIC) {
95  elgg_deprecated_notice('Setting $access_id to a value other than ACCESS_PUBLIC is deprecated. '
96  . 'All metadata will be public in 3.0.', '2.3');
97  }
98 
99  return _elgg_services()->metadataTable->update($id, $name, $value,
100  $value_type, $owner_guid, $access_id);
101 }
102 
120 function create_metadata_from_array($entity_guid, array $name_and_values, $value_type, $owner_guid,
121  $access_id = null, $allow_multiple = false) {
122 
123  if ($access_id === null) {
124  $access_id = ACCESS_PRIVATE;
125  } elseif ($access_id != ACCESS_PUBLIC) {
126  elgg_deprecated_notice('Setting $access_id to a value other than ACCESS_PUBLIC is deprecated. '
127  . 'All metadata will be public in 3.0.', '2.3');
128  }
129 
130  return _elgg_services()->metadataTable->createFromArray($entity_guid, $name_and_values,
131  $value_type, $owner_guid, $access_id, $allow_multiple);
132 }
133 
164 function elgg_get_metadata(array $options = array()) {
165  return _elgg_services()->metadataTable->getAll($options);
166 }
167 
180  return _elgg_services()->metadataTable->deleteAll($options);
181 }
182 
193  return _elgg_services()->metadataTable->disableAll($options);
194 }
195 
209  return _elgg_services()->metadataTable->enableAll($options);
210 }
211 
276 function elgg_get_entities_from_metadata(array $options = array()) {
277  return _elgg_services()->metadataTable->getEntities($options);
278 }
279 
291  return elgg_list_entities($options, 'elgg_get_entities_from_metadata');
292 }
293 
317 function _elgg_get_entity_metadata_where_sql($e_table, $n_table, $names = null, $values = null,
318  $pairs = null, $pair_operator = 'AND', $case_sensitive = true, $order_by_metadata = null,
319  $owner_guids = null) {
320  return _elgg_services()->metadataTable->getEntityMetadataWhereSql($e_table, $n_table, $names,
321  $values, $pairs, $pair_operator, $case_sensitive, $order_by_metadata, $owner_guids);
322 }
323 
332 function metadata_array_to_values($array) {
333  $valuearray = array();
334 
335  if (is_array($array)) {
336  foreach ($array as $element) {
337  $valuearray[] = $element->value;
338  }
339  }
340 
341  return $valuearray;
342 }
343 
354  return _elgg_services()->metadataTable->getUrl($id);
355 }
356 
367  _elgg_services()->metadataTable->registerMetadataAsIndependent($type, $subtype);
368 }
369 
380  return _elgg_services()->metadataTable->isMetadataIndependent($type, $subtype);
381 }
382 
393 function metadata_update($event, $object_type, $object) {
394  return _elgg_services()->metadataTable->handleUpdate($event, $object_type, $object);
395 }
396 
407  _elgg_services()->metadataCache->invalidateByOptions($options);
408 }
409 
422  global $CONFIG;
423  $value[] = $CONFIG->path . 'engine/tests/ElggCoreMetadataAPITest.php';
424  $value[] = $CONFIG->path . 'engine/tests/ElggCoreMetadataCacheTest.php';
425  return $value;
426 }
427 
428 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
430  $events->registerHandler('update', 'all', 'metadata_update', 600);
431 
432  $hooks->registerHandler('unit_test', 'system', '_elgg_metadata_test');
433 };
elgg_delete_metadata_by_id($id)
Deletes metadata using its ID.
Definition: metadata.php:45
update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
Update a specific piece of metadata.
Definition: metadata.php:93
$object
These two snippets demonstrates triggering an event and how to register for that event.
Definition: trigger.php:7
get_metadata_url($id)
Get the URL for this metadata.
Definition: metadata.php:353
$action
Definition: full.php:133
elgg_get_entities_from_metadata(array $options=array())
interfaces
Definition: metadata.php:276
elgg_disable_metadata(array $options)
Disables metadata based on $options.
Definition: metadata.php:192
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
create_metadata($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=null, $allow_multiple=false)
Create a new metadata object, or update an existing one.
Definition: metadata.php:66
register_metadata_as_independent($type, $subtype= '*')
Mark entities with a particular type and subtype as having access permissions that can be changed ind...
Definition: metadata.php:366
$value
Definition: longtext.php:42
$subtype
Definition: delete.php:28
elgg_list_entities_from_metadata($options)
Returns a list of entities filtered by provided metadata.
Definition: metadata.php:290
row_to_elggmetadata($row)
Convert a database row to a new .
Definition: metadata.php:18
create_metadata_from_array($entity_guid, array $name_and_values, $value_type, $owner_guid, $access_id=null, $allow_multiple=false)
This function creates metadata from an associative array of "key => value" pairs. ...
Definition: metadata.php:120
elgg_get_metadata_from_id($id)
Get a specific metadata object by its id.
Definition: metadata.php:35
$options
Elgg admin footer.
Definition: footer.php:6
$params
Definition: login.php:72
$entity_guid
Definition: save.php:9
_elgg_get_entity_metadata_where_sql($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.
Definition: metadata.php:317
$owner_guid
metadata_array_to_values($array)
Takes a metadata array (which has all kinds of properties) and turns it into a simple array of string...
Definition: metadata.php:332
is_metadata_independent($type, $subtype)
Determines whether entities of a given type and subtype should not change their metadata in line with...
Definition: metadata.php:379
elgg_enable_metadata(array $options)
Enables metadata based on $options.
Definition: metadata.php:208
global $CONFIG
const ACCESS_PRIVATE
Definition: elgglib.php:2082
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
elgg global
Pointer to the global context.
Definition: elgglib.js:12
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
metadata_update($event, $object_type, $object)
When an entity is updated, resets the access ID on all of its child metadata.
Definition: metadata.php:393
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:393
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:179
const ACCESS_PUBLIC
Definition: elgglib.php:2084
elgg_get_metadata(array $options=array())
Returns metadata.
Definition: metadata.php:164
$row
_elgg_metadata_test($hook, $type, $value, $params)
Metadata unit test.
Definition: metadata.php:421
if(!$collection_name) $id
Definition: add.php:17
_elgg_invalidate_metadata_cache($action, array $options)
Invalidate the metadata cache based on options passed to various *_metadata functions.
Definition: metadata.php:406
if(!$display_name) $type
Definition: delete.php:27