1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ElggMetadata |
5
|
|
|
* |
6
|
|
|
* This class describes metadata that can be attached to an \ElggEntity. |
7
|
|
|
* It is rare that a plugin developer needs to use this API for metadata. |
8
|
|
|
* Almost all interaction with metadata occurs through the methods of \ElggEntity. |
9
|
|
|
* See its __set(), __get(), and setMetadata() methods. |
10
|
|
|
*/ |
11
|
|
|
class ElggMetadata extends ElggExtender { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
1031 |
|
protected function initializeAttributes() { |
17
|
1031 |
|
parent::initializeAttributes(); |
18
|
|
|
|
19
|
1031 |
|
$this->attributes['type'] = "metadata"; |
20
|
1031 |
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor |
24
|
|
|
* |
25
|
|
|
* @param stdClass $row Database row |
26
|
|
|
*/ |
27
|
1031 |
|
public function __construct(stdClass $row = null) { |
28
|
1031 |
|
$this->initializeAttributes(); |
29
|
|
|
|
30
|
1031 |
|
if ($row) { |
31
|
209 |
|
foreach ((array) $row as $key => $value) { |
32
|
209 |
|
$this->$key = $value; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
1031 |
|
$this->access_id = ACCESS_PUBLIC; |
37
|
1031 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Determines whether or not the user can edit this piece of metadata |
41
|
|
|
* |
42
|
|
|
* @param int $user_guid The GUID of the user (defaults to currently logged in user) |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
* @see elgg_set_ignore_access() |
46
|
|
|
*/ |
47
|
333 |
|
public function canEdit($user_guid = 0) { |
48
|
333 |
|
if ($entity = get_entity($this->entity_guid)) { |
49
|
333 |
|
return $entity->canEditMetadata($this, $user_guid); |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Save metadata object |
57
|
|
|
* |
58
|
|
|
* Returns metadata on success, false on failure |
59
|
|
|
* |
60
|
|
|
* @return int|false |
61
|
|
|
*/ |
62
|
17 |
|
public function save() { |
63
|
17 |
|
if (!$this->id) { |
64
|
17 |
|
return _elgg_services()->metadataTable->create($this); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return _elgg_services()->metadataTable->update($this); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Delete the metadata |
72
|
|
|
* |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
199 |
|
public function delete() { |
76
|
199 |
|
return _elgg_services()->metadataTable->delete($this); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function getObjectFromID($id) { |
83
|
|
|
return elgg_get_metadata_from_id($id); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|