1: <?php
2:
3: 4: 5: 6: 7:
8:
9: namespace app\views\search;
10:
11:
12: include_once("/var/www/hbrutvikling/hbr/app/views/search/Fylke.php");
13:
14: class Fylker {
15:
16: protected $fylkenvn = array( "Østfold",
17: "Akershus",
18: "Oslo",
19: "Hedmark",
20: "Oppland",
21: "Buskerud",
22: "Vestfold",
23: "Telemark",
24: "Aust-Agder",
25: "Vest-Agder",
26: "Rogaland",
27: "Hordaland",
28: "Bergen",
29: "Sogn og Fjordane",
30: "Møre og Romsdal",
31: "Sør-Trøndelag",
32: "Nord-Trøndelag",
33: "Nordland",
34: "Troms",
35: "Finnmark" );
36: protected $fylker = array();
37:
38: 39: 40:
41: function __construct() {
42:
43:
44:
45: $filename = "/var/www/hbrutvikling/hbr/app/views/search/kommuner.txt";
46:
47: $file = @fopen($filename, "r");
48: $fylkenum = "00";
49: $num = -1;
50: if ($file) {
51: while (!feof($file))
52: {
53: $line = fgets($file, 4096);
54: if ($line)
55: {
56: $kommune = explode(";", $line);
57: if (substr($kommune[0], 0, 2) != $fylkenum)
58: {
59:
60:
61: $fylkenum = substr($kommune[0], 0, 2);
62: $num = $num + 1;
63:
64: $flk = new Fylke($this->fylkenvn[$num]);
65:
66: $this->fylker[] = $flk;
67:
68: }
69: $this->fylker[$num]->AddKommune($kommune);
70:
71: }
72:
73: }
74: fclose($file);
75: }
76: else
77: {
78:
79: }
80:
81:
82: }
83:
84:
85:
86:
87: 88: 89: 90: 91: 92:
93: public function getNumberOfFylker() {
94: return count( $this->fylker);
95: }
96:
97:
98:
99:
100: 101: 102: 103:
104: public function getFylke( $inx) {
105: return $this->fylker[$inx];
106: }
107:
108:
109: 110: 111: 112:
113: public function getFylkeNavn( $inx) {
114: return $this->fylkenvn[$inx];
115: }
116:
117:
118: 119: 120: 121:
122: public function getKommuneNavn( $inx) {
123: foreach ($this->fylker as $fylke)
124: {
125: for ($ii = 0; $ii < $fylke->getNumberOfKommuner(); $ii++)
126: {
127: $kom = $fylke->getKommune($ii);
128: if ($kom[0] == $inx)
129: {
130: return $kom[1];
131: }
132: }
133:
134: }
135: return $inx;
136: }
137:
138:
139: }
140: