Elgg  Version 2.3
ElggAnnotation.php
Go to the documentation of this file.
1 <?php
2 
4 
18 
26  protected function initializeAttributes() {
27  parent::initializeAttributes();
28 
29  $this->attributes['type'] = 'annotation';
30  }
31 
40  public function __construct($row = null) {
41  $this->initializeAttributes();
42 
43  if (!empty($row)) {
44  // Create from db row
45  if ($row instanceof \stdClass) {
46  $annotation = $row;
47 
48  $objarray = (array) $annotation;
49  foreach ($objarray as $key => $value) {
50  $this->attributes[$key] = $value;
51  }
52  } else {
53  // get an \ElggAnnotation object and copy its attributes
54  elgg_deprecated_notice('Passing an ID to constructor is deprecated. Use elgg_get_annotation_from_id()', 1.9);
56  $this->attributes = $annotation->attributes;
57  }
58  }
59  }
60 
68  public function save() {
69  if ($this->id > 0) {
70  return update_annotation($this->id, $this->name, $this->value, $this->value_type,
71  $this->owner_guid, $this->access_id);
72  } else {
73  $this->id = create_annotation($this->entity_guid, $this->name, $this->value,
74  $this->value_type, $this->owner_guid, $this->access_id);
75 
76  if (!$this->id) {
77  throw new \IOException("Unable to save new " . get_class());
78  }
79  return $this->id;
80  }
81  }
82 
88  public function delete() {
89  $result = _elgg_delete_metastring_based_object_by_id($this->id, 'annotation');
90  if ($result) {
91  _elgg_delete_river(array('annotation_id' => $this->id));
92  }
93 
94  return $result;
95  }
96 
103  public function disable() {
104  return _elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'annotations');
105  }
106 
113  public function enable() {
114  return _elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'annotations');
115  }
116 
125  public function canEdit($user_guid = 0) {
126  $entity = $this->getEntity();
127  return _elgg_services()->userCapabilities->canEditAnnotation($entity, $user_guid, $this);
128  }
129 
130  // SYSTEM LOG INTERFACE
131 
141  public function getObjectFromID($id) {
143  }
144 }
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.
_elgg_delete_river(array $options=[])
Alias of elgg_delete_river() that doesn&#39;t raise notices.
$value
Definition: longtext.php:42
update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
Update an annotation.
Definition: annotations.php:80
initializeAttributes()
(non-PHPdoc)
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
$key
Definition: summary.php:34
_elgg_delete_metastring_based_object_by_id($id, $type)
Deletes a metastring-based object by its id.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
$comment access_id
Definition: save.php:60
$site name
$entity
Definition: delete.php:7
__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
_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.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:5
$comment owner_guid
Definition: save.php:58