// Make sure we can get the comment in question
$annotation_id = (int) get_input('annotation_id');
-if ($comment = get_annotation($annotation_id)) {
+if ($comment = elgg_get_annotation_from_id($annotation_id)) {
$entity = get_entity($comment->entity_guid);
// Make sure we can get the comment in question
$annotation_id = (int) get_input('annotation_id');
-if ($likes = get_annotation($annotation_id)) {
+if ($likes = elgg_get_annotation_from_id($annotation_id)) {
$entity = get_entity($likes->entity_guid);
// go through custom fields
if (sizeof($input) > 0) {
foreach ($input as $shortname => $value) {
- remove_metadata($owner->guid, $shortname);
+ $options = array(
+ 'guid' => $owner->guid,
+ 'metadata_name' => $shortname
+ );
+ elgg_delete_metadata($options);
if (isset($accesslevel[$shortname])) {
$access_id = (int) $accesslevel[$shortname];
} else {
if ($id instanceof stdClass) {
$annotation = $id;
} else {
- $annotation = get_annotation($id);
+ $annotation = elgg_get_annotation_from_id($id);
}
if ($annotation) {
* @return ElggAnnotation
*/
public function getObjectFromID($id) {
- return get_annotation($id);
+ return elgg_get_annotation_from_id($id);
}
}
'limit' => 0
);
if ($name) {
- $options['annotations_name'] = $name;
+ $options['annotation_name'] = $name;
}
return elgg_delete_annotations($options);
// no longer have access to an entity they created annotations on.
$ia = elgg_set_ignore_access(true);
$options = array(
- 'annotations_owner_guid' => $this->guid,
+ 'annotation_owner_guid' => $this->guid,
'limit' => 0
);
if ($name) {
- $options['annotations_name'] = $name;
+ $options['annotation_name'] = $name;
}
$r = elgg_delete_annotations($options);
'limit' => 0
);
if ($name) {
- $options['annotations_name'] = $name;
+ $options['annotation_name'] = $name;
}
return elgg_disable_annotations($options);
'limit' => 0
);
if ($name) {
- $options['annotations_name'] = $name;
+ $options['annotation_name'] = $name;
}
return elgg_enable_annotations($options);
* @return ElggAnnotation
*/
public function getAnnotation() {
- return get_annotation($this->annotation_id);
+ return elgg_get_annotation_from_id($this->annotation_id);
}
/**
$m = elgg_get_metadata_from_id($id_or_name);
break;
case 'annotation' :
- $m = get_annotation($id_or_name);
+ $m = elgg_get_annotation_from_id($id_or_name);
break;
case 'relationship' :
$r = get_relationship($id_or_name);
* @return false|ElggAnnotation
*/
function elgg_get_annotation_from_id($id) {
- return elgg_get_metastring_based_object_by_id($id, 'annotations');
+ return elgg_get_metastring_based_object_from_id($id, 'annotations');
+}
+
+/**
+ * Deletes an annotation using its ID.
+ *
+ * @param int $id The annotation ID to delete.
+ * @return bool
+ */
+function elgg_delete_annotation_by_id($id) {
+ $annotation = elgg_get_annotation_from_id($id);
+ if (!$annotation) {
+ return false;
+ }
+ return $annotation->delete();
}
/**
($entity_guid,'$name',$value,'$value_type', $owner_guid, $time, $access_id)");
if ($result !== false) {
- $obj = get_annotation($result);
+ $obj = elgg_get_annotation_from_id($result);
if (elgg_trigger_event('create', 'annotation', $obj)) {
return $result;
} else {
// plugin returned false to reject annotation
- delete_annotation($result);
+ elgg_delete_annotation_by_id($result);
return FALSE;
}
}
where id=$annotation_id and name_id='$name' and $access");
if ($result !== false) {
- $obj = get_annotation($annotation_id);
+ $obj = elgg_get_annotation_from_id($annotation_id);
if (elgg_trigger_event('update', 'annotation', $obj)) {
return true;
} else {
// @todo add plugin hook that sends old and new annotation information before db access
- delete_annotation($annotation_id);
+ elgg_delete_annotation_by_id($annotation_id);
}
}
function get_annotation_url($id) {
$id = (int)$id;
- if ($extender = get_annotation($id)) {
+ if ($extender = elgg_get_annotation_from_id($id)) {
return get_extender_url($extender);
}
return false;
* @return false|ElggMetadata
*/
function elgg_get_metadata_from_id($id) {
- return elgg_get_metastring_based_object_by_id($id, 'metadata');
+ return elgg_get_metastring_based_object_from_id($id, 'metadata');
+}
+
+/**
+ * Deletes metadata using its ID.
+ *
+ * @param int $id The metadata ID to delete.
+ * @return bool
+ */
+function elgg_delete_metadata_by_id($id) {
+ $metadata = elgg_get_metadata_from_id($id);
+ if (!$metadata) {
+ return false;
+ }
+ return $metadata->delete();
}
/**
$options['metastring_type'] = $type;
- $prefixes = array('metadata_', 'annotation_');
+ // support annotation_ and annotations_ because they're way too easy to confuse
+ $prefixes = array('metadata_', 'annotation_', 'annotations_');
// map the metadata_* options to metastring_* options
$map = array(
$id = (int)$id;
$db_prefix = elgg_get_config('dbprefix');
- $object = elgg_get_metastring_based_object_by_id($id, $type);
+ $object = elgg_get_metastring_based_object_from_id($id, $type);
switch($type) {
case 'annotation':
* @since 1.8
* @access private
*/
-function elgg_get_metastring_based_object_by_id($id, $type) {
+function elgg_get_metastring_based_object_from_id($id, $type) {
$id = (int)$id;
if (!$id) {
return false;
return false;
}
- $obj = elgg_get_metastring_based_object_by_id($id, $type);
+ $obj = elgg_get_metastring_based_object_from_id($id, $type);
$table = $db_prefix . $type;
if ($obj) {
$name = 'test_annotation_name_' . rand();
$value = rand();
$id = create_annotation($entity->getGUID(), $name, $value, 'integer', $entity->getGUID());
- $annotations[] = get_annotation($id);
+ $annotations[] = elgg_get_annotation_from_id($id);
}
return $annotations;
} while(in_array($e->guid, $a_e_map));
// remove annotations left over from previous tests.
- clear_annotations($e->guid);
+ elgg_delete_annotations(array('annotation_owner_guid' => $e->guid));
$annotations = $this->createRandomAnnotations($e);
foreach($annotations as $a) {
}
}
- public function testGetMetastringObjectByID() {
+ 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_by_id($id, $type);
+ $test = elgg_get_metastring_based_object_from_id($id, $type);
$this->assertEqual($id, $test->id);
}
public function __construct() {
$this->ia = elgg_set_ignore_access(TRUE);
parent::__construct();
-
+
// all __construct() code should come after here
}
public function testElggObjectClearAnnotations() {
$this->entity = new ElggObject();
$guid = $this->entity->save();
-
+
$this->entity->annotate('test', 'hello', ACCESS_PUBLIC);
-
- $this->entity->clearAnnotations('does not exist');
-
+
+ $this->entity->deleteAnnotations('does not exist');
+
$num = $this->entity->countAnnotations('test');
-
+
//$this->assertIdentical($num, 1);
$this->assertEqual($num, 1);
-
+
// clean up
$this->entity->delete();
}
-
+
/**
* #2063 - get_resized_image_from_existing_file() fails asked for image larger than selection and not scaling an image up
* Test get_image_resize_parameters().
public function testElggResizeImage() {
$orig_width = 100;
$orig_height = 150;
-
+
// test against selection > max
$options = array(
'maxwidth' => 50,
'maxheight' => 50,
'square' => TRUE,
'upscale' => FALSE,
-
+
'x1' => 25,
'y1' => 75,
'x2' => 100,
'y2' => 150
);
-
- // should get back the same x/y offset == x1, y1 and an image of 50x50
+
+ // should get back the same x/y offset == x1, y1 and an image of 50x50
$params = get_image_resize_parameters($orig_width, $orig_height, $options);
-
+
$this->assertEqual($params['newwidth'], $options['maxwidth']);
$this->assertEqual($params['newheight'], $options['maxheight']);
$this->assertEqual($params['xoffset'], $options['x1']);
$this->assertEqual($params['yoffset'], $options['y1']);
-
+
// test against selection < max
$options = array(
'maxwidth' => 50,
'maxheight' => 50,
'square' => TRUE,
'upscale' => FALSE,
-
+
'x1' => 75,
'y1' => 125,
'x2' => 100,
'y2' => 150
);
-
+
// should get back the same x/y offset == x1, y1 and an image of 25x25
$params = get_image_resize_parameters($orig_width, $orig_height, $options);
-
+
$this->assertEqual($params['newwidth'], 25);
$this->assertEqual($params['newheight'], 25);
$this->assertEqual($params['xoffset'], $options['x1']);
$title .= ": \"$blog->title\"";
if ($revision) {
- $revision = get_annotation((int)$revision);
+ $revision = elgg_get_annotation_from_id((int)$revision);
$vars['revision'] = $revision;
$title .= ' ' . elgg_echo('blog:edit_revision_notice');
$annotation_id = (int) get_input('annotation_id');
//make sure that there is a message on the message board matching the passed id
-if ($message = get_annotation($annotation_id)) {
+if ($message = elgg_get_annotation_from_id($annotation_id)) {
//grab the user or group entity
$entity = get_entity($message->entity_guid);
*/
$id = get_input('id');
-$annotation = get_annotation($id);
+$annotation = elgg_get_annotation_from_id($id);
if (!$annotation) {
forward();
}