diff options
Diffstat (limited to 'engine/classes/ElggAnnotation.php')
| -rw-r--r-- | engine/classes/ElggAnnotation.php | 103 |
1 files changed, 63 insertions, 40 deletions
diff --git a/engine/classes/ElggAnnotation.php b/engine/classes/ElggAnnotation.php index ec2cedfe5..175e7049d 100644 --- a/engine/classes/ElggAnnotation.php +++ b/engine/classes/ElggAnnotation.php @@ -8,74 +8,70 @@ * * @internal Annotations are stored in the annotations table. * - * @package Elgg.Core + * @package Elgg.Core * @subpackage DataModel.Annotations - * @link http://docs.elgg.org/DataModel/Annotations + * @link http://docs.elgg.org/DataModel/Annotations + * + * @property string $value_type + * @property string $enabled */ class ElggAnnotation extends ElggExtender { /** - * Construct a new annotation, optionally from a given id value or db object. + * (non-PHPdoc) + * + * @see ElggData::initializeAttributes() + * + * @return void + */ + protected function initializeAttributes() { + parent::initializeAttributes(); + + $this->attributes['type'] = 'annotation'; + } + + /** + * Construct a new annotation object * - * @param mixed $id + * @param mixed $id The annotation ID or a database row as stdClass object */ function __construct($id = null) { - $this->attributes = array(); + $this->initializeAttributes(); if (!empty($id)) { + // Create from db row if ($id instanceof stdClass) { $annotation = $id; - } else { - $annotation = get_annotation($id); - } - if ($annotation) { $objarray = (array) $annotation; - - foreach($objarray as $key => $value) { + foreach ($objarray as $key => $value) { $this->attributes[$key] = $value; } - - $this->attributes['type'] = "annotation"; + } else { + // get an ElggAnnotation object and copy its attributes + $annotation = elgg_get_annotation_from_id($id); + $this->attributes = $annotation->attributes; } } } /** - * Class member get overloading - * - * @param string $name - * @return mixed - */ - function __get($name) { - return $this->get($name); - } - - /** - * Class member set overloading - * - * @param string $name - * @param mixed $value - * @return void - */ - function __set($name, $value) { - return $this->set($name, $value); - } - - /** * Save this instance * * @return int an object id + * + * @throws IOException */ function save() { if ($this->id > 0) { - return update_annotation($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); + return update_annotation($this->id, $this->name, $this->value, $this->value_type, + $this->owner_guid, $this->access_id); } else { $this->id = create_annotation($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); if (!$this->id) { - throw new IOException(sprintf(elgg_echo('IOException:UnableToSaveNew'), get_class())); + throw new IOException(elgg_echo('IOException:UnableToSaveNew', array(get_class()))); } return $this->id; } @@ -83,9 +79,32 @@ class ElggAnnotation extends ElggExtender { /** * Delete the annotation. + * + * @return bool */ function delete() { - return delete_annotation($this->id); + elgg_delete_river(array('annotation_id' => $this->id)); + return elgg_delete_metastring_based_object_by_id($this->id, 'annotations'); + } + + /** + * Disable the annotation. + * + * @return bool + * @since 1.8 + */ + function disable() { + return elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'annotations'); + } + + /** + * Enable the annotation. + * + * @return bool + * @since 1.8 + */ + function enable() { + return elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'annotations'); } /** @@ -97,14 +116,18 @@ class ElggAnnotation extends ElggExtender { return get_annotation_url($this->id); } - // SYSTEM LOG INTERFACE //////////////////////////////////////////////////////////// + // SYSTEM LOG INTERFACE /** * For a given ID, return the object associated with it. * This is used by the river functionality primarily. * This is useful for checking access permissions etc on objects. + * + * @param int $id An annotation ID. + * + * @return ElggAnnotation */ public function getObjectFromID($id) { - return get_annotation($id); + return elgg_get_annotation_from_id($id); } -}
\ No newline at end of file +} |
