Category   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 83
ccs 0
cts 51
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 4 1
A category_list() 0 8 1
A add_sub() 0 8 2
A edit() 0 8 1
A edit_sub() 0 15 1
A del_sub() 0 4 1
1
<?php
2
3
/**
4
 * Category Controller
5
 */
6
class Category extends MY_Controller {
7
8
	/**
9
	 * Constructor
10
	 */
11
	public function __construct()
12
	{
13
		parent::__construct();
14
		$this->page->set_foot_js_group('js');
15
		$this->page->set_title('Categories');
16
	}
17
18
	/**
19
	 * Redirect to list
20
	 */
21
	public function index()
22
	{
23
		$this->todo->redirect_303(site_url('category/list'));
24
	}
25
26
	/**
27
	 * List of categories
28
	 */
29
	public function category_list()
30
	{
31
		$data = [
32
			'category' => $this->todo->get_category_list()
33
		];
34
		$this->page->set_title("Category List");
35
		$this->page->build('task/cat_list', $data);
36
	}
37
38
	/**
39
	 * Add a category
40
	 */
41
	public function add_sub()
42
	{
43
		if($this->input->post('add_sub') != FALSE)
44
		{
45
			$this->todo->add_category();
46
			$this->todo->redirect_303(site_url('category/list'));
47
		}
48
	}
49
50
	/**
51
	 * Category edit form
52
	 */
53
	public function edit($cat_id)
54
	{
55
		$data = [
56
			'cat' => $this->todo->get_category((int) $cat_id)
57
		];
58
		$this->page->set_title("Edit Category");
59
		$this->page->build('task/cat_add', $data);
60
	}
61
62
	/**
63
	 * Update the category
64
	 */
65
	public function edit_sub()
66
	{
67
		$title = $this->input->post('title', TRUE);
68
		$desc = $this->input->post('desc', TRUE);
69
		$cat_id = (int) $this->input->post('id');
70
		$group_id = $this->todo->get_user_group();
71
72
		$this->db->set('title', $title)
73
			->set('description', $desc)
74
			->where('group_id', $group_id)
75
			->where('id', $cat_id)
76
			->update('category');
77
78
		$this->todo->redirect_303('category/list');
79
	}
80
81
	/**
82
	 * Delete a category
83
	 */
84
	public function del_sub($cat_id)
85
	{
86
		$this->output->set_output($this->todo->del_cat((int) $cat_id));
87
	}
88
}
89
// End of controllers/category.php