3
3
4
4
$ files = scandir ("data " );
5
5
6
- function readYaml ($ file ) {
6
+ function readYaml ($ file )
7
+ {
7
8
return yaml_parse (
8
9
file_get_contents ($ file )
9
10
);
@@ -28,19 +29,19 @@ function readYaml($file) {
28
29
}
29
30
}
30
31
31
- if (array_key_exists ("performed " , $ _GET )) {
32
+ if (array_key_exists ("performed " , $ _GET )) {
32
33
$ showPerformed = $ _GET ['performed ' ];
33
-
34
- if ($ showPerformed != "true " ) $ showPerformed = false ;
35
- }else {
34
+
35
+ if ($ showPerformed != "true " ) $ showPerformed = false ;
36
+ } else {
36
37
$ showPerformed = false ;
37
38
}
38
39
39
- if (array_key_exists ("planned " , $ _GET )) {
40
+ if (array_key_exists ("planned " , $ _GET )) {
40
41
$ showPlanned = $ _GET ['planned ' ];
41
42
42
- if ($ showPlanned != "true " ) $ showPlanned = false ;
43
- }else {
43
+ if ($ showPlanned != "true " ) $ showPlanned = false ;
44
+ } else {
44
45
$ showPlanned = false ;
45
46
}
46
47
$ filteredDimensions = array ();
@@ -49,25 +50,25 @@ function readYaml($file) {
49
50
foreach ($ subDimension as $ subDimensionName => $ elements ) {
50
51
$ newElements = $ elements ;
51
52
ksort ($ newElements );
52
- foreach ($ newElements as $ activityName => $ activity ) {
53
- if (elementIsSelected ($ activityName ) && !$ showPerformed ) {
53
+ foreach ($ newElements as $ activityName => $ activity ) {
54
+ if (elementIsSelected ($ activityName ) && !$ showPerformed ) {
54
55
continue ;
55
56
}
56
57
57
- if (!elementIsSelected ($ activityName ) && !$ showPlanned ) {
58
+ if (!elementIsSelected ($ activityName ) && !$ showPlanned ) {
58
59
continue ;
59
- }
60
+ }
60
61
$ filteredDimensions [$ dimensionName ][$ subDimensionName ][$ activityName ] = $ activity ;
61
62
}
62
-
63
+
63
64
}
64
65
}
65
66
66
67
67
68
function getDifficultyOfImplementationWithDependencies ($ dimensions , $ elementImplementation , &$ allElements )
68
69
{
69
- if ($ elementImplementation == null ) {
70
- return ;
70
+ if ($ elementImplementation == null ) {
71
+ return ;
71
72
}
72
73
$ knowledge = getKnowledge ($ elementImplementation );
73
74
@@ -94,8 +95,8 @@ function getDifficultyOfImplementationWithDependencies($dimensions, $elementImpl
94
95
95
96
function getDifficultyOfImplementation ($ dimensions , $ elementImplementation )
96
97
{
97
- if ($ elementImplementation == null ) {
98
- return ;
98
+ if ($ elementImplementation == null ) {
99
+ return ;
99
100
}
100
101
$ knowledge = getKnowledge ($ elementImplementation );
101
102
@@ -131,6 +132,49 @@ function getKnowledge($elementImplementation)
131
132
return $ knowledge ;
132
133
}
133
134
135
+ function getElementContentAndCheckExistence ($ parent , $ name )
136
+ {
137
+ if (array_key_exists ($ name , $ parent )) {
138
+ return getElementContent ($ parent [$ name ]);
139
+ }
140
+ return "" ;
141
+ }
142
+
143
+ function getElementContent ($ element )
144
+ {
145
+ $ contentString = "" ;
146
+ if (is_array ($ element )) {
147
+ if (isAssoc ($ element )) {
148
+ foreach ($ element as $ title => $ elementContent ) {
149
+ $ titleWithSpace = preg_replace ('/(?<=[a-z])[A-Z]|[A-Z](?=[a-z])/ ' , ' $0 ' , $ title );
150
+ $ contentString .= "<b> " . ucfirst ($ titleWithSpace ) . "</b> " ;
151
+ $ contentString .= "<ul> " ;
152
+ if (is_array ($ elementContent )) {
153
+ $ contentString .= getElementContent ($ elementContent );
154
+ } else
155
+ $ contentString .= "<li> " . str_replace ("\"" , "' " , $ elementContent ) . "</li> " ;
156
+ $ contentString .= "</ul> " ;
157
+ }
158
+
159
+ } else {
160
+ $ contentString .= "<ul> " ;
161
+ foreach ($ element as $ content ) {
162
+ $ contentString .= "<li> " . str_replace ("\"" , "' " , $ content ) . "</li> " ;
163
+ }
164
+ $ contentString .= "</ul> " ;
165
+ }
166
+
167
+ } else {
168
+ $ contentString = str_replace ("\"" , "' " , $ element );
169
+ }
170
+ return $ contentString ;
171
+ }
172
+
173
+ function isAssoc (array $ arr )
174
+ {
175
+ if (array () === $ arr ) return false ;
176
+ return array_keys ($ arr ) !== range (0 , count ($ arr ) - 1 );
177
+ }
134
178
135
179
function build_table_tooltip ($ array , $ headerWeight = 2 )
136
180
{
@@ -139,33 +183,24 @@ function build_table_tooltip($array, $headerWeight = 2)
139
183
$ mapResources = $ mapTime ;
140
184
$ mapUsefulness = $ mapTime ;
141
185
142
- $ evidenceContent = "" ;
143
- if (array_key_exists ("evidence " , $ array )) {
144
- if ( is_array ($ array ['evidence ' ])) {
145
- $ evidenceContent .= "<ul> " ;
146
- foreach ($ array ['evidence ' ] as $ content ) {
147
- $ evidenceContent .= "<li> " .str_replace ("\"" , "' " , $ content ) . "</li> " ;
148
- }
149
- $ evidenceContent .= "</ul> " ;
150
- }else {
151
- $ evidenceContent = str_replace ("\"" , "' " , $ array ['evidence ' ]);
152
- }
153
- }else {
186
+ getElementContentAndCheckExistence ($ array , "meta " );
187
+ $ evidenceContent = getElementContentAndCheckExistence ($ array , "evidence " );
188
+ if ($ evidenceContent == "" ) {
154
189
$ evidenceContent = "TODO " ;
155
190
}
156
191
157
192
$ html = "" ;
158
193
$ html .= "<h " . $ headerWeight . ">Risk and Opportunity</h $ headerWeight> " ;
159
194
$ html .= "<div><b> " . "Risk " . ":</b> " . $ array ['risk ' ] . "</div> " ;
160
195
$ html .= "<div><b> " . "Opportunity " . ":</b> " . $ array ['measure ' ] . "</div> " ;
161
- if (IS_SHOW_EVIDENCE_TODO || $ evidenceContent != "TODO " )
162
- $ html .= "<div><b> " . "Evidence " . ":</b> " . $ evidenceContent . "</div> " ;
196
+ if (IS_SHOW_EVIDENCE_TODO || $ evidenceContent != "TODO " )
197
+ $ html .= "<div><b> " . "Evidence " . ":</b> " . $ evidenceContent . "</div> " ;
163
198
$ html .= "<hr /> " ;
164
199
$ html .= "<h $ headerWeight>Exploit details</h $ headerWeight> " ;
165
- $ html .= "<div><b>Usefullness:</b> " . ucfirst ($ mapUsefulness [$ array ['usefulness ' ]- 1 ]) . "</div> " ;
166
- $ html .= "<div><b>Required knowledge:</b> " . ucfirst ($ mapKnowLedge [$ array ['difficultyOfImplementation ' ]['knowledge ' ]- 1 ]) . "</div> " ;
167
- $ html .= "<div><b>Required time:</b> " . ucfirst ($ mapTime [$ array ['difficultyOfImplementation ' ]['time ' ]- 1 ]) . "</div> " ;
168
- $ html .= "<div><b>Required resources (systems):</b> " . ucfirst ($ mapResources [$ array ['difficultyOfImplementation ' ]['resources ' ]- 1 ]) . "</div> " ;
200
+ $ html .= "<div><b>Usefullness:</b> " . ucfirst ($ mapUsefulness [$ array ['usefulness ' ] - 1 ]) . "</div> " ;
201
+ $ html .= "<div><b>Required knowledge:</b> " . ucfirst ($ mapKnowLedge [$ array ['difficultyOfImplementation ' ]['knowledge ' ] - 1 ]) . "</div> " ;
202
+ $ html .= "<div><b>Required time:</b> " . ucfirst ($ mapTime [$ array ['difficultyOfImplementation ' ]['time ' ] - 1 ]) . "</div> " ;
203
+ $ html .= "<div><b>Required resources (systems):</b> " . ucfirst ($ mapResources [$ array ['difficultyOfImplementation ' ]['resources ' ] - 1 ]) . "</div> " ;
169
204
return $ html ;
170
205
}
171
206
0 commit comments