1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Entity Annotation |
||
5 | * |
||
6 | * Annotations allow you to attach bits of information to entities. |
||
7 | * Unlike entity metadata, annotation is access controlled and has owners. |
||
8 | */ |
||
9 | class ElggAnnotation extends \ElggExtender { |
||
10 | |||
11 | /** |
||
12 | * {@inheritdoc} |
||
13 | */ |
||
14 | 124 | protected function initializeAttributes() { |
|
15 | 124 | parent::initializeAttributes(); |
|
16 | |||
17 | 124 | $this->attributes['type'] = 'annotation'; |
|
18 | 124 | } |
|
19 | |||
20 | /** |
||
21 | * Constructor |
||
22 | * |
||
23 | * @param stdClass $row Database row |
||
24 | */ |
||
25 | 124 | public function __construct(stdClass $row = null) { |
|
26 | 124 | $this->initializeAttributes(); |
|
27 | |||
28 | 124 | if ($row) { |
|
29 | 51 | foreach ((array) $row as $key => $value) { |
|
30 | 51 | $this->$key = $value; |
|
31 | } |
||
32 | } |
||
33 | 124 | } |
|
34 | |||
35 | /** |
||
36 | * Save this instance and returns an annotation ID |
||
37 | * |
||
38 | * @return int|false |
||
39 | */ |
||
40 | 118 | public function save() { |
|
41 | 118 | if (!isset($this->access_id)) { |
|
42 | $this->access_id = ACCESS_PRIVATE; |
||
43 | } |
||
44 | |||
45 | 118 | if (!isset($this->owner_guid)) { |
|
46 | $this->owner_guid = elgg_get_logged_in_user_guid(); |
||
47 | } |
||
48 | |||
49 | 118 | if ($this->id) { |
|
50 | return _elgg_services()->annotationsTable->update($this); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
51 | } |
||
52 | |||
53 | 118 | $entity = get_entity($this->entity_guid); |
|
54 | 118 | if (!$entity) { |
|
55 | return false; |
||
56 | } |
||
57 | |||
58 | 118 | if (_elgg_services()->annotationsTable->create($this, $entity)) { |
|
59 | 118 | return $this->id; |
|
60 | } |
||
61 | |||
62 | return false; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Delete the annotation. |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | 30 | public function delete() { |
|
71 | 30 | return _elgg_services()->annotationsTable->delete($this); |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Disable the annotation. |
||
76 | * |
||
77 | * @return bool |
||
78 | * @since 1.8 |
||
79 | */ |
||
80 | 9 | public function disable() { |
|
81 | 9 | return _elgg_services()->annotationsTable->disable($this); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * Enable the annotation. |
||
86 | * |
||
87 | * @return bool |
||
88 | * @since 1.8 |
||
89 | */ |
||
90 | 4 | public function enable() { |
|
91 | 4 | return _elgg_services()->annotationsTable->enable($this); |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Determines whether or not the user can edit this annotation |
||
96 | * |
||
97 | * @param int $user_guid The GUID of the user (defaults to currently logged in user) |
||
98 | * |
||
99 | * @return bool |
||
100 | * @see elgg_set_ignore_access() |
||
101 | */ |
||
102 | 35 | public function canEdit($user_guid = 0) { |
|
103 | 35 | $entity = $this->getEntity(); |
|
104 | |||
105 | 35 | return _elgg_services()->userCapabilities->canEditAnnotation($entity, $user_guid, $this); |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function getObjectFromID($id) { |
||
112 | return elgg_get_annotation_from_id($id); |
||
113 | } |
||
114 | } |
||
115 |