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 | protected function initializeAttributes() { |
||
15 | parent::initializeAttributes(); |
||
16 | |||
17 | $this->attributes['type'] = 'annotation'; |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * Constructor |
||
22 | * |
||
23 | * @param stdClass $row Database row |
||
24 | */ |
||
25 | public function __construct(stdClass $row = null) { |
||
26 | $this->initializeAttributes(); |
||
27 | |||
28 | if ($row) { |
||
29 | foreach ((array) $row as $key => $value) { |
||
30 | $this->$key = $value; |
||
31 | } |
||
32 | } |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Save this instance and returns an annotation ID |
||
37 | * |
||
38 | * @return int|bool |
||
39 | */ |
||
40 | public function save() { |
||
41 | if (!isset($this->access_id)) { |
||
42 | $this->access_id = ACCESS_PRIVATE; |
||
43 | } |
||
44 | |||
45 | if (!isset($this->owner_guid)) { |
||
46 | $this->owner_guid = _elgg_services()->session->getLoggedInUserGuid(); |
||
47 | } |
||
48 | |||
49 | if ($this->id) { |
||
50 | return _elgg_services()->annotationsTable->update($this); |
||
51 | } |
||
52 | |||
53 | $entity = get_entity($this->entity_guid); |
||
54 | if (!$entity) { |
||
55 | return false; |
||
56 | } |
||
57 | |||
58 | if (_elgg_services()->annotationsTable->create($this, $entity)) { |
||
59 | return $this->id; |
||
0 ignored issues
–
show
|
|||
60 | } |
||
61 | |||
62 | return false; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Delete the annotation. |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function delete() { |
||
71 | return _elgg_services()->annotationsTable->delete($this); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Disable the annotation. |
||
76 | * |
||
77 | * @return bool |
||
78 | * @since 1.8 |
||
79 | */ |
||
80 | public function disable() { |
||
81 | return _elgg_services()->annotationsTable->disable($this); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Enable the annotation. |
||
86 | * |
||
87 | * @return bool |
||
88 | * @since 1.8 |
||
89 | */ |
||
90 | public function enable() { |
||
91 | 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 | */ |
||
101 | public function canEdit($user_guid = 0) { |
||
102 | $entity = $this->getEntity(); |
||
103 | |||
104 | return _elgg_services()->userCapabilities->canEditAnnotation($entity, $user_guid, $this); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | public function getObjectFromID($id) { |
||
111 | return elgg_get_annotation_from_id($id); |
||
112 | } |
||
113 | } |
||
114 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: