1: <?php
2:
3: namespace Mapbender\WmsBundle\Entity;
4:
5: use Doctrine\Common\Collections\ArrayCollection;
6: use Doctrine\ORM\EntityManager;
7: use Doctrine\ORM\Mapping as ORM;
8: use Mapbender\CoreBundle\Component\Utils;
9: use Mapbender\CoreBundle\Entity\Contact;
10: use Mapbender\CoreBundle\Entity\Keyword;
11: use Mapbender\CoreBundle\Entity\Source;
12: use Mapbender\WmsBundle\Component\RequestInformation;
13: use Mapbender\WmsBundle\Entity\WmsLayerSource;
14: use Symfony\Component\Validator\Constraints as Assert;
15:
16: 17: 18: 19: 20: 21:
22: class WmsSource extends Source
23: {
24:
25: 26: 27: 28: 29: 30:
31: protected $originUrl = "";
32:
33: 34: 35: 36:
37: protected $name = "";
38:
39: 40: 41: 42:
43: protected $version = "";
44:
45: 46: 47: 48:
49: protected $onlineResource;
50:
51: 52: 53: 54:
55: protected $contact;
56:
57: 58: 59: 60:
61: protected $fees = "";
62:
63: 64: 65: 66:
67: protected $accessConstraints = "";
68:
69: 70: 71: 72:
73: protected $layerLimit;
74:
75: 76: 77: 78:
79: protected $maxWidth;
80:
81: 82: 83: 84:
85: protected $maxHeight;
86:
87: 88: 89: 90:
91: protected $exceptionFormats = array();
92:
93: 94: 95: 96:
97: protected $supportSld = false;
98:
99: 100: 101: 102:
103: protected $userLayer = false;
104:
105: 106: 107: 108:
109: protected $userStyle = false;
110:
111: 112: 113: 114:
115: protected $remoteWfs = false;
116:
117: 118: 119: 120:
121: protected $inlineFeature = false;
122:
123: 124: 125: 126:
127: protected $remoteWcs = false;
128:
129: 130: 131: 132:
133:
134: public $getCapabilities = null;
135:
136: 137: 138: 139:
140:
141: public $getMap = null;
142:
143: 144: 145: 146:
147:
148: public $getFeatureInfo = null;
149:
150: 151: 152: 153:
154:
155: public $describeLayer = null;
156:
157: 158: 159: 160:
161:
162: public $getLegendGraphic = null;
163:
164: 165: 166: 167:
168:
169: public $getStyles = null;
170:
171: 172: 173: 174:
175:
176: public $putStyles = null;
177:
178: 179: 180: 181:
182: protected $username = null;
183:
184: 185: 186: 187:
188: protected $password = null;
189:
190: 191: 192: 193: 194:
195: protected $layers;
196:
197:
198:
199: 200: 201: 202:
203: protected $keywords;
204:
205: 206: 207: 208: 209:
210: protected $wmsinstance;
211:
212: public function __construct()
213: {
214: $this->keywords = new ArrayCollection();
215: $this->layers = new ArrayCollection();
216: $this->exceptionFormats = array();
217: }
218:
219: public function getType()
220: {
221: return "WMS";
222: }
223:
224: public function getManagertype()
225: {
226: return "wms";
227: }
228:
229: 230: 231: 232: 233: 234:
235: public function setOriginUrl($originUrl)
236: {
237: $this->originUrl = $originUrl;
238: return $this;
239: }
240:
241: 242: 243: 244: 245:
246: public function getOriginUrl()
247: {
248: return $this->originUrl;
249: }
250:
251: 252: 253: 254: 255: 256:
257: public function setName($name)
258: {
259: $this->name = $name;
260: return $this;
261: }
262:
263: 264: 265: 266: 267:
268: public function getName()
269: {
270: return $this->name;
271: }
272:
273: 274: 275: 276: 277: 278:
279: public function setVersion($version)
280: {
281: $this->version = $version;
282: return $this;
283: }
284:
285: 286: 287: 288: 289:
290: public function getVersion()
291: {
292: return $this->version;
293: }
294:
295: 296: 297: 298: 299: 300:
301: public function setOnlineResource($onlineResource)
302: {
303: $this->onlineResource = $onlineResource;
304: return $this;
305: }
306:
307: 308: 309: 310: 311:
312: public function getOnlineResource()
313: {
314: return $this->onlineResource;
315: }
316:
317: 318: 319: 320: 321: 322:
323: public function setContact($contact)
324: {
325: $this->contact = $contact;
326: return $this;
327: }
328:
329: 330: 331: 332: 333:
334: public function getContact()
335: {
336: return $this->contact;
337: }
338:
339: 340: 341: 342: 343: 344:
345: public function setFees($fees)
346: {
347: $this->fees = $fees;
348: return $this;
349: }
350:
351: 352: 353: 354: 355:
356: public function getFees()
357: {
358: return $this->fees;
359: }
360:
361: 362: 363: 364: 365: 366:
367: public function setAccessConstraints($accessConstraints)
368: {
369: $this->accessConstraints = $accessConstraints;
370: return $this;
371: }
372:
373: 374: 375: 376: 377:
378: public function getAccessConstraints()
379: {
380: return $this->accessConstraints;
381: }
382:
383: 384: 385: 386: 387: 388:
389: public function setLayerLimit($layerLimit)
390: {
391: $this->layerLimit = $layerLimit;
392: return $this;
393: }
394:
395: 396: 397: 398: 399:
400: public function getLayerLimit()
401: {
402: return $this->layerLimit;
403: }
404:
405: 406: 407: 408: 409: 410:
411: public function setMaxWidth($maxWidth)
412: {
413: $this->maxWidth = $maxWidth;
414: return $this;
415: }
416:
417: 418: 419: 420: 421:
422: public function getMaxWidth()
423: {
424: return $this->maxWidth;
425: }
426:
427: 428: 429: 430: 431: 432:
433: public function setMaxHeight($maxHeight)
434: {
435: $this->maxHeight = $maxHeight;
436: return $this;
437: }
438:
439: 440: 441: 442: 443:
444: public function getMaxHeight()
445: {
446: return $this->maxHeight;
447: }
448:
449: 450: 451: 452: 453: 454:
455: public function setExceptionFormats($exceptionFormats)
456: {
457: $this->exceptionFormats = $exceptionFormats;
458: return $this;
459: }
460:
461: 462: 463: 464: 465: 466:
467: public function addExceptionFormat($exceptionFormat)
468: {
469: $this->exceptionFormats[] = $exceptionFormat;
470: return $this;
471: }
472:
473: 474: 475: 476: 477:
478: public function getExceptionFormats()
479: {
480: return $this->exceptionFormats;
481: }
482:
483: 484: 485: 486: 487: 488:
489: public function setSupportSld($supportSld)
490: {
491: $this->supportSld = $supportSld;
492: return $this;
493: }
494:
495: 496: 497: 498: 499:
500: public function getSupportSld()
501: {
502: return $this->supportSld;
503: }
504:
505: 506: 507: 508: 509: 510:
511: public function setUserLayer($userLayer)
512: {
513: $this->userLayer = $userLayer;
514: return $this;
515: }
516:
517: 518: 519: 520: 521:
522: public function getUserLayer()
523: {
524: return $this->userLayer;
525: }
526:
527: 528: 529: 530: 531: 532:
533: public function setUserStyle($userStyle)
534: {
535: $this->userStyle = $userStyle;
536: return $this;
537: }
538:
539: 540: 541: 542: 543:
544: public function getUserStyle()
545: {
546: return $this->userStyle;
547: }
548:
549: 550: 551: 552: 553: 554:
555: public function setRemoteWfs($remoteWfs)
556: {
557: $this->remoteWfs = $remoteWfs;
558: return $this;
559: }
560:
561: 562: 563: 564: 565:
566: public function getRemoteWfs()
567: {
568: return $this->remoteWfs;
569: }
570:
571: 572: 573: 574: 575: 576:
577: public function setInlineFeature($inlineFeature)
578: {
579: $this->inlineFeature = $inlineFeature;
580: return $this;
581: }
582:
583: 584: 585: 586: 587:
588: public function getInlineFeature()
589: {
590: return $this->inlineFeature;
591: }
592:
593: 594: 595: 596: 597: 598:
599: public function setRemoteWcs($remoteWcs)
600: {
601: $this->remoteWcs = $remoteWcs;
602: return $this;
603: }
604:
605: 606: 607: 608: 609:
610: public function getRemoteWcs()
611: {
612: return $this->remoteWcs;
613: }
614:
615: 616: 617: 618: 619: 620:
621: public function setGetCapabilities(RequestInformation $getCapabilities)
622: {
623: $this->getCapabilities = $getCapabilities;
624: return $this;
625: }
626:
627: 628: 629: 630: 631:
632: public function getGetCapabilities()
633: {
634: return $this->getCapabilities;
635: }
636:
637: 638: 639: 640: 641: 642:
643: public function setGetMap(RequestInformation $getMap)
644: {
645: $this->getMap = $getMap;
646: return $this;
647: }
648:
649: 650: 651: 652: 653:
654: public function getGetMap()
655: {
656: return $this->getMap;
657: }
658:
659: 660: 661: 662: 663: 664:
665: public function setGetFeatureInfo(RequestInformation $getFeatureInfo)
666: {
667: $this->getFeatureInfo = $getFeatureInfo;
668: return $this;
669: }
670:
671: 672: 673: 674: 675:
676: public function getGetFeatureInfo()
677: {
678: return $this->getFeatureInfo;
679: }
680:
681: 682: 683: 684: 685: 686:
687: public function setDescribeLayer(RequestInformation $describeLayer)
688: {
689: $this->describeLayer = $describeLayer;
690: return $this;
691: }
692:
693: 694: 695: 696: 697:
698: public function getDescribeLayer()
699: {
700: return $this->describeLayer;
701: }
702:
703: 704: 705: 706: 707: 708:
709: public function setGetLegendGraphic(RequestInformation $getLegendGraphic)
710: {
711: $this->getLegendGraphic = $getLegendGraphic;
712: return $this;
713: }
714:
715: 716: 717: 718: 719:
720: public function getGetLegendGraphic()
721: {
722: return $this->getLegendGraphic;
723: }
724:
725: 726: 727: 728: 729: 730:
731: public function setGetStyles(RequestInformation $getStyles)
732: {
733: $this->getStyles = $getStyles;
734: return $this;
735: }
736:
737: 738: 739: 740: 741:
742: public function getGetStyles()
743: {
744: return $this->getStyles;
745: }
746:
747: 748: 749: 750: 751: 752:
753: public function setPutStyles(RequestInformation $putStyles)
754: {
755: $this->putStyles = $putStyles;
756: return $this;
757: }
758:
759: 760: 761: 762: 763:
764: public function getPutStyles()
765: {
766: return $this->putStyles;
767: }
768:
769: 770: 771: 772: 773: 774:
775: public function setUsername($username)
776: {
777: $this->username = $username;
778: return $this;
779: }
780:
781: 782: 783: 784: 785:
786: public function getUsername()
787: {
788: return $this->username;
789: }
790:
791: 792: 793: 794: 795: 796:
797: public function setPassword($password)
798: {
799: $this->password = $password;
800: return $this;
801: }
802:
803: 804: 805: 806: 807:
808: public function getPassword()
809: {
810: return $this->password;
811: }
812:
813: 814: 815: 816: 817: 818:
819: public function setLayers($layers)
820: {
821: $this->layers = $layers;
822: return $this;
823: }
824:
825: 826: 827: 828: 829:
830: public function getLayers()
831: {
832: return $this->layers;
833: }
834:
835: 836: 837: 838: 839: 840:
841: public function addLayer(WmsLayerSource $layer)
842: {
843: $this->layers->add($layer);
844: return $this;
845: }
846:
847: 848: 849: 850: 851:
852: public function getRootlayer()
853: {
854: foreach($this->layers as $layer)
855: {
856: if($layer->getParent() === null)
857: {
858: return $layer;
859: }
860: }
861: return null;
862:
863:
864:
865:
866:
867: }
868:
869: 870: 871: 872: 873: 874:
875: public function setKeywords($keywords)
876: {
877: $this->keywords = $keywords;
878: return $this;
879: }
880:
881: 882: 883: 884: 885:
886: public function getKeywords()
887: {
888: return $this->keywords;
889: }
890:
891: 892: 893: 894: 895: 896:
897: public function addKeyword(Keyword $keyword)
898: {
899: $this->keywords->add($keyword);
900: return $this;
901: }
902:
903: 904: 905: 906: 907:
908: public function removeLayer(WmsLayerSource $layers)
909: {
910: $this->layers->removeElement($layers);
911: }
912:
913: 914: 915: 916: 917:
918: public function removeKeyword(Keyword $keywords)
919: {
920: $this->keywords->removeElement($keywords);
921: }
922:
923: public function __toString()
924: {
925: return (string) $this->getId();
926: }
927:
928: 929: 930:
931: public function createInstance()
932: {
933: $instance = new WmsInstance();
934: $instance->setSource($this);
935: $instance->setTitle($this->getTitle());
936: $formats = $this->getGetMap()->getFormats();
937: $instance->setFormat(count($formats) > 0 ? $formats[0] : null);
938: $infoformats = $this->getGetFeatureInfo() !== null ?
939: $this->getGetFeatureInfo()->getFormats() : array();
940: $instance->setInfoformat(count($infoformats) > 0 ? $infoformats[0] : null);
941: $excformats = $this->getExceptionFormats();
942: $instance->setExceptionformat(count($excformats) > 0 ? $excformats[0] : null);
943:
944: $num = 0;
945: $wmslayer_root = $this->getRootlayer();
946: $instLayer_root = new WmsInstanceLayer();
947: $instLayer_root->setWmsinstance($instance);
948: $instLayer_root->setWmslayersource($wmslayer_root);
949: $instLayer_root->setTitle($wmslayer_root->getTitle());
950:
951: $instLayer_root->setMinScale(
952: $wmslayer_root->getScaleRecursive() !== null ?
953: $wmslayer_root->getScaleRecursive()->getMin() : null);
954: $instLayer_root->setMaxScale(
955: $wmslayer_root->getScaleRecursive() !== null ?
956: $wmslayer_root->getScaleRecursive()->getMax() : null);
957: $queryable = $wmslayer_root->getQueryable();
958: $instLayer_root->setInfo(Utils::getBool($queryable));
959: $instLayer_root->setAllowinfo(Utils::getBool($queryable));
960:
961: $instLayer_root->setToggle(true);
962: $instLayer_root->setAllowtoggle(true);
963:
964: $instLayer_root->setPriority($num);
965: $instance->addLayer($instLayer_root);
966: $this->addSublayer($instLayer_root, $wmslayer_root, $num, $instance);
967: return $instance;
968: }
969:
970: 971: 972: 973: 974: 975: 976: 977:
978: private function addSublayer($instlayer, $wmslayer, $num, $instance)
979: {
980: foreach($wmslayer->getSublayer() as $wmssublayer)
981: {
982: $num++;
983: $instsublayer = new WmsInstanceLayer();
984: $instsublayer->setWmsinstance($instance);
985: $instsublayer->setWmslayersource($wmssublayer);
986: $instsublayer->setTitle($wmssublayer->getTitle());
987:
988: $instsublayer->setMinScale(
989: $wmssublayer->getScaleRecursive() !== null ?
990: $wmssublayer->getScaleRecursive()->getMin() : null);
991: $instsublayer->setMaxScale(
992: $wmssublayer->getScaleRecursive() !== null ?
993: $wmssublayer->getScaleRecursive()->getMax() : null);
994: $queryable = $wmssublayer->getQueryable();
995: $instsublayer->setInfo(Utils::getBool($queryable));
996: $instsublayer->setAllowinfo(Utils::getBool($queryable));
997:
998: $instsublayer->setPriority($num);
999: $instsublayer->setParent($instlayer);
1000: $instance->addLayer($instsublayer);
1001: if($wmssublayer->getSublayer()->count() > 0){
1002: $instsublayer->setToggle(true);
1003: $instsublayer->setAllowtoggle(true);
1004: }
1005: $this->addSublayer($instsublayer, $wmssublayer, $num, $instance);
1006: }
1007: }
1008:
1009: 1010: 1011:
1012: public function remove(EntityManager $em)
1013: {
1014: $this->removeSourceRecursive($em, $this->getRootlayer());
1015: $em->remove($this);
1016: }
1017:
1018: 1019: 1020: 1021: 1022:
1023: private function removeSourceRecursive(EntityManager $em, WmsLayerSource $wmslayer)
1024: {
1025: foreach($wmslayer->getSublayer() as $sublayer)
1026: {
1027: $this->removeSourceRecursive($em, $sublayer);
1028: }
1029: $em->remove($wmslayer);
1030: $em->flush();
1031: }
1032:
1033: }