1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Elgg metadata |
4
|
|
|
* Functions to manage entity metadata. |
5
|
|
|
* |
6
|
|
|
* @package Elgg.Core |
7
|
|
|
* @subpackage DataModel.Metadata |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Get a specific metadata object by its id. |
12
|
|
|
* If you want multiple metadata objects, use |
13
|
|
|
* {@link elgg_get_metadata()}. |
14
|
|
|
* |
15
|
|
|
* @param int $id The id of the metadata object being retrieved. |
16
|
|
|
* |
17
|
|
|
* @return \ElggMetadata|false false if not found |
18
|
|
|
*/ |
19
|
|
|
function elgg_get_metadata_from_id($id) { |
20
|
9 |
|
return _elgg_services()->metadataTable->get($id); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Deletes metadata using its ID. |
25
|
|
|
* |
26
|
|
|
* @param int $id The metadata ID to delete. |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
|
|
function elgg_delete_metadata_by_id($id) { |
30
|
|
|
$metadata = elgg_get_metadata_from_id($id); |
31
|
|
|
if (!$metadata) { |
32
|
|
|
return; |
33
|
|
|
} |
34
|
|
|
return $metadata->delete(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Fetch metadata or perform a calculation on them |
39
|
|
|
* |
40
|
|
|
* Accepts all options supported by {@link elgg_get_entities()} |
41
|
|
|
* |
42
|
|
|
* @see elgg_get_entities() |
43
|
|
|
* |
44
|
|
|
* @param array $options Options |
45
|
|
|
* |
46
|
|
|
* @return \ElggMetadata[]|mixed |
47
|
|
|
* @since 1.8.0 |
48
|
|
|
*/ |
49
|
|
|
function elgg_get_metadata(array $options = []) { |
50
|
4083 |
|
return _elgg_services()->metadataTable->getAll($options); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Deletes metadata based on $options. |
55
|
|
|
* |
56
|
|
|
* @warning Unlike elgg_get_metadata() this will not accept an empty options array! |
57
|
|
|
* This requires at least one constraint: |
58
|
|
|
* metadata_name(s), metadata_value(s), or guid(s) must be set. |
59
|
|
|
* |
60
|
|
|
* @param array $options An options array. {@link elgg_get_metadata()} |
61
|
|
|
* @return bool|null true on success, false on failure, null if no metadata to delete. |
62
|
|
|
* @since 1.8.0 |
63
|
|
|
*/ |
64
|
|
|
function elgg_delete_metadata(array $options) { |
65
|
271 |
|
return _elgg_services()->metadataTable->deleteAll($options); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* \ElggEntities interfaces |
70
|
|
|
*/ |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Takes a metadata array (which has all kinds of properties) |
74
|
|
|
* and turns it into a simple array of strings |
75
|
|
|
* |
76
|
|
|
* @param array $array Metadata array |
77
|
|
|
* |
78
|
|
|
* @return array Array of strings |
79
|
|
|
*/ |
80
|
|
|
function metadata_array_to_values($array) { |
81
|
|
|
$valuearray = []; |
82
|
|
|
|
83
|
|
|
if (is_array($array)) { |
84
|
|
|
foreach ($array as $element) { |
85
|
|
|
$valuearray[] = $element->value; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $valuearray; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Invalidate the metadata cache based on options passed to various *_metadata functions |
94
|
|
|
* |
95
|
|
|
* @param string $action Action performed on metadata. "delete", "disable", or "enable" |
96
|
|
|
* @param array $options Options passed to elgg_(delete|disable|enable)_metadata |
97
|
|
|
* @return void |
98
|
|
|
* @access private |
99
|
|
|
* @todo not used |
100
|
|
|
*/ |
101
|
|
|
function _elgg_invalidate_metadata_cache($action, array $options) { |
|
|
|
|
102
|
|
|
_elgg_services()->metadataCache->invalidateByOptions($options); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Metadata unit test |
107
|
|
|
* |
108
|
|
|
* @param string $hook unit_test |
109
|
|
|
* @param string $type system |
110
|
|
|
* @param mixed $value Array of other tests |
111
|
|
|
* @param mixed $params Params |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
* @access private |
115
|
|
|
* @codeCoverageIgnore |
116
|
|
|
*/ |
117
|
|
|
function _elgg_metadata_test($hook, $type, $value, $params) { |
|
|
|
|
118
|
|
|
$value[] = ElggCoreMetadataAPITest::class; |
119
|
|
|
return $value; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
124
|
|
|
*/ |
125
|
|
|
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
126
|
18 |
|
$hooks->registerHandler('unit_test', 'system', '_elgg_metadata_test'); |
127
|
|
|
}; |
128
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.