123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- class ElggAnnotation extends \ElggExtender {
-
- protected function initializeAttributes() {
- parent::initializeAttributes();
- $this->attributes['type'] = 'annotation';
- }
-
- public function __construct($row = null) {
- $this->initializeAttributes();
- if (!empty($row)) {
-
- if ($row instanceof \stdClass) {
- $annotation = $row;
- $objarray = (array) $annotation;
- foreach ($objarray as $key => $value) {
- $this->attributes[$key] = $value;
- }
- } else {
-
- elgg_deprecated_notice('Passing an ID to constructor is deprecated. Use elgg_get_annotation_from_id()', 1.9);
- $annotation = elgg_get_annotation_from_id($row);
- $this->attributes = $annotation->attributes;
- }
- }
- }
-
- public function save() {
- if ($this->id > 0) {
- 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("Unable to save new " . get_class());
- }
- return $this->id;
- }
- }
-
- public function delete() {
- $result = _elgg_delete_metastring_based_object_by_id($this->id, 'annotation');
- if ($result) {
- elgg_delete_river(array('annotation_id' => $this->id));
- }
- return $result;
- }
-
- public function disable() {
- return _elgg_set_metastring_based_object_enabled_by_id($this->id, 'no', 'annotations');
- }
-
- public function enable() {
- return _elgg_set_metastring_based_object_enabled_by_id($this->id, 'yes', 'annotations');
- }
-
- public function canEdit($user_guid = 0) {
- if ($user_guid) {
- $user = get_user($user_guid);
- if (!$user) {
- return false;
- }
- } else {
- $user = _elgg_services()->session->getLoggedInUser();
- $user_guid = _elgg_services()->session->getLoggedInUserGuid();
- }
- $result = false;
- if ($user) {
-
- if ($this->getOwnerGUID() == $user_guid) {
- $result = true;
- }
-
- $entity = $this->getEntity();
- if ($result == false && $entity->canEdit($user->getGUID())) {
- $result = true;
- }
- }
-
- $params = array('entity' => $entity, 'user' => $user, 'annotation' => $this);
- return _elgg_services()->hooks->trigger('permissions_check', 'annotation', $params, $result);
- }
-
-
- public function getObjectFromID($id) {
- return elgg_get_annotation_from_id($id);
- }
- }
|