1: <?php
2:
3: namespace app\views\personview;
4:
5: 6: 7: 8: 9:
10:
11: use \mako\utility\HTML;
12: use app\views\search\HTMLWrapper;
13: use app\views\search\Format;
14:
15:
16:
17: class PersonDetails {
18:
19: private $details;
20: private $authenticated;
21: private $edit;
22: private $wrapper;
23: protected $html;
24:
25: protected $pikenavn = "pikenavn";
26: protected $altern = "alternEtternavn";
27: protected $names = array("fornavn" => "Fornavn", "mellomnavn" => "Mellomnavn", "patronymikon" => "Patronymikon", "etternavn" => "Etternavn", "pikenavn" => "Pikenavn", "alternEtternavn" => "Alternativt etternavn");
28: protected $gender = array("mann" => array("m", ""), "kvinne" => array("k", ""));
29:
30: public function __construct() {
31: $this->wrapper = new HTMLWrapper();
32: $this->html = new HTML();
33: }
34:
35: 36: 37: 38: 39: 40: 41:
42: public function setDetails($details, $edit, $authenticated) {
43: $this->details = $details;
44: $this->edit = $edit;
45: $this->authenticated = $authenticated;
46: }
47:
48: 49: 50: 51: 52: 53: 54:
55: private function getDate($entry, $type) {
56: $res = '';
57: if (array_key_exists($type . 'dato', $entry) && !empty($entry[$type . 'dato']))
58: $res .= $entry[$type . 'dato'] . ".";
59: if (array_key_exists($type . 'aar', $entry) && !empty($entry[$type . 'aar'])) {
60: if (array_key_exists($type . 'dato', $entry) && $entry[$type . 'dato'] == $entry[$type . 'aar']) {
61:
62: } else {
63: $res .= $entry[$type . 'aar'];
64: }
65: }
66: $res = trim($res);
67: $res = trim($res, ".");
68: return $res;
69: }
70:
71: 72: 73: 74: 75: 76: 77: 78:
79: private function getNamesBoxes() {
80:
81: $res = '';
82: foreach ($this->names as $field => $title) {
83:
84: if ($field == $this->pikenavn && array_key_exists('kjonn', $this->details) && $this->details['kjonn'] == 'm')
85: continue;
86: $row = '';
87: $value = '';
88: if (array_key_exists($field, $this->details)) {
89: $value = $this->details[$field];
90: }
91: $row .= $this->wrapper->createLabelElement($title . ': ', $field . 'label');
92: $row .= $this->wrapper->createTextElement($field, $value, $field, 30);
93: $res .= $this->html->tag('li', [], $row);
94: }
95: return $res;
96: }
97:
98: public function getFullName() {
99: $name = '';
100: foreach ($this->names as $field => $title) {
101: if (array_key_exists($field, $this->details) && !empty($this->details[$field]) && $field != $this->pikenavn && $field != $this->altern) {
102: $name .= $this->details[$field] . ' ';
103: }
104: }
105: $name = trim($name);
106: if (array_key_exists($this->altern, $this->details) && !empty($this->details[$this->altern])) {
107: $name = $name . ' (' . $this->details[$this->altern] . ')';
108: }
109: if ($this->details['kjonn'] == 'k' && array_key_exists($this->pikenavn, $this->details) && !empty($this->details[$this->pikenavn])) {
110: $name = $name . ', f. ' . $this->details[$this->pikenavn];
111: }
112:
113: return $name;
114: }
115:
116: 117: 118: 119: 120: 121: 122: 123:
124: private function createPersonDetails() {
125: $res = '';
126: $disable = 'disabled';
127: $close = '';
128: $kjonn = '';
129: if ($this->authenticated === true)
130: $disable = '';
131:
132:
133:
134: if ($this->edit === true) {
135: $buttenresponce = 'savepersondata';
136: $buttenname = 'Lagre endringene';
137: } else {
138: $buttenresponce = 'openeditpersondetails';
139: $buttenname = 'Rediger';
140: }
141:
142: if ($this->edit == 'true') {
143: $name = $this->getNamesBoxes();
144: } else {
145:
146: $name = $this->getFullName();
147:
148:
149:
150: if (array_key_exists('kjonn', $this->details)) {
151: if ($this->details['kjonn'] == 'm') {
152: $kjonn = 'Mann';
153: } elseif ($this->details['kjonn'] == 'k') {
154: $kjonn = 'Kvinne';
155: }
156: }
157: }
158: $genderinput = '';
159: if ($this->edit == 'true') {
160:
161: if (array_key_exists('kjonn', $this->details)) {
162: if ($this->details['kjonn'] == 'm')
163: $this->gender["mann"][1] = "checked";
164: elseif ($this->details['kjonn'] == 'k')
165: $this->gender["kvinne"][1] = "checked";
166: }
167: $genderinput .=$this->html->tag('legend', [], 'Kjønn');
168: foreach ($this->gender as $index => $value) {
169: $genderinput .= $this->wrapper->createBoxElement('kjonn', $this->gender[$index][0], 'radio', 'kjonn', $this->gender[$index][1]);
170: $genderinput .= $index;
171: $genderinput .= '<br>';
172: }
173:
174: $genderinput = $this->html->tag('fieldset', [], $genderinput);
175:
176:
177: }
178: $f = '';
179: if ($this->edit === true) {
180: $f = $this->wrapper->createLabelElement('Dato', 'personbdatolabel');
181: $f .= $this->wrapper->createTextElement('fodselsdato', $this->getDate($this->details, 'fodsels'), 'fodselsdato', 30);
182: $f .= $this->wrapper->createLabelElement('Sted', 'personbplacelabel');
183: $f .= $this->wrapper->createTextElement('fodested', $this->details['fodested'], 'fodested', 30);
184: $f = $this->html->tag('li', [], $f);
185: } else {
186: if (empty($this->details['fodselsdato']) && empty($this->details['fodselsaar']))
187: $f = 'Ukjent dato, ';
188: else {
189: $f = $this->getDate($this->details, 'fodsels');
190: if (!empty($f))
191: $f .= ', ';
192: }
193: if ($this->details['fodested'] == '')
194: $f .= 'Ukjent sted';
195: else
196: $f .= $this->details['fodested'];
197: }
198: $d = '';
199: if ($this->edit === true) {
200: $d = $this->wrapper->createLabelElement('Dato', 'personddatolabel');
201: $d .= $this->wrapper->createTextElement('dodsdato', $this->getDate($this->details, 'dods'), 'dodsdato', 30);
202: $d .= $this->wrapper->createLabelElement('Sted', 'persondplacelabel');
203: $d .= $this->wrapper->createTextElement('dodssted', $this->details['dodssted'], 'dodssted', 30);
204: $d = $this->html->tag('li', [], $d);
205: } else {
206: if (empty($this->details['dodsdato']))
207: $d = 'Ukjent dato, ';
208: else
209: $d = $this->details['dodsdato'] . ', ';
210: if (empty($this->details['dodssted']))
211: $d .= 'Ukjent sted';
212: else
213: $d .= $this->details['dodssted'];
214: }
215: $res .= '<div>';
216: $res .= '<form action="" method="get">';
217: if ($this->edit === true) {
218: $res .= $this->html->tag('ul', ["class" => "persondetails"], $name . $f . $d);
219: $res .= $genderinput;
220: } else {
221: $res .= '<h2>' . $name . '</h2>';
222:
223: $k = $this->html->tag('th', [], $kjonn);
224: $k = $this->html->tag('tr', [], $k);
225: $f = $this->html->tag('th', [], 'Født: ' . $f);
226: $f = $this->html->tag('tr', [], $f);
227: $d = $this->html->tag('th', [], 'Død: ' . $d);
228: $d = $this->html->tag('tr', [], $d);
229: $res .= $this->html->tag('table', ["id" => "prdetails"], $k . $f . $d);
230: }
231: if ($this->authenticated === true) {
232: $res .= $this->html->tag('button', array('type' => 'submit', 'name' => $buttenresponce, $disable), $buttenname);
233: }
234: $res .= '</form>';
235: $res .= '</div>';
236: return $res;
237: }
238:
239: public function getPersonDetailsPanel() {
240: $panel = "";
241: $panel .= '<div id="DetailsPanel" class="panel"> ';
242: if ($this->details == NULL)
243: return $panel;
244: else {
245: $panel .= $this->createPersonDetails();
246: }
247: if ($this->edit === true) {
248: $panel .= '<form action="" method="get">';
249: $panel .= $this->html->tag('button', array('type' => 'submit', 'name' => 'closepersondata'), 'Close');
250: $panel .= '</form>';
251: }
252: $panel .= '</div>';
253: return $panel;
254: }
255:
256: }
257: