diff options
Diffstat (limited to 'engine/classes/ElggMetadata.php')
| -rw-r--r-- | engine/classes/ElggMetadata.php | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/engine/classes/ElggMetadata.php b/engine/classes/ElggMetadata.php index f85bac6ce..3a8e2d817 100644 --- a/engine/classes/ElggMetadata.php +++ b/engine/classes/ElggMetadata.php @@ -6,9 +6,20 @@ * * @package Elgg.Core * @subpackage Metadata + * + * @property string $value_type + * @property int $owner_guid + * @property string $enabled */ class ElggMetadata extends ElggExtender { + /** + * (non-PHPdoc) + * + * @see ElggData::initializeAttributes() + * + * @return void + */ protected function initializeAttributes() { parent::initializeAttributes(); @@ -16,11 +27,9 @@ class ElggMetadata extends ElggExtender { } /** - * Construct a new site object, optionally from a given id value or row. - * - * @param mixed $id ID of metadata from DB + * Construct a metadata object * - * @return void + * @param mixed $id ID of metadata or a database row as stdClass object */ function __construct($id = null) { $this->initializeAttributes(); @@ -29,15 +38,15 @@ class ElggMetadata extends ElggExtender { // Create from db row if ($id instanceof stdClass) { $metadata = $id; - } else { - $metadata = elgg_get_metadata_from_id($id); - } - - if ($metadata) { + $objarray = (array) $metadata; foreach ($objarray as $key => $value) { $this->attributes[$key] = $value; } + } else { + // get an ElggMetadata object and copy its attributes + $metadata = elgg_get_metadata_from_id($id); + $this->attributes = $metadata->attributes; } } } @@ -45,19 +54,23 @@ class ElggMetadata extends ElggExtender { /** * Determines whether or not the user can edit this piece of metadata * - * @return true|false Depending on permissions + * @param int $user_guid The GUID of the user (defaults to currently logged in user) + * + * @return bool Depending on permissions */ - function canEdit() { + function canEdit($user_guid = 0) { if ($entity = get_entity($this->get('entity_guid'))) { - return $entity->canEditMetadata($this); + return $entity->canEditMetadata($this, $user_guid); } return false; } /** - * Save matadata object + * Save metadata object * - * @return int the metadata object id + * @return int|bool the metadata object id or true if updated + * + * @throws IOException */ function save() { if ($this->id > 0) { @@ -80,7 +93,13 @@ class ElggMetadata extends ElggExtender { * @return bool */ function delete() { - return elgg_delete_metastring_based_object_by_id($this->id, 'metadata'); + $success = elgg_delete_metastring_based_object_by_id($this->id, 'metadata'); + if ($success) { + // we mark unknown here because this deletes only one value + // under this name, and there may be others remaining. + elgg_get_metadata_cache()->markUnknown($this->entity_guid, $this->name); + } + return $success; } /** @@ -90,17 +109,27 @@ class ElggMetadata extends ElggExtender { * @since 1.8 */ function disable() { - return elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'metadata'); + $success = elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'metadata'); + if ($success) { + // we mark unknown here because this disables only one value + // under this name, and there may be others remaining. + elgg_get_metadata_cache()->markUnknown($this->entity_guid, $this->name); + } + return $success; } /** - * Disable the metadata + * Enable the metadata * * @return bool * @since 1.8 */ function enable() { - return elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'metadata'); + $success = elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'metadata'); + if ($success) { + elgg_get_metadata_cache()->markUnknown($this->entity_guid, $this->name); + } + return $success; } /** |
