table   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 27
dl 0
loc 45
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get_array_keys() 0 2 1
A genere_body() 0 14 3
A get_datas_from_json() 0 9 1
A genere_header() 0 11 3
1
<?php
2
namespace phoponent\app\component\custom\Table\mvc\model;
3
4
use phoponent\app\component\custom\Table\mvc\view\td;
5
use phoponent\app\component\custom\Table\mvc\view\th;
6
use phoponent\app\component\custom\Table\mvc\view\tr;
7
use phoponent\framework\traits\model;
8
use phoponent\framework\service\json_reader;
9
10
    class table extends \phoponent\app\component\core\Table\mvc\model\table {
11
        use model;
12
13
		private function get_array_keys($array) {
14
			return array_keys($array);
15
		}
16
17
        public function get_datas_from_json($file) {
18
        	$file = __DIR__."/../{$file}";
19
			/**
20
			 * @var json_reader $json_reader_service
21
			 */
22
        	$json_reader_service = $this->get_service('json_reader');
23
        	return $json_reader_service
24
				->set_file($file)
25
				->get('datas');
26
        }
27
28
        public function genere_header(array $json_datas, tr $tr_view, th $th_view) {
29
        	$json_datas = $this->get_array_keys((array)$json_datas[0]);
30
			$header = '';
31
        	foreach ($json_datas as $json_data) {
32
				foreach ((array)$json_data as $data) {
33
					$new_th_view = $th_view;
34
					$header .= 	$new_th_view->set_vars(['text' => $data])->render();
35
        		}
36
        	}
37
        	$tr_view->set_vars(['text' => $header]);
38
        	return $tr_view->render();
39
		}
40
41
		public function genere_body(array $json_datas, tr $tr_view, td $td_view) {
42
        	$lines = '';
43
        	foreach ($json_datas as $id => $json_data) {
44
        		$json_data = (array)$json_data;
45
        		$header_keys = $this->get_array_keys($json_data);
46
				$tr = $tr_view;
47
				$line = '';
48
        		foreach ($header_keys as $header_key) {
49
        			$td = $td_view;
50
					$line .= $td->set_vars(['text' => ''.$json_data[$header_key]])->render();
51
        		}
52
        		$lines .= $tr->set_vars(['text' => $line])->render();
53
        	}
54
			return $lines;
55
56
		}
57
    }