From 5a955c633c1ac314ccff3fe5a719ae730105c13a Mon Sep 17 00:00:00 2001 From: brettp Date: Sun, 13 Feb 2011 23:53:30 +0000 Subject: Deprecated ElggEntity->clearMetadata() by ElggEntity->deleteMetadata(). Disabling entities now disables their annotations and metadata. Enabling entities enables annotations and metadata. Fixes #1115. git-svn-id: http://code.elgg.org/elgg/trunk@8213 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggEntity.php | 119 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 11 deletions(-) (limited to 'engine/classes/ElggEntity.php') diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 4e1bc586c..37422d702 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -271,7 +271,7 @@ abstract class ElggEntity extends ElggData implements if (array_key_exists($name, $this->attributes)) { $this->attributes[$name] = ""; } else { - $this->clearMetaData($name); + $this->deleteMetadata($name); } } @@ -340,21 +340,79 @@ abstract class ElggEntity extends ElggData implements } } + /** + * Deletes all metadata on this object. If you pass a name, only + * metadata matching that name will be deleted. + * + * @warning Calling this with no or empty arguments will clear all metadata on the entity. + * + * @param string $name The metadata name to remove. + * @return bool + * @since 1.8 + */ + public function deleteMetadata($name = null) { + $options = array( + 'guid' => $this->guid, + 'limit' => 0 + ); + if ($name) { + $options['metadata_name'] = $name; + } + + return elgg_delete_metadata($options); + } + /** * Remove metadata * * @warning Calling this with no or empty arguments will clear all metadata on the entity. * * @param string $name The name of the metadata to clear - * * @return mixed bool + * @deprecated 1.8 Use deleteMetadata() */ public function clearMetaData($name = '') { - if (empty($name)) { - return clear_metadata($this->getGUID()); - } else { - return remove_metadata($this->getGUID(), $name); + return $this->deleteMetadata($name); + } + + /** + * Disables metadata for this entity, optionally based on name. + * + * @param string $name An options name of metadata to disable. + * @return bool + * @since 1.8 + */ + public function disableMetadata($name = '') { + $options = array( + 'guid' => $this->guid, + 'limit' => 0 + ); + if ($name) { + $options['metadata_name'] = $name; + } + + return elgg_disable_metadata($options); + } + + /** + * Enables metadata for this entity, optionally based on name. + * + * @warning Before calling this, you must use {@link access_show_hidden_entities()} + * + * @param string $name An options name of metadata to enable. + * @return bool + * @since 1.8 + */ + public function enableMetadata($name = '') { + $options = array( + 'guid' => $this->guid, + 'limit' => 0 + ); + if ($name) { + $options['metadata_name'] = $name; } + + return elgg_enable_metadata($options); } /** @@ -376,7 +434,6 @@ abstract class ElggEntity extends ElggData implements } } - /** * Set a piece of volatile (non-persisted) data on this entity * @@ -393,7 +450,6 @@ abstract class ElggEntity extends ElggData implements $this->volatile[$name] = $value; } - /** * Remove all relationships to and from this entity. * @@ -488,11 +544,52 @@ abstract class ElggEntity extends ElggData implements return remove_private_setting($this->getGUID(), $name); } + /** + * Disables annotations for this entity, optionally based on name. + * + * @param string $name An options name of annotations to disable. + * @return bool + * @since 1.8 + */ + public function disableAnnotations($name = '') { + $options = array( + 'guid' => $this->guid, + 'limit' => 0 + ); + if ($name) { + $options['annotations_name'] = $name; + } + + return elgg_disable_annotations($options); + } + + /** + * Enables annotations for this entity, optionally based on name. + * + * @warning Before calling this, you must use {@link access_show_hidden_entities()} + * + * @param string $name An options name of annotations to enable. + * @return bool + * @since 1.8 + */ + public function enableAnnotations($name = '') { + $options = array( + 'guid' => $this->guid, + 'limit' => 0 + ); + if ($name) { + $options['annotations_name'] = $name; + } + + return elgg_enable_annotations($options); + } + /** * Helper function to return annotation calculation results * * @param string $name The annotation name. * @param string $calculation A valid MySQL function to run its values through + * @return mixed */ private function getAnnotationCalculation($name, $calculation) { $options = array( @@ -726,9 +823,9 @@ abstract class ElggEntity extends ElggData implements /** * Can a user write to this entity * - * @param int $user_guid The user. - * @param string $type The type of entity we're looking to write - * @param string $subtype The subtype of the entity we're looking to write + * @param int $user_guid The user. + * @param string $type The type of entity we're looking to write + * @param string $subtype The subtype of the entity we're looking to write * * @return bool */ -- cgit v1.2.3