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 "Renders 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:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76: 77: 78:
79: public static function getDefaultConfiguration()
80: {
81: return array(
82: "target" => null,
83: "autoOpen" => false,
84: "print_directly" => true,
85: "templates" => array(
86: array(
87: 'template' => "a4portrait",
88: "label" => "A4 Portrait",
89: "format" => "a4")
90: ,
91: array(
92: 'template' => "a4landscape",
93: "label" => "A4 Landscape",
94: "format" => "a4")
95: ,
96: array(
97: 'template' => "a3portrait",
98: "label" => "A3 Portrait",
99: "format" => "a3")
100: ,
101: array(
102: 'template' => "a3landscape",
103: "label" => "A3 Landscape",
104: "format" => "a3")
105: ),
106: "scales" => array(500, 1000, 5000, 10000, 25000),
107: "quality_levels" => array(array('dpi' => "72", 'label' => "Draft (72dpi)"),
108: array('dpi' => "288", 'label' => "Draft (288dpi)")),
109: "rotatable" => true,
110: "optional_fields" => null
111: );
112: }
113:
114: 115: 116:
117: public function getConfiguration()
118: {
119: $config = parent::getConfiguration();
120: if(isset($config["templates"])){
121: $templates = array();
122: foreach ($config["templates"] as $template) {
123: $templates[$template['template']] = $template;
124: }
125: $config["templates"] = $templates;
126: }
127: if(isset($config["quality_levels"])){
128: $levels = array();
129: foreach ($config["quality_levels"] as $level) {
130: $levels[$level['dpi']] = $level['label'];
131: }
132: $config["quality_levels"] = $levels;
133: }
134: return $config;
135: }
136:
137: 138: 139:
140: public static function getType()
141: {
142: return 'Mapbender\CoreBundle\Element\Type\PrintClientAdminType';
143: }
144:
145: 146: 147:
148: public static function getFormTemplate()
149: {
150: return 'MapbenderCoreBundle:ElementAdmin:printclient.html.twig';
151: }
152:
153: 154: 155:
156: public function getWidgetName()
157: {
158: return 'mapbender.mbPrintClient';
159: }
160:
161: 162: 163:
164: public function render()
165: {
166: return $this->container->get('templating')
167: ->render('MapbenderCoreBundle:Element:printclient.html.twig',
168: array(
169: 'id' => $this->getId(),
170: 'title' => $this->getTitle(),
171: 'configuration' => $this->getConfiguration()
172: ));
173: }
174:
175: 176: 177:
178: public function httpAction($action) {
179: switch ($action) {
180: case 'direct':
181:
182: $request = $this->container->get('request');
183: $data = $request->request->all();
184:
185: foreach ($request->request->keys() as $key) {
186: $request->request->remove($key);
187: }
188:
189: foreach ($data['layers'] as $idx => $layer) {
190: $data['layers'][$idx] = json_decode($layer, true);
191: }
192: $content = json_encode($data);
193:
194:
195: $configuration = $this->getConfiguration();
196: $url = $this->container->get('router')->generate('mapbender_print_print_service', array(), true);
197:
198: return $this->container->get('http_kernel')->forward(
199: 'OwsProxy3CoreBundle:OwsProxy:genericProxy', array(
200: 'url' => $url,
201: 'content' => $content
202: )
203: );
204:
205: case 'queued':
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224: case 'template':
225: $response = new Response();
226: $response->headers->set('Content-Type', 'application/json');
227: $request = $this->container->get('request');
228: $data = json_decode($request->getContent(), true);
229: $container = $this->container;
230: $odgParser = new OdgParser($container);
231: $size = $odgParser->getMapSize($data['template']);
232: $response->setContent($size->getContent());
233: return $response;
234: }
235: }
236: }
237: