getActiveSlide(); $shape = $slide->createDrawingShape(); $shape->setName(APP_NAME . " logo") ->setDescription(APP_NAME . " logo") ->setPath("./public/img/logo.png") ->setWidth(200) ->setOffsetX(380) ->setOffsetY(10); $retests_title = "All Tests"; if($retests !== null) { switch($retests) { case 0: $retests_title = "Excluding Retests"; break; case 1: $retests_title = "Retests Only"; break; } } $dt_now = CarbonImmutable::now(TIMEZONE); if($has_logo) { $shape = $slide->createDrawingShape(); $shape->setName("$customer->name logo") ->setDescription("$customer->name logo") ->setPath($logo_file_path) ->setWidth(720) ->setOffsetX(120) ->setOffsetY(180); $shape = $slide->createRichTextShape() ->setHeight(60) ->setWidth(940) ->setOffsetX(120) ->setOffsetY(120); } else { // Title $shape = $slide->createRichTextShape() ->setHeight(120) ->setWidth(940) ->setOffsetX(10) ->setOffsetY(315); } $title_lines = [ $customer->name, $template->name, $date_range_label, $retests_title, "", __("Report Generated at %s", $dt_now->format("d/m/Y H:i")), ]; foreach($title_lines as $title_line) { $paragraph = $shape->getActiveParagraph(); $paragraph->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); $run = new Run($title_line); $run->getFont()->setBold(true)->setSize(16); $paragraph->addText($run); $paragraph = $shape->createParagraph(); } $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; $has_stages = true; } // 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); // 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); break; } } // 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_config->reports->gamingStatsPage->title ?? null, "chart_prefix" => $template_config->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 ]); } 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 = []; $charts_b64 = http::value("charts_b64"); foreach($charts_b64 as $index => $b64) { $chart = $charts[$index] ?? null; if(!$chart) { continue; } $slide = $presentation->createSlide(); // Write chart list($ignore, $png_b64) = explode("base64,", $b64); $name = tempnam("/tmp", "ppt"); $name .= ".png"; $handle = fopen($name, "wb"); fwrite($handle, base64_decode($png_b64)); fclose($handle); $names[] = $name; $chart->addChart($slide, $name); // Write data table if($chart->print) { $chart->addDataTable($slide); } } // Region/Area Manager Stats foreach([0, 1, 2, 3, 4, 5] as $mode) { switch($mode) { case 0: $current_data = $region_data; $mode_text = $customer->getRegionLabel(1); break; case 1: $current_data = $area_manager_data; $mode_text = $customer->getAreaManagerLabel(1); break; case 2: $current_data = $operations_manager_data; $mode_text = $customer->getOperationsManagerLabel(1); break; case 3: $current_data = $brand_data; $mode_text = $customer->getBrandLabel(1); break; case 4: $current_data = $gaming_manager_data; $mode_text = $customer->getGamingManagerLabel(1); break; case 5: $current_data = $senior_gaming_manager_data; $mode_text = $customer->getSeniorGamingManagerLabel(1); break; } foreach($current_data as $data_id => $rows) { $slide = $presentation->createSlide(); // Title $shape = $slide->createRichTextShape() ->setHeight(120)->setWidth(940) ->setOffsetX(30)->setOffsetY(30); $run = $shape->createTextRun("$mode_text: $data_id"); $run->getFont()->setSize(36); // Table $shape = $slide->createTableShape(5) ->setWidth(900) ->setOffsetX(30) ->setOffsetY(110); // Create header row $row = $shape->createRow(); $row->setHeight(20); foreach(["Period", "Tests", "Passes", "Fails", "Rate"] as $label) { $cell = $row->nextCell(); $cell->getActiveParagraph()->getAlignment() ->setMarginBottom(4) ->setMarginLeft(4) ->setMarginRight(4) ->setMarginTop(4); $cell->createTextRun($label) ->getFont()->setBold(true); } $index = 0; foreach($rows as $key => $data) { $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2); $label = $key_labels[$index]; $values = [$data->testCount, $data->passCount, $data->failCount, "$rate%"]; $row = $shape->createRow(); $row->setHeight(20); $cell = $row->nextCell(); $cell->getActiveParagraph()->getAlignment() ->setMarginBottom(4) ->setMarginLeft(4) ->setMarginRight(4) ->setMarginTop(4); $cell->createTextRun($label) ->getFont()->setBold(true); foreach($values as $value) { $cell = $row->nextCell(); $cell->getActiveParagraph()->getAlignment() ->setHorizontal(Alignment::HORIZONTAL_RIGHT) ->setMarginBottom(4) ->setMarginLeft(4) ->setMarginRight(4) ->setMarginTop(4); $cell->createTextRun($value); } $index++; } } } 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") { header("Content-Type: application/vnd.oasis.opendocument.presentation"); http::setDownloadHeaders("report.odp"); $odp_writer = IOFactory::createWriter($presentation, "ODPresentation"); $odp_writer->save("php://output"); } foreach($names as $name) { @unlink($name); } exit;