1: <?php
2:
3: 4: 5: 6: 7:
8:
9: namespace app\controllers;
10: use \mako\http\routing\Controller;
11: use \mako\syringe\ContainerAwareTrait;
12: use \mako\auth\Gatekeeper;
13:
14:
15:
16:
17:
18:
19:
20: 21: 22: 23: 24: 25:
26:
27: class AvisQuery
28: {
29: protected $fields = array( "id"=>"pfid", "avispersonid"=>"pfid","pfid"=>"pfid", "fornavn"=>"fornavn", "forenamn"=>"fornavn", "etternavn"=>"etternavn", "etternamn"=>"etternavn", "slektsnavn"=>"etternavn", "patronymikon"=>"patronymikon", "kjonn"=>"kjonn",
30: "fodselsaar"=>"fodselsaar", "year_birth"=>"fodselsaar", "fodselsdato"=>"fodselsdato", "dodsdato"=>"dodsdato", "fodested"=>"fodested", "dodssted"=>"dodssted");
31:
32: protected $tableFields = array( "rolle"=>"rolle", "navn"=>"navn", "bosted"=>"bosted", "bustad"=>"bosted" , "familiestilling"=>"familiestilling", "sivilstand"=>"sivilstand", "yrke"=>"yrke",
33: "stilling_stand"=>"yrke", "kildeid"=> "kildeid", "far"=>"", "mor"=>"", "barn"=>"", "partner"=>""
34:
35: );
36:
37: protected $rollerMapping = array(
38: "far"=> array("barn"=>"far", "konfirmant"=>"far", "brudgom"=>"brudgommens far", "brur"=>"bruras far","trulovar"=> "brudgom"),
39: "mor"=> array("barn"=>"mor", "konfirmant"=>"mor", "trulovar"=> "brur"),
40: "barn"=> array("mor"=>"barn", "far"=>"barn", "mor"=>"konfirmant", "far"=>"konfirmant", "fadder"=>"barn", "bruras far"=> "brur", "brur far"=> "brur", "brudgommens far"=>"brudgom"),
41: "partner"=> array("mor"=>"far", "far"=>"mor", "brur"=>"brudgom", "brudgom"=>"brur")
42: );
43:
44: protected $familyMapping = array(
45: "far"=> array("barn"=>"far", "konfirmant"=>"far", "brudgom"=>"brudgommens far", "brur"=>"bruras far"),
46: "mor"=> array("barn"=>"mor", "konfirmant"=>"mor"),
47: "barn"=> array("mor"=>"barn", "far"=>"barn", "mor"=>"konfirmant", "far"=>"konfirmant", "bruras far"=> "brur", "brur far"=> "brur", "brudgommens far"=>"brudgom"),
48: "partner"=> array("mor"=>"far", "far"=>"mor", "brur"=>"brudgom", "brudgom"=>"brur")
49: );
50:
51: public $types = array('da'=>'daid', 'hbr'=>'hbrid','avis'=>'avisid');
52:
53: private function initPersonData()
54: {
55: $person = array();
56: foreach ($this->fields as $field=>$value)
57: {
58: if(!array_key_exists($value, $person))
59: $person[$value] = "";
60: }
61: return $person;
62: }
63:
64:
65:
66: public function getPersonfromFK($entry)
67: {
68: $person = NULL;
69: if (!empty($entry))
70: {
71: $person = $this->initPersonData();
72: foreach ($this->fields as $field=>$value)
73: {
74: if (property_exists($entry, $field) && !empty($entry->{$field}))
75: {
76: $person[$value] = $entry->{$field};
77: }
78: }
79: }
80: return $person;
81: }
82:
83: private function packMember($pfid, $entry)
84: {
85:
86: $res = array();
87:
88: foreach ($entry["other"] as $key=>$member)
89: {
90: if ($member["pfid"] == $pfid)
91: {
92: $name = $member["navn"];
93: }
94: }
95: $res['pfid'] = $pfid;
96: $res['name'] = $name;
97: $res['type'] ='daid';
98: return $res;
99:
100: }
101:
102: public function getFamilyforAvis($entries)
103: {
104: $families = array();
105: $dbfamily = array();
106: $pfid = '';
107: $avisSearch = new SearchAvisData();
108: if ($entries != NULL && property_exists($entries, 'autoid'))
109: {
110: $dbfamily = $avisSearch->getFamilyById($entries->autoid);
111: if ($dbfamily != NULL)
112: {
113: $dbfamily = $this->processAvisEntry($dbfamily);
114: if ($dbfamily != NULL)
115: {
116: $families['Partner og barn'] = array();
117: $families['Partner og barn'][] = array();
118: $pfid = $dbfamily->pfid;
119: $families['Partner og barn'][0][] = array('partner', array("pfid"=>$dbfamily->pfid, "name"=>$dbfamily->navn, "type"=>"avisid"));
120: }
121: }
122: }
123:
124: return array('families'=>$families, 'other'=>$dbfamily, 'pfid'=>$pfid);
125: }
126:
127:
128: private function processDate($date)
129: {
130:
131: $res = trim($date);
132: if (strlen($res) == 5)
133: {
134: $parts = explode ("-" , $res);
135: if (count($parts) == 2)
136: {
137: $res = $parts[1].".".$parts[0];
138: return $res;
139: }
140: }
141: return $res;
142: }
143:
144: private function wrappDate($date)
145: {
146: if (strlen ($date) == 1)
147: return '0'.$date;
148: else
149: return $date;
150: }
151:
152: public function processAvisEntry($entries)
153: {
154: if ($entries != NULL)
155: {
156: $entries->type = 'avisid';
157: if (property_exists($entries,"navn" ))
158: {
159: $entries->fornavn = $entries->navn;
160: unset($entries->navn);
161: }
162: if (property_exists($entries,"avispersonid" ))
163: {
164: $entries->pfid = $entries->avispersonid;
165: unset($entries->avispersonid);
166: }
167: $entries->fodselsdato = '';
168: $entries->dodsdato = '';
169: if (property_exists($entries,"day_birth" ) && (!empty($entries->day_birth)))
170: {
171: $entries->fodselsdato = $this->wrappDate($entries->day_birth).'.';
172: }
173: if (property_exists($entries,"month_birth" ) && (!empty($entries->month_birth)))
174: {
175: $entries->fodselsdato .= $this->wrappDate($entries->month_birth).'.';
176: }
177: if (property_exists($entries,"year_birth" ) && (!empty($entries->year_birth)))
178: {
179: $entries->fodselsdato .= $entries->year_birth;
180: }
181: if (property_exists($entries,"avispersonid" ))
182: {
183: $entries->pfid = $entries->avispersonid;
184: unset($entries->avispersonid);
185: }
186: if (property_exists($entries,"day_death" ) && (!empty($entries->day_death)))
187: {
188: $entries->dodsdato = $this->wrappDate($entries->day_death).'.';
189: }
190: if (property_exists($entries,"month_death" ) && (!empty($entries->month_death)))
191: {
192: $entries->dodsdato .= $this->wrappDate($entries->month_death).'.';
193: }
194: if (property_exists($entries,"year_death" ) && (!empty($entries->year_death)))
195: {
196: $entries->dodsdato .= $entries->year_death;
197: }
198: $entries->fodselsdato = trim($entries->fodselsdato);
199: $entries->fodselsdato = rtrim($entries->fodselsdato, '.');
200: $entries->dodsdato = trim($entries->dodsdato);
201: $entries->dodsdato = rtrim($entries->dodsdato, '.');
202: $entries->navn = $entries->fornavn.' '.$entries->etternavn;
203: $entries->navn = trim($entries->navn);
204: }
205: return $entries;
206: }
207:
208: public function getEntries($id)
209: {
210: $avisSearch = new SearchAvisData();
211: $entries = $avisSearch->getPersonByPFid($id);
212: $entries = $this->processAvisEntry($entries);
213: return $entries;
214: }
215:
216: 217: 218: 219: 220: 221: 222: 223:
224:
225: public function getPersonData($id)
226: {
227: $avisSearch = new SearchAvisData();
228: $person = NULL;
229: $entries = $avisSearch->getPersonByPFid($id);
230: if (!empty($entries))
231: {
232: $entries = $this->processAvisEntry($entries);
233: $persondata = $this->getPersonfromFK($entries);
234: $avisfamily = $this->getFamilyforAvis($entries);
235: $entries->partner = $avisfamily['pfid'];
236: $person['family'] = $avisfamily['families'] ;
237: $person['persondata'] = $persondata;
238: $allentries = array();
239: $oneentry = array();
240: $oneentry["individual"] = (array) $entries;
241: if ($avisfamily['other'] != NULL)
242: {
243: $oneentry["other"] = array();
244: $oneentry["other"]["partner"] = (array)$avisfamily['other'];
245: }
246: $allentries[] = $oneentry;
247: $person['entries'] = $allentries;
248: }
249: return $person;
250: }
251: }