Completed
Push — master ( 4a1c4b...dec28d )
by Angus
03:08
created

PublicList   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 76
ccs 0
cts 53
cp 0
rs 10
c 0
b 0
f 0
wmc 19
lcom 1
cbo 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
C index() 0 53 14
A _walk_recursive_remove() 0 13 4
1
<?php defined('BASEPATH') or exit('No direct script access allowed');
2
3
class PublicList extends MY_Controller {
4
	public function __construct() {
5
		parent::__construct();
6
7
8
		$this->load->library('form_validation');
9
	}
10
11
	public function index(?string $username = NULL, string $type = 'html') : void {
12
		$show_404 = FALSE;
13
14
		$type = mb_strtolower($type);
15
		if(
16
			(!is_null($username) && $this->form_validation->valid_username($username) && ($user = $this->User->get_user_by_username($username)))
17
			&& in_array($type, ['html', 'json'/*, 'txt'*/])
18
			&& (($this->User->id == $user->id) || ($this->User_Options->get('enable_public_list', $user->id) == 'enabled' ? TRUE : FALSE))//&& get option enabled
19
		) {
20
			$this->header_data['title'] = "{$username}'s list";
21
			$this->header_data['page']  = "dashboard";
22
23
			$trackerData = $this->Tracker->list->get($user->id);
24
			switch($type) {
25
				//case 'txt':
26
				//	break;
27
28
				case 'html':
29
					$this->body_data['trackerData']  = $trackerData['series'];
30
31
					$this->header_data['show_header'] = FALSE;
32
					$this->footer_data['show_footer'] = FALSE;
33
34
					$this->body_data['category_custom_1']      = ($this->User_Options->get('category_custom_1', $user->id) == 'enabled' ? TRUE : FALSE);
35
					$this->body_data['category_custom_1_text'] = $this->User_Options->get('category_custom_1_text', $user->id);
36
37
					$this->body_data['category_custom_2']      = ($this->User_Options->get('category_custom_2', $user->id) == 'enabled' ? TRUE : FALSE);
38
					$this->body_data['category_custom_2_text'] = $this->User_Options->get('category_custom_2_text', $user->id);
39
40
					$this->body_data['category_custom_3']      = ($this->User_Options->get('category_custom_3', $user->id) == 'enabled' ? TRUE : FALSE);
41
					$this->body_data['category_custom_3_text'] = $this->User_Options->get('category_custom_3_text', $user->id);
42
43
					$this->_render_page('User/PublicList');
44
					break;
45
46
				case 'json':
47
					$trackerData = $this->_walk_recursive_remove($trackerData, function($v, $k) {
48
						return in_array($k, ['mal_icon']);
49
					});
50
					$this->_render_json($trackerData);
51
					break;
52
53
				default:
54
					//This will never happen.
55
					break;
56
			}
57
58
		} else {
59
			$show_404 = TRUE;
60
		}
61
62
		if($show_404) show_404();
63
	}
64
65
	private function _walk_recursive_remove (array $array, callable $callback) : array {
66
		foreach ($array as $k => $v) {
67
			if (is_array($v)) {
68
				$array[$k] = $this->_walk_recursive_remove($v, $callback);
69
			} else {
70
				if ($callback($v, $k)) {
71
					unset($array[$k]);
72
				}
73
			}
74
		}
75
76
		return $array;
77
	}
78
}
79