-
Notifications
You must be signed in to change notification settings - Fork 16
/
XBRL-ESMA-ESEF.php
311 lines (273 loc) · 9.37 KB
/
XBRL-ESMA-ESEF.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
/**
* UK FRC taxonomy implementation
*
* @author Bill Seddon
* @version 0.9
* @Copyright (C) 2018 Lyquidity Solutions Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Load the XBRL implementation
*/
require_once('XBRL.php');
/**
* Define the namespaces of the entry points supported by this taxonomy
* @var array
*/
$entrypoint_namespaces = array(
"http://www.esma.europa.eu/taxonomy/2017-03-31/esef_all",
"http://www.esma.europa.eu/taxonomy/2017-03-31/esef_cor",
"http://www.esma.europa.eu/taxonomy/2017-03-31/technical"
);
/**
* Register namespace to class map entries
*
* This call defines the namespaces that apply to the use of the XBRL decendent class defined in this file.
* The static function XBRL::withtaxonomy() will use the information provided by this call to instantiate
* the correct (this) class.
*/
XBRL::add_namespace_to_class_map_entries( $entrypoint_namespaces, "XBRL_ESMA_ESEF" );
// XBRL::add_namespace_to_class_map_entries( array('http://xbrl.ifrs.org/taxonomy/2017-03-09/ifrs-full'), "XBRL_ESMA_ESEF" );
XBRL::add_entry_namespace_to_class_map_entries( $entrypoint_namespaces, "XBRL_ESMA_ESEF" );
/**
* Register XSD to compiled taxonomy entries
*/
XBRL::add_xsd_to_compiled_map_entries( array(
"esef_all.xsd",
), "esef_all" );
XBRL::add_xsd_to_compiled_map_entries( array(
"esef_cor.xsd",
), "esef_cor" );
/**
* Implements an XBRL descendent for the UK GAAP taxonomy.
* @author Bill Seddon
*/
class XBRL_ESMA_ESEF extends XBRL
{
// TODO: Create this list programatically. For example, all the entity officer member names, notes that has a string type, address lines, etc.
/**
* An array of element ids that when they appear in a report their values should be treated as text.
* This has a specific meaning in the default report: the associated values are not shown tied to a
* specific financial year.
* @var string[]
*/
private static $textItems = array();
/**
* Elements for which the value should be used as a label. Usually used with tuples.
* @var array[string]
*/
public static $labelItems = array();
/**
* Default contructor
*/
public function __construct()
{
parent::__construct();
}
/**
* Get a list of all the members
* @param array $dimensionalNode
* @return array An array of the member ids
*/
private function getValidMembers( $dimensionalNode )
{
$result = array();
if ( ! $dimensionalNode || $dimensionalNode['nodeclass'] !== 'dimensional' )
{
return $result;
}
if ( $dimensionalNode['taxonomy_element']['type'] === 'types:domainItemType' )
{
$result[ $dimensionalNode['taxonomy_element']['id'] ] = true;
}
if ( ! isset( $dimensionalNode['children'] ) )
{
return $result;
}
foreach ( $dimensionalNode['children'] as $nodeKey => $node )
{
$result += $this->getValidMembers( $node );
}
return $result;
}
/**
* Provides an opportunity for a descendant class implemenentation to take action when the main taxonomy is loaded
*/
public function afterMainTaxonomy()
{
// Do nothing - for now
}
/**
* This function is overridden to add the members to the parent node before it is deleted
*
* @param array $dimensionalNode A node which has element 'nodeclass' === 'dimensional'
* @param array $parentNode The parent node so it can be updated
* @return bool True if the dimensional information should be deleted
*/
protected function beforeDimensionalPruned( $dimensionalNode, &$parentNode )
{
return parent::beforeDimensionalPruned( $dimensionalNode, $parentNode );
// The dimensional information probably contains valid dimensional information
// That indicate which members of possible hypercubes are valid for the nodes
// of the parent.
$members = $this->getValidMembers( $dimensionalNode );
if ( count( $members ) )
{
$parentNode['members'] = $members;
}
return true;
}
/**
* This function provides an opportunity for a taxonomy to sanitize and/or translate a string
*
* @param string $text The text to be sanitized
* @param string $type An optional element type such as num:integer
* @param string $language An optional language locale
* @return string The sanitized string
*/
public function sanitizeText( $text, $type = null, $language = null )
{
$text = preg_replace( "/\[heading\]/", "", $text );
$text = preg_replace( "/\[Dimension\]/", "", $text );
$text = preg_replace( "/\[default\]/", "", $text );
$text = str_replace( utf8_encode( '£' ), "£", $text ); // This is necessary to make sure the whole of the unicode character is replaced.
return rtrim( $text );
}
/**
* Returns the value of $elemment formatted according to the type defined in the taxonomy
* @param array $element A representation of an element from an instance document
* @param XBRL_Instance $instance An instance of an instance class related to the $element
* @param bool $includeCurrency True if the returned monetary value should include a currency symbol
* @return mixed
*/
public function formattedValue( $element, $instance = null, $includeCurrency = true )
{
$value = $element['value'];
$type = XBRL_Instance::getElementType( $element );
switch ( $type )
{
case XBRL_Constants::$xbrliMonetaryItemType:
case 'xbrli:sharesItemType':
$element['value'] = str_replace( ',', '', $element['value'] );
return parent::formattedValue( $element, $instance, $includeCurrency );
case 'types:fixedItemType':
return parent::formattedValue( $element, $instance, $includeCurrency );
default:
return parent::formattedValue( $element, $instance, $includeCurrency );
}
}
/**
* Return the value of the element after removing any formatting.
* @param array $element
* @return float
* {@inheritDoc}
* @see XBRL::removeValueFormatting()
*/
public function removeNumberValueFormatting( $element )
{
return parent::removeNumberValueFormatting( $element );
}
/**
* Gets the alignment for the element based on the type
* @param string $namespace
* @param string $name
* @return string The alignment to use
*/
public function valueAlignmentForNamespace( $namespace, $name )
{
$prefix = "";
switch ( $namespace )
{
default:
return parent::valueAlignmentForNamespace( $namespace, $name );
}
$type = "$prefix:$name";
switch ( $type )
{
default:
return "left";
}
}
/**
* Get the default currency
*/
public function getDefaultCurrency()
{
return "GBP";
}
/**
* Return a default for the language code. Can be overridden.
*/
public function getDefaultLanguage()
{
return 'en';
}
/**
* Returns True if the $key is for a row that should be excluded.
* Overloads the implementation in XBRL
* @param string $key The key to lookup to determine whether the row should be excluded
* @param string $type The type of the item being tested (defaults to null)
* @return boolean
*/
public function excludeFromOutput( $key, $type = null )
{
if ( $key === 'http://www.xbrl.org/uk/cd/role/XBRL-Document-Information' ) return true;
return parent::excludeFromOutput( $key, $type );
}
/**
* Returns true if instance documents associated with the taxonomy normally provide opening balances.
* If they do not, then a user of the taxonomy knows to compute an opening balance from available information.
* Override in a descendent implementation.
* @return boolean
*/
public function openingBalancesSupplied()
{
return true;
}
/**
* Returns true if the element value with the $key is defined as one to display as text
* Can be overridden in a descendent.
* @param string $key The key to lookup to determine whether the row should be treated as text
* @param string $type The type of the element
* @return boolean Defaults to false
*/
public function treatAsText( $key, $type )
{
if ( in_array( $key, self::$textItems ) ) return true;
return parent::treatAsText( $key, $type );
}
/**
* Returns true if the element value with the $key is defined as one that should be used as a label - usually in tuple
* Can be overridden in a descendent.
* @param string $key The key to lookup to determine whether the row should be treated as a label
* @return boolean Defaults to false
*/
public function treatAsLabel( $key )
{
if ( isset( XBRL_IFRS::$labelItems[ $key ] ) ) return XBRL_IFRS::$labelItems[ $key ];
return parent::treatAsLabel( $key );
}
/**
* Whether all roles should be used when collecting primary items,
* @return bool True if all roles are to be used as the basis for collecting primary items
*/
public function useAllRoles()
{
return true;
}
}
?>