-
Notifications
You must be signed in to change notification settings - Fork 16
/
XBRL-DFR.php
5570 lines (4810 loc) · 212 KB
/
XBRL-DFR.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Digital Financial Reporting taxonomy implementation
*
* @author Bill Seddon
* @version 0.9
* @Copyright (C) 2019 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');
use XBRL\Formulas\Resources\Filters\ConceptName;
use XBRL\Formulas\Resources\Formulas\Formula;
use lyquidity\xml\QName;
use XBRL\Formulas\Resources\Assertions\ExistenceAssertion;
use XBRL\Formulas\Resources\Assertions\ValueAssertion;
use XBRL\Formulas\Resources\Assertions\VariableSetAssertion;
use XBRL\Formulas\Resources\Assertions\ConsistencyAssertion;
use XBRL\Formulas\Resources\Variables\Parameter;
define( 'NEGATIVE_AS_BRACKETS', 'brackets' );
define( 'NEGATIVE_AS_MINUS', 'minus' );
class XBRL_DFR
{
/**
* This is set in getConceptualModelRoles
* @var string
*/
public static $originallyStatedLabel = "";
/**
* An array of conceptual model arcroles and relationships
* @var array|null
*/
private static $conceptualModelRoles;
private static $defaultConceptualModelRoles;
/**
* Returns the current set of conceptual model roles. If not defined, creates a default set from?:
* http://xbrlsite.azurewebsites.net/2016/conceptual-model/reporting-scheme/ipsas/model-structure/ModelStructure-rules-ipsas-def.xml
* @param string $cacheLocation (optional)
* @return array
*/
public static function getConceptualModelRoles( $cacheLocation = null )
{
if ( is_null( self::$conceptualModelRoles ) )
{
$context = XBRL_Global::getInstance();
if ( ! $context->useCache && $cacheLocation )
{
$context->cacheLocation = $cacheLocation;
$context->useCache = true;
$context->initializeCache();
}
$taxonomy = XBRL::withTaxonomy("http://xbrlsite.azurewebsites.net/2016/conceptual-model/cm-roles.xsd", "conceptual-model-roles", true);
$taxonomy->context = $context;
$taxonomy->addLinkbaseRef( "http://xbrlsite.azurewebsites.net/2016/conceptual-model/reporting-scheme/ipsas/model-structure/ModelStructure-rules-ipsas-def.xml", "conceptual-model");
$roleTypes = $taxonomy->getRoleTypes();
// $cm = $taxonomy->getTaxonomyForXSD("cm.xsd");
// $nonDimensionalRoleRef = $cm->getNonDimensionalRoleRefs( XBRL_Constants::$defaultLinkRole );
// $cmArcRoles = $nonDimensionalRoleRef[ XBRL_Constants::$defaultLinkRole ];
$originallyStated = array_filter( $roleTypes['link:label'], function( $role ) { return $role['id']; } );
self::$originallyStatedLabel = reset( $originallyStated )['roleURI'];
self::setConceptualModelRoles( $taxonomy );
self::$defaultConceptualModelRoles = self::$conceptualModelRoles;
unset( $taxonomy );
XBRL::reset();
// self::$conceptualModelRoles = $cmArcRoles;
}
return self::$conceptualModelRoles;
}
/**
* Sets some model roles if there are any in the taxonomy or sets the default model roles
* @param XBRL $taxonomy A taxonomy to use or null
*/
public static function setConceptualModelRoles( $taxonomy = null )
{
$cmTaxonomy = $taxonomy ? $taxonomy->getTaxonomyForXSD("cm.xsd") : null;
if ( $cmTaxonomy )
{
$nonDimensionalRoleRef = $cmTaxonomy->getNonDimensionalRoleRefs( XBRL_Constants::$defaultLinkRole );
if ( isset( $nonDimensionalRoleRef[ XBRL_Constants::$defaultLinkRole ] ) )
{
$cmArcRoles = $nonDimensionalRoleRef[ XBRL_Constants::$defaultLinkRole ];
self::$conceptualModelRoles = $cmArcRoles;
return;
}
}
// Fallback
self::$conceptualModelRoles = self::$defaultConceptualModelRoles;
}
/**
* Include a rendering of the components grid
* @var string
*/
public $includeComponent = true;
/**
* Include a rendering of the structure grid
* @var string
*/
public $includeStructure = true;
/**
* Include a rendering of the slicers grid
* @var string
*/
public $includeSlicers = true;
/**
* Include a rendering of the report grid
* @var string
*/
public $includeReport = true;
/**
* Include a rendering of the facts table grid
* @var string
*/
public $includeFactsTable = true;
/**
* Include the checkbox controls
* @var string
*/
public $includeCheckboxControls = true;
/**
* Include wider/narrower controls with the table grid
* @var string
*/
public $includeWidthcontrols = true;
/**
* Include a rendering of the business rules grid
* @var string
*/
public $includeBusinessRules = true;
/**
* When true all grids will be shown (visible). When false only the rendered table will be visible by default.
* @var string
*/
public $showAllGrids = false;
/**
* Holds a list of features
* @var array
*/
private $features = array();
/**
* How to style negative numbers
* @var string NEGATIVE_AS_BRACKETS | NEGATIVE_AS_MINUS
*/
private $negativeStyle = NEGATIVE_AS_BRACKETS;
/**
* When true, any columns that contain no values or only closing balance values will be removed
* @var string
*/
private $stripEmptyColumns = false;
/**
* A fixed list of dimensions to exclude when determining if there should be a grid layout
* @var array
*/
private $axesToExclude = array();
/**
* A list of aliases for the DFR ReportDateAxis
* @var array
*/
private $reportDateAxisAliases = array();
// Private variables for the function validateDFR
/**
* A list of primary items within each ELR in the presentation linkbase being evaluated
* @var [][] $presentationPIs
*/
private $presentationPIs = array();
/**
* A list of primary items within each ELR in the calculation linkbase being evaluated
* @var [][] $calculationPIs
*/
private $calculationPIs = array();
/**
* A list of primary items within each ELR in the definition linkbase being evaluated
* @var [][] $definitionPIs
*/
private $definitionPIs = array();
/**
* A list of the calculation networks or roles defined in the taxonomy.
* By default the full structure is not realized so this variable holds
* the realized network so they do not have to be realized repeatedly.
* @var array
*/
private $calculationNetworks = array();
/**
* A list of the definition networks or roles defined in the taxonomy.
* By default the full structure is not realized so this variable holds
* the realized network so they do not have to be realized repeatedly.
* @var array $definitionNetworks
*/
private $definitionNetworks = array();
/**
* A list of the presentation networks or roles defined in the taxonomy.
* By default the full structure is not realized so this variable holds
* the realized network so they do not have to be realized repeatedly.
* @var array $presentationNetworks
*/
private $presentationNetworks = array();
/**
* A list of translations of the reporting constants like 'axis' and 'period'
* @var array $constantLabels
*/
private static $constantTextTranslations = array(
'da' => array(
'Axis' => 'Akse',
'Component' => 'Komponent',
'Component: Network plus Table' => 'Komponent: Netværk plus tabel',
'Network' => 'Netærk',
'Network plus Table' => 'Netværk plus tabel',
'Period' => 'Periode',
'Period [Axis]' => 'Periode [Akse]',
'Reporting Entity' => 'Rapporteringsenhed',
'Reporting Entity [Axis]' => 'Rapporteringsenhed [Akse]',
'Table' => 'Tabel',
'Context' => 'Kontekst',
'Concept' => 'koncept',
'Value' => 'Værdi',
'Unit' => 'Enhed',
'Rounding' => 'Afrunding',
'Fact table for' => 'Fakta tabel for',
'Label' => 'Etiket',
'Fact set type' => 'Fact set type',
'Report Element Class' => 'Rapport Element Klasse',
'Period Type' => 'Periodetype',
'Balance' => 'Balance',
'Name' => 'Navn',
'Report sections' => 'Rapport sektioner',
'Structure' => 'Struktur',
'Slicers' => 'Slicers',
'Report' => 'Rapport',
'Facts' => 'Fakta',
'Rules' => 'Regler',
'There are no business rules' => 'Der er ingen forretningsregler',
'Business rules' => 'Forretningsregel',
'Line item' => 'Regnskabskoncept',
'Calculated' => 'Beregnet',
'Decimals' => 'Decimaler',
'There is no data to report' => 'Der er ingen data at rapportere',
'Columns' => 'Kolonner',
'Wider' => 'Bredere',
'Narrower' => 'Smallere',
'Order' => 'Order',
'Parent concept' => 'Parent concept'
),
'de' => array(
'Axis' => 'Achse',
'Component' => 'Komponente',
'Component: Network plus Table' => 'Komponente: Netzwerk plus tabelle',
'Network' => 'Netzwerk',
'Network plus Table' => 'Netzwerk plus tabelle',
'Period' => 'Zeitspanne',
'Period [Axis]' => 'Zeitspanne [Achse]',
'Reporting Entity' => 'Berichtseinheit',
'Reporting Entity [Axis]' => 'Berichtseinheit [Achse]',
'Table' => 'Tabelle',
'Context' => 'Zusammenhang',
'Concept' => 'Konzept',
'Value' => 'Wert',
'Unit' => 'Einheit',
'Rounding' => 'Runden',
'Fact table for' => 'Faktentabelle für',
'Label' => 'Etikette',
'Fact set type' => 'Typ des Faktensatzes',
'Report Element Class' => 'Berichtselementklasse',
'Period Type' => 'Periodentyp',
'Balance' => 'Balance',
'Name' => 'Name',
'Report sections' => 'Berichtsabschnitte',
'Structure' => 'Struktur',
'Slicers' => 'Slicers',
'Report' => 'Bericht',
'Facts' => 'Fakten',
'Rules' => 'Regeln',
'There are no business rules' => 'Es gibt keine Geschäftsregeln',
'Business rules' => 'Geschäftsregel',
'Line item' => 'Buchhaltungbegriff',
'Calculated' => 'Berechnet',
'Decimals' => 'Dezimalstellen',
'There is no data to report' => 'Es sind keine Daten zu melden',
'Columns' => 'Säulen',
'Wider' => 'Breiter',
'Narrower' => 'Schmaler',
'Order' => 'Order',
'Parent concept' => 'Parent concept'
),
'es' => array(
'Axis' => 'Eje',
'Component' => 'Componente',
'Component: Network plus Table' => 'Componente: Red más tabla',
'Network' => 'Red',
'Network plus Table' => 'Red más tabla',
'Period' => 'Período',
'Period [Axis]' => 'Período [Eje]',
'Reporting Entity' => 'Entidad que informa',
'Reporting Entity [Axis]' => 'Entidad que informa [Eje]',
'Table' => 'Tabla',
'Context' => 'Contexto',
'Concept' => 'Concepto',
'Value' => 'Valor',
'Unit' => 'Unidad',
'Rounding' => 'Redondeo',
'Fact table for' => 'Tabla de hechos para',
'Label' => 'Etiqueta',
'Fact set type' => 'Tipo de conjunto de hechos',
'Report Element Class' => 'Clase de elemento de informe',
'Period Type' => 'Tipo de periodo',
'Balance' => 'Equilibrar',
'Name' => 'Nombre',
'Report sections' => 'Secciones de informes',
'Structure' => 'Estructura',
'Slicers' => 'Slicers',
'Report' => 'Informe',
'Facts' => 'Hechos',
'Rules' => 'Reglas',
'There are no business rules' => 'No hay reglas de negocio',
'Business rules' => 'Reglas de negocio',
'Line item' => 'Término contable',
'Calculated' => 'Calculado',
'Decimals' => 'Decimales',
'There is no data to report' => 'No hay datos para reportar',
'Columns' => 'Columnas',
'Wider' => 'Más amplio',
'Narrower' => 'Más estrecho',
'Order' => 'Order',
'Parent concept' => 'Parent concept'
),
'fr' => array(
'Axis' => 'Axe',
'Component' => 'Composant',
'Component: Network plus Table' => 'Composant: Réseau de tableau',
'Network' => 'Réseau',
'Network plus Table' => 'Réseau de tableau',
'Period' => 'Période',
'Period [Axis]' => 'Période [Axe]',
'Reporting Entity' => 'Entité comptable',
'Reporting Entity [Axis]' => 'Entité comptable [Axe]',
'Table' => 'Tableau',
'Context' => 'Contexte',
'Concept' => 'Concept',
'Value' => 'Valeur',
'Unit' => 'Unité',
'Rounding' => 'Arrondi',
'Fact table for' => 'Table de faits pour',
'Label' => 'Étiquette',
'Fact set type' => 'Type d\'ensemble factuel',
'Report Element Class' => 'Classe d\'élément de rapport',
'Period Type' => 'Type de période',
'Balance' => 'Équilibre',
'Name' => 'Nom',
'Report sections' => 'Sections du rapport',
'Structure' => 'Structure',
'Slicers' => 'Slicers',
'Report' => 'Rapport',
'Facts' => 'Faits',
'Rules' => 'Règles',
'There are no business rules' => 'Il n\'y a pas de règles d\'affaires',
'Business rules' => 'Règle d\'affaires',
'Line item' => 'Terme comptable',
'Calculated' => 'Calculé',
'Decimals' => 'Décimales',
'There is no data to report' => 'Il n\'y a pas de données à signaler',
'Columns' => 'Les colonnes',
'Wider' => 'Plus large',
'Narrower' => 'Plus étroit',
'Order' => 'Order',
'Parent concept' => 'Parent concept'
),
'it' => array(
'Axis' => 'Asse',
'Component' => 'Componente',
'Component: Network plus Table' => 'Componente: Rete più Tabella',
'Network' => 'Rete',
'Network plus Table' => 'Rete più Tabella',
'Period' => 'Periodo',
'Period' => 'Periodo [Asse]',
'Reporting Entity' => 'Entità segnalante',
'Reporting Entity [Axis]' => 'Entità segnalante [Asse]',
'Table' => 'Tabella',
'Context' => 'Contesto',
'Concept' => 'Concetto',
'Value' => 'Valore',
'Unit' => 'Unità',
'Rounding' => 'Arrotondamento',
'Fact table for' => 'Tabella dei fatti per',
'Label' => 'Etichetta',
'Fact set type' => 'Fatto impostato tipo',
'Report Element Class' => 'Segnala la classe degli elementi',
'Period Type' => 'Tipo di periodo',
'Balance' => 'Equilibrio',
'Name' => 'Nome',
'Report sections' => 'Segnala sezioni',
'Structure' => 'Struttura',
'Slicers' => 'Slicers',
'Report' => 'Rapporto',
'Facts' => 'Fatti',
'Rules' => 'Regole',
'There are no business rules' => 'Non ci sono regole attività commerciale',
'Business rules' => 'Regola attività commerciale',
'Line item' => 'Termine di contabilità',
'Calculated' => 'Calcolato',
'Decimals' => 'Decimali',
'There is no data to report' => 'Non ci sono dati da segnalare',
'Columns' => 'Colonne',
'Wider' => 'Più ampia',
'Narrower' => 'Più stretto',
'Order' => 'Order',
'Parent concept' => 'Parent concept'
)
);
/**
* Created by the constructor to hold the list of valid presentation relationships
* @var array
*/
private $allowed = array();
/**
* Constructor
* @var XBRL $taxonomy
*/
private $taxonomy = null;
/**
*
* @var array
*/
private static $beginEndPreferredLabelPairs = array();
/**
* A static constructor
* @param string $cacheLocation
*/
public static function Initialize( $cacheLocation )
{
$cmArcRoles = XBRL_DFR::getConceptualModelRoles( $cacheLocation );
self::$beginEndPreferredLabelPairs = array(
array(
XBRL_DFR::$originallyStatedLabel,
XBRL_Constants::$labelRoleRestatedLabel
),
array(
// self::$originallyStatedLabel,
XBRL_Constants::$labelRoleVerboseLabel
)
);
array_push( XBRL_DFR::$beginEndPreferredLabelPairs, reset( XBRL::$beginEndPreferredLabelPairs ) );
XBRL::$beforeDimensionalPrunedDelegate = function( XBRL $taxonomy, array $dimensionalNode, array &$parentNode )
{
return false;
};
XBRL::$beginEndPreferredLabelPairsDelegate = function()
{
return XBRL_DFR::$beginEndPreferredLabelPairs;
};
}
/**
* Constructor
* @param XBRL $taxonomy
*/
function __construct( XBRL $taxonomy )
{
$this->taxonomy = $taxonomy;
$this->features = array( "conceptual-model" => array(
'PeriodAxis' => 'PeriodAxis',
'ReportDateAxis' => XBRL_Constants::$dfrReportDateAxis,
'ReportingEntityAxis' => XBRL_Constants::$dfrReportingEntityAxis,
'LegalEntityAxis' => XBRL_Constants::$dfrLegalEntityAxis,
'ConceptAxis' => XBRL_Constants::$dfrConceptAxis,
'BusinessSegmentAxis' => XBRL_Constants::$dfrBusinessSegmentAxis,
'GeographicAreaAxis' => XBRL_Constants::$dfrGeographicAreaAxis,
'OperatingActivitiesAxis' => XBRL_Constants::$dfrOperatingActivitiesAxis,
'InstrumentAxis' => XBRL_Constants::$dfrInstrumentAxis,
'RangeAxis' => XBRL_Constants::$dfrRangeAxis,
'ReportingScenarioAxis' => XBRL_Constants::$dfrReportingScenarioAxis,
'CalendarPeriodAxis' => XBRL_Constants::$dfrCalendarPeriodAxis,
'FiscalPeriodAxis' => XBRL_Constants::$dfrFiscalPeriodAxis,
'origionallyStatedLabel' => 'origionallyStated',
'restatedLabel' => XBRL_Constants::$labelRoleRestatedLabel,
'periodStartLabel' => XBRL_Constants::$labelRolePeriodStartLabel,
'periodEndLabel' => XBRL_Constants::$labelRolePeriodEndLabel
) );
$this->axesToExclude = array(
'PeriodAxis', // Exists or implied
XBRL_Constants::$dfrLegalEntityAxis, // Exists or implied
XBRL_Constants::$dfrReportDateAxis, // Adjustment
'CreationDateAxis', // ifrs and us-gaap ReportDateAxis
// XBRL_Constants::$dfrReportingScenarioAxis // Variance
);
$this->reportDateAxisAliases = array(
'CreationDateAxis', // ifrs and us-gaap
XBRL_Constants::$dfrReportDateAxis
);
$cmArcRoles = XBRL_DFR::getConceptualModelRoles();
$this->allowed = $cmArcRoles[ XBRL_Constants::$arcRoleConceptualModelAllowed ]['arcs'];
if ( ! isset( $allowed['cm.xsd#cm_Concept'] ) )
{
$this->allowed['cm.xsd#cm_Concept'] = array();
}
}
/**
* Translate constant text used in the slicers, components and elsewhere
* Will return the input $text if $lang is null or begins with 'en'
* @param string $lang
* @param string $text
* @return string
*/
public function getConstantTextTranslation( $lang, $text )
{
if ( is_null( $lang ) || strpos( $lang, 'en' ) === 0 || ! isset( self::$constantTextTranslations[ $lang ][ $text ] ) )
{
return $text;
}
return self::$constantTextTranslations[ $lang ][ $text ];
}
/**
* Gets an array containing a list of extra features supported usually by descendent implementation
* @param string $feature (optional) If supplied just the array for the feature is returned or all
* features. If supplied and not found an empty array is returned
* @return array By default there are no additional features so the array is empty
*/
public function supportedFeatures( $feature = null )
{
return $feature
? ( isset( $this->features[ $feature ] ) ? $this->features[ $feature ] : array() )
: $this->featrues;
}
/**
* Renders an evidence package for a set of networks
* @param array $networks
* @param XBRL_Instance $instance
* @param array $report
* @param \Log_observer $observer
* @param string|null $lang (optional: default = null) The language to use or null for the default
* @param bool $echo
* @param array $factsData @reference If not null an array
* @return array
*/
public function renderPresentationNetworks( $networks, $instance, &$report, $observer, $lang = null, $echo = true, &$factsData = null )
{
// If the checkboxes are not displayed then make sure all selected tables are shown
if ( ! $this->includeCheckboxControls ) $this->showAllGrids = true;
$result = array();
foreach ( $networks as $elr => $network )
{
// if ( ! \XBRL::endsWith( $elr, "http://www.microsoft.com/20180630/taxonomy/role/DisclosureDeferredIncomeTaxAssetsAndLiabilitiesDetail" ) ) continue;
$entityHasReport = false;
$data = is_array( $factsData ) ? array() : null;
$entities = $this->renderPresentationNetwork( $network, $elr, $instance, $report, $observer, $entityHasReport, $lang, $echo, $data );
if ( is_array( $factsData ) ) $factsData[ $elr ] = $data;
// error_log( $elr );
$result[ $elr ] = array(
'entities' => $entities,
'text' => $networks[ $elr ]['text'],
'hasReport' => $entityHasReport
);
}
return $result;
}
/**
* Renders an evidence package for a network
* @param array $network
* @param string $elr
* @param XBRL_Instance $instance
* @param array $report
* @param \Log_observer $observer
* @param bool $entityHasReport
* @param string|null $lang (optional: default = null) The language to use or null for the default
* @param bool $echo
* @param array $factsData @reference If not null an array
* @return array
*/
public function renderPresentationNetwork( $network, $elr, $instance, &$report, $observer, &$entityHasReport = false, $lang = null, $echo = true, &$factsData = null )
{
$entities = $instance->getContexts()->AllEntities();
// Add a depth to each node
$addDepth = function( &$nodes, $depth = 0 ) use( &$addDepth )
{
foreach ( $nodes as $label => &$node )
{
$node['depth'] = $depth;
if ( ! isset( $node['children'] ) ) continue;
$addDepth( $node['children'], $depth + 1 );
}
unset( $node );
};
$addDepth( $network['hierarchy'] );
$result = array();
foreach ( $entities as $entity )
{
$entityQName = qname( $entity );
$hasReport = false;
$data = is_array( $factsData ) ? array() : null;
$result[ $entity ] = $this->renderNetworkReport( $network, $elr, $instance, $entityQName, $report, $observer, $hasReport, $lang, $echo, $data );
if ( is_array( $factsData ) ) $factsData[ $entity ] = $data;
$entityHasReport |= $hasReport;
}
return $result;
}
/**
* Validate the the taxonomy against the model structure rules
* @param array $formulaSummaries An evaluated formulas instance
* @param bool $rebuildDefinitionsCache
* @param string $lang A locale to use when returning the text. Defaults to null to use the default.
* @param bool $keepDefinitionlessPresentations This will be true if the caller wants to keep presentations
* for which there is no matching definition and the caller is
* going to handle the unmatched presentations.
* @return array|null
*/
public function validateDFR( &$formulaSummaries, $rebuildDefinitionsCache = false, $lang = null, $keepDefinitionlessPresentations = false )
{
global $reportModelStructureRuleViolations;
$log = XBRL_Log::getInstance();
// Makes sure they are reset in case the same taxonomy is validated twice.
$this->calculationNetworks = array();
$this->presentationNetworks = array();
$this->definitionNetworks = $this->taxonomy->getAllDefinitionRoles( $rebuildDefinitionsCache );
$this->taxonomy->generateAllDRSs();
foreach ( $this->definitionNetworks as $elr => &$roleRef )
{
$roleRef = $this->taxonomy->getDefinitionRoleRef( $elr );
if ( property_exists( $this, 'definitionRoles' ) && ! in_array( $elr, $this->definitionRoles ) )
{
unset( $this->definitionNetworks[ $elr ] );
continue;
}
// Capture primary items
$this->definitionPIs[ $elr ] = array_filter( array_keys( $roleRef['primaryitems'] ), function( $label )
{
$taxonomy = $this->taxonomy->getTaxonomyForXSD( $label );
$element = $taxonomy->getElementById( $label );
return ! $element['abstract' ];
} );
sort( $this->definitionPIs[ $elr ] );
// Check members
foreach ( $roleRef['members'] as $memberLabel => $member )
{
$memberTaxonomy = $this->taxonomy->getTaxonomyForXSD( $memberLabel );
$memberElement = $memberTaxonomy->getElementById( $memberLabel );
if ( ! $memberElement['abstract' ] )
{
global $reportModelStructureRuleViolations;
if ( $reportModelStructureRuleViolations )
$log->business_rules_validation('Model Structure Rules', 'All dimension member elements MUST be abstract',
array(
'member' => $memberLabel,
'role' => $elr,
'error' => 'error:MemberRequiredToBeAbstract'
)
);
}
// BMS 2019-03-23 TODO typed members MUST NOT use complex types
unset( $memberTaxonomy );
unset( $memberElement );
}
// Check hypercube
if ( $reportModelStructureRuleViolations )
foreach ( $roleRef['hypercubes'] as $hypercubeLabel => $hypercube )
{
if ( ! isset( $hypercube['parents'] ) ) continue;
foreach ( $hypercube['parents'] as $primaryItemLabel => $primaryItem )
{
if ( ! isset( $primaryItem['closed'] ) || ! $primaryItem['closed'] )
{
if ( ! isset( $this->definitionNetworks[ $elr ]['primaryitems'][ $primaryItemLabel ]['parents'] ) ) // Only report the error on the line items node
{
$log->business_rules_validation('Model Structure Rules', 'All line items to hypercubes MUST be closed',
array(
'hypercube' => $hypercubeLabel,
'primary item' => $primaryItemLabel,
'role' => $elr,
'error' => 'error:HypercubesRequiredToBeClosed'
)
);
}
}
if ( $primaryItem['arcrole'] == XBRL_Constants::$arcRoleNotAll )
{
$log->business_rules_validation('Model Structure Rules', 'All line items to hypercubes MUST be \'all\'',
array(
'hypercube' => $hypercubeLabel,
'primary item' => $primaryItemLabel,
'role' => $elr,
'error' => 'error:HypercubeMustUseAllArcrole'
)
);
}
if ( $primaryItem['contextElement'] != XBRL_Constants::$xbrliSegment )
{
$log->business_rules_validation('Model Structure Rules', 'Dimensions in contexts MUST use the segment container',
array(
'hypercube' => $hypercubeLabel,
'primary item' => $primaryItemLabel,
'role' => $elr,
'error' => 'error:DimensionsMustUseSegmentContainer'
)
);
}
}
}
}
unset( $roleRef );
$this->calculationNetworks = $this->taxonomy->getCalculationRoleRefs();
$this->calculationNetworks = array_filter( $this->calculationNetworks, function( $roleRef ) { return isset( $roleRef['calculations'] ); } );
foreach ( $this->calculationNetworks as $elr => $role )
{
if ( property_exists( $this, 'calculationRoles' ) && ! in_array( $elr, $this->calculationRoles ) )
{
unset( $this->calculationNetworks[ $elr ] );
continue;
}
if ( ! isset( $role['calculations'] ) ) continue;
foreach ( $role['calculations'] as $totalLabel => $components )
{
$calculationELRPIs = array_keys( $components );
$calculationELRPIs[] = $totalLabel;
$this->calculationPIs[ $elr ] = isset( $this->calculationPIs[ $elr ] )
? array_merge( $this->calculationPIs[ $elr ], $calculationELRPIs )
: $calculationELRPIs;
}
unset( $calculationELRPIs );
}
$this->presentationNetworks = &$this->taxonomy->getPresentationRoleRefs( null, null, $lang );
// If there are no defined networks create one and add all the elements as nodes
if ( $this->presentationNetworks )
{
if ( property_exists( $this, 'presentationRoles' ) )
foreach ( $this->presentationNetworks as $elr => $role )
{
if ( in_array( $elr, $this->presentationRoles ) ) continue;
unset( $this->presentationNetworks[ $elr ] );
}
}
else
{
$xsd = $this->taxonomy->getTaxonomyXSD();
$hierarchy = array();
$locators = array();
$paths = array();
$roleUri = 'http://allConceptsAbstract';
$order = 0;
// Add presentation and defintion networks and also a line item abstract element
$elements =& $this->taxonomy->getElements();
$name = 'AllConceptsAbstract';
$id = $this->taxonomy->getPrefix() . "_$name";
$root = "{$xsd}#{$id}";
$hierarchy[ $root ] = array(
'label' => $root,
'order' => 0,
'use' => 'optional',
'priority' => "0",
'nodeclass' => 'primaryItem',
'dt' => 'p',
'hypercubes' => array(),
'hypercubespruned' => true,
);
$locators[ $id ] = $root;
foreach ( $elements as $label => $element )
{
$order++;
$hierarchy[ $root ]['children']["{$xsd}#{$label}"] = array(
'label' => "{$xsd}#{$label}",
'order' => $order,
'use' => 'optional',
'priority' => "0",
'nodeclass' => 'primaryItem',
'dt' => 'p',
'hypercubes' => array(),
'hypercubespruned' => true,
);
$locators[ $label ] = "{$xsd}#{$label}";
$paths[ $label ] = array( "$root/{$xsd}#{$label}" );
}
$elements[ $id ] = array(
'id' => $id,
'name' => $name,
'type' => 'xbrli:stringItemType',
'substitutionGroup' => 'xbrli:item',
'abstract' => 1,
'nilable' => 1,
'periodType' => 'duration',
'prefix' => $this->taxonomy->getPrefix(),
);
$paths[ $id ] = array( $root );
$this->presentationNetworks[ $roleUri ] = array(
'type' => 'simple',
'href' => "{$this->taxonomy->getSchemaLocation()}#all",
'roleUri' => $roleUri,
'used' => true,
'hierarchy' => $hierarchy,
'locators' => $locators,
'paths' => $paths,
'hypercubes' => array(),
'text' => 'All members network',
);
$this->definitionNetworks[ $roleUri ] = array(
'members' => array(),
'primaryitems' => array_reduce( $elements, function( $carry, $element ) use( $xsd )
{
$carry[ "$xsd#{$element['id']}" ] = array(
'hypercubes' => array(),
'localhypercubes' => array(),
);
return $carry;
}, array() ),
'dimensions' => array(),
'hypercubes' => array(),
'type' => 'simple',
'href' => $this->taxonomy->getSchemaLocation(),
'roleUri' => $roleUri,
);
}
// Check the definition and presentation roles are consistent then make sure the calculation roles are a sub-set
global $reportModelStructureRuleViolations;
if ( $reportModelStructureRuleViolations )
if ( $this->definitionNetworks && array_diff_key( $this->presentationNetworks, $this->definitionNetworks ) || array_diff_key( $this->definitionNetworks, $this->presentationNetworks ) )
{
$log->business_rules_validation('Model Structure Rules', 'Networks in definition and presentation linkbases MUST be the same',
array(
'presentation' => implode( ', ', array_keys( array_diff_key( $this->presentationNetworks, $this->definitionNetworks ) ) ),
'definition' => implode( ', ', array_keys( array_diff_key( $this->definitionNetworks, $this->presentationNetworks ) ) ),
'error' => 'error:NetworksMustBeTheSame'
)
);
}
else
{
if ( array_diff_key( $this->calculationNetworks, $this->presentationNetworks ) )
{
$log->business_rules_validation('Model Structure Rules', 'Networks in calculation linkbases MUST be a sub-set of those in definition and presentation linkbases',
array(
'calculation' => implode( ', ', array_keys( array_diff_key( $this->calculationNetworks, $this->presentationNetworks ) ) ),
'error' => 'error:NetworksMustBeTheSame'
)
);
}
}
$presentationRollupPIs = array();
foreach ( $this->presentationNetworks as $elr => &$role )
{
$this->presentationPIs[$elr] = array();
foreach ( $role['locators'] as $locatorId => $label )
{
$locatorTaxonomy = $this->taxonomy->getTaxonomyForXSD( $label );
if ( ! $locatorTaxonomy )
continue;
$locatorElement = $locatorTaxonomy->getElementById( $label );
if ( $locatorElement['abstract'] || $locatorElement['type'] == 'nonnum:domainItemType' ) continue;
// BMS 2019-03-23 TODO Check the concept is not a tuple
if ( $locatorElement['substitutionGroup'] == "xbrli:tuple" )
{
continue;
}
// One or more of the labels may include the preferred label role so convert all PIs back to their id
$this->presentationPIs[$elr][] = $locatorTaxonomy->getTaxonomyXSD() . "#{$locatorElement['id']}";
}
unset( $locatorElement );
unset( $locatorId );
unset( $locatorTaxonomy );
// If there were preferred label roles in any of the PIs then there will be duplicates. This also sorts the list.
$this->presentationPIs[ $elr ] = array_unique( $this->presentationPIs[ $elr ] );
$calculationELRPIs = isset( $this->calculationPIs[ $elr ] ) ? $this->calculationPIs[ $elr ] : array();
$axes = array();
$lineItems = array();
$tables = array();
$concepts = array();
// Access the list of primary items
// $primaryItems = $this->getDefinitionPrimaryItems();
$primaryItems = $this->taxonomy->getDefinitionRolePrimaryItems( $elr );
$currentPrimaryItem = array();
$this->processNodes( $role['hierarchy'], null, false, $this->allowed['cm.xsd#cm_Network'], false, $calculationELRPIs, $elr, $presentationRollupPIs, $tables, $lineItems, $axes, $concepts, $formulaSummaries, $primaryItems, $currentPrimaryItem, null, null );
if ( isset( $this->definitionNetworks[ $elr ] ) )
{
if ( $reportModelStructureRuleViolations && count( $tables ) != 1 )
{
XBRL_Log::getInstance()->business_rules_validation('Model Structure Rules', 'There MUST be one and only one table per network',
array(
'tables' => $tables ? implode( ', ', $tables ) : 'There is no table',
'role' => $elr,
'error' => 'error:MustBeOnlyOneTablePerNetwork'
)
);
}
if ( $reportModelStructureRuleViolations && count( $lineItems ) != 1 )