From 7839b3c3ec721e08921b8e76aa6e72f9b0d0a7d7 Mon Sep 17 00:00:00 2001 From: Roberto Polli Date: Thu, 25 Feb 2021 16:31:13 +0100 Subject: [PATCH] Reformat with phptidy. --- bib.php | 116 +++++++----- data.php | 339 +++++++++++++++++++++-------------- detail.php | 176 ++++++++++-------- functions.php | 273 ++++++++++++++++++---------- graph.php | 138 ++++++++------ head.php | 224 ++++++++++++++--------- index.php | 8 +- mappings.php | 190 +++++++++++--------- md.php | 10 +- navi.php | 51 ++++-- newFolder-Migration-2021.php | 72 ++++---- report-samm.php | 74 ++++---- report.php | 73 ++++---- scutter.php | 67 ++++--- spiderweb.php | 13 +- spiderwebData.php | 224 +++++++++++++---------- test-yaml.php | 28 ++- usefulnessHardness.php | 317 +++++++++++++++++--------------- 18 files changed, 1421 insertions(+), 972 deletions(-) diff --git a/bib.php b/bib.php index dfbe16a62..be043462f 100644 --- a/bib.php +++ b/bib.php @@ -1,4 +1,13 @@ "; - foreach($potentialArray as $element => $content) { - $return .= "
  • $content
  • "; - } - $return .= ""; - }else { - $return .= $potentialArray; + $return = ""; + $potentialArray = $array[$index]; + if (is_array($potentialArray)) { + $return .= ""; + }else { + $return .= $potentialArray; + } + return $return; +} diff --git a/data.php b/data.php index e09c15234..8e5d255f6 100644 --- a/data.php +++ b/data.php @@ -1,5 +1,23 @@ $activity) { - if (elementIsSelected($activityName) && !$showPerformed) { - continue; - } +foreach (getActions($dimensions) as list($dimension, $subdimension, $activities)) { + foreach ($activities as $activityName => $activity) { + if (elementIsSelected($activityName) && !$showPerformed) { + continue; + } - if (!elementIsSelected($activityName) && !$showPlanned) { - continue; - } - $filteredDimensions[$dimension][$subdimension][$activityName] = $activity; + if (!elementIsSelected($activityName) && !$showPlanned) { + continue; } + $filteredDimensions[$dimension][$subdimension][$activityName] = $activity; + } } -function getDifficultyOfImplementationWithDependencies($dimensions, $elementImplementation, &$allElements) -{ - $aggregated = ($_GET['aggregated'] ?? false) == "true" ? "true" : false; - if ($elementImplementation == null) { - return; - } - $knowledge = getKnowledge($elementImplementation); +/** + * + * @param unknown $dimensions + * @param unknown $elementImplementation + * @param unknown $allElements (reference) + */ +function getDifficultyOfImplementationWithDependencies($dimensions, $elementImplementation, &$allElements) { + $aggregated = ($_GET['aggregated'] ?? false) == "true" ? "true" : false; + if ($elementImplementation == null) { + return; + } + $knowledge = getKnowledge($elementImplementation); - $allElements[] = $knowledge; - $allElements[] = $elementImplementation['difficultyOfImplementation']["time"]; - $allElements[] = $elementImplementation['difficultyOfImplementation']["time"]; - $allElements[] = $elementImplementation['difficultyOfImplementation']["resources"]; + $allElements[] = $knowledge; + $allElements[] = $elementImplementation['difficultyOfImplementation']["time"]; + $allElements[] = $elementImplementation['difficultyOfImplementation']["time"]; + $allElements[] = $elementImplementation['difficultyOfImplementation']["resources"]; - if (array_key_exists('dependsOn', $elementImplementation) && $aggregated == "true") { - foreach ($elementImplementation['dependsOn'] as $dependency) { - $dependencyElement = getActivity($dimensions, $dependency); - getDifficultyOfImplementationWithDependencies($dimensions, $dependencyElement, $allElements); + if (array_key_exists('dependsOn', $elementImplementation) && $aggregated == "true") { + foreach ($elementImplementation['dependsOn'] as $dependency) { + $dependencyElement = getActivity($dimensions, $dependency); + getDifficultyOfImplementationWithDependencies($dimensions, $dependencyElement, $allElements); - $knowledge = getKnowledge($elementImplementation); + $knowledge = getKnowledge($elementImplementation); - $allElements[] = $knowledge; - $allElements[] = $elementImplementation['difficultyOfImplementation']["time"]; - $allElements[] = $elementImplementation['difficultyOfImplementation']["time"]; - $allElements[] = $elementImplementation['difficultyOfImplementation']["resources"]; - } + $allElements[] = $knowledge; + $allElements[] = $elementImplementation['difficultyOfImplementation']["time"]; + $allElements[] = $elementImplementation['difficultyOfImplementation']["time"]; + $allElements[] = $elementImplementation['difficultyOfImplementation']["resources"]; } + } } -function getDifficultyOfImplementation($dimensions, $elementImplementation) -{ - $aggregated = ($_GET['aggregated'] ?? false) == "true" ? "true" : false; - if ($elementImplementation == null) { - return; - } - $knowledge = getKnowledge($elementImplementation); +/** + * + * @param unknown $dimensions + * @param unknown $elementImplementation + * @return unknown + */ +function getDifficultyOfImplementation($dimensions, $elementImplementation) { + $aggregated = ($_GET['aggregated'] ?? false) == "true" ? "true" : false; + if ($elementImplementation == null) { + return; + } + $knowledge = getKnowledge($elementImplementation); - $value = $knowledge + $elementImplementation['difficultyOfImplementation']["time"] * 2 + $elementImplementation['difficultyOfImplementation']["resources"]; - $value = $value / 4; - if (array_key_exists('dependsOn', $elementImplementation) && $aggregated == "true") { - foreach ($elementImplementation['dependsOn'] as $dependency) { - $dependencyElement = getActivity($dimensions, $dependency); - $value += getDifficultyOfImplementation($dimensions, $dependencyElement); - } - } - if ($value > 5) { - $value = 5; + $value = $knowledge + $elementImplementation['difficultyOfImplementation']["time"] * 2 + $elementImplementation['difficultyOfImplementation']["resources"]; + $value = $value / 4; + + if (array_key_exists('dependsOn', $elementImplementation) && $aggregated == "true") { + foreach ($elementImplementation['dependsOn'] as $dependency) { + $dependencyElement = getActivity($dimensions, $dependency); + $value += getDifficultyOfImplementation($dimensions, $dependencyElement); } + } + if ($value > 5) { + $value = 5; + } - return number_format((float)$value, 2, '.', ''); + return number_format((float)$value, 2, '.', ''); } -function getKnowledge($elementImplementation) -{ - $knowledge = $elementImplementation['difficultyOfImplementation']["knowledge"]; - if (is_array($knowledge)) { - $sum = 0; - // areas = operation, development, expertise, security - $areaCount = 4; - foreach ($knowledge as $knowledgeAttribute) { - $sum += $knowledgeAttribute; - } - $knowledge = $sum / $areaCount; + +/** + * + * @param unknown $elementImplementation + * @return unknown + */ +function getKnowledge($elementImplementation) { + $knowledge = $elementImplementation['difficultyOfImplementation']["knowledge"]; + if (is_array($knowledge)) { + $sum = 0; + // areas = operation, development, expertise, security + $areaCount = 4; + foreach ($knowledge as $knowledgeAttribute) { + $sum += $knowledgeAttribute; } - return $knowledge; + $knowledge = $sum / $areaCount; + } + return $knowledge; } -function getElementContentAndCheckExistence($parent, $name) -{ - if (array_key_exists($name, $parent)) { - return getElementContent($parent[$name]); - } - return ""; + +/** + * + * @param unknown $parent + * @param unknown $name + * @return unknown + */ +function getElementContentAndCheckExistence($parent, $name) { + if (array_key_exists($name, $parent)) { + return getElementContent($parent[$name]); + } + return ""; } -function getElementContent($element) -{ - $Extra = new ParsedownExtra(); - if (!is_array($element)){ - return str_replace("\"", "'", $element); - } - if (isAssoc($element)) { - $contentString = ""; - foreach ($element as $title => $elementContent) { - $titleWithSpace = preg_replace('/(?<=[a-z])[A-Z]|[A-Z](?=[a-z])/', ' $0', $title); - $contentString .= "" . ucfirst($titleWithSpace) . ""; - $contentString .= ""; - } - return $contentString; - - } - - // default - $contentString = ""; +/** + * + * @param unknown $element + * @return unknown + */ +function getElementContent($element) { + $Extra = new ParsedownExtra(); + if (!is_array($element)) { + return str_replace("\"", "'", $element); + } + if (isAssoc($element)) { + $contentString = ""; + foreach ($element as $title => $elementContent) { + $titleWithSpace = preg_replace('/(?<=[a-z])[A-Z]|[A-Z](?=[a-z])/', ' $0', $title); + $contentString .= "" . ucfirst($titleWithSpace) . ""; + $contentString .= ""; + } return $contentString; + + } + + // default + $contentString = ""; + + return $contentString; } -function isAssoc(array $arr) -{ - if (array() === $arr) return false; - return array_keys($arr) !== range(0, count($arr) - 1); + +/** + * + * @param array $arr + * @return unknown + */ +function isAssoc(array $arr) { + if (array() === $arr) return false; + return array_keys($arr) !== range(0, count($arr) - 1); } +/** + * + * @param unknown $risk + * @return unknown + */ function render_risk($risk) { - if (is_array($risk)) { - return implode("\ ", $risk); - } - return $risk; + if (is_array($risk)) { + return implode("\ ", $risk); + } + return $risk; } + + /** * Render an activity in a tooltip. + * + * @param unknown $array + * @param unknown $headerWeight (optional) + * @return unknown */ -function build_table_tooltip($array, $headerWeight = 2) -{ - $mapKnowLedge = array("Very Low (one discipline)", "Low (one discipline)", "Medium (two disciplines)", "High (two disciplines)", "Very High (three or more disciplines)"); - $mapTime = array("Very Low", "Low", "Medium", "High", "Very High"); - $mapResources = $mapTime; - $mapUsefulness = $mapTime; - - getElementContentAndCheckExistence($array, "meta"); - $evidenceContent = getElementContentAndCheckExistence($array, "evidence"); - if ($evidenceContent == "") { - $evidenceContent = "TODO"; - } +function build_table_tooltip($array, $headerWeight = 2) { + $mapKnowLedge = array("Very Low (one discipline)", "Low (one discipline)", "Medium (two disciplines)", "High (two disciplines)", "Very High (three or more disciplines)"); + $mapTime = array("Very Low", "Low", "Medium", "High", "Very High"); + $mapResources = $mapTime; + $mapUsefulness = $mapTime; + + getElementContentAndCheckExistence($array, "meta"); + $evidenceContent = getElementContentAndCheckExistence($array, "evidence"); + if ($evidenceContent == "") { + $evidenceContent = "TODO"; + } - $html = ""; - $html .= "Risk and Opportunity"; - $html .= "
    " . "Risk" . ": " . render_risk($array['risk']) . "
    "; - $html .= "
    " . "Opportunity" . ": " . $array['measure'] . "
    "; - if (IS_SHOW_EVIDENCE_TODO || $evidenceContent != "TODO") - $html .= "
    " . "Evidence" . ": " . $evidenceContent . "
    "; - $html .= "
    "; - $html .= "Exploit details"; - $html .= "
    Usefullness: " . ucfirst($mapUsefulness[$array['usefulness'] - 1]) . "
    "; - $html .= "
    Required knowledge: " . ucfirst($mapKnowLedge[$array['difficultyOfImplementation']['knowledge'] - 1]) . "
    "; - $html .= "
    Required time: " . ucfirst($mapTime[$array['difficultyOfImplementation']['time'] - 1]) . "
    "; - $html .= "
    Required resources (systems): " . ucfirst($mapResources[$array['difficultyOfImplementation']['resources'] - 1]) . "
    "; - return $html; + $html = ""; + $html .= "Risk and Opportunity"; + $html .= "
    " . "Risk" . ": " . render_risk($array['risk']) . "
    "; + $html .= "
    " . "Opportunity" . ": " . $array['measure'] . "
    "; + if (IS_SHOW_EVIDENCE_TODO || $evidenceContent != "TODO") + $html .= "
    " . "Evidence" . ": " . $evidenceContent . "
    "; + $html .= "
    "; + $html .= "Exploit details"; + $html .= "
    Usefullness: " . ucfirst($mapUsefulness[$array['usefulness'] - 1]) . "
    "; + $html .= "
    Required knowledge: " . ucfirst($mapKnowLedge[$array['difficultyOfImplementation']['knowledge'] - 1]) . "
    "; + $html .= "
    Required time: " . ucfirst($mapTime[$array['difficultyOfImplementation']['time'] - 1]) . "
    "; + $html .= "
    Required resources (systems): " . ucfirst($mapResources[$array['difficultyOfImplementation']['resources'] - 1]) . "
    "; + return $html; } -function getActivity($dimensions, $name) -{ - foreach ($dimensions as $dimensionName => $subDimension) { - foreach ($subDimension as $subDimensionName => $activities) { - foreach ($activities as $activityName => $activity) { - if ($activityName == $name) { - return $activity; - } - } +/** + * + * @param unknown $dimensions + * @param unknown $name + * @return unknown + */ +function getActivity($dimensions, $name) { + foreach ($dimensions as $dimensionName => $subDimension) { + foreach ($subDimension as $subDimensionName => $activities) { + foreach ($activities as $activityName => $activity) { + if ($activityName == $name) { + return $activity; } + } } + } } diff --git a/detail.php b/detail.php index ebfd15c0c..90ca0101e 100644 --- a/detail.php +++ b/detail.php @@ -1,7 +1,16 @@ @@ -14,93 +23,108 @@ $subdimension = $_GET['subdimension'] ?? null; $activityName = $_GET['element'] ?? null; -function printDetail($dimension, $subdimension, $activityName, $dimensions, $report = false) -{ - $element = $dimensions[$dimension][$subdimension][$activityName] ?? null; - if ($element == null) { //Whitelist approach for security reasons (deny XSS) - //echo "Sorry, we could not found the element"; - return; +/** + * + * @param unknown $dimension + * @param unknown $subdimension + * @param unknown $activityName + * @param unknown $dimensions + * @param unknown $report (optional) + */ +function printDetail($dimension, $subdimension, $activityName, $dimensions, $report = false) { + $element = $dimensions[$dimension][$subdimension][$activityName] ?? null; + + if ($element == null) { //Whitelist approach for security reasons (deny XSS) + //echo "Sorry, we could not found the element"; + return; + } + if ($report) { + $headerWeight = 3; + } else { + $headerWeight = 1; + } + + $pageH1 = ""; + if (!$report) { + $pageH1 .= $dimension; + + if ($dimension != $subdimension) { + + $pageH1 .= " -> $subdimension"; + } + $pageH1 .= ": $activityName"; + } else { + $pageH1 .= "$activityName"; + } + + echo "$pageH1"; + echo build_table_tooltip($element, $headerWeight + 1); + echo "
    "; + + if (array_key_exists("dependsOn", $element) || array_key_exists("implementation", $element) || array_key_exists("comment", $element) || array_key_exists("meta", $element)) { + echo "Additional Information"; + if (array_key_exists("dependsOn", $element)) { + $dependsOn = $element['dependsOn']; + $dependencies = implode(", ", $dependsOn); + echo "
    Dependencies: $dependencies
    "; } - if ($report) { - $headerWeight = 3; - } else { - $headerWeight = 1; + echo getElementContentAndCheckExistence($element, "meta"); + } + + + if (array_key_exists("md-description", $element) && !empty($element['md-description'])) { + echo "
    "; + } + if (array_key_exists("implementation", $element) && !empty($element['implementation'])) { + $implementation = $element['implementation']; + echo "
    Implementation hints: "; + if (is_array($implementation)) { + echo "
      "; + foreach ($implementation as $implementationElement) { + echo "
    • $implementationElement
    • "; + } + echo "
    "; + }else { + echo $implementation; } + echo "
    "; + } - $pageH1 = ""; - if (!$report) { - $pageH1 .= $dimension; + if (array_key_exists("comment", $element) && !empty($element['comment'])) { + $comment = $element['comment']; + echo "
    Comments: $comment
    "; + } - if ($dimension != $subdimension) { + printReferences($element); +} - $pageH1 .= " -> $subdimension"; - } - $pageH1 .= ": $activityName"; - } else { - $pageH1 .= "$activityName"; - } - echo "$pageH1"; - echo build_table_tooltip($element, $headerWeight + 1); - echo "
    "; - - if (array_key_exists("dependsOn", $element) || array_key_exists("implementation", $element) || array_key_exists("comment", $element) || array_key_exists("meta", $element)) { - echo "Additional Information"; - if (array_key_exists("dependsOn", $element)) { - $dependsOn = $element['dependsOn']; - $dependencies = implode(", ", $dependsOn); - echo "
    Dependencies: $dependencies
    "; - } - echo getElementContentAndCheckExistence($element, "meta"); - } +/** + * + * @param unknown $element + */ +function printReferences($element) { + if (!array_key_exists("references", $element)) { + return; + } + $actionLabels = readYaml("data/strings.yml#/actionLabels"); + $references = $element['references']; + foreach ($references as $r => $values) { + // if it's not an array, array-ze it. Remove after fixing all yamls. + $values = is_array($values) ? $values : array($values); - if (array_key_exists("md-description", $element) && !empty($element['md-description'])) { - echo "
    "; - } - if (array_key_exists("implementation", $element) && !empty($element['implementation'])) { - $implementation = $element['implementation']; - echo "
    Implementation hints: "; - if(is_array($implementation)){ - echo "
      "; - foreach($implementation as $implementationElement) { - echo "
    • $implementationElement
    • "; - } - echo "
    "; - }else { - echo $implementation; - } - echo "
    "; - } + $label = getReferenceLabel($r); + echo "

    $label

    "; + echo "
    • ". implode("
    • ", $values) ."
    "; + } - if (array_key_exists("comment", $element) && !empty($element['comment'])) { - $comment = $element['comment']; - echo "
    Comments: $comment
    "; - } - printReferences($element); } -function printReferences($element) { - if (!array_key_exists("references", $element)) { - return; - } - $actionLabels = readYaml("data/strings.yml#/actionLabels"); - - $references = $element['references']; - foreach ($references as $r => $values) { - // if it's not an array, array-ze it. Remove after fixing all yamls. - $values = is_array($values) ? $values : array($values); - $label = getReferenceLabel($r); - echo "

    $label

    "; - echo "
    • ". implode("
    • ", $values) ."
    "; - } - - -} // echo var_dump($dimensions); -printDetail($dimension, $subdimension, $activityName, $dimensions); \ No newline at end of file +printDetail($dimension, $subdimension, $activityName, $dimensions); diff --git a/functions.php b/functions.php index a0a3079f7..de4a92a35 100644 --- a/functions.php +++ b/functions.php @@ -1,137 +1,218 @@ $subDimension) { - ksort($subDimension); - foreach ($subDimension as $subDimensionName => $elements) { - - // Q: should I retain this? - if (substr($subDimensionName, 0, 1) == "_") - continue; - - // Upgrade old configuration to `references:` - // this code can be modified to other models. - foreach ($elements as $activityName => $content) { - - if ($content["references"] ?? null) // ignore new lines - continue; - - $content["references"]["samm2"] = $content["samm2"] ?? array(); - unset($content["samm2"]); - $content["references"]["iso27001-2017"] = $content["iso27001-2017"] ?? array(); - unset($content["iso27001-2017"]); - //echo var_dump($elements[$activityName]); - //echo "
    "; - $elements[$activityName] = $content; - - } - $newElements = $elements; - ksort($newElements); - $dimensions[$dimensionName][$subDimensionName] = $newElements; - } + $dimensions = readYaml("data/dimensions.yaml"); + + // reorder in-place $dimensions. This should wrap readYaml(data/dimensions.yaml) + ksort($dimensions); + foreach ($dimensions as $dimensionName => $subDimension) { + ksort($subDimension); + foreach ($subDimension as $subDimensionName => $elements) { + + // Q: should I retain this? + if (substr($subDimensionName, 0, 1) == "_") + continue; + + // Upgrade old configuration to `references:` + // this code can be modified to other models. + foreach ($elements as $activityName => $content) { + + if ($content["references"] ?? null) // ignore new lines + continue; + + $content["references"]["samm2"] = $content["samm2"] ?? array(); + unset($content["samm2"]); + $content["references"]["iso27001-2017"] = $content["iso27001-2017"] ?? array(); + unset($content["iso27001-2017"]); + //echo var_dump($elements[$activityName]); + //echo "
    "; + $elements[$activityName] = $content; + + } + $newElements = $elements; + ksort($newElements); + $dimensions[$dimensionName][$subDimensionName] = $newElements; } - return $dimensions; + } + return $dimensions; } -/** This function should be a sort of db wrapper. */ + +/** + * This function should be a sort of db wrapper. + * + * @param unknown $dimensions + */ function getActions($dimensions) { - ksort($dimensions); - foreach ($dimensions as $dimension => $subdimensions) { - ksort($subdimensions); - - foreach ($subdimensions as $subdimension => $element) { - if (substr($subdimension, 0, 1) == "_") - continue; - yield array($dimension, $subdimension, $element); - } + ksort($dimensions); + foreach ($dimensions as $dimension => $subdimensions) { + ksort($subdimensions); + + foreach ($subdimensions as $subdimension => $element) { + if (substr($subdimension, 0, 1) == "_") + continue; + yield array($dimension, $subdimension, $element); } + } } -function getReferenceLabels(){ - return readYaml("data/strings.yml#/strings/en/references"); + +/** + * + * @return unknown + */ +function getReferenceLabels() { + return readYaml("data/strings.yml#/strings/en/references"); } + + +/** + * + * @param unknown $reference_id + * @return unknown + */ function getReferenceLabel($reference_id) { - $referenceLabels = readYaml("data/strings.yml#/strings/en/references"); + $referenceLabels = readYaml("data/strings.yml#/strings/en/references"); - return $referenceLabels[$reference_id]["label"] ?? $reference_id; + return $referenceLabels[$reference_id]["label"] ?? $reference_id; } -function thead($headings){ - echo '' - .implode('', $headings) - .''; + +/** + * + * @param unknown $headings + */ +function thead($headings) { + echo '' + .implode('', $headings) + .''; } + +/** + * + * @param unknown $title + * @param unknown $html_content + * @param unknown $html_tooltip + * @return unknown + */ function div_tooltip($title, $html_content, $html_tooltip) { - $tooltip = "
    " .$html_tooltip . "
    "; - return "
    "; + return "
    " . $html_content . "
    "; } -function renderSamm($samm_reference){ - return "$samm_reference"; + + +/** + * + * @param unknown $samm_reference + * @return unknown + */ +function renderSamm($samm_reference) { + return "$samm_reference"; } -function as_list($items){ - if(is_array($items)){ - yield from $items; - } else { - yield $items; - } + + +/** + * + * @param unknown $items + */ +function as_list($items) { + if (is_array($items)) { + yield from $items; + } else { + yield $items; + } } -function ul($samm_references, $callback='renderSamm') { - if( ! is_array($samm_references) ){ - return ($callback)($samm_references); - } - $ret = "
    • " - . implode("
    • ", array_map($callback, $samm_references)) - ."
    "; - return $ret; + +/** + * + * @param unknown $samm_references + * @param unknown $callback (optional) + * @return unknown + */ +function ul($samm_references, $callback='renderSamm') { + if ( ! is_array($samm_references) ) { + return ($callback)($samm_references); + } + + $ret = "
    • " + . implode("
    • ", array_map($callback, $samm_references)) + ."
    "; + return $ret; } + + +/** + * + * @param unknown $references + */ function getReferences($references) { - foreach ($references as $r_name => $rlist) { + foreach ($references as $r_name => $rlist) { - } + } } + // TODO create testcases -function test_getActions(){ - $dimensions = readYaml("data/dimensions.yaml"); - echo var_dump(getActions($dimensions)); + +/** + * + */ +function test_getActions() { + $dimensions = readYaml("data/dimensions.yaml"); + echo var_dump(getActions($dimensions)); } + + +/** + * + */ function test_readYaml() { - $ret = readYaml("data/strings.yml"); - echo var_dump($ret); - echo "
    "; - $ret = readYaml("data/strings.yml#/strings/en"); - echo var_dump($ret); - echo "
    "; + $ret = readYaml("data/strings.yml"); + echo var_dump($ret); + echo "
    "; + $ret = readYaml("data/strings.yml#/strings/en"); + echo var_dump($ret); + echo "
    "; } -?> \ No newline at end of file + + +?> diff --git a/graph.php b/graph.php index 97ebc04a7..2b06f9758 100644 --- a/graph.php +++ b/graph.php @@ -1,4 +1,11 @@ @@ -11,20 +18,27 @@ $activity) { - if ($activity["dependsOn"] ?? null) - return true; - } - return false; + foreach ($activities as $activityName => $activity) { + if ($activity["dependsOn"] ?? null) + return true; + } + return false; } + foreach (getActions($dimensions) as list($dimension, $subdimension, $activities)) { - if (hasElementChildren($activities)) { - echo " $dimension - $subdimension
    "; - } + if (hasElementChildren($activities)) { + echo " $dimension - $subdimension
    "; + } } ?> $dimension - $subdimension"; - ?> + echo "

    $dimension - $subdimension

    "; +?> + src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" + integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" + crossorigin="anonymous"> @@ -30,7 +49,7 @@ + href="assets/css/default.min.css"> @@ -42,9 +61,9 @@ + href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" + integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" + crossorigin="anonymous" /> @@ -52,9 +71,9 @@ -"; +"; ?> @@ -34,4 +41,4 @@ }); - \ No newline at end of file + diff --git a/spiderwebData.php b/spiderwebData.php index a8776ec47..095decfdb 100644 --- a/spiderwebData.php +++ b/spiderwebData.php @@ -1,130 +1,170 @@ $activity) { - if ($level == $activity["level"]) { - $data[$level][$dimension][$subdimension]['count']++; - if (elementIsSelected($activityName)) { - $data[$level][$dimension][$subdimension]['selected']++; - } - } - - } + + +/** + * + * @param unknown $dimensions + * @return unknown + */ +function getSpiderWebData($dimensions) { + $data = array(); + foreach (getActions($dimensions) as list($dimension, $subdimension, $activities)) { + for ($level = 1; $level <= 4; $level++) { + // initialize $data cells + if (! ($data[$level][$dimension][$subdimension] ?? null)) { + $data[$level][$dimension][$subdimension]['count'] = 0; + $data[$level][$dimension][$subdimension]['selected'] = 0; + } + foreach ($activities as $activityName => $activity) { + if ($level == $activity["level"]) { + $data[$level][$dimension][$subdimension]['count']++; + if (elementIsSelected($activityName)) { + $data[$level][$dimension][$subdimension]['selected']++; + } } + + } } - return $data; + } + return $data; } + +/** + * + * @param unknown $haystack + * @param unknown $needle + * @return unknown + */ function startsWith($haystack, $needle) { - // search backwards starting from haystack length characters from the end - return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false; + // search backwards starting from haystack length characters from the end + return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false; } -function fwritecsv2($filePointer, $dataArray, $delimiter = ",", $enclosure = "\"") -{ - // Write a line to a file - // $filePointer = the file resource to write to - // $dataArray = the data to write out - // $delimeter = the field separator - // Build the string - $string = ""; - // for each array element, which represents a line in the csv file... - foreach ($dataArray as $line) { +/** + * + * @param unknown $filePointer + * @param unknown $dataArray + * @param unknown $delimiter (optional) + * @param unknown $enclosure (optional) + */ +function fwritecsv2($filePointer, $dataArray, $delimiter = ",", $enclosure = "\"") { + // Write a line to a file + // $filePointer = the file resource to write to + // $dataArray = the data to write out + // $delimeter = the field separator - // No leading delimiter - $writeDelimiter = FALSE; + // Build the string + $string = ""; - foreach ($line as $dataElement) { - // Replaces a double quote with two double quotes - $dataElement = str_replace("\"", "\"\"", $dataElement); + // for each array element, which represents a line in the csv file... + foreach ($dataArray as $line) { - // Adds a delimiter before each field (except the first) - if ($writeDelimiter) $string .= $delimiter; + // No leading delimiter + $writeDelimiter = FALSE; - // Encloses each field with $enclosure and adds it to the string - $string .= $enclosure . $dataElement . $enclosure; + foreach ($line as $dataElement) { + // Replaces a double quote with two double quotes + $dataElement = str_replace("\"", "\"\"", $dataElement); - // Delimiters are used every time except the first. - $writeDelimiter = TRUE; - } - // Append new line - $string .= "\n"; + // Adds a delimiter before each field (except the first) + if ($writeDelimiter) $string .= $delimiter; - } // end foreach($dataArray as $line) + // Encloses each field with $enclosure and adds it to the string + $string .= $enclosure . $dataElement . $enclosure; - $string = str_replace('""', '"element"', $string); - if (!startsWith($string, "element") && !startsWith($string, '"element"')) { - $string = "element" . $string; + // Delimiters are used every time except the first. + $writeDelimiter = TRUE; } - // Write the string to the file - fwrite($filePointer, $string); + // Append new line + $string .= "\n"; + + } // end foreach($dataArray as $line) + + $string = str_replace('""', '"element"', $string); + if (!startsWith($string, "element") && !startsWith($string, '"element"')) { + $string = "element" . $string; + } + // Write the string to the file + fwrite($filePointer, $string); } + //var_dump( getSpiderWebData($dimensions));exit; -function deleteElement(&$data, $activityName) -{ - $count = 0; - foreach ($data as $element) { - if ($activityName == $element["element"]) { - unset($data[$count]); - } - $count++; + +/** + * + * @param unknown $data (reference) + * @param unknown $activityName + */ +function deleteElement(&$data, $activityName) { + $count = 0; + foreach ($data as $element) { + if ($activityName == $element["element"]) { + unset($data[$count]); } + $count++; + } } -function isElementExisting($dimensions, $givenElementName) -{ - foreach ($dimensions as $dimension => $subdimensions) { - foreach ($subdimensions as $subdimension => $element) { - foreach ($element as $activityName => $content) { - if ($activityName == $givenElementName) { - return true; - } - } + +/** + * + * @param unknown $dimensions + * @param unknown $givenElementName + * @return unknown + */ +function isElementExisting($dimensions, $givenElementName) { + foreach ($dimensions as $dimension => $subdimensions) { + foreach ($subdimensions as $subdimension => $element) { + foreach ($element as $activityName => $content) { + if ($activityName == $givenElementName) { + return true; } + } } - return false; + } + return false; } + if ($elementParam == null) { - echo json_encode(getSpiderWebData($dimensions)); - return; -} + echo json_encode(getSpiderWebData($dimensions)); + return; +} { - $csvFile = 'selectedData.csv'; - $csv = getCsv(); - $element = $elementParam; - - if (elementIsSelected($element)) { - deleteElement($csv, $element); - } else { - if (!isElementExisting($dimensions, $element)) { - echo "Could not find element"; - exit; - } - $newEntry['element'] = $element; - $csv[] = $newEntry; + $csvFile = 'selectedData.csv'; + $csv = getCsv(); + $element = $elementParam; + + if (elementIsSelected($element)) { + deleteElement($csv, $element); + } else { + if (!isElementExisting($dimensions, $element)) { + echo "Could not find element"; + exit; } - - $keys = array_keys($csv[0]); - $csv = array_merge(array($keys), $csv); - $fp = fopen($csvFile, 'w'); - fwritecsv2($fp, $csv, ","); - fclose($fp); + $newEntry['element'] = $element; + $csv[] = $newEntry; + } + + $keys = array_keys($csv[0]); + $csv = array_merge(array($keys), $csv); + $fp = fopen($csvFile, 'w'); + fwritecsv2($fp, $csv, ","); + fclose($fp); } diff --git a/test-yaml.php b/test-yaml.php index 7373c2ac0..4bbe4f9ff 100644 --- a/test-yaml.php +++ b/test-yaml.php @@ -1,13 +1,27 @@ -
    +include_once "navi.php"; +?> $subdimensions) { - foreach ($subdimensions as $subdimension => $element) { - - for ($i = 1; $i < 5; $i++) { - if (!array_key_exists($i, $all)) { - $all[$i] = array(); - } - if (array_key_exists($subdimension, $all[$i])) { - $all[$subdimension][$i] = array(); - $all[$subdimension][$i]['usefulness'] = array(); - $all[$subdimension][$i]['difficultyOfImplementation'] = array(); - } - foreach ($element as $activityName => $elementImplementation) { - if ($elementImplementation['level'] != $i) continue; - $all[$subdimension][$i]['usefulness'][] = $elementImplementation['usefulness']; - - $knowledge = getKnowledge($elementImplementation); - - $all[$subdimension][$i]['difficultyOfImplementation'][] = $knowledge; - $all[$subdimension][$i]['difficultyOfImplementation'][] = $elementImplementation['difficultyOfImplementation']["time"]; - $all[$subdimension][$i]['difficultyOfImplementation'][] = $elementImplementation['difficultyOfImplementation']["time"]; - $all[$subdimension][$i]['difficultyOfImplementation'][] = $elementImplementation['difficultyOfImplementation']["resources"]; - } - - } +include_once "data.php"; + + +/** + * + * @param unknown $dimensions + * @param unknown $colors + */ +function printDimensionUsefull($dimensions, $colors) { + $all = array(); + foreach ($dimensions as $dimension => $subdimensions) { + foreach ($subdimensions as $subdimension => $element) { + + for ($i = 1; $i < 5; $i++) { + if (!array_key_exists($i, $all)) { + $all[$i] = array(); + } + if (array_key_exists($subdimension, $all[$i])) { + $all[$subdimension][$i] = array(); + $all[$subdimension][$i]['usefulness'] = array(); + $all[$subdimension][$i]['difficultyOfImplementation'] = array(); + } + foreach ($element as $activityName => $elementImplementation) { + if ($elementImplementation['level'] != $i) continue; + $all[$subdimension][$i]['usefulness'][] = $elementImplementation['usefulness']; + + $knowledge = getKnowledge($elementImplementation); + + $all[$subdimension][$i]['difficultyOfImplementation'][] = $knowledge; + $all[$subdimension][$i]['difficultyOfImplementation'][] = $elementImplementation['difficultyOfImplementation']["time"]; + $all[$subdimension][$i]['difficultyOfImplementation'][] = $elementImplementation['difficultyOfImplementation']["time"]; + $all[$subdimension][$i]['difficultyOfImplementation'][] = $elementImplementation['difficultyOfImplementation']["resources"]; } + + } } - ?> + } +?> $levelElements) { - echo ""; - } - exit; - echo ""; - - foreach (reset($all) as $level => $levelElements) { - echo ""; - echo ""; - } - echo ""; - foreach ($all as $level => $levelElements) { - echo ""; - echo ""; - foreach ($levelElements as $subdimension => $elements) { - $std = stats_standard_deviation($elements["usefulness"]); - - $avg = 0; - foreach ($elements['usefulness'] as $element) { - $avg += $element; - } - $avg = $avg / count($elements['usefulness']); - - $stdImp = stats_standard_deviation($elements['difficultyOfImplementation']); - - $avgImp = 0; - foreach ($elements['difficultyOfImplementation'] as $element) { - $avgImp += $element; - } - - $avgImp = $avgImp / count($elements['difficultyOfImplementation']); - - - echo ""; - } - echo ""; - } - echo '
    Level $level
    DimensionNutzenSchwere
    $level" . number_format((float)$avg, 2, '.', '') . "
    σ=" . number_format((float)$std, 2, '.', '') . "
    " . number_format((float)$avgImp, 2, '.', '') . "
    σ=" . number_format((float)$stdImp, 2, '.', '') . "
    '; - } - - function getColor($val, $colors) - { - - return getColorFordifficultyOfImplementation($val, array_reverse($colors)); - } - - function getColorFordifficultyOfImplementation($val, $colors) - { - if ($val < 1.49) { - return $colors[0]; - } - if ($val < 2.49) { - return $colors[1]; - } - if ($val < 3.49) { - return $colors[2]; - } - if ($val < 4.49) { - return $colors[3]; - } - return $colors[4]; - } - - if (!function_exists('stats_standard_deviation')) { - /** - * This user-land implementation follows the implementation quite strictly; - * it does not attempt to improve the code or algorithm in any way. It will - * raise a warning if you have fewer than 2 values in your array, just like - * the extension does (although as an E_USER_WARNING, not E_WARNING). - * - * @param array $a - * @param bool $sample [optional] Defaults to false - * @return float|bool The standard deviation or false on error. - */ - function stats_standard_deviation(array $a, $sample = false) - { - $n = count($a); - if ($n === 0) { - trigger_error("The array has zero elements", E_USER_WARNING); - return false; - } - if ($sample && $n === 1) { - trigger_error("The array has only 1 element", E_USER_WARNING); - return false; - } - $mean = array_sum($a) / $n; - $carry = 0.0; - foreach ($a as $val) { - $d = ((double)$val) - $mean; - $carry += $d * $d; - }; - if ($sample) { - --$n; - } - return sqrt($carry / $n); - } - } - - $usefulnessMap= array("Sehr gering", "Gering", "Mittel", "Hoch", "Sehr hoch"); - $usefulnessMap = array_reverse($usefulnessMap); - $hardnessMap =array("Sehr einfach", "Einfach", "Mittel", "Schwer", "Sehr Schwer"); - $colors = array("#81F781", "#BEF781", "#F3F781", "#F7BE81", "#FA5858"); - printDimensionUsefull($dimensions, $colors); - - ?> + foreach (reset($all) as $level => $levelElements) { + echo "Level $level"; + } + exit; + echo "Dimension"; + + foreach (reset($all) as $level => $levelElements) { + echo "Nutzen"; + echo "Schwere"; + } + echo ""; + foreach ($all as $level => $levelElements) { + echo ""; + echo "$level"; + foreach ($levelElements as $subdimension => $elements) { + $std = stats_standard_deviation($elements["usefulness"]); + + $avg = 0; + foreach ($elements['usefulness'] as $element) { + $avg += $element; + } + $avg = $avg / count($elements['usefulness']); + + $stdImp = stats_standard_deviation($elements['difficultyOfImplementation']); + + $avgImp = 0; + foreach ($elements['difficultyOfImplementation'] as $element) { + $avgImp += $element; + } + + $avgImp = $avgImp / count($elements['difficultyOfImplementation']); + + + echo "" . number_format((float)$avg, 2, '.', '') . "
    σ=" . number_format((float)$std, 2, '.', '') . "" . number_format((float)$avgImp, 2, '.', '') . "
    σ=" . number_format((float)$stdImp, 2, '.', '') . ""; + } + echo ""; + } + echo ''; +} + + +/** + * + * @param unknown $val + * @param unknown $colors + * @return unknown + */ +function getColor($val, $colors) { + + return getColorFordifficultyOfImplementation($val, array_reverse($colors)); +} + + +/** + * + * @param unknown $val + * @param unknown $colors + * @return unknown + */ +function getColorFordifficultyOfImplementation($val, $colors) { + if ($val < 1.49) { + return $colors[0]; + } + if ($val < 2.49) { + return $colors[1]; + } + if ($val < 3.49) { + return $colors[2]; + } + if ($val < 4.49) { + return $colors[3]; + } + return $colors[4]; +} + + +if (!function_exists('stats_standard_deviation')) { + + + /** + * This user-land implementation follows the implementation quite strictly; + * it does not attempt to improve the code or algorithm in any way. It will + * raise a warning if you have fewer than 2 values in your array, just like + * the extension does (although as an E_USER_WARNING, not E_WARNING). + * + * @param array $a + * @param bool $sample (optional) [optional] Defaults to false + * @return float|bool The standard deviation or false on error. + */ + function stats_standard_deviation(array $a, $sample = false) { + $n = count($a); + if ($n === 0) { + trigger_error("The array has zero elements", E_USER_WARNING); + return false; + } + if ($sample && $n === 1) { + trigger_error("The array has only 1 element", E_USER_WARNING); + return false; + } + $mean = array_sum($a) / $n; + $carry = 0.0; + foreach ($a as $val) { + $d = ((double)$val) - $mean; + $carry += $d * $d; + }; + if ($sample) { + --$n; + } + return sqrt($carry / $n); + } + + +} + +$usefulnessMap= array("Sehr gering", "Gering", "Mittel", "Hoch", "Sehr hoch"); +$usefulnessMap = array_reverse($usefulnessMap); +$hardnessMap =array("Sehr einfach", "Einfach", "Mittel", "Schwer", "Sehr Schwer"); +$colors = array("#81F781", "#BEF781", "#F3F781", "#F7BE81", "#FA5858"); +printDimensionUsefull($dimensions, $colors); + +?>
    Legende
    "; - echo "
    "; - echo ""; - } +for ($i = 0; $i < count($usefulnessMap); $i++) { + echo ""; + echo ""; + echo ""; +} - ?> +?>
    NutzenSchwere " . $usefulnessMap[$i] . "".$hardnessMap[$i]."
    " . $usefulnessMap[$i] . "".$hardnessMap[$i]."
    - \ No newline at end of file +