1: <?php
2:
3: namespace Mapbender\CoreBundle\Element;
4:
5: use Mapbender\CoreBundle\Component\Element;
6: use Symfony\Component\HttpFoundation\Response;
7: use Mapbender\PrintBundle\Component\OdgParser;
8:
9: 10: 11:
12: class PrintClient extends Element
13: {
14:
15: 16: 17:
18: static public function getClassTitle()
19: {
20: return "Print Client";
21: }
22:
23: 24: 25:
26: static public function getClassDescription()
27: {
28: return "Render a Print dialog";
29: }
30:
31: 32: 33:
34: static public function getClassTags()
35: {
36: return array('Print');
37: }
38:
39: 40: 41:
42: public function getAssets()
43: {
44: return array('js' => array('mapbender.element.printClient.js'),'css' => array());
45: }
46:
47: 48: 49:
50: public static function getDefaultConfiguration()
51: {
52: return array(
53: "target" => null,
54: "autoOpen" => false,
55: "print_directly" => true,
56: "templates" => array(
57: "a4portrait" => array(
58: "label" => "A4 Portrait",
59: "format" => "a4"),
60: "a4landscape" => array(
61: "label" => "A4 Landscape",
62: "format" => "a4"),
63: "a3portrait" => array(
64: "label" => "A3 Portrait",
65: "format" => "a3"),
66: "a3landscape" => array(
67: "label" => "A3 Landscape",
68: "format" => "a3")),
69: "scales" => array(500, 1000, 5000, 10000, 25000),
70: "quality_levels" => array("72" => "Entwurf", "288" => "Document"),
71: "rotatable" => true,
72: "optional_fields" => null
73: );
74: }
75:
76: 77: 78:
79: public function getWidgetName()
80: {
81: return 'mapbender.mbPrintClient';
82: }
83:
84: 85: 86:
87: public function render()
88: {
89: $configuration = $this->getConfiguration();
90: $forms = array();
91: if(isset($configuration['optional_fields']) && null !== $configuration['optional_fields'])
92: {
93: $form_builder = $this->container->get('form.factory')->createNamedBuilder('extra',
94: 'form',
95: null,
96: array(
97: 'csrf_protection' => false
98: ));
99: foreach($configuration['optional_fields'] as $k => $c)
100: {
101: $options = array_key_exists('options', $c) ? $c['options'] : array();
102: $form_builder->add($k, $c['type'], $options);
103: }
104: $forms['extra'] = $form_builder->getForm()->createView();
105: }
106:
107: return $this->container->get('templating')
108: ->render('MapbenderCoreBundle:Element:printclient.html.twig',
109: array(
110: 'id' => $this->getId(),
111: 'title' => $this->getTitle(),
112: 'configuration' => $this->getConfiguration(),
113: 'forms' => $forms));
114: }
115:
116: 117: 118:
119: public function httpAction($action) {
120: switch ($action) {
121: case 'direct':
122:
123: $request = $this->container->get('request');
124: $data = $request->request->all();
125:
126: foreach ($request->request->keys() as $key) {
127: $request->request->remove($key);
128: }
129:
130: foreach ($data['layers'] as $idx => $layer) {
131: $data['layers'][$idx] = json_decode($layer, true);
132: }
133: $content = json_encode($data);
134:
135:
136: $configuration = $this->getConfiguration();
137: $url = $this->container->get('router')->generate('mapbender_print_print_service', array(), true);
138:
139: return $this->container->get('http_kernel')->forward(
140: 'OwsProxy3CoreBundle:OwsProxy:genericProxy', array(
141: 'url' => $url,
142: 'content' => $content
143: )
144: );
145:
146: case 'queued':
147: $content = $this->container->get('request')->getContent();
148: if (empty($content)) {
149: throw new \RuntimeException('No Request Data received');
150: }
151:
152:
153: $configuration = $this->getConfiguration();
154: $url = (null !== $configuration['printer']['service'] ?
155: $configuration['printer']['service'] :
156: $this->container->get('router')->generate('mapbender_print_print_service', array(), true));
157: return $this->container->get('http_kernel')->forward(
158: 'OwsProxy3CoreBundle:OwsProxy:genericProxy', array(
159: 'url' => $url,
160: 'content' => $content
161: )
162: );
163: case 'template':
164: $response = new Response();
165: $response->headers->set('Content-Type', 'application/json');
166: $request = $this->container->get('request');
167: $data = json_decode($request->getContent(), true);
168: $container = $this->container;
169: $odgParser = new OdgParser($container);
170: $size = $odgParser->getMapSize($data['template']);
171: $response->setContent($size->getContent());
172: return $response;
173: }
174: }
175:
176: 177: 178:
179: public static function getFormTemplate()
180: {
181: return 'MapbenderManagerBundle:Element:printclient.html.twig';
182: }
183: }
184: