Elgg  Version 1.11
ElggAnnotation.php
Go to the documentation of this file.
1 <?php
15 
23  protected function initializeAttributes() {
24  parent::initializeAttributes();
25 
26  $this->attributes['type'] = 'annotation';
27  }
28 
37  public function __construct($row = null) {
38  $this->initializeAttributes();
39 
40  if (!empty($row)) {
41  // Create from db row
42  if ($row instanceof \stdClass) {
43  $annotation = $row;
44 
45  $objarray = (array) $annotation;
46  foreach ($objarray as $key => $value) {
47  $this->attributes[$key] = $value;
48  }
49  } else {
50  // get an \ElggAnnotation object and copy its attributes
51  elgg_deprecated_notice('Passing an ID to constructor is deprecated. Use elgg_get_annotation_from_id()', 1.9);
53  $this->attributes = $annotation->attributes;
54  }
55  }
56  }
57 
65  public function save() {
66  if ($this->id > 0) {
67  return update_annotation($this->id, $this->name, $this->value, $this->value_type,
68  $this->owner_guid, $this->access_id);
69  } else {
70  $this->id = create_annotation($this->entity_guid, $this->name, $this->value,
71  $this->value_type, $this->owner_guid, $this->access_id);
72 
73  if (!$this->id) {
74  throw new \IOException("Unable to save new " . get_class());
75  }
76  return $this->id;
77  }
78  }
79 
85  public function delete() {
86  $result = _elgg_delete_metastring_based_object_by_id($this->id, 'annotation');
87  if ($result) {
88  elgg_delete_river(array('annotation_id' => $this->id));
89  }
90 
91  return $result;
92  }
93 
100  public function disable() {
101  return _elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'annotations');
102  }
103 
110  public function enable() {
111  return _elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'annotations');
112  }
113 
122  public function canEdit($user_guid = 0) {
123 
124  if ($user_guid) {
126  if (!$user) {
127  return false;
128  }
129  } else {
130  $user = _elgg_services()->session->getLoggedInUser();
131  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
132  }
133 
134  $result = false;
135  if ($user) {
136  // If the owner of annotation is the specified user, they can edit.
137  if ($this->getOwnerGUID() == $user_guid) {
138  $result = true;
139  }
140 
141  // If the user can edit the entity this is attached to, they can edit.
142  $entity = $this->getEntity();
143  if ($result == false && $entity->canEdit($user->getGUID())) {
144  $result = true;
145  }
146  }
147 
148  // Trigger plugin hook - note that $user may be null
149  $params = array('entity' => $entity, 'user' => $user, 'annotation' => $this);
150  return _elgg_services()->hooks->trigger('permissions_check', 'annotation', $params, $result);
151  }
152 
153  // SYSTEM LOG INTERFACE
154 
164  public function getObjectFromID($id) {
166  }
167 }
disable()
Disable the annotation.
save()
Save this instance.
$annotation
Elgg default annotation view.
Definition: default.php:10
create_annotation($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE)
Create a new annotation.
Definition: annotations.php:62
getEntity()
Get the entity this describes.
$value
Definition: longtext.php:26
update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
Update an annotation.
Definition: annotations.php:80
initializeAttributes()
(non-PHPdoc)
$params
Definition: login.php:72
canEdit($user_guid=0)
Determines whether or not the user can edit this annotation.
elgg_get_annotation_from_id($id)
Get a specific annotation by its id.
Definition: annotations.php:36
$filehandler owner_guid
Definition: crop.php:21
get_user($guid)
Get a user object from a GUID.
Definition: users.php:87
$key
Definition: summary.php:34
_elgg_delete_metastring_based_object_by_id($id, $type)
Deletes a metastring-based object by its id.
_elgg_services()
Definition: autoloader.php:14
$user
Definition: ban.php:13
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1006
getOwnerGUID()
Get the GUID of the extender&#39;s owner entity.
$comment access_id
Definition: save.php:61
$site name
elgg_delete_river(array $options=array())
Delete river items.
Definition: river.php:162
__construct($row=null)
Construct a new annotation object.
getObjectFromID($id)
For a given ID, return the object associated with it.
$row
$user_guid
Avatar remove action.
Definition: remove.php:6
$entity
Definition: delete.php:10
_elgg_set_metastring_based_object_enabled_by_id($id, $enabled, $type)
Enables or disables a metastrings-based object by its id.
if(!$collection_name) $id
Definition: add.php:17
enable()
Enable the annotation.