if (array_key_exists($name, $this->attributes)) {
$this->attributes[$name] = "";
} else {
- $this->clearMetaData($name);
+ $this->deleteMetadata($name);
}
}
}
}
+ /**
+ * 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);
}
/**
}
}
-
/**
* Set a piece of volatile (non-persisted) data on this entity
*
$this->volatile[$name] = $value;
}
-
/**
* Remove all relationships to and from this entity.
*
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(
/**
* 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
*/
* pagination => BOOL Display pagination links
* gallery => BOOL display in gallery view
*
- * @param mixed $getter The entity getter function to use to fetch the entities
- * @param mixed $viewer The function to use to view the entity list.
+ * @param mixed $getter The entity getter function to use to fetch the entities
+ * @param mixed $viewer The function to use to view the entity list.
*
* @return string
* @since 1.7
}
}
- // disable annotations
- // Now delete the entity itself
-// $entity->clearMetadata();
-// $entity->clearAnnotations();
-// $entity->clearRelationships();
-//
-// $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
-// if ($res) {
-// $sub_table = "";
-// }
-
$__RECURSIVE_DELETE_TOKEN = null;
}
+ $entity->disableMetadata();
+ $entity->disableAnnotations();
+ // relationships can't be disabled. hope they join to the entities table.
+ //$entity->disableRelationships();
+
$res = update_data("UPDATE {$CONFIG->dbprefix}entities
set enabled='no'
where guid={$guid}");
$result = update_data("UPDATE {$CONFIG->dbprefix}entities
set enabled='yes'
where guid={$guid}");
- $entity->clearMetaData('disable_reason');
+
+ $entity->deleteMetadata('disable_reason');
+ $entity->enableMetadata();
+ $entity->enableAnnotations();
return $result;
}
/**
* Sets the URL handler for a particular entity type and subtype
*
- * @param string $function_name The function to register
* @param string $entity_type The entity type
* @param string $entity_subtype The entity subtype
+ * @param string $function_name The function to register
*
* @return true|false Depending on success
* @see get_entity_url()
* @since 1.8.0
*/
function elgg_register_entity_url_handler($entity_type, $entity_subtype, $function_name) {
-
global $CONFIG;
if (!is_callable($function_name)) {
* @link http://docs.elgg.org/Search
* @link http://docs.elgg.org/Tutorials/Search
*/
-function register_entity_type($type, $subtype=null) {
+function register_entity_type($type, $subtype = null) {
global $CONFIG;
$type = strtolower($type);
*
* @return true|false Depending on whether or not the type has been registered
*/
-function is_registered_entity_type($type, $subtype=null) {
+function is_registered_entity_type($type, $subtype = null) {
global $CONFIG;
if (!isset($CONFIG->registered_entities)) {
// ensure enabled
$this->assertTrue($this->entity->isEnabled());
- // false on disable
+ // false on disable because it's not saved yet.
$this->assertFalse($this->entity->disable());
// save and disable
$this->save_entity();
+
+ // add annotations and metadata to check if they're disabled.
+ $annotation_id = create_annotation($this->entity->guid, 'test_annotation_' . rand(), 'test_value_' . rand());
+ $metadata_id = create_metadata($this->entity->guid, 'test_metadata_' . rand(), 'test_value_' . rand());
+
$this->assertTrue($this->entity->disable());
// ensure disabled by comparing directly with database
$entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'");
$this->assertIdentical($entity->enabled, 'no');
+ $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '$annotation_id'");
+ $this->assertIdentical($annotation->enabled, 'no');
+
+ $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '$metadata_id'");
+ $this->assertIdentical($metadata->enabled, 'no');
+
// re-enable for deletion to work
$this->assertTrue($this->entity->enable());
+
+ // check enabled
+ // check annotations and metadata enabled.
+ $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'");
+ $this->assertIdentical($entity->enabled, 'yes');
+
+ $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '$annotation_id'");
+ $this->assertIdentical($annotation->enabled, 'yes');
+
+ $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '$metadata_id'");
+ $this->assertIdentical($metadata->enabled, 'yes');
+
$this->assertTrue($this->entity->delete());
}