00001 <?php
00018 class ElggAnnotation extends ElggExtender {
00019
00027 protected function initializeAttributes() {
00028 parent::initializeAttributes();
00029
00030 $this->attributes['type'] = 'annotation';
00031 }
00032
00038 function __construct($id = null) {
00039 $this->initializeAttributes();
00040
00041 if (!empty($id)) {
00042
00043 if ($id instanceof stdClass) {
00044 $annotation = $id;
00045
00046 $objarray = (array) $annotation;
00047 foreach ($objarray as $key => $value) {
00048 $this->attributes[$key] = $value;
00049 }
00050 } else {
00051
00052 $annotation = elgg_get_annotation_from_id($id);
00053 $this->attributes = $annotation->attributes;
00054 }
00055 }
00056 }
00057
00065 function save() {
00066 if ($this->id > 0) {
00067 return update_annotation($this->id, $this->name, $this->value, $this->value_type,
00068 $this->owner_guid, $this->access_id);
00069 } else {
00070 $this->id = create_annotation($this->entity_guid, $this->name, $this->value,
00071 $this->value_type, $this->owner_guid, $this->access_id);
00072
00073 if (!$this->id) {
00074 throw new IOException(elgg_echo('IOException:UnableToSaveNew', array(get_class())));
00075 }
00076 return $this->id;
00077 }
00078 }
00079
00085 function delete() {
00086 elgg_delete_river(array('annotation_id' => $this->id));
00087 return elgg_delete_metastring_based_object_by_id($this->id, 'annotations');
00088 }
00089
00096 function disable() {
00097 return elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'annotations');
00098 }
00099
00106 function enable() {
00107 return elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'annotations');
00108 }
00109
00115 public function getURL() {
00116 return get_annotation_url($this->id);
00117 }
00118
00119
00120
00130 public function getObjectFromID($id) {
00131 return elgg_get_annotation_from_id($id);
00132 }
00133 }