/** * Get a specific metadata object by its id. * If you want multiple metadata objects, use * {@link elgg_get_metadata()}. * * @param int $id The id of the metadata object being retrieved. * * @return false|ElggMetadata */ function elgg_get_metadata_from_id($id) { return elgg_get_metastring_based_object_from_id($id, 'metadata'); }
public function testGetMetastringObjectFromID() { $db_prefix = elgg_get_config('dbprefix'); $annotations = $this->createAnnotations(1); $metadata = $this->createMetadata(1); foreach ($this->metastringTypes as $type) { $id = ${$type}[0]; $test = elgg_get_metastring_based_object_from_id($id, $type); $this->assertEqual($id, $test->id); } }
/** * Deletes a metastring-based object by its id * * @param int $id The object's ID * @param string $type The object's metastring type: annotation or metadata * @return bool * * @since 1.8.0 * @access private */ function elgg_delete_metastring_based_object_by_id($id, $type) { $id = (int) $id; $db_prefix = elgg_get_config('dbprefix'); switch ($type) { case 'annotation': case 'annotations': $type = 'annotations'; break; case 'metadata': $type = 'metadata'; break; default: return false; } $obj = elgg_get_metastring_based_object_from_id($id, $type); $table = $db_prefix . $type; if ($obj) { // Tidy up if memcache is enabled. // @todo only metadata is supported if ($type == 'metadata') { static $metabyname_memcache; if (!$metabyname_memcache && is_memcache_available()) { $metabyname_memcache = new ElggMemcache('metabyname_memcache'); } if ($metabyname_memcache) { $metabyname_memcache->delete("{$obj->entity_guid}:{$obj->name_id}"); } } if ($obj->canEdit() && elgg_trigger_event('delete', $type, $obj)) { return delete_data("DELETE from {$table} where id={$id}"); } } return false; }
/** * Get a specific annotation by its id. * If you want multiple annotation objects, use * {@link elgg_get_annotations()}. * * @param int $id The id of the annotation object being retrieved. * * @return false|ElggAnnotation */ function elgg_get_annotation_from_id($id) { return elgg_get_metastring_based_object_from_id($id, 'annotations'); }
public function testGetMetastringObjectFromIDWithDisabledAnnotation() { $name = 'test_annotation_name' . rand(); $value = 'test_annotation_value' . rand(); $id = create_annotation($this->object->guid, $name, $value); $annotation = elgg_get_annotation_from_id($id); $this->assertTrue($annotation->disable()); $test = elgg_get_metastring_based_object_from_id($id, 'annotation'); $this->assertEqual(false, $test); }