From b54b053917ceacd639f0329d979d43530567a460 Mon Sep 17 00:00:00 2001 From: pwheregroup <25791018+pwheregroup@users.noreply.github.com> Date: Wed, 7 Mar 2018 13:21:04 +0100 Subject: [PATCH 1/3] Added php_cs and comments --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1565e0c2..206304a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ -# IDEA Project Files +# .dots .idea/ +.php_cs.cache + +# misc vendor/ composer.lock \ No newline at end of file From be89a1146af2dfcc1f4c2b0e8cccdcfce7092802 Mon Sep 17 00:00:00 2001 From: pwheregroup <25791018+pwheregroup@users.noreply.github.com> Date: Wed, 7 Mar 2018 13:33:58 +0100 Subject: [PATCH 2/3] Added .editorconfig for bundle --- .editorconfig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..87193dea --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*.php] + +indent_style = space +indent_size = 4 +tab_width = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true From 5e4f5973e31d42dbc9074c4531e7fb202d3b9815 Mon Sep 17 00:00:00 2001 From: pwheregroup <25791018+pwheregroup@users.noreply.github.com> Date: Wed, 7 Mar 2018 13:34:31 +0100 Subject: [PATCH 3/3] Fixed code styling --- Component/CSSColorParser.php | 281 +++--- Component/ImageExportService.php | 111 +-- Component/OdgParser.php | 27 +- Component/PDF_Extensions.php | 36 +- Component/PrintService.php | 850 ++++++++++-------- Element/ImageExport.php | 46 +- Element/PrintClient.php | 72 +- Element/Type/ImageExportAdminType.php | 21 +- Element/Type/PrintClientAdminType.php | 65 +- Element/Type/PrintClientQualityAdminType.php | 7 +- Element/Type/PrintClientTemplateAdminType.php | 10 +- Form/EventListener/PrintClientSubscriber.php | 55 +- MapbenderPrintBundle.php | 5 +- 13 files changed, 872 insertions(+), 714 deletions(-) diff --git a/Component/CSSColorParser.php b/Component/CSSColorParser.php index 4d00b572..a974c6f5 100644 --- a/Component/CSSColorParser.php +++ b/Component/CSSColorParser.php @@ -2,168 +2,167 @@ namespace Mapbender\PrintBundle\Component; - class CSSColorParser { // Color definitions are taken from http://psoug.org/snippet/CSS-Colornames-to-RGB-values_415.htm - static function parse($nameOrHex) + public static function parse($nameOrHex) { $hexMatchCount = preg_match('/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/', $nameOrHex, $hexMatches); - if($hexMatchCount > 0) { + if ($hexMatchCount > 0) { $width = (4 === strlen($nameOrHex)) ? 1 : 2; return array( hexdec(substr($nameOrHex, 1, $width)), hexdec(substr($nameOrHex, 1 + $width, $width)), - hexdec(substr($nameOrHex, 1 + 2 * $width, $width))); + hexdec(substr($nameOrHex, 1 + 2 * $width, $width)) + ); } $colors = array( // Colors as they are defined in HTML 3.2 - "black" => array(0x00, 0x00, 0x00), - "maroon" => array(0x80, 0x00, 0x00), - "green" => array(0x00, 0x80, 0x80), - "olive" => array(0x80, 0x80, 0x80), - "navy" => array(0x00, 0x00, 0x00), - "purple" => array(0x80, 0x00, 0x00), - "teal" => array(0x00, 0x80, 0x80), - "gray" => array(0x80, 0x80, 0x80), - "silver" => array(0xC0, 0xC0, 0xC0), - "red" => array(0xFF, 0x00, 0x00), - "lime" => array(0x00, 0xFF, 0xFF), - "yellow" => array(0xFF, 0xFF, 0xFF), - "blue" => array(0x00, 0x00, 0x00), - "fuchsia" => array(0xFF, 0x00, 0x00), - "aqua" => array(0x00, 0xFF, 0xFF), - "white" => array(0xFF, 0xFF, 0xFF), + "black" => array(0x00, 0x00, 0x00), + "maroon" => array(0x80, 0x00, 0x00), + "green" => array(0x00, 0x80, 0x80), + "olive" => array(0x80, 0x80, 0x80), + "navy" => array(0x00, 0x00, 0x00), + "purple" => array(0x80, 0x00, 0x00), + "teal" => array(0x00, 0x80, 0x80), + "gray" => array(0x80, 0x80, 0x80), + "silver" => array(0xC0, 0xC0, 0xC0), + "red" => array(0xFF, 0x00, 0x00), + "lime" => array(0x00, 0xFF, 0xFF), + "yellow" => array(0xFF, 0xFF, 0xFF), + "blue" => array(0x00, 0x00, 0x00), + "fuchsia" => array(0xFF, 0x00, 0x00), + "aqua" => array(0x00, 0xFF, 0xFF), + "white" => array(0xFF, 0xFF, 0xFF), // Additional colors as they are used by Netscape and IE - "aliceblue" => array(0xF0, 0xF8, 0xF8), - "antiquewhite" => array(0xFA, 0xEB, 0xEB), - "aquamarine" => array(0x7F, 0xFF, 0xFF), - "azure" => array(0xF0, 0xFF, 0xFF), - "beige" => array(0xF5, 0xF5, 0xF5), - "blueviolet" => array(0x8A, 0x2B, 0x2B), - "brown" => array(0xA5, 0x2A, 0x2A), - "burlywood" => array(0xDE, 0xB8, 0xB8), - "cadetblue" => array(0x5F, 0x9E, 0x9E), - "chartreuse" => array(0x7F, 0xFF, 0xFF), - "chocolate" => array(0xD2, 0x69, 0x69), - "coral" => array(0xFF, 0x7F, 0x7F), - "cornflowerblue" => array(0x64, 0x95, 0x95), - "cornsilk" => array(0xFF, 0xF8, 0xF8), - "crimson" => array(0xDC, 0x14, 0x14), - "darkblue" => array(0x00, 0x00, 0x00), - "darkcyan" => array(0x00, 0x8B, 0x8B), - "darkgoldenrod" => array(0xB8, 0x86, 0x86), - "darkgray" => array(0xA9, 0xA9, 0xA9), - "darkgreen" => array(0x00, 0x64, 0x64), - "darkkhaki" => array(0xBD, 0xB7, 0xB7), - "darkmagenta" => array(0x8B, 0x00, 0x00), - "darkolivegreen" => array(0x55, 0x6B, 0x6B), - "darkorange" => array(0xFF, 0x8C, 0x8C), - "darkorchid" => array(0x99, 0x32, 0x32), - "darkred" => array(0x8B, 0x00, 0x00), - "darksalmon" => array(0xE9, 0x96, 0x96), - "darkseagreen" => array(0x8F, 0xBC, 0xBC), - "darkslateblue" => array(0x48, 0x3D, 0x3D), - "darkslategray" => array(0x2F, 0x4F, 0x4F), - "darkturquoise" => array(0x00, 0xCE, 0xCE), - "darkviolet" => array(0x94, 0x00, 0x00), - "deeppink" => array(0xFF, 0x14, 0x14), - "deepskyblue" => array(0x00, 0xBF, 0xBF), - "dimgray" => array(0x69, 0x69, 0x69), - "dodgerblue" => array(0x1E, 0x90, 0x90), - "firebrick" => array(0xB2, 0x22, 0x22), - "floralwhite" => array(0xFF, 0xFA, 0xFA), - "forestgreen" => array(0x22, 0x8B, 0x8B), - "gainsboro" => array(0xDC, 0xDC, 0xDC), - "ghostwhite" => array(0xF8, 0xF8, 0xF8), - "gold" => array(0xFF, 0xD7, 0xD7), - "goldenrod" => array(0xDA, 0xA5, 0xA5), - "greenyellow" => array(0xAD, 0xFF, 0xFF), - "honeydew" => array(0xF0, 0xFF, 0xFF), - "hotpink" => array(0xFF, 0x69, 0x69), - "indianred" => array(0xCD, 0x5C, 0x5C), - "indigo" => array(0x4B, 0x00, 0x00), - "ivory" => array(0xFF, 0xFF, 0xFF), - "khaki" => array(0xF0, 0xE6, 0xE6), - "lavender" => array(0xE6, 0xE6, 0xE6), - "lavenderblush" => array(0xFF, 0xF0, 0xF0), - "lawngreen" => array(0x7C, 0xFC, 0xFC), - "lemonchiffon" => array(0xFF, 0xFA, 0xFA), - "lightblue" => array(0xAD, 0xD8, 0xD8), - "lightcoral" => array(0xF0, 0x80, 0x80), - "lightcyan" => array(0xE0, 0xFF, 0xFF), + "aliceblue" => array(0xF0, 0xF8, 0xF8), + "antiquewhite" => array(0xFA, 0xEB, 0xEB), + "aquamarine" => array(0x7F, 0xFF, 0xFF), + "azure" => array(0xF0, 0xFF, 0xFF), + "beige" => array(0xF5, 0xF5, 0xF5), + "blueviolet" => array(0x8A, 0x2B, 0x2B), + "brown" => array(0xA5, 0x2A, 0x2A), + "burlywood" => array(0xDE, 0xB8, 0xB8), + "cadetblue" => array(0x5F, 0x9E, 0x9E), + "chartreuse" => array(0x7F, 0xFF, 0xFF), + "chocolate" => array(0xD2, 0x69, 0x69), + "coral" => array(0xFF, 0x7F, 0x7F), + "cornflowerblue" => array(0x64, 0x95, 0x95), + "cornsilk" => array(0xFF, 0xF8, 0xF8), + "crimson" => array(0xDC, 0x14, 0x14), + "darkblue" => array(0x00, 0x00, 0x00), + "darkcyan" => array(0x00, 0x8B, 0x8B), + "darkgoldenrod" => array(0xB8, 0x86, 0x86), + "darkgray" => array(0xA9, 0xA9, 0xA9), + "darkgreen" => array(0x00, 0x64, 0x64), + "darkkhaki" => array(0xBD, 0xB7, 0xB7), + "darkmagenta" => array(0x8B, 0x00, 0x00), + "darkolivegreen" => array(0x55, 0x6B, 0x6B), + "darkorange" => array(0xFF, 0x8C, 0x8C), + "darkorchid" => array(0x99, 0x32, 0x32), + "darkred" => array(0x8B, 0x00, 0x00), + "darksalmon" => array(0xE9, 0x96, 0x96), + "darkseagreen" => array(0x8F, 0xBC, 0xBC), + "darkslateblue" => array(0x48, 0x3D, 0x3D), + "darkslategray" => array(0x2F, 0x4F, 0x4F), + "darkturquoise" => array(0x00, 0xCE, 0xCE), + "darkviolet" => array(0x94, 0x00, 0x00), + "deeppink" => array(0xFF, 0x14, 0x14), + "deepskyblue" => array(0x00, 0xBF, 0xBF), + "dimgray" => array(0x69, 0x69, 0x69), + "dodgerblue" => array(0x1E, 0x90, 0x90), + "firebrick" => array(0xB2, 0x22, 0x22), + "floralwhite" => array(0xFF, 0xFA, 0xFA), + "forestgreen" => array(0x22, 0x8B, 0x8B), + "gainsboro" => array(0xDC, 0xDC, 0xDC), + "ghostwhite" => array(0xF8, 0xF8, 0xF8), + "gold" => array(0xFF, 0xD7, 0xD7), + "goldenrod" => array(0xDA, 0xA5, 0xA5), + "greenyellow" => array(0xAD, 0xFF, 0xFF), + "honeydew" => array(0xF0, 0xFF, 0xFF), + "hotpink" => array(0xFF, 0x69, 0x69), + "indianred" => array(0xCD, 0x5C, 0x5C), + "indigo" => array(0x4B, 0x00, 0x00), + "ivory" => array(0xFF, 0xFF, 0xFF), + "khaki" => array(0xF0, 0xE6, 0xE6), + "lavender" => array(0xE6, 0xE6, 0xE6), + "lavenderblush" => array(0xFF, 0xF0, 0xF0), + "lawngreen" => array(0x7C, 0xFC, 0xFC), + "lemonchiffon" => array(0xFF, 0xFA, 0xFA), + "lightblue" => array(0xAD, 0xD8, 0xD8), + "lightcoral" => array(0xF0, 0x80, 0x80), + "lightcyan" => array(0xE0, 0xFF, 0xFF), "lightgoldenrodyellow" => array(0xFA, 0xFA, 0xFA), - "lightgreen" => array(0x90, 0xEE, 0xEE), - "lightgrey" => array(0xD3, 0xD3, 0xD3), - "lightpink" => array(0xFF, 0xB6, 0xB6), - "lightsalmon" => array(0xFF, 0xA0, 0xA0), - "lightseagreen" => array(0x20, 0xB2, 0xB2), - "lightskyblue" => array(0x87, 0xCE, 0xCE), - "lightslategray" => array(0x77, 0x88, 0x88), - "lightsteelblue" => array(0xB0, 0xC4, 0xC4), - "lightyellow" => array(0xFF, 0xFF, 0xFF), - "limegreen" => array(0x32, 0xCD, 0xCD), - "linen" => array(0xFA, 0xF0, 0xF0), - "mediumaquamarine" => array(0x66, 0xCD, 0xCD), - "mediumblue" => array(0x00, 0x00, 0x00), - "mediumorchid" => array(0xBA, 0x55, 0x55), - "mediumpurple" => array(0x93, 0x70, 0x70), - "mediumseagreen" => array(0x3C, 0xB3, 0xB3), - "mediumslateblue" => array(0x7B, 0x68, 0x68), - "mediumspringgreen" => array(0x00, 0xFA, 0xFA), - "mediumturquoise" => array(0x48, 0xD1, 0xD1), - "mediumvioletred" => array(0xC7, 0x15, 0x15), - "midnightblue" => array(0x19, 0x19, 0x19), - "mintcream" => array(0xF5, 0xFF, 0xFF), - "mistyrose" => array(0xFF, 0xE4, 0xE4), - "moccasin" => array(0xFF, 0xE4, 0xE4), - "navajowhite" => array(0xFF, 0xDE, 0xDE), - "oldlace" => array(0xFD, 0xF5, 0xF5), - "olivedrab" => array(0x6B, 0x8E, 0x8E), - "orange" => array(0xFF, 0xA5, 0xA5), - "orangered" => array(0xFF, 0x45, 0x45), - "orchid" => array(0xDA, 0x70, 0x70), - "palegoldenrod" => array(0xEE, 0xE8, 0xE8), - "palegreen" => array(0x98, 0xFB, 0xFB), - "paleturquoise" => array(0xAF, 0xEE, 0xEE), - "palevioletred" => array(0xDB, 0x70, 0x70), - "papayawhip" => array(0xFF, 0xEF, 0xEF), - "peachpuff" => array(0xFF, 0xDA, 0xDA), - "peru" => array(0xCD, 0x85, 0x85), - "pink" => array(0xFF, 0xC0, 0xC0), - "plum" => array(0xDD, 0xA0, 0xA0), - "powderblue" => array(0xB0, 0xE0, 0xE0), - "rosybrown" => array(0xBC, 0x8F, 0x8F), - "royalblue" => array(0x41, 0x69, 0x69), - "saddlebrown" => array(0x8B, 0x45, 0x45), - "salmon" => array(0xFA, 0x80, 0x80), - "sandybrown" => array(0xF4, 0xA4, 0xA4), - "seagreen" => array(0x2E, 0x8B, 0x8B), - "seashell" => array(0xFF, 0xF5, 0xF5), - "sienna" => array(0xA0, 0x52, 0x52), - "skyblue" => array(0x87, 0xCE, 0xCE), - "slateblue" => array(0x6A, 0x5A, 0x5A), - "slategray" => array(0x70, 0x80, 0x80), - "snow" => array(0xFF, 0xFA, 0xFA), - "springgreen" => array(0x00, 0xFF, 0xFF), - "steelblue" => array(0x46, 0x82, 0x82), - "tan" => array(0xD2, 0xB4, 0xB4), - "thistle" => array(0xD8, 0xBF, 0xBF), - "tomato" => array(0xFF, 0x63, 0x63), - "turquoise" => array(0x40, 0xE0, 0xE0), - "violet" => array(0xEE, 0x82, 0x82), - "wheat" => array(0xF5, 0xDE, 0xDE), - "whitesmoke" => array(0xF5, 0xF5, 0xF5), - "yellowgreen" => array(0x9A, 0xCD, 0xCD) + "lightgreen" => array(0x90, 0xEE, 0xEE), + "lightgrey" => array(0xD3, 0xD3, 0xD3), + "lightpink" => array(0xFF, 0xB6, 0xB6), + "lightsalmon" => array(0xFF, 0xA0, 0xA0), + "lightseagreen" => array(0x20, 0xB2, 0xB2), + "lightskyblue" => array(0x87, 0xCE, 0xCE), + "lightslategray" => array(0x77, 0x88, 0x88), + "lightsteelblue" => array(0xB0, 0xC4, 0xC4), + "lightyellow" => array(0xFF, 0xFF, 0xFF), + "limegreen" => array(0x32, 0xCD, 0xCD), + "linen" => array(0xFA, 0xF0, 0xF0), + "mediumaquamarine" => array(0x66, 0xCD, 0xCD), + "mediumblue" => array(0x00, 0x00, 0x00), + "mediumorchid" => array(0xBA, 0x55, 0x55), + "mediumpurple" => array(0x93, 0x70, 0x70), + "mediumseagreen" => array(0x3C, 0xB3, 0xB3), + "mediumslateblue" => array(0x7B, 0x68, 0x68), + "mediumspringgreen" => array(0x00, 0xFA, 0xFA), + "mediumturquoise" => array(0x48, 0xD1, 0xD1), + "mediumvioletred" => array(0xC7, 0x15, 0x15), + "midnightblue" => array(0x19, 0x19, 0x19), + "mintcream" => array(0xF5, 0xFF, 0xFF), + "mistyrose" => array(0xFF, 0xE4, 0xE4), + "moccasin" => array(0xFF, 0xE4, 0xE4), + "navajowhite" => array(0xFF, 0xDE, 0xDE), + "oldlace" => array(0xFD, 0xF5, 0xF5), + "olivedrab" => array(0x6B, 0x8E, 0x8E), + "orange" => array(0xFF, 0xA5, 0xA5), + "orangered" => array(0xFF, 0x45, 0x45), + "orchid" => array(0xDA, 0x70, 0x70), + "palegoldenrod" => array(0xEE, 0xE8, 0xE8), + "palegreen" => array(0x98, 0xFB, 0xFB), + "paleturquoise" => array(0xAF, 0xEE, 0xEE), + "palevioletred" => array(0xDB, 0x70, 0x70), + "papayawhip" => array(0xFF, 0xEF, 0xEF), + "peachpuff" => array(0xFF, 0xDA, 0xDA), + "peru" => array(0xCD, 0x85, 0x85), + "pink" => array(0xFF, 0xC0, 0xC0), + "plum" => array(0xDD, 0xA0, 0xA0), + "powderblue" => array(0xB0, 0xE0, 0xE0), + "rosybrown" => array(0xBC, 0x8F, 0x8F), + "royalblue" => array(0x41, 0x69, 0x69), + "saddlebrown" => array(0x8B, 0x45, 0x45), + "salmon" => array(0xFA, 0x80, 0x80), + "sandybrown" => array(0xF4, 0xA4, 0xA4), + "seagreen" => array(0x2E, 0x8B, 0x8B), + "seashell" => array(0xFF, 0xF5, 0xF5), + "sienna" => array(0xA0, 0x52, 0x52), + "skyblue" => array(0x87, 0xCE, 0xCE), + "slateblue" => array(0x6A, 0x5A, 0x5A), + "slategray" => array(0x70, 0x80, 0x80), + "snow" => array(0xFF, 0xFA, 0xFA), + "springgreen" => array(0x00, 0xFF, 0xFF), + "steelblue" => array(0x46, 0x82, 0x82), + "tan" => array(0xD2, 0xB4, 0xB4), + "thistle" => array(0xD8, 0xBF, 0xBF), + "tomato" => array(0xFF, 0x63, 0x63), + "turquoise" => array(0x40, 0xE0, 0xE0), + "violet" => array(0xEE, 0x82, 0x82), + "wheat" => array(0xF5, 0xDE, 0xDE), + "whitesmoke" => array(0xF5, 0xF5, 0xF5), + "yellowgreen" => array(0x9A, 0xCD, 0xCD) ); - if(array_key_exists(strtolower($nameOrHex), $colors)) { + if (array_key_exists(strtolower($nameOrHex), $colors)) { return $colors[strtolower($nameOrHex)]; } throw new \RuntimeException('Can not parse color definition "' . $nameOrHex . '".'); } } - diff --git a/Component/ImageExportService.php b/Component/ImageExportService.php index 49ac0162..8815e0f3 100644 --- a/Component/ImageExportService.php +++ b/Component/ImageExportService.php @@ -1,4 +1,5 @@ requests[$i] = $layer['url']; } - if(isset($this->data['vectorLayers'])){ - foreach ($this->data['vectorLayers'] as $idx => $layer){ + if (isset($this->data['vectorLayers'])) { + foreach ($this->data['vectorLayers'] as $idx => $layer) { $this->data['vectorLayers'][$idx] = json_decode($this->data['vectorLayers'][$idx], true); } } @@ -44,20 +45,19 @@ private function getImages() { $temp_names = array(); foreach ($this->requests as $k => $url) { - $url = strstr($url, '&WIDTH', true); $width = '&WIDTH=' . $this->data['width']; $height = '&HEIGHT=' . $this->data['height']; $url .= $width . $height; - + $this->container->get("logger")->debug("Image Export Request Nr.: " . $k . ' ' . $url); - $parsed = parse_url($url); + $parsed = parse_url($url); $hostpath = $parsed['host'] . $parsed['path']; - $pos = strpos($hostpath, $this->urlHostPath); + $pos = strpos($hostpath, $this->urlHostPath); if ($pos === 0 && ($routeStr = substr($hostpath, strlen($this->urlHostPath))) !== false) { $attributes = $this->container->get('router')->match($routeStr); - $gets = array(); + $gets = array(); parse_str($parsed['query'], $gets); $subRequest = new Request($gets, array(), $attributes, array(), array(), array(), ''); } else { @@ -74,19 +74,19 @@ private function getImages() file_put_contents($imagename, $response->getContent()); $rawImage = null; switch (trim($response->headers->get('content-type'))) { - case 'image/png' : + case 'image/png': $rawImage = imagecreatefrompng($imagename); break; - case 'image/png8' : + case 'image/png8': $rawImage = imagecreatefrompng($imagename); break; - case 'image/png; mode=24bit' : + case 'image/png; mode=24bit': $rawImage = imagecreatefrompng($imagename); break; - case 'image/jpeg' : + case 'image/jpeg': $rawImage = imagecreatefromjpeg($imagename); break; - case 'image/gif' : + case 'image/gif': $rawImage = imagecreatefromgif($imagename); break; default: @@ -107,7 +107,7 @@ private function getImages() // Taking the painful way to alpha blending. Stupid PHP-GD $opacity = floatVal($this->data['requests'][$k]['opacity']); - if(1.0 !== $opacity) { + if (1.0 !== $opacity) { for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $colorIn = imagecolorsforindex($image, imagecolorat($image, $x, $y)); @@ -118,7 +118,8 @@ private function getImages() $colorIn['red'], $colorIn['green'], $colorIn['blue'], - $alphaOut); + $alphaOut + ); imagesetpixel($image, $x, $y, $colorOut); imagecolordeallocate($image, $colorOut); } @@ -171,11 +172,11 @@ private function drawFeatures($finalImageName) imagesavealpha($image, true); imagealphablending($image, true); - foreach($this->data['vectorLayers'] as $idx => $layer) { - foreach($layer['geometries'] as $geometry) { + foreach ($this->data['vectorLayers'] as $idx => $layer) { + foreach ($layer['geometries'] as $geometry) { $renderMethodName = 'draw' . $geometry['type']; - if(!method_exists($this, $renderMethodName)) { + if (!method_exists($this, $renderMethodName)) { continue; //throw new \RuntimeException('Can not draw geometries of type "' . $geometry['type'] . '".'); } @@ -190,7 +191,7 @@ private function getColor($color, $alpha, $image) { list($r, $g, $b) = CSSColorParser::parse($color); - if(0 == $alpha) { + if (0 == $alpha) { return ImageColorAllocate($image, $r, $g, $b); } else { $a = (1 - $alpha) * 127.0; @@ -200,31 +201,33 @@ private function getColor($color, $alpha, $image) private function drawPolygon($geometry, $image) { - foreach($geometry['coordinates'] as $ring) { - if(count($ring) < 3) { + foreach ($geometry['coordinates'] as $ring) { + if (count($ring) < 3) { continue; } $points = array(); - foreach($ring as $c) { + foreach ($ring as $c) { $p = $this->realWorld2mapPos($c[0], $c[1]); $points[] = floatval($p[0]); $points[] = floatval($p[1]); } imagesetthickness($image, 0); // Filled area - if($geometry['style']['fillOpacity'] > 0){ + if ($geometry['style']['fillOpacity'] > 0) { $color = $this->getColor( $geometry['style']['fillColor'], $geometry['style']['fillOpacity'], - $image); + $image + ); imagefilledpolygon($image, $points, count($ring), $color); } // Border $color = $this->getColor( $geometry['style']['strokeColor'], $geometry['style']['strokeOpacity'], - $image); + $image + ); imagesetthickness($image, $geometry['style']['strokeWidth']); imagepolygon($image, $points, count($ring), $color); } @@ -232,31 +235,33 @@ private function drawPolygon($geometry, $image) private function drawMultiPolygon($geometry, $image) { - foreach($geometry['coordinates'][0] as $ring) { - if(count($ring) < 3) { + foreach ($geometry['coordinates'][0] as $ring) { + if (count($ring) < 3) { continue; } $points = array(); - foreach($ring as $c) { + foreach ($ring as $c) { $p = $this->realWorld2mapPos($c[0], $c[1]); $points[] = floatval($p[0]); $points[] = floatval($p[1]); } imagesetthickness($image, 0); // Filled area - if($geometry['style']['fillOpacity'] > 0){ + if ($geometry['style']['fillOpacity'] > 0) { $color = $this->getColor( $geometry['style']['fillColor'], $geometry['style']['fillOpacity'], - $image); + $image + ); imagefilledpolygon($image, $points, count($ring), $color); } // Border $color = $this->getColor( $geometry['style']['strokeColor'], $geometry['style']['strokeOpacity'], - $image); + $image + ); imagesetthickness($image, $geometry['style']['strokeWidth']); imagepolygon($image, $points, count($ring), $color); } @@ -267,17 +272,19 @@ private function drawLineString($geometry, $image) $color = $this->getColor( $geometry['style']['strokeColor'], $geometry['style']['strokeOpacity'], - $image); + $image + ); imagesetthickness($image, $geometry['style']['strokeWidth']); - for($i = 1; $i < count($geometry['coordinates']); $i++) { - + for ($i = 1; $i < count($geometry['coordinates']); $i++) { $from = $this->realWorld2mapPos( $geometry['coordinates'][$i - 1][0], - $geometry['coordinates'][$i - 1][1]); + $geometry['coordinates'][$i - 1][1] + ); $to = $this->realWorld2mapPos( $geometry['coordinates'][$i][0], - $geometry['coordinates'][$i][1]); + $geometry['coordinates'][$i][1] + ); imageline($image, $from[0], $from[1], $to[0], $to[1], $color); } @@ -289,38 +296,40 @@ private function drawPoint($geometry, $image) $p = $this->realWorld2mapPos($c[0], $c[1]); - if(isset($geometry['style']['label'])){ + if (isset($geometry['style']['label'])) { // draw label with white halo $color = $this->getColor('#ff0000', 1, $image); $bgcolor = $this->getColor('#ffffff', 1, $image); $fontPath = $this->container->getParameter('kernel.root_dir') . '/Resources/MapbenderPrintBundle/fonts/'; $font = $fontPath . 'OpenSans-Bold.ttf'; - imagettftext($image, 14, 0, $p[0], $p[1]+1, $bgcolor, $font, $geometry['style']['label']); - imagettftext($image, 14, 0, $p[0], $p[1]-1, $bgcolor, $font, $geometry['style']['label']); - imagettftext($image, 14, 0, $p[0]-1, $p[1], $bgcolor, $font, $geometry['style']['label']); - imagettftext($image, 14, 0, $p[0]+1, $p[1], $bgcolor, $font, $geometry['style']['label']); + imagettftext($image, 14, 0, $p[0], $p[1] + 1, $bgcolor, $font, $geometry['style']['label']); + imagettftext($image, 14, 0, $p[0], $p[1] - 1, $bgcolor, $font, $geometry['style']['label']); + imagettftext($image, 14, 0, $p[0] - 1, $p[1], $bgcolor, $font, $geometry['style']['label']); + imagettftext($image, 14, 0, $p[0] + 1, $p[1], $bgcolor, $font, $geometry['style']['label']); imagettftext($image, 14, 0, $p[0], $p[1], $color, $font, $geometry['style']['label']); return; } $radius = $geometry['style']['pointRadius']; // Filled circle - if($geometry['style']['fillOpacity'] > 0){ + if ($geometry['style']['fillOpacity'] > 0) { $color = $this->getColor( $geometry['style']['fillColor'], $geometry['style']['fillOpacity'], - $image); - imagefilledellipse($image, $p[0], $p[1], 2*$radius, 2*$radius, $color); + $image + ); + imagefilledellipse($image, $p[0], $p[1], 2 * $radius, 2 * $radius, $color); } // Circle border $color = $this->getColor( $geometry['style']['strokeColor'], $geometry['style']['strokeOpacity'], - $image); - imageellipse($image, $p[0], $p[1], 2*$radius, 2*$radius, $color); + $image + ); + imageellipse($image, $p[0], $p[1], 2 * $radius, 2 * $radius, $color); } - private function realWorld2mapPos($rw_x,$rw_y) + private function realWorld2mapPos($rw_x, $rw_y) { $quality = 72; $map_width = $this->data['extentwidth']; @@ -336,14 +345,14 @@ private function realWorld2mapPos($rw_x,$rw_y) $maxX = $centerx + $map_width * 0.5; $maxY = $centery + $map_height * 0.5; - $extentx = $maxX - $minX ; - $extenty = $maxY - $minY ; + $extentx = $maxX - $minX; + $extenty = $maxY - $minY; - $pixPos_x = (($rw_x - $minX)/$extentx) * $width; - $pixPos_y = (($maxY - $rw_y)/$extenty) * $height; + $pixPos_x = (($rw_x - $minX) / $extentx) * $width; + $pixPos_y = (($maxY - $rw_y) / $extenty) * $height; $pixPos = array($pixPos_x, $pixPos_y); - return $pixPos; + return $pixPos; } } diff --git a/Component/OdgParser.php b/Component/OdgParser.php index 9cc162e5..128e6209 100644 --- a/Component/OdgParser.php +++ b/Component/OdgParser.php @@ -1,4 +1,5 @@ container->getParameter('kernel.root_dir') . '/Resources/MapbenderPrintBundle'; $odgfile = $resource_dir . '/templates/' . $template . '.odg'; - if(!is_file($odgfile)){ + if (!is_file($odgfile)) { throw new Exception("Print template '$template' doesn't exists."); } @@ -113,21 +114,21 @@ public function getConf($template) if ($name == '') { continue; } - $width = $node->getAttribute('svg:width'); + $width = $node->getAttribute('svg:width'); $height = $node->getAttribute('svg:height'); - $x = $node->getAttribute('svg:x'); - $y = $node->getAttribute('svg:y'); - $field = array( - 'font' => 'Arial', - 'width' => substr($width, 0, -2) * 10, - 'height' => substr($height, 0, -2) * 10, - 'x' => substr($x, 0, -2) * 10, - 'y' => substr($y, 0, -2) * 10, + $x = $node->getAttribute('svg:x'); + $y = $node->getAttribute('svg:y'); + $field = array( + 'font' => 'Arial', + 'width' => substr($width, 0, -2) * 10, + 'height' => substr($height, 0, -2) * 10, + 'x' => substr($x, 0, -2) * 10, + 'y' => substr($y, 0, -2) * 10, ); // Recognize font name and size $textParagraph = $xpath->query("draw:text-box/text:p", $node)->item(0); - $textNode = $xpath->query("draw:text-box/text:p/text:span", $node)->item(0); + $textNode = $xpath->query("draw:text-box/text:p/text:span", $node)->item(0); if ($textNode) { $style = $textNode->getAttribute('text:style-name'); } elseif ($textParagraph) { @@ -140,8 +141,8 @@ public function getConf($template) } $field['fontsize'] = $fontsize != '' ? $fontsize : '10pt'; $field['color'] = $color != '' ? $color : '#000000'; - $data['fields'][ $name ] = $field; + $data['fields'][$name] = $field; } return $data; } -} \ No newline at end of file +} diff --git a/Component/PDF_Extensions.php b/Component/PDF_Extensions.php index 3f15bf7e..bd3a9273 100644 --- a/Component/PDF_Extensions.php +++ b/Component/PDF_Extensions.php @@ -21,21 +21,27 @@ public function getWidth() return $this->w; } - - function TextWithDirection($x, $y, $txt, $direction='R') + + public function TextWithDirection($x, $y, $txt, $direction = 'R') { - if ($direction=='R') - $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 1, 0, 0, 1, $x*$this->k, ($this->h-$y)*$this->k, $this->_escape($txt)); - elseif ($direction=='L') - $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', -1, 0, 0, -1, $x*$this->k, ($this->h-$y)*$this->k, $this->_escape($txt)); - elseif ($direction=='U') - $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 0, 1, -1, 0, $x*$this->k, ($this->h-$y)*$this->k, $this->_escape($txt)); - elseif ($direction=='D') - $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 0, -1, 1, 0, $x*$this->k, ($this->h-$y)*$this->k, $this->_escape($txt)); - else - $s=sprintf('BT %.2F %.2F Td (%s) Tj ET', $x*$this->k, ($this->h-$y)*$this->k, $this->_escape($txt)); - if ($this->ColorFlag) - $s='q '.$this->TextColor.' '.$s.' Q'; + if ($direction == 'R') { + $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 1, 0, 0, 1, $x * $this->k, + ($this->h - $y) * $this->k, $this->_escape($txt)); + } elseif ($direction == 'L') { + $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', -1, 0, 0, -1, $x * $this->k, + ($this->h - $y) * $this->k, $this->_escape($txt)); + } elseif ($direction == 'U') { + $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 0, 1, -1, 0, $x * $this->k, + ($this->h - $y) * $this->k, $this->_escape($txt)); + } elseif ($direction == 'D') { + $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 0, -1, 1, 0, $x * $this->k, + ($this->h - $y) * $this->k, $this->_escape($txt)); + } else { + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); + } + if ($this->ColorFlag) { + $s = 'q ' . $this->TextColor . ' ' . $s . ' Q'; + } $this->_out($s); } -} \ No newline at end of file +} diff --git a/Component/PrintService.php b/Component/PrintService.php index 231b343e..717b4439 100644 --- a/Component/PrintService.php +++ b/Component/PrintService.php @@ -1,9 +1,10 @@ setup($data); - + if ($data['rotation'] == 0) { $this->createFinalMapImage(); } else { @@ -65,13 +66,13 @@ private function setup($data) $this->tempDir = sys_get_temp_dir(); // resource dir $this->resourceDir = $this->container->getParameter('kernel.root_dir') . '/Resources/MapbenderPrintBundle'; - + // get user /** @var SecurityContext $securityContext */ $securityContext = $this->container->get('security.context'); - $token = $securityContext->getToken(); - $this->user = $token->getUser(); - + $token = $securityContext->getToken(); + $this->user = $token->getUser(); + // data from client $this->data = $data; @@ -93,7 +94,7 @@ private function setup($data) $this->mapRequests[$i] = $url; } - if(isset($this->data['replace_pattern'])){ + if (isset($this->data['replace_pattern'])) { $this->addReplacePattern(); } @@ -112,9 +113,9 @@ private function setup($data) $maxY = $centery + $extentHeight * 0.5; $width = '&WIDTH=' . $this->imageWidth; - $height = '&HEIGHT=' . $this->imageHeight; - }else{ - // calculate needed bbox + $height = '&HEIGHT=' . $this->imageHeight; + } else { + // calculate needed bbox $neededExtentWidth = abs(sin(deg2rad($rotation)) * $extentHeight) + abs(cos(deg2rad($rotation)) * $extentWidth); $neededExtentHeight = abs(sin(deg2rad($rotation)) * $extentWidth) + @@ -138,14 +139,14 @@ private function setup($data) $this->neededImageHeight = $neededImageHeight; $width = '&WIDTH=' . $neededImageWidth; - $height = '&HEIGHT=' . $neededImageHeight; + $height = '&HEIGHT=' . $neededImageHeight; } foreach ($this->mapRequests as $i => $request) { $request .= '&BBOX=' . $minX . ',' . $minY . ',' . $maxX . ',' . $maxY; $request .= $width . $height; - if(!isset($this->data['replace_pattern'])){ + if (!isset($this->data['replace_pattern'])) { if ($this->data['quality'] != '72') { $request .= '&map_resolution=' . $this->data['quality']; } @@ -161,24 +162,23 @@ private function addReplacePattern() $default = ''; foreach ($this->mapRequests as $k => $url) { foreach ($this->data['replace_pattern'] as $rKey => $pattern) { - if(isset($pattern['default'])){ - if(isset($pattern['default'][$quality])){ + if (isset($pattern['default'])) { + if (isset($pattern['default'][$quality])) { $default = $pattern['default'][$quality]; } continue; } - if(strpos($url,$pattern['pattern']) === false){ + if (strpos($url, $pattern['pattern']) === false) { continue; } - if(strpos($url,$pattern['pattern']) !== false){ - if(isset($pattern['replacement'][$quality])){ + if (strpos($url, $pattern['pattern']) !== false) { + if (isset($pattern['replacement'][$quality])) { $url = str_replace($pattern['pattern'], $pattern['replacement'][$quality], $url); $signer = $this->container->get('signer'); $this->mapRequests[$k] = $signer->signUrl($url); continue 2; } } - } $url .= $default; $this->mapRequests[$k] = $url; @@ -199,7 +199,7 @@ private function createFinalMapImage() foreach ($imageNames as $imageName) { // Note: suppressing the errors IS bad, bad PHP wants us to do it that way - $src = imagecreatefrompng($imageName); + $src = imagecreatefrompng($imageName); // Check that imagecreatefrompng did yield something if ($src) { $dest = $finalImage; @@ -220,7 +220,7 @@ private function createFinalRotatedMapImage() $imageWidth = $this->imageWidth; $imageHeight = $this->imageHeight; - $imageNames = $this->getImages($neededImageWidth,$neededImageHeight); + $imageNames = $this->getImages($neededImageWidth, $neededImageHeight); // create temp merged image $tempImageName = tempnam($this->tempDir, 'mb_print_temp'); @@ -235,8 +235,16 @@ private function createFinalRotatedMapImage() // Check that imagecreatefrompng did yield something if ($src) { $dest = imagecreatefrompng($tempImageName); - imagecopy($dest, $src, 0, 0, 0, 0, $neededImageWidth, - $neededImageHeight); + imagecopy( + $dest, + $src, + 0, + 0, + 0, + 0, + $neededImageWidth, + $neededImageHeight + ); imagepng($dest, $tempImageName); unlink($imageName); } @@ -262,14 +270,22 @@ private function createFinalRotatedMapImage() abs(cos(deg2rad($rotation)) * $neededImageWidth)); $rotatedHeight = round(abs(sin(deg2rad($rotation)) * $neededImageWidth) + abs(cos(deg2rad($rotation)) * $neededImageHeight)); - $newx = ($rotatedWidth - $imageWidth ) / 2; - $newy = ($rotatedHeight - $imageHeight ) / 2; + $newx = ($rotatedWidth - $imageWidth) / 2; + $newy = ($rotatedHeight - $imageHeight) / 2; $clippedImage = imagecreatetruecolor($imageWidth, $imageHeight); imagealphablending($clippedImage, false); imagesavealpha($clippedImage, true); - imagecopy($clippedImage, $rotatedImage, 0, 0, $newx, $newy, - $imageWidth, $imageHeight); + imagecopy( + $clippedImage, + $rotatedImage, + 0, + 0, + $newx, + $newy, + $imageWidth, + $imageHeight + ); $this->finalImageName = tempnam($this->tempDir, 'mb_print_final'); imagepng($clippedImage, $this->finalImageName); @@ -277,18 +293,18 @@ private function createFinalRotatedMapImage() private function getImages($width, $height) { - $logger = $this->container->get("logger"); - $imageNames = array(); + $logger = $this->container->get("logger"); + $imageNames = array(); foreach ($this->mapRequests as $i => $url) { $logger->debug("Print Request Nr.: " . $i . ' ' . $url); // find urls from this host (tunnel connection for secured services) - $parsed = parse_url($url); + $parsed = parse_url($url); $host = isset($parsed['host']) ? $parsed['host'] : $this->container->get('request')->getHttpHost(); $hostpath = $host . $parsed['path']; - $pos = strpos($hostpath, $this->urlHostPath); + $pos = strpos($hostpath, $this->urlHostPath); if ($pos === 0 && ($routeStr = substr($hostpath, strlen($this->urlHostPath))) !== false) { $attributes = $this->container->get('router')->match($routeStr); - $gets = array(); + $gets = array(); parse_str($parsed['query'], $gets); $subRequest = new Request($gets, array(), $attributes, array(), array(), array(), ''); } else { @@ -299,29 +315,29 @@ private function getImages($width, $height) } $response = $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); - $imageName = tempnam($this->tempDir, 'mb_print'); + $imageName = tempnam($this->tempDir, 'mb_print'); $imageNames[] = $imageName; file_put_contents($imageName, $response->getContent()); $rawImage = null; switch (trim($response->headers->get('content-type'))) { - case 'image/png' : + case 'image/png': $rawImage = imagecreatefrompng($imageName); break; - case 'image/png8' : + case 'image/png8': $rawImage = imagecreatefrompng($imageName); break; - case 'image/png; mode=24bit' : + case 'image/png; mode=24bit': $rawImage = imagecreatefrompng($imageName); break; - case 'image/jpeg' : + case 'image/jpeg': $rawImage = imagecreatefromjpeg($imageName); break; - case 'image/gif' : + case 'image/gif': $rawImage = imagecreatefromgif($imageName); break; - case 'image/bmp' : + case 'image/bmp': $logger->debug("Unsupported mimetype image/bmp"); print_r("Unsupported mimetype image/bmp"); break; @@ -346,15 +362,20 @@ private function getImages($width, $height) // Taking the painful way to alpha blending. Stupid PHP-GD $opacity = floatVal($this->data['layers'][$i]['opacity']); if (1.0 !== $opacity) { - $width = imagesx($image); + $width = imagesx($image); $height = imagesy($image); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { - $colorIn = imagecolorsforindex($image, imagecolorat($image, $x, $y)); + $colorIn = imagecolorsforindex($image, imagecolorat($image, $x, $y)); $alphaOut = 127 - (127 - $colorIn['alpha']) * $opacity; $colorOut = imagecolorallocatealpha( - $image, $colorIn['red'], $colorIn['green'], $colorIn['blue'], $alphaOut); + $image, + $colorIn['red'], + $colorIn['green'], + $colorIn['blue'], + $alphaOut + ); imagesetpixel($image, $x, $y, $colorOut); imagecolordeallocate($image, $colorOut); } @@ -371,11 +392,11 @@ private function buildPdf() require_once('PDF_Extensions.php'); // set format - if($this->conf['orientation'] == 'portrait'){ - $format = array($this->conf['pageSize']['width'],$this->conf['pageSize']['height']); + if ($this->conf['orientation'] == 'portrait') { + $format = array($this->conf['pageSize']['width'], $this->conf['pageSize']['height']); $orientation = 'P'; - }else{ - $format = array($this->conf['pageSize']['height'],$this->conf['pageSize']['width']); + } else { + $format = array($this->conf['pageSize']['height'], $this->conf['pageSize']['width']); $orientation = 'L'; } @@ -389,7 +410,7 @@ private function buildPdf() $pdf->addPage($orientation, $format); $hasTransparentBg = $this->checkPdfBackground($pdf); - if ($hasTransparentBg == false){ + if ($hasTransparentBg == false) { $pdf->useTemplate($tplidx); } @@ -399,13 +420,24 @@ private function buildPdf() $mapWidth = $this->conf['map']['width']; $mapHeight = $this->conf['map']['height']; - $pdf->Image($this->finalImageName, $mapUlX, $mapUlY, - $mapWidth, $mapHeight, 'png', '', false, 0, 5, -1 * 0); + $pdf->Image( + $this->finalImageName, + $mapUlX, + $mapUlY, + $mapWidth, + $mapHeight, + 'png', + '', + false, + 0, + 5, + -1 * 0 + ); // add map border (default is black) $pdf->Rect($mapUlX, $mapUlY, $mapWidth, $mapHeight); unlink($this->finalImageName); - if ($hasTransparentBg == true){ + if ($hasTransparentBg == true) { $pdf->useTemplate($tplidx); } @@ -421,47 +453,57 @@ private function buildPdf() } // fill text fields - if (isset($this->conf['fields']) ) { + if (isset($this->conf['fields'])) { foreach ($this->conf['fields'] as $k => $v) { list($r, $g, $b) = CSSColorParser::parse($this->conf['fields'][$k]['color']); - $pdf->SetTextColor($r,$g,$b); + $pdf->SetTextColor($r, $g, $b); $pdf->SetFont('Arial', '', $this->conf['fields'][$k]['fontsize']); - $pdf->SetXY($this->conf['fields'][$k]['x'] - 1, - $this->conf['fields'][$k]['y']); + $pdf->SetXY( + $this->conf['fields'][$k]['x'] - 1, + $this->conf['fields'][$k]['y'] + ); // continue if extent field is set - if(preg_match("/^extent/", $k)){ + if (preg_match("/^extent/", $k)) { continue; } switch ($k) { - case 'date' : + case 'date': $date = new \DateTime; - $pdf->Cell($this->conf['fields']['date']['width'], + $pdf->Cell( + $this->conf['fields']['date']['width'], $this->conf['fields']['date']['height'], - $date->format('d.m.Y')); + $date->format('d.m.Y') + ); break; - case 'scale' : - $pdf->Cell($this->conf['fields']['scale']['width'], + case 'scale': + $pdf->Cell( + $this->conf['fields']['scale']['width'], $this->conf['fields']['scale']['height'], - '1 : ' . $this->data['scale_select']); + '1 : ' . $this->data['scale_select'] + ); break; default: if (isset($this->data['extra'][$k])) { - $pdf->MultiCell($this->conf['fields'][$k]['width'], + $pdf->MultiCell( + $this->conf['fields'][$k]['width'], $this->conf['fields'][$k]['height'], - utf8_decode($this->data['extra'][$k])); + utf8_decode($this->data['extra'][$k]) + ); } // fill digitizer feature fields - if(preg_match("/^feature./", $k)){ - if($feature == false){ + if (preg_match("/^feature./", $k)) { + if ($feature == false) { continue; } $attribute = substr(strrchr($k, "."), 1); - $pdf->MultiCell($this->conf['fields'][$k]['width'], + $pdf->MultiCell( + $this->conf['fields'][$k]['width'], $this->conf['fields'][$k]['height'], - $feature->getAttribute($attribute)); + $feature->getAttribute($attribute) + ); } break; } @@ -469,39 +511,38 @@ private function buildPdf() } // reset text color to default black - $pdf->SetTextColor(0,0,0); + $pdf->SetTextColor(0, 0, 0); // add overview map - if (isset($this->data['overview']) && isset($this->conf['overview']) ) { + if (isset($this->data['overview']) && isset($this->conf['overview'])) { $this->addOverviewMap(); } // add scalebar - if (isset($this->conf['scalebar']) ) { + if (isset($this->conf['scalebar'])) { $this->addScaleBar(); } - + // add coordinates - if (isset($this->conf['fields']['extent_ur_x']) && isset($this->conf['fields']['extent_ur_y']) - && isset($this->conf['fields']['extent_ll_x']) && isset($this->conf['fields']['extent_ll_y'])) - { + if (isset($this->conf['fields']['extent_ur_x']) && isset($this->conf['fields']['extent_ur_y']) + && isset($this->conf['fields']['extent_ll_x']) && isset($this->conf['fields']['extent_ll_y'])) { $this->addCoordinates(); } - + // add dynamic logo - if (isset($this->conf['dynamic_image']) && $this->conf['dynamic_image']){ + if (isset($this->conf['dynamic_image']) && $this->conf['dynamic_image']) { $this->addDynamicImage(); } - + // add dynamic text if (isset($this->conf['fields']) && isset($this->conf['fields']['dynamic_text']) - && $this->conf['fields']['dynamic_text']){ + && $this->conf['fields']['dynamic_text']) { $this->addDynamicText(); } - + // add legend - if (isset($this->data['legends']) && !empty($this->data['legends'])){ + if (isset($this->data['legends']) && !empty($this->data['legends'])) { $this->addLegend(); } @@ -514,7 +555,7 @@ private function addNorthArrow() $rotation = $this->rotation; $rotatedImageName = null; - if($rotation != 0){ + if ($rotation != 0) { $image = imagecreatefrompng($northarrow); $transColor = imagecolorallocatealpha($image, 255, 255, 255, 0); $rotatedImage = imagerotate($image, $rotation, $transColor); @@ -536,13 +577,15 @@ private function addNorthArrow() $northarrow = $rotatedImageName; } - $this->pdf->Image($northarrow, - $this->conf['northarrow']['x'], - $this->conf['northarrow']['y'], - $this->conf['northarrow']['width'], - $this->conf['northarrow']['height'], - 'png'); - if($rotatedImageName){ + $this->pdf->Image( + $northarrow, + $this->conf['northarrow']['x'], + $this->conf['northarrow']['y'], + $this->conf['northarrow']['width'], + $this->conf['northarrow']['height'], + 'png' + ); + if ($rotatedImageName) { unlink($rotatedImageName); } } @@ -576,12 +619,12 @@ private function addOverviewMap() $logger->debug("Print Overview Request Nr.: " . $i . ' ' . $url); - $parsed = parse_url($url); + $parsed = parse_url($url); $hostpath = $parsed['host'] . $parsed['path']; - $pos = strpos($hostpath, $this->urlHostPath); + $pos = strpos($hostpath, $this->urlHostPath); if ($pos === 0 && ($routeStr = substr($hostpath, strlen($this->urlHostPath))) !== false) { $attributes = $this->container->get('router')->match($routeStr); - $gets = array(); + $gets = array(); parse_str($parsed['query'], $gets); $subRequest = new Request($gets, array(), $attributes, array(), array(), array(), ''); } else { @@ -598,13 +641,13 @@ private function addOverviewMap() file_put_contents($imageName, $response->getContent()); $im = null; switch (trim($response->headers->get('content-type'))) { - case 'image/png' : + case 'image/png': $im = imagecreatefrompng($imageName); break; - case 'image/jpeg' : + case 'image/jpeg': $im = imagecreatefromjpeg($imageName); break; - case 'image/gif' : + case 'image/gif': $im = imagecreatefromgif($imageName); break; default: @@ -621,8 +664,14 @@ private function addOverviewMap() $finalImageName = tempnam($this->tempdir, 'mb_print_merged'); $finalImage = imagecreatetruecolor($ovImageWidth, $ovImageHeight); $bg = ImageColorAllocate($finalImage, 255, 255, 255); - imagefilledrectangle($finalImage, 0, 0, $ovImageWidth, - $ovImageHeight, $bg); + imagefilledrectangle( + $finalImage, + 0, + 0, + $ovImageWidth, + $ovImageHeight, + $bg + ); imagepng($finalImage, $finalImageName); foreach ($tempNames as $tempName) { // Note: suppressing the errors IS bad, bad PHP wants us to do it that way @@ -631,8 +680,16 @@ private function addOverviewMap() if ($src) { $dest = imagecreatefrompng($finalImageName); $src = imagecreatefrompng($tempName); - imagecopy($dest, $src, 0, 0, 0, 0, $ovImageWidth, - $ovImageHeight); + imagecopy( + $dest, + $src, + 0, + 0, + 0, + 0, + $ovImageWidth, + $ovImageHeight + ); imagepng($dest, $finalImageName); } unlink($tempName); @@ -656,26 +713,30 @@ private function addOverviewMap() $p3 = $this->realWorld2ovMapPos($ovWidth, $ovHeight, $ur_x, $ur_y); $p4 = $this->realWorld2ovMapPos($ovWidth, $ovHeight, $lr_x, $lr_y); - $red = ImageColorAllocate($image,255,0,0); - imageline ( $image, $p1[0], $p1[1], $p2[0], $p2[1], $red); - imageline ( $image, $p2[0], $p2[1], $p3[0], $p3[1], $red); - imageline ( $image, $p3[0], $p3[1], $p4[0], $p4[1], $red); - imageline ( $image, $p4[0], $p4[1], $p1[0], $p1[1], $red); + $red = ImageColorAllocate($image, 255, 0, 0); + imageline($image, $p1[0], $p1[1], $p2[0], $p2[1], $red); + imageline($image, $p2[0], $p2[1], $p3[0], $p3[1], $red); + imageline($image, $p3[0], $p3[1], $p4[0], $p4[1], $red); + imageline($image, $p4[0], $p4[1], $p1[0], $p1[1], $red); imagepng($image, $finalImageName); // add image to pdf - $this->pdf->Image($finalImageName, - $this->conf['overview']['x'], - $this->conf['overview']['y'], - $this->conf['overview']['width'], - $this->conf['overview']['height'], - 'png'); + $this->pdf->Image( + $finalImageName, + $this->conf['overview']['x'], + $this->conf['overview']['y'], + $this->conf['overview']['width'], + $this->conf['overview']['height'], + 'png' + ); // draw border rectangle - $this->pdf->Rect($this->conf['overview']['x'], - $this->conf['overview']['y'], - $this->conf['overview']['width'], - $this->conf['overview']['height']); + $this->pdf->Rect( + $this->conf['overview']['x'], + $this->conf['overview']['y'], + $this->conf['overview']['width'], + $this->conf['overview']['height'] + ); unlink($finalImageName); } @@ -685,107 +746,119 @@ private function addScaleBar() $pdf = $this->pdf; $pdf->SetLineWidth(0.1); $pdf->SetDrawColor(0, 0, 0); - $pdf->SetFillColor(0,0,0); - $pdf->SetFont('arial', '', 10 ); + $pdf->SetFillColor(0, 0, 0); + $pdf->SetFont('arial', '', 10); $length = 0.01 * $this->data['scale_select'] * 5; $suffix = 'm'; - $pdf->Text( $this->conf['scalebar']['x'] -1 , $this->conf['scalebar']['y'] - 1 , '0' ); - $pdf->Text( $this->conf['scalebar']['x'] + 46, $this->conf['scalebar']['y'] - 1 , $length . '' . $suffix); + $pdf->Text($this->conf['scalebar']['x'] - 1, $this->conf['scalebar']['y'] - 1, '0'); + $pdf->Text($this->conf['scalebar']['x'] + 46, $this->conf['scalebar']['y'] - 1, $length . '' . $suffix); $pdf->Rect($this->conf['scalebar']['x'], $this->conf['scalebar']['y'], 10, 2, 'FD'); $pdf->SetFillColor(255, 255, 255); - $pdf->Rect($this->conf['scalebar']['x'] + 10 , $this->conf['scalebar']['y'], 10, 2, 'FD'); - $pdf->SetFillColor(0,0,0); - $pdf->Rect($this->conf['scalebar']['x'] + 20 , $this->conf['scalebar']['y'], 10, 2, 'FD'); + $pdf->Rect($this->conf['scalebar']['x'] + 10, $this->conf['scalebar']['y'], 10, 2, 'FD'); + $pdf->SetFillColor(0, 0, 0); + $pdf->Rect($this->conf['scalebar']['x'] + 20, $this->conf['scalebar']['y'], 10, 2, 'FD'); $pdf->SetFillColor(255, 255, 255); - $pdf->Rect($this->conf['scalebar']['x'] + 30 , $this->conf['scalebar']['y'], 10, 2, 'FD'); - $pdf->SetFillColor(0,0,0); - $pdf->Rect($this->conf['scalebar']['x'] + 40 , $this->conf['scalebar']['y'], 10, 2, 'FD'); + $pdf->Rect($this->conf['scalebar']['x'] + 30, $this->conf['scalebar']['y'], 10, 2, 'FD'); + $pdf->SetFillColor(0, 0, 0); + $pdf->Rect($this->conf['scalebar']['x'] + 40, $this->conf['scalebar']['y'], 10, 2, 'FD'); } - + private function addCoordinates() { $pdf = $this->pdf; - + $corrFactor = 2; $precision = 2; // correction factor and round precision if WGS84 - if($this->data['extent']['width'] < 1){ - $corrFactor = 3; - $precision = 6; + if ($this->data['extent']['width'] < 1) { + $corrFactor = 3; + $precision = 6; } - + // upper right Y $pdf->SetFont('Arial', '', $this->conf['fields']['extent_ur_y']['fontsize']); - $pdf->Text($this->conf['fields']['extent_ur_y']['x'] + $corrFactor, - $this->conf['fields']['extent_ur_y']['y'] + 3, - round($this->data['extent_feature'][2]['y'], $precision)); + $pdf->Text( + $this->conf['fields']['extent_ur_y']['x'] + $corrFactor, + $this->conf['fields']['extent_ur_y']['y'] + 3, + round($this->data['extent_feature'][2]['y'], $precision) + ); // upper right X $pdf->SetFont('Arial', '', $this->conf['fields']['extent_ur_x']['fontsize']); - $pdf->TextWithDirection($this->conf['fields']['extent_ur_x']['x'] + 1, - $this->conf['fields']['extent_ur_x']['y'], - round($this->data['extent_feature'][2]['x'], $precision),'D'); + $pdf->TextWithDirection( + $this->conf['fields']['extent_ur_x']['x'] + 1, + $this->conf['fields']['extent_ur_x']['y'], + round($this->data['extent_feature'][2]['x'], $precision), + 'D' + ); // lower left Y $pdf->SetFont('Arial', '', $this->conf['fields']['extent_ll_y']['fontsize']); - $pdf->Text($this->conf['fields']['extent_ll_y']['x'], - $this->conf['fields']['extent_ll_y']['y'] + 3, - round($this->data['extent_feature'][0]['y'], $precision)); + $pdf->Text( + $this->conf['fields']['extent_ll_y']['x'], + $this->conf['fields']['extent_ll_y']['y'] + 3, + round($this->data['extent_feature'][0]['y'], $precision) + ); // lower left X $pdf->SetFont('Arial', '', $this->conf['fields']['extent_ll_x']['fontsize']); - $pdf->TextWithDirection($this->conf['fields']['extent_ll_x']['x'] + 3, - $this->conf['fields']['extent_ll_x']['y'] + 30, - round($this->data['extent_feature'][0]['x'], $precision),'U'); + $pdf->TextWithDirection( + $this->conf['fields']['extent_ll_x']['x'] + 3, + $this->conf['fields']['extent_ll_x']['y'] + 30, + round($this->data['extent_feature'][0]['x'], $precision), + 'U' + ); } - + private function addDynamicImage() { - if($this->user == 'anon.'){ + if ($this->user == 'anon.') { return; } $groups = $this->user->getGroups(); $group = $groups[0]; - - if(!isset($group)){ + + if (!isset($group)) { return; } - + $dynImage = $this->resourceDir . '/images/' . $group->getTitle() . '.png'; - if(file_exists ($dynImage)){ - $this->pdf->Image($dynImage, - $this->conf['dynamic_image']['x'], - $this->conf['dynamic_image']['y'], - 0, - $this->conf['dynamic_image']['height'], - 'png'); + if (file_exists($dynImage)) { + $this->pdf->Image( + $dynImage, + $this->conf['dynamic_image']['x'], + $this->conf['dynamic_image']['y'], + 0, + $this->conf['dynamic_image']['height'], + 'png' + ); return; } - } - + private function addDynamicText() { - if($this->user == 'anon.'){ + if ($this->user == 'anon.') { return; } - + $groups = $this->user->getGroups(); $group = $groups[0]; - - if(!isset($group)){ + + if (!isset($group)) { return; } - + $this->pdf->SetFont('Arial', '', $this->conf['fields']['dynamic_text']['fontsize']); - $this->pdf->MultiCell($this->conf['fields']['dynamic_text']['width'], - $this->conf['fields']['dynamic_text']['height'], - utf8_decode($group->getDescription())); - + $this->pdf->MultiCell( + $this->conf['fields']['dynamic_text']['width'], + $this->conf['fields']['dynamic_text']['height'], + utf8_decode($group->getDescription()) + ); } private function getFeature($schemaName, $featureId) @@ -800,7 +873,7 @@ private function getColor($color, $alpha, $image) { list($r, $g, $b) = CSSColorParser::parse($color); - if(0 == $alpha) { + if (0 == $alpha) { return ImageColorAllocate($image, $r, $g, $b); } else { $a = (1 - $alpha) * 127.0; @@ -811,16 +884,16 @@ private function getColor($color, $alpha, $image) private function drawPolygon($geometry, $image) { $style = $this->getStyle($geometry); - foreach($geometry['coordinates'] as $ring) { - if(count($ring) < 3) { + foreach ($geometry['coordinates'] as $ring) { + if (count($ring) < 3) { continue; } $points = array(); - foreach($ring as $c) { - if($this->rotation == 0){ + foreach ($ring as $c) { + if ($this->rotation == 0) { $p = $this->realWorld2mapPos($c[0], $c[1]); - }else{ + } else { $p = $this->realWorld2rotatedMapPos($c[0], $c[1]); } $points[] = floatval($p[0]); @@ -828,11 +901,12 @@ private function drawPolygon($geometry, $image) } imagesetthickness($image, 0); - if($style['fillOpacity'] > 0){ + if ($style['fillOpacity'] > 0) { $color = $this->getColor( $style['fillColor'], $style['fillOpacity'], - $image); + $image + ); imagefilledpolygon($image, $points, count($ring), $color); } // Border @@ -840,7 +914,8 @@ private function drawPolygon($geometry, $image) $color = $this->getColor( $style['strokeColor'], $style['strokeOpacity'], - $image); + $image + ); imagesetthickness($image, $style['strokeWidth']); imagepolygon($image, $points, count($ring), $color); } @@ -850,17 +925,17 @@ private function drawPolygon($geometry, $image) private function drawMultiPolygon($geometry, $image) { $style = $this->getStyle($geometry); - foreach($geometry['coordinates'] as $element) { - foreach($element as $ring) { - if(count($ring) < 3) { + foreach ($geometry['coordinates'] as $element) { + foreach ($element as $ring) { + if (count($ring) < 3) { continue; } $points = array(); - foreach($ring as $c) { - if($this->rotation == 0){ + foreach ($ring as $c) { + if ($this->rotation == 0) { $p = $this->realWorld2mapPos($c[0], $c[1]); - }else{ + } else { $p = $this->realWorld2rotatedMapPos($c[0], $c[1]); } $points[] = floatval($p[0]); @@ -868,11 +943,12 @@ private function drawMultiPolygon($geometry, $image) } imagesetthickness($image, 0); // Filled area - if($style['fillOpacity'] > 0){ + if ($style['fillOpacity'] > 0) { $color = $this->getColor( $style['fillColor'], $style['fillOpacity'], - $image); + $image + ); imagefilledpolygon($image, $points, count($ring), $color); } // Border @@ -880,7 +956,8 @@ private function drawMultiPolygon($geometry, $image) $color = $this->getColor( $style['strokeColor'], $style['strokeOpacity'], - $image); + $image + ); imagesetthickness($image, $style['strokeWidth']); imagepolygon($image, $points, count($ring), $color); } @@ -894,69 +971,76 @@ private function drawLineString($geometry, $image) $color = $this->getColor( $style['strokeColor'], $style['strokeOpacity'], - $image); + $image + ); if ($style['strokeWidth'] == 0) { return; } imagesetthickness($image, $style['strokeWidth']); - for($i = 1; $i < count($geometry['coordinates']); $i++) { - - if($this->rotation == 0){ + for ($i = 1; $i < count($geometry['coordinates']); $i++) { + if ($this->rotation == 0) { $from = $this->realWorld2mapPos( $geometry['coordinates'][$i - 1][0], - $geometry['coordinates'][$i - 1][1]); + $geometry['coordinates'][$i - 1][1] + ); $to = $this->realWorld2mapPos( $geometry['coordinates'][$i][0], - $geometry['coordinates'][$i][1]); - }else{ + $geometry['coordinates'][$i][1] + ); + } else { $from = $this->realWorld2rotatedMapPos( $geometry['coordinates'][$i - 1][0], - $geometry['coordinates'][$i - 1][1]); + $geometry['coordinates'][$i - 1][1] + ); $to = $this->realWorld2rotatedMapPos( $geometry['coordinates'][$i][0], - $geometry['coordinates'][$i][1]); + $geometry['coordinates'][$i][1] + ); } imageline($image, $from[0], $from[1], $to[0], $to[1], $color); } } - + private function drawMultiLineString($geometry, $image) { $style = $this->getStyle($geometry); $color = $this->getColor( $style['strokeColor'], $style['strokeOpacity'], - $image); + $image + ); if ($style['strokeWidth'] == 0) { return; } imagesetthickness($image, $style['strokeWidth']); - - foreach($geometry['coordinates'] as $coords) { - - for($i = 1; $i < count($coords); $i++) { - - if($this->rotation == 0){ - $from = $this->realWorld2mapPos( - $coords[$i - 1][0], - $coords[$i - 1][1]); - $to = $this->realWorld2mapPos( - $coords[$i][0], - $coords[$i][1]); - }else{ - $from = $this->realWorld2rotatedMapPos( - $coords[$i - 1][0], - $coords[$i - 1][1]); - $to = $this->realWorld2rotatedMapPos( - $coords[$i][0], - $coords[$i][1]); - } - - imageline($image, $from[0], $from[1], $to[0], $to[1], $color); - } - } + + foreach ($geometry['coordinates'] as $coords) { + for ($i = 1; $i < count($coords); $i++) { + if ($this->rotation == 0) { + $from = $this->realWorld2mapPos( + $coords[$i - 1][0], + $coords[$i - 1][1] + ); + $to = $this->realWorld2mapPos( + $coords[$i][0], + $coords[$i][1] + ); + } else { + $from = $this->realWorld2rotatedMapPos( + $coords[$i - 1][0], + $coords[$i - 1][1] + ); + $to = $this->realWorld2rotatedMapPos( + $coords[$i][0], + $coords[$i][1] + ); + } + + imageline($image, $from[0], $from[1], $to[0], $to[1], $color); + } + } } private function drawPoint($geometry, $image) @@ -964,42 +1048,44 @@ private function drawPoint($geometry, $image) $style = $this->getStyle($geometry); $c = $geometry['coordinates']; - if($this->rotation == 0){ + if ($this->rotation == 0) { $p = $this->realWorld2mapPos($c[0], $c[1]); - }else{ + } else { $p = $this->realWorld2rotatedMapPos($c[0], $c[1]); } - if(isset($style['label'])){ + if (isset($style['label'])) { // draw label with white halo $color = $this->getColor('#ff0000', 1, $image); $bgcolor = $this->getColor('#ffffff', 1, $image); - $fontPath = $this->resourceDir.'/fonts/'; + $fontPath = $this->resourceDir . '/fonts/'; $font = $fontPath . 'OpenSans-Bold.ttf'; - imagettftext($image, 14, 0, $p[0], $p[1]+1, $bgcolor, $font, $geometry['style']['label']); - imagettftext($image, 14, 0, $p[0], $p[1]-1, $bgcolor, $font, $geometry['style']['label']); - imagettftext($image, 14, 0, $p[0]-1, $p[1], $bgcolor, $font, $geometry['style']['label']); - imagettftext($image, 14, 0, $p[0]+1, $p[1], $bgcolor, $font, $geometry['style']['label']); + imagettftext($image, 14, 0, $p[0], $p[1] + 1, $bgcolor, $font, $geometry['style']['label']); + imagettftext($image, 14, 0, $p[0], $p[1] - 1, $bgcolor, $font, $geometry['style']['label']); + imagettftext($image, 14, 0, $p[0] - 1, $p[1], $bgcolor, $font, $geometry['style']['label']); + imagettftext($image, 14, 0, $p[0] + 1, $p[1], $bgcolor, $font, $geometry['style']['label']); imagettftext($image, 14, 0, $p[0], $p[1], $color, $font, $style['label']); //return; } $radius = $style['pointRadius']; // Filled circle - if($style['fillOpacity'] > 0){ + if ($style['fillOpacity'] > 0) { $color = $this->getColor( $style['fillColor'], $style['fillOpacity'], - $image); - imagefilledellipse($image, $p[0], $p[1], 2*$radius, 2*$radius, $color); + $image + ); + imagefilledellipse($image, $p[0], $p[1], 2 * $radius, 2 * $radius, $color); } // Circle border if ($style['strokeWidth'] > 0) { $color = $this->getColor( $style['strokeColor'], $style['strokeOpacity'], - $image); - imageellipse($image, $p[0], $p[1], 2*$radius, 2*$radius, $color); + $image + ); + imageellipse($image, $p[0], $p[1], 2 * $radius, 2 * $radius, $color); } } @@ -1028,34 +1114,33 @@ private function drawFeatures() private function addLegend() { - if(isset($this->conf['legend']) && $this->conf['legend']){ - // print legend on first - $height = $this->conf['legend']['height']; - $width = $this->conf['legend']['width']; - $xStartPosition = $this->conf['legend']['x']; - $yStartPosition = $this->conf['legend']['y']; - $x = $xStartPosition + 5; - $y = $yStartPosition + 5; - $legendConf = true; - }else{ - // print legend on second page - $this->pdf->addPage('P'); - $this->pdf->SetFont('Arial', 'B', 11); - $x = 5; - $y = 10; - $height = $this->pdf->getHeight(); - $width = $this->pdf->getWidth(); - $legendConf = false; - if(isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']){ - $this->addLegendPageImage(); - } + if (isset($this->conf['legend']) && $this->conf['legend']) { + // print legend on first + $height = $this->conf['legend']['height']; + $width = $this->conf['legend']['width']; + $xStartPosition = $this->conf['legend']['x']; + $yStartPosition = $this->conf['legend']['y']; + $x = $xStartPosition + 5; + $y = $yStartPosition + 5; + $legendConf = true; + } else { + // print legend on second page + $this->pdf->addPage('P'); + $this->pdf->SetFont('Arial', 'B', 11); + $x = 5; + $y = 10; + $height = $this->pdf->getHeight(); + $width = $this->pdf->getWidth(); + $legendConf = false; + if (isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']) { + $this->addLegendPageImage(); + } } foreach ($this->data['legends'] as $idx => $legendArray) { - $c = 1; + $c = 1; $arraySize = count($legendArray); foreach ($legendArray as $title => $legendUrl) { - if (preg_match('/request=GetLegendGraphic/i', urldecode($legendUrl)) === 0) { continue; } @@ -1064,49 +1149,49 @@ private function addLegend() if (false === @imagecreatefromstring(@file_get_contents($image))) { continue; } - $size = getimagesize($image); + $size = getimagesize($image); $tempY = round($size[1] * 25.4 / 96) + 10; if ($c > 1) { // print legend on second page - if($y + $tempY + 10 > ($this->pdf->getHeight()) && $legendConf == false){ + if ($y + $tempY + 10 > ($this->pdf->getHeight()) && $legendConf == false) { $x += 105; $y = 10; - if(isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']){ - $this->addLegendPageImage(); - } - if($x + 20 > ($this->pdf->getWidth())){ + if (isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']) { + $this->addLegendPageImage(); + } + if ($x + 20 > ($this->pdf->getWidth())) { $this->pdf->addPage('P'); $x = 5; $y = 10; - if(isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']){ - $this->addLegendPageImage(); - } + if (isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']) { + $this->addLegendPageImage(); + } } } // print legend on first page - if(($y-$yStartPosition) + $tempY + 10 > $height && $width > 100 && $legendConf == true){ + if (($y - $yStartPosition) + $tempY + 10 > $height && $width > 100 && $legendConf == true) { $x += $x + 105; $y = $yStartPosition + 5; - if($x - $xStartPosition + 20 > $width){ + if ($x - $xStartPosition + 20 > $width) { $this->pdf->addPage('P'); $x = 5; $y = 10; $legendConf = false; - if(isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']){ - $this->addLegendPageImage(); - } + if (isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']) { + $this->addLegendPageImage(); + } + } + } elseif (($y - $yStartPosition) + $tempY + 10 > $height && $legendConf == true) { + $this->pdf->addPage('P'); + $x = 5; + $y = 10; + $legendConf = false; + if (isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']) { + $this->addLegendPageImage(); } - }else if (($y-$yStartPosition) + $tempY + 10 > $height && $legendConf == true){ - $this->pdf->addPage('P'); - $x = 5; - $y = 10; - $legendConf = false; - if(isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']){ - $this->addLegendPageImage(); - } } } @@ -1114,52 +1199,58 @@ private function addLegend() if ($legendConf == true) { // add legend in legend region on first page // To Be doneCell(0,0, utf8_decode($title)); - $this->pdf->setXY($x,$y); - $this->pdf->Cell(0,0, utf8_decode($title)); - $this->pdf->Image($image, - $x, - $y +5 , - ($size[0] * 25.4 / 96), ($size[1] * 25.4 / 96), 'png', '', false, 0); - - $y += round($size[1] * 25.4 / 96) + 10; - if(($y - $yStartPosition + 10 ) > $height && $width > 100){ - $x += 105; - $y = $yStartPosition + 10; - } - if(($x - $xStartPosition + 10) > $width && $c < $arraySize ){ - $this->pdf->addPage('P'); - $x = 5; - $y = 10; - $this->pdf->SetFont('Arial', 'B', 11); - $height = $this->pdf->getHeight(); - $width = $this->pdf->getWidth(); - $legendConf = false; - if(isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']){ - $this->addLegendPageImage(); - } + $this->pdf->setXY($x, $y); + $this->pdf->Cell(0, 0, utf8_decode($title)); + $this->pdf->Image( + $image, + $x, + $y + 5, + ($size[0] * 25.4 / 96), + ($size[1] * 25.4 / 96), + 'png', + '', + false, + 0 + ); + + $y += round($size[1] * 25.4 / 96) + 10; + if (($y - $yStartPosition + 10) > $height && $width > 100) { + $x += 105; + $y = $yStartPosition + 10; + } + if (($x - $xStartPosition + 10) > $width && $c < $arraySize) { + $this->pdf->addPage('P'); + $x = 5; + $y = 10; + $this->pdf->SetFont('Arial', 'B', 11); + $height = $this->pdf->getHeight(); + $width = $this->pdf->getWidth(); + $legendConf = false; + if (isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']) { + $this->addLegendPageImage(); } + } + } else { + // print legend on second page + $this->pdf->setXY($x, $y); + $this->pdf->Cell(0, 0, utf8_decode($title)); + $this->pdf->Image($image, $x, $y + 5, ($size[0] * 25.4 / 96), ($size[1] * 25.4 / 96), 'png', '', + false, 0); - }else{ - // print legend on second page - $this->pdf->setXY($x,$y); - $this->pdf->Cell(0,0, utf8_decode($title)); - $this->pdf->Image($image, $x, $y + 5, ($size[0] * 25.4 / 96), ($size[1] * 25.4 / 96), 'png', '', false, 0); - - $y += round($size[1] * 25.4 / 96) + 10; - if($y > ($this->pdf->getHeight())){ - $x += 105; - $y = 10; - } - if($x + 20 > ($this->pdf->getWidth()) && $c < $arraySize){ - $this->pdf->addPage('P'); - $x = 5; - $y = 10; - if(isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']){ - $this->addLegendPageImage(); - } - } - - } + $y += round($size[1] * 25.4 / 96) + 10; + if ($y > ($this->pdf->getHeight())) { + $x += 105; + $y = 10; + } + if ($x + 20 > ($this->pdf->getWidth()) && $c < $arraySize) { + $this->pdf->addPage('P'); + $x = 5; + $y = 10; + if (isset($this->conf['legendpage_image']) && $this->conf['legendpage_image']) { + $this->addLegendPageImage(); + } + } + } unlink($image); $c++; @@ -1170,24 +1261,23 @@ private function addLegend() private function getLegendImage($url) { - - $url = urldecode($url); - $parsed = parse_url($url); + $url = urldecode($url); + $parsed = parse_url($url); $host = isset($parsed['host']) ? $parsed['host'] : $this->container->get('request')->getHttpHost(); $hostpath = $host . $parsed['path']; - $pos = strpos($hostpath, $this->urlHostPath); + $pos = strpos($hostpath, $this->urlHostPath); if ($pos === 0 && ($routeStr = substr($hostpath, strlen($this->urlHostPath))) !== false) { $attributes = $this->container->get('router')->match($routeStr); - $gets = array(); + $gets = array(); parse_str($parsed['query'], $gets); $subRequest = new Request($gets, array(), $attributes, array(), array(), array(), ''); - $response = $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); - $imagename = tempnam($this->tempdir, 'mb_printlegend'); + $response = $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); + $imagename = tempnam($this->tempdir, 'mb_printlegend'); file_put_contents($imagename, $response->getContent()); } else { - $proxy_config = $this->container->getParameter("owsproxy.proxy"); - $proxy_query = ProxyQuery::createFromUrl($url); - $proxy = new CommonProxy($proxy_config, $proxy_query); + $proxy_config = $this->container->getParameter("owsproxy.proxy"); + $proxy_query = ProxyQuery::createFromUrl($url); + $proxy = new CommonProxy($proxy_config, $proxy_query); $browserResponse = $proxy->handle(); $imagename = tempnam($this->tempdir, 'mb_printlegend'); @@ -1198,63 +1288,63 @@ private function getLegendImage($url) } - private function realWorld2mapPos($rw_x, $rw_y) { - $quality = $this->data['quality']; - $mapWidth = $this->data['extent']['width']; + $quality = $this->data['quality']; + $mapWidth = $this->data['extent']['width']; $mapHeight = $this->data['extent']['height']; - $centerx = $this->data['center']['x']; - $centery = $this->data['center']['y']; - $minX = $centerx - $mapWidth * 0.5; - $minY = $centery - $mapHeight * 0.5; - $maxX = $centerx + $mapWidth * 0.5; - $maxY = $centery + $mapHeight * 0.5; - $extentx = $maxX - $minX; - $extenty = $maxY - $minY; - $pixPos_x = (($rw_x - $minX) / $extentx) * round($this->conf['map']['width'] / 25.4 * $quality); - $pixPos_y = (($maxY - $rw_y) / $extenty) * round($this->conf['map']['height'] / 25.4 * $quality); + $centerx = $this->data['center']['x']; + $centery = $this->data['center']['y']; + $minX = $centerx - $mapWidth * 0.5; + $minY = $centery - $mapHeight * 0.5; + $maxX = $centerx + $mapWidth * 0.5; + $maxY = $centery + $mapHeight * 0.5; + $extentx = $maxX - $minX; + $extenty = $maxY - $minY; + $pixPos_x = (($rw_x - $minX) / $extentx) * round($this->conf['map']['width'] / 25.4 * $quality); + $pixPos_y = (($maxY - $rw_y) / $extenty) * round($this->conf['map']['height'] / 25.4 * $quality); return array($pixPos_x, $pixPos_y); } private function addLegendPageImage() { + $legendpageImage = $this->resourceDir . '/images/' . 'legendpage_image' . '.png'; - $legendpageImage = $this->resourceDir . '/images/' . 'legendpage_image'. '.png'; - - if($this->user == 'anon.'){ - $legendpageImage = $this->resourceDir . '/images/' . 'legendpage_image'. '.png'; - }else{ - $groups = $this->user->getGroups(); - $group = $groups[0]; - - if(isset($group)){ - $legendpageImage = $this->resourceDir . '/images/' . $group->getTitle() . '.png'; - } + if ($this->user == 'anon.') { + $legendpageImage = $this->resourceDir . '/images/' . 'legendpage_image' . '.png'; + } else { + $groups = $this->user->getGroups(); + $group = $groups[0]; + + if (isset($group)) { + $legendpageImage = $this->resourceDir . '/images/' . $group->getTitle() . '.png'; + } } - if(file_exists ($legendpageImage)){ - $this->pdf->Image($legendpageImage, - $this->conf['legendpage_image']['x'], - $this->conf['legendpage_image']['y'], - 0, - $this->conf['legendpage_image']['height'], - 'png'); + if (file_exists($legendpageImage)) { + $this->pdf->Image( + $legendpageImage, + $this->conf['legendpage_image']['x'], + $this->conf['legendpage_image']['y'], + 0, + $this->conf['legendpage_image']['height'], + 'png' + ); } } private function realWorld2ovMapPos($ovWidth, $ovHeight, $rw_x, $rw_y) { - $quality = $this->data['quality']; - $centerx = $this->data['center']['x']; - $centery = $this->data['center']['y']; - $minX = $centerx - $ovWidth * 0.5; - $minY = $centery - $ovHeight * 0.5; - $maxX = $centerx + $ovWidth * 0.5; - $maxY = $centery + $ovHeight * 0.5; - $extentx = $maxX - $minX; - $extenty = $maxY - $minY; + $quality = $this->data['quality']; + $centerx = $this->data['center']['x']; + $centery = $this->data['center']['y']; + $minX = $centerx - $ovWidth * 0.5; + $minY = $centery - $ovHeight * 0.5; + $maxX = $centerx + $ovWidth * 0.5; + $maxY = $centery + $ovHeight * 0.5; + $extentx = $maxX - $minX; + $extenty = $maxY - $minY; $pixPos_x = (($rw_x - $minX) / $extentx) * round($this->conf['overview']['width'] / 25.4 * $quality); $pixPos_y = (($maxY - $rw_y) / $extenty) * round($this->conf['overview']['height'] / 25.4 * $quality); @@ -1263,14 +1353,14 @@ private function realWorld2ovMapPos($ovWidth, $ovHeight, $rw_x, $rw_y) private function realWorld2rotatedMapPos($rw_x, $rw_y) { - $centerx = $this->data['center']['x']; - $centery = $this->data['center']['y']; - $minX = $centerx - $this->neededExtentWidth * 0.5; - $minY = $centery - $this->neededExtentHeight * 0.5; - $maxX = $centerx + $this->neededExtentWidth * 0.5; - $maxY = $centery + $this->neededExtentHeight * 0.5; - $extentx = $maxX - $minX; - $extenty = $maxY - $minY; + $centerx = $this->data['center']['x']; + $centery = $this->data['center']['y']; + $minX = $centerx - $this->neededExtentWidth * 0.5; + $minY = $centery - $this->neededExtentHeight * 0.5; + $maxX = $centerx + $this->neededExtentWidth * 0.5; + $maxY = $centery + $this->neededExtentHeight * 0.5; + $extentx = $maxX - $minX; + $extenty = $maxY - $minY; $pixPos_x = (($rw_x - $minX) / $extentx) * $this->neededImageWidth; $pixPos_y = (($maxY - $rw_y) / $extenty) * $this->neededImageHeight; @@ -1288,10 +1378,11 @@ private function getStyle($geometry) return array_merge($this->defaultStyle, $geometry['style']); } - private function checkPdfBackground($pdf) { - $pdfArray = (array) $pdf; + private function checkPdfBackground($pdf) + { + $pdfArray = (array)$pdf; $pdfFile = $pdfArray['currentFilename']; - $pdfSubArray = (array) $pdfArray['parsers'][$pdfFile]; + $pdfSubArray = (array)$pdfArray['parsers'][$pdfFile]; $prefix = chr(0) . '*' . chr(0); $pdfSubArray2 = $pdfSubArray[$prefix . '_root'][1][1]; @@ -1301,5 +1392,4 @@ private function checkPdfBackground($pdf) { return false; } - } diff --git a/Element/ImageExport.php b/Element/ImageExport.php index 034e3796..8d8fb455 100644 --- a/Element/ImageExport.php +++ b/Element/ImageExport.php @@ -3,10 +3,11 @@ namespace Mapbender\PrintBundle\Element; use Mapbender\CoreBundle\Component\Element; -use Mapbender\PrintBundle\Component\ImageExportService;; +use Mapbender\PrintBundle\Component\ImageExportService; /** - * + * Class ImageExport + * @package Mapbender\PrintBundle\Element */ class ImageExport extends Element { @@ -14,7 +15,7 @@ class ImageExport extends Element /** * @inheritdoc */ - static public function getClassTitle() + public static function getClassTitle() { return "mb.print.imageexport.class.title"; } @@ -22,7 +23,7 @@ static public function getClassTitle() /** * @inheritdoc */ - static public function getClassDescription() + public static function getClassDescription() { return "mb.print.imageexport.class.description"; } @@ -30,13 +31,14 @@ static public function getClassDescription() /** * @inheritdoc */ - static public function getTags() + public static function getTags() { return array( "mb.print.imageexport.tag.image", "mb.print.imageexport.tag.export", "mb.print.imageexport.tag.jpeg", - "mb.print.imageexport.tag.png"); + "mb.print.imageexport.tag.png" + ); } /** @@ -50,14 +52,19 @@ public function getWidgetName() /** * @inheritdoc */ - static public function listAssets() + public static function listAssets() { - return array('js' => array('mapbender.element.imageExport.js', + return array( + 'js' => array( + 'mapbender.element.imageExport.js', '@FOMCoreBundle/Resources/public/js/widgets/popup.js', - '@FOMCoreBundle/Resources/public/js/widgets/dropdown.js'), - 'css' => array( - 'sass/element/imageexport.scss'), - 'trans' => array('MapbenderPrintBundle:Element:imageexport.json.twig')); + '@FOMCoreBundle/Resources/public/js/widgets/dropdown.js' + ), + 'css' => array( + 'sass/element/imageexport.scss' + ), + 'trans' => array('MapbenderPrintBundle:Element:imageexport.json.twig') + ); } /** @@ -75,8 +82,7 @@ public static function getDefaultConfiguration() */ public function getConfiguration() { - $config = parent::getConfiguration(); - return $config; + return parent::getConfiguration(); } /** @@ -101,11 +107,11 @@ public static function getFormTemplate() public function render() { return $this->container->get('templating') - ->render('MapbenderPrintBundle:Element:imageexport.html.twig', array( - 'id' => $this->getId(), - 'title' => $this->getTitle(), - 'configuration' => $this->getConfiguration() - )); + ->render('MapbenderPrintBundle:Element:imageexport.html.twig', array( + 'id' => $this->getId(), + 'title' => $this->getTitle(), + 'configuration' => $this->getConfiguration() + )); } /** @@ -114,7 +120,6 @@ public function render() public function httpAction($action) { switch ($action) { - case 'export': $request = $this->container->get('request'); $data = $request->get('data'); @@ -122,5 +127,4 @@ public function httpAction($action) $exportservice->export($data); } } - } diff --git a/Element/PrintClient.php b/Element/PrintClient.php index 6d28dceb..5a89d4f9 100644 --- a/Element/PrintClient.php +++ b/Element/PrintClient.php @@ -2,18 +2,19 @@ namespace Mapbender\PrintBundle\Element; +use Symfony\Component\HttpFoundation\JsonResponse; use Mapbender\CoreBundle\Component\Element; use Mapbender\PrintBundle\Component\OdgParser; use Mapbender\PrintBundle\Component\PrintService; -use Symfony\Component\HttpFoundation\JsonResponse; /** - * + * Class PrintClient + * @package Mapbender\PrintBundle\Element */ class PrintClient extends Element { - public static $merge_configurations = false; + /** * @inheritdoc */ @@ -41,7 +42,8 @@ public static function getClassTags() "mb.print.client.tag.png", "mb.print.client.tag.gif", "mb.print.client.tag.jpg", - "mb.print.client.tag.jpeg"); + "mb.print.client.tag.jpeg" + ); } /** @@ -70,43 +72,52 @@ public static function listAssets() public static function getDefaultConfiguration() { return array( - "target" => null, - "templates" => array( + "target" => null, + "templates" => array( array( 'template' => "a4portrait", - "label" => "A4 Portrait") - , + "label" => "A4 Portrait" + ) + , array( 'template' => "a4landscape", - "label" => "A4 Landscape") - , + "label" => "A4 Landscape" + ) + , array( 'template' => "a3portrait", - "label" => "A3 Portrait") - , + "label" => "A3 Portrait" + ) + , array( 'template' => "a3landscape", - "label" => "A3 Landscape") - , + "label" => "A3 Landscape" + ) + , array( 'template' => "a4_landscape_offical", - "label" => "A4 Landscape offical"), + "label" => "A4 Landscape offical" + ), array( 'template' => "a2_landscape_offical", - "label" => "A2 Landscape offical") + "label" => "A2 Landscape offical" + ) + ), + "scales" => array(500, 1000, 5000, 10000, 25000), + "quality_levels" => array( + array('dpi' => "72", 'label' => "Draft (72dpi)"), + array('dpi' => "288", 'label' => "Document (288dpi)") ), - "scales" => array(500, 1000, 5000, 10000, 25000), - "quality_levels" => array(array('dpi' => "72", 'label' => "Draft (72dpi)"), - array('dpi' => "288", 'label' => "Document (288dpi)")), - "rotatable" => true, - "legend" => true, + "rotatable" => true, + "legend" => true, "legend_default_behaviour" => true, - "optional_fields" => array( - "title" => array("label" => 'Title', "options" => array("required" => false)), + "optional_fields" => array( + "title" => array("label" => 'Title', "options" => array("required" => false)), "comment1" => array("label" => 'Comment 1', "options" => array("required" => false)), - "comment2" => array("label" => 'Comment 2', "options" => array("required" => false))), - "replace_pattern" => null, - "file_prefix" => 'mapbender3' + "comment2" => array("label" => 'Comment 2', "options" => array("required" => false)) + ), + "replace_pattern" => null, + "file_prefix" => 'mapbender3' ); } @@ -168,8 +179,8 @@ public function render() return $this->container->get('templating')->render( 'MapbenderPrintBundle:Element:printclient.html.twig', array( - 'id' => $this->getId(), - 'title' => $this->getTitle(), + 'id' => $this->getId(), + 'title' => $this->getTitle(), 'configuration' => $this->getConfiguration() ) ); @@ -184,7 +195,6 @@ public function httpAction($action) $configuration = $this->getConfiguration(); switch ($action) { case 'print': - $data = $request->request->all(); foreach ($data['layers'] as $idx => $layer) { @@ -221,11 +231,11 @@ public function httpAction($action) $displayInline = true; $filename = 'mapbender_print.pdf'; - if(array_key_exists('file_prefix', $configuration)) { + if (array_key_exists('file_prefix', $configuration)) { $filename = $configuration['file_prefix'] . '_' . date("YmdHis") . '.pdf'; } $response = new Response($printservice->doPrint($data), 200, array( - 'Content-Type' => $displayInline ? 'application/pdf' : 'application/octet-stream', + 'Content-Type' => $displayInline ? 'application/pdf' : 'application/octet-stream', 'Content-Disposition' => 'attachment; filename=' . $filename )); diff --git a/Element/Type/ImageExportAdminType.php b/Element/Type/ImageExportAdminType.php index 855af689..3cf3285e 100644 --- a/Element/Type/ImageExportAdminType.php +++ b/Element/Type/ImageExportAdminType.php @@ -1,4 +1,5 @@ add('target', 'target_element', + $builder->add( + 'target', + 'target_element', array( - 'element_class' => 'Mapbender\\CoreBundle\\Element\\Map', - 'application' => $options['application'], - 'property_path' => '[target]', - 'required' => false)); + 'element_class' => 'Mapbender\\CoreBundle\\Element\\Map', + 'application' => $options['application'], + 'property_path' => '[target]', + 'required' => false + ) + ); } - -} \ No newline at end of file +} diff --git a/Element/Type/PrintClientAdminType.php b/Element/Type/PrintClientAdminType.php index c0ddac66..0cc94cb9 100644 --- a/Element/Type/PrintClientAdminType.php +++ b/Element/Type/PrintClientAdminType.php @@ -1,4 +1,5 @@ getFormFactory(), - $options["application"]); + $subscriber = new PrintClientSubscriber( + $builder->getFormFactory(), + $options["application"] + ); $builder->addEventSubscriber($subscriber); - $builder->add('target', 'target_element', - array( + $builder->add( + 'target', + 'target_element', + array( 'element_class' => 'Mapbender\\CoreBundle\\Element\\Map', - 'application' => $options['application'], + 'application' => $options['application'], 'property_path' => '[target]', - 'required' => false)) + 'required' => false + ) + ) ->add('type', 'choice', array( - 'required' => true, - 'choices' => array( - 'dialog' => 'Dialog', - 'element' => 'Element'))) + 'required' => true, + 'choices' => array( + 'dialog' => 'Dialog', + 'element' => 'Element' + ) + )) ->add('scales', 'text', array('required' => false)) ->add('file_prefix', 'text', array('required' => false)) - ->add('rotatable', 'checkbox',array('required' => false)) - ->add('legend', 'checkbox',array('required' => false)) - ->add('legend_default_behaviour', 'checkbox',array('required' => false)) - ->add('optional_fields', new YAMLConfigurationType(), array('required' => false,'attr' => array('class' => 'code-yaml'))) - ->add('replace_pattern', new YAMLConfigurationType(),array('required' => false,'attr' => array('class' => 'code-yaml'))) + ->add('rotatable', 'checkbox', array('required' => false)) + ->add('legend', 'checkbox', array('required' => false)) + ->add('legend_default_behaviour', 'checkbox', array('required' => false)) + ->add( + 'optional_fields', + new YAMLConfigurationType(), + array( + 'required' => false, + 'attr' => array('class' => 'code-yaml') + ) + ) + ->add( + 'replace_pattern', + new YAMLConfigurationType(), + array( + 'required' => false, + 'attr' => array('class' => 'code-yaml') + ) + ) ->add('templates', 'collection', array( - 'type' => new PrintClientTemplateAdminType(), - 'allow_add' => true, - 'allow_delete' => true, + 'type' => new PrintClientTemplateAdminType(), + 'allow_add' => true, + 'allow_delete' => true, 'auto_initialize' => false, )); } - -} \ No newline at end of file +} diff --git a/Element/Type/PrintClientQualityAdminType.php b/Element/Type/PrintClientQualityAdminType.php index 39e2cbfa..9565eb3e 100644 --- a/Element/Type/PrintClientQualityAdminType.php +++ b/Element/Type/PrintClientQualityAdminType.php @@ -1,4 +1,5 @@ add('dpi', 'text', array('required' => false)) ->add('label', 'text', array('required' => false)); } - -} \ No newline at end of file +} diff --git a/Element/Type/PrintClientTemplateAdminType.php b/Element/Type/PrintClientTemplateAdminType.php index d9f54741..043e5283 100644 --- a/Element/Type/PrintClientTemplateAdminType.php +++ b/Element/Type/PrintClientTemplateAdminType.php @@ -1,4 +1,5 @@ add('template', 'text', array('required' => false)) + $builder + ->add('template', 'text', array('required' => false)) ->add('label', 'text', array('required' => false)); } - -} \ No newline at end of file +} diff --git a/Form/EventListener/PrintClientSubscriber.php b/Form/EventListener/PrintClientSubscriber.php index cfe18bcb..e1668b63 100644 --- a/Form/EventListener/PrintClientSubscriber.php +++ b/Form/EventListener/PrintClientSubscriber.php @@ -2,35 +2,36 @@ namespace Mapbender\PrintBundle\Form\EventListener; -use Mapbender\PrintBundle\Element\Type\PrintClientQualityAdminType; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormFactoryInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Mapbender\PrintBundle\Element\Type\PrintClientQualityAdminType; /** - * + * Class PrintClientSubscriber + * @package Mapbender\PrintBundle\Form\EventListener */ class PrintClientSubscriber implements EventSubscriberInterface { /** * A FormFactoryInterface 's Factory - * - * @var \Symfony\Component\Form\FormFactoryInterface + * + * @var \Symfony\Component\Form\FormFactoryInterface */ private $factory; /** * The application - * + * * @var application */ private $application; /** * Creates a subscriber - * + * * @param \Symfony\Component\Form\FormFactoryInterface $factory */ public function __construct(FormFactoryInterface $factory, $application) @@ -46,12 +47,13 @@ public static function getSubscribedEvents() { return array( FormEvents::PRE_SET_DATA => 'preSetData', - FormEvents::PRE_SUBMIT => 'preBind'); + FormEvents::PRE_SUBMIT => 'preBind' + ); } /** * Checkt form fields by PRE_SUBMIT FormEvent - * + * * @param FormEvent $event */ public function preBind(FormEvent $event) @@ -68,19 +70,23 @@ public function preBind(FormEvent $event) if (key_exists("quality_levels", $data)) { $form->add($this->factory->createNamed( - 'quality_levels', "collection", null, array( - 'property_path' => '[quality_levels]', + 'quality_levels', + "collection", + null, + array( + 'property_path' => '[quality_levels]', 'auto_initialize' => false, - 'required' => false, - 'type' => new PrintClientQualityAdminType(), - 'options' => array( - )))); + 'required' => false, + 'type' => new PrintClientQualityAdminType(), + 'options' => array() + ) + )); } } /** * Checkt form fields by PRE_SET_DATA FormEvent - * + * * @param FormEvent $event */ public function preSetData(FormEvent $event) @@ -98,14 +104,17 @@ public function preSetData(FormEvent $event) if (key_exists("quality_levels", $data)) { $form->add($this->factory->createNamed( - 'quality_levels', "collection", null, array( - 'property_path' => '[quality_levels]', + 'quality_levels', + "collection", + null, + array( + 'property_path' => '[quality_levels]', 'auto_initialize' => false, - 'required' => false, - 'type' => new PrintClientQualityAdminType(), - 'options' => array( - )))); + 'required' => false, + 'type' => new PrintClientQualityAdminType(), + 'options' => array() + ) + )); } } - } diff --git a/MapbenderPrintBundle.php b/MapbenderPrintBundle.php index b8a1b7f0..202e3793 100644 --- a/MapbenderPrintBundle.php +++ b/MapbenderPrintBundle.php @@ -1,4 +1,5 @@