|
|
@@ -1,9 +1,19 @@
|
|
|
<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
|
-/** @noinspection PhpUndefinedMethodInspection */
|
|
|
|
|
|
/**
|
|
|
* @var string $date_range_label
|
|
|
* @var string[] $key_labels
|
|
|
+ * @var ?bool $retests
|
|
|
+ * @var Customer $customer
|
|
|
+ * @var Template $template
|
|
|
+ * @var object $template_config
|
|
|
+ * @var bool $has_logo
|
|
|
+ * @var string $logo_file_path
|
|
|
+ * @var array $total_data
|
|
|
+ * @var array $charts
|
|
|
+ * @var array $region_data
|
|
|
+ * @var array $area_manager_data
|
|
|
+ * @var string $action
|
|
|
*/
|
|
|
|
|
|
use PhpOffice\PhpPresentation\PhpPresentation;
|
|
|
@@ -35,7 +45,6 @@ if($retests !== null) {
|
|
|
$title = sprintf("%s %s %s Tests (%s)", $customer->name, $template->name, date("F Y"), $retests_title);
|
|
|
|
|
|
if($has_logo) {
|
|
|
-
|
|
|
$shape = $slide->createDrawingShape();
|
|
|
$shape->setName("$customer->name logo")
|
|
|
->setDescription("$customer->name logo")
|
|
|
@@ -49,10 +58,6 @@ if($has_logo) {
|
|
|
->setWidth(940)
|
|
|
->setOffsetX(120)
|
|
|
->setOffsetY(120);
|
|
|
- $run = $shape->createTextRun($title);
|
|
|
- $run->getFont()->setBold(true)->setSize(16);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
else {
|
|
|
// Title
|
|
|
@@ -62,60 +67,114 @@ else {
|
|
|
->setOffsetX(10)
|
|
|
->setOffsetY(315);
|
|
|
$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
|
|
|
- $run = $shape->createTextRun($title);
|
|
|
- $run->getFont()->setBold(true)
|
|
|
- ->setSize(16);
|
|
|
}
|
|
|
|
|
|
-// Create summary slide
|
|
|
-$slide = $presentation->createSlide();
|
|
|
-
|
|
|
-// Title
|
|
|
-$shape = $slide->createRichTextShape()
|
|
|
- ->setHeight(60)->setWidth(900)
|
|
|
- ->setOffsetX(30)->setOffsetY(10);
|
|
|
-$run = $shape->createTextRun("Summary");
|
|
|
-$run->getFont()->setBold(true)->setSize(24);
|
|
|
-
|
|
|
-// Date range
|
|
|
-$shape = $slide->createRichTextShape()
|
|
|
- ->setHeight(60)->setWidth(900)
|
|
|
- ->setOffsetX(30)->setOffsetY(70);
|
|
|
-$run = $shape->createTextRun($date_range_label);
|
|
|
-$run->getFont()->setBold(true)->setSize(24);
|
|
|
-
|
|
|
-// Test Count
|
|
|
-$count_text = "Test Count: {$total_data->testCount}";
|
|
|
-
|
|
|
-// Pass/Fail count
|
|
|
-if(isset($total_data->passCount)) {
|
|
|
- $pass_percentage = 0;
|
|
|
- $fail_percentage = 0;
|
|
|
- if($total_data->testCount > 0) {
|
|
|
- $pass_percentage = number_format(($total_data->passCount * 100) / $total_data->testCount, 2);
|
|
|
- $fail_percentage = 100 - $pass_percentage;
|
|
|
+$run = $shape->createTextRun($title);
|
|
|
+$run->getFont()->setBold(true)->setSize(16);
|
|
|
+
|
|
|
+$create_summary_slide = static function(array $options) use ($presentation, $charts, $date_range_label, $total_data) {
|
|
|
+
|
|
|
+ $title = $options["title"] ?? "Summary";
|
|
|
+ $array_key = $options["array_key"] ?? null;
|
|
|
+ $chart_prefix = $options["chart_prefix"] ?? "Totals by";
|
|
|
+
|
|
|
+ if($array_key) {
|
|
|
+ $pass_count = $total_data->$array_key["pass"];
|
|
|
+ $fail_count = $total_data->$array_key["fail"];
|
|
|
+ $test_count = $pass_count + $fail_count;
|
|
|
+
|
|
|
+ $has_stages = false;
|
|
|
}
|
|
|
+ else {
|
|
|
+ $test_count = $total_data->testCount;
|
|
|
+ $pass_count = $total_data->passCount;
|
|
|
+ $fail_count = $total_data->failCount;
|
|
|
|
|
|
- $count_text .= "\nPass Count: {$total_data->passCount} ({$pass_percentage}%)";
|
|
|
- $count_text .= "\nFail Count: {$total_data->failCount} ({$fail_percentage}%)";
|
|
|
-}
|
|
|
+ $has_stages = true;
|
|
|
+ }
|
|
|
|
|
|
-$shape = $slide->createRichTextShape()
|
|
|
- ->setHeight(60)->setWidth(900)
|
|
|
- ->setOffsetX(30)->setOffsetY(130);
|
|
|
-$run = $shape->createTextRun($count_text);
|
|
|
-$run->getFont()->setBold(true)->setSize(16);
|
|
|
+ // Create summary slide
|
|
|
+ $slide = $presentation->createSlide();
|
|
|
+
|
|
|
+ // Title
|
|
|
+ $shape = $slide->createRichTextShape()
|
|
|
+ ->setHeight(60)->setWidth(900)
|
|
|
+ ->setOffsetX(30)->setOffsetY(10);
|
|
|
+ $run = $shape->createTextRun($title);
|
|
|
+ $run->getFont()->setBold(true)->setSize(24);
|
|
|
|
|
|
-// Tests by stage
|
|
|
-foreach($charts as $chart) {
|
|
|
- if(stripos($chart->getTitle(), "Tests by Stage") === false) continue;
|
|
|
- $chart->addDataTable($slide, 30, 260);
|
|
|
+ // Date range
|
|
|
+ $shape = $slide->createRichTextShape()
|
|
|
+ ->setHeight(60)->setWidth(900)
|
|
|
+ ->setOffsetX(30)->setOffsetY(70);
|
|
|
+ $run = $shape->createTextRun($date_range_label);
|
|
|
+ $run->getFont()->setBold(true)->setSize(24);
|
|
|
+
|
|
|
+ // Test Count
|
|
|
+ $count_text = "Test Count: {$test_count}";
|
|
|
+
|
|
|
+ // Pass/Fail count
|
|
|
+ if(isset($pass_count)) {
|
|
|
+ $pass_percentage = 0;
|
|
|
+ $fail_percentage = 0;
|
|
|
+ if($test_count > 0) {
|
|
|
+ $pass_percentage = number_format(($pass_count * 100) / $test_count, 2);
|
|
|
+ $fail_percentage = 100 - $pass_percentage;
|
|
|
+ }
|
|
|
+
|
|
|
+ $count_text .= "\nPass Count: {$pass_count} ({$pass_percentage}%)";
|
|
|
+ $count_text .= "\nFail Count: {$fail_count} ({$fail_percentage}%)";
|
|
|
+ }
|
|
|
+
|
|
|
+ $shape = $slide->createRichTextShape()
|
|
|
+ ->setHeight(60)->setWidth(900)
|
|
|
+ ->setOffsetX(30)->setOffsetY(130);
|
|
|
+ $run = $shape->createTextRun($count_text);
|
|
|
+ $run->getFont()->setBold(true)->setSize(16);
|
|
|
+
|
|
|
+ if($has_stages) {
|
|
|
+ // Tests by stage
|
|
|
+
|
|
|
+ /** @var Chart $chart */
|
|
|
+ foreach($charts as $chart) {
|
|
|
+ if(stripos($chart->getTitle(), "Tests by Stage") === false) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $chart->addDataTable($slide, 30, 260);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // Totals by period
|
|
|
+
|
|
|
+ /** @var Chart $chart */
|
|
|
+ foreach($charts as $chart) {
|
|
|
+ if(stripos($chart->getTitle(), $chart_prefix) !== false) {
|
|
|
+ $chart->addDataTable($slide, 30, 360);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+$create_summary_slide([
|
|
|
+ "title" => $template->reports->gamingStatsPage->title ?? null,
|
|
|
+ "chart_prefix" => $template->reports->gamingStatsPage->chartPrefix ?? null
|
|
|
+]);
|
|
|
+
|
|
|
+if(isset($template_config->reports->barStatsPage)) {
|
|
|
+ $create_summary_slide([
|
|
|
+ "title" => $template_config->reports->barStatsPage->title ?? null,
|
|
|
+ "array_key" => "barCounts",
|
|
|
+ "chart_prefix" => $template_config->reports->barStatsPage->chartPrefix ?? null
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
-// Totals by month/quarter
|
|
|
-foreach($charts as $chart) {
|
|
|
- if(stripos($chart->getTitle(), "Totals by") === false) continue;
|
|
|
- $chart->addDataTable($slide, 30, 360);
|
|
|
+if(isset($template_config->reports->combinedStatsPage)) {
|
|
|
+ $create_summary_slide([
|
|
|
+ "title" => $template_config->reports->combinedStatsPage->title ?? null,
|
|
|
+ "array_key" => "combinedCounts",
|
|
|
+ "chart_prefix" => $template_config->reports->combinedStatsPage->chartPrefix ?? null
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
$names = [];
|
|
|
@@ -123,7 +182,10 @@ $names = [];
|
|
|
$charts_b64 = http::value("charts_b64");
|
|
|
foreach($charts_b64 as $index => $b64) {
|
|
|
|
|
|
- $chart = $charts[$index];
|
|
|
+ $chart = $charts[$index] ?? null;
|
|
|
+ if(!$chart) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
$slide = $presentation->createSlide();
|
|
|
|
|
|
@@ -133,7 +195,7 @@ foreach($charts_b64 as $index => $b64) {
|
|
|
$name = tempnam("/tmp", "ppt");
|
|
|
$name .= ".png";
|
|
|
|
|
|
- $handle = fopen($name, "w");
|
|
|
+ $handle = fopen($name, "wb");
|
|
|
fwrite($handle, base64_decode($png_b64));
|
|
|
|
|
|
fclose($handle);
|
|
|
@@ -229,14 +291,14 @@ foreach([0, 1] as $mode) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-if($action == "export-pptx") {
|
|
|
+if($action === "export-pptx") {
|
|
|
header("Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation");
|
|
|
http::setDownloadHeaders("report.pptx");
|
|
|
$pptx_writer = IOFactory::createWriter($presentation, "PowerPoint2007");
|
|
|
$pptx_writer->save("php://output");
|
|
|
}
|
|
|
|
|
|
-if($action == "export-odp") {
|
|
|
+if($action === "export-odp") {
|
|
|
header("Content-Type: application/vnd.oasis.opendocument.presentation");
|
|
|
http::setDownloadHeaders("report.odp");
|
|
|
$odp_writer = IOFactory::createWriter($presentation, "ODPresentation");
|