Passed
Push — master ( 4ca170...784f70 )
by Julito
12:58
created

ThematicController::thematic_advance()   D

Complexity

Conditions 13
Paths 264

Size

Total Lines 61
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 43
nc 264
nop 1
dl 0
loc 61
rs 4.9833
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use ChamiloSession as Session;
5
6
/**
7
 * Thematic Controller script.
8
 * Prepares the common background variables to give to the scripts corresponding to
9
 * the requested action.
10
 *
11
 * This file contains class used like controller for thematic,
12
 * it should be included inside a dispatcher file (e.g: index.php)
13
 *
14
 * !!! WARNING !!! : ALL DATES IN THIS MODULE ARE STORED IN UTC !
15
 * DO NOT CONVERT DURING THE TRANSITION FROM CHAMILO 1.8.x TO 2.0
16
 *
17
 * @author Christian Fasanando <[email protected]>
18
 * @author Julio Montoya <[email protected]> token support improving UI
19
 */
20
class ThematicController
21
{
22
    /**
23
     * Constructor.
24
     */
25
    public function __construct()
26
    {
27
        $this->toolname = 'course_progress';
0 ignored issues
show
Bug Best Practice introduced by
The property toolname does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
        $this->view = new View($this->toolname);
0 ignored issues
show
Deprecated Code introduced by
The class View has been deprecated: use Template class ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

28
        $this->view = /** @scrutinizer ignore-deprecated */ new View($this->toolname);
Loading history...
Bug Best Practice introduced by
The property view does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
    }
30
31
    /**
32
     * This method is used for thematic advance control (update, insert or listing)
33
     * render to thematic_advance.php.
34
     *
35
     * @param string $action
36
     */
37
    public function thematic_advance($action)
38
    {
39
        $thematic = new Thematic();
40
        $attendance = new Attendance();
41
        $data = [];
42
        $displayHeader = !empty($_REQUEST['display']) && 'no_header' === $_REQUEST['display'] ? false : true;
43
44
45
        $thematic_id = intval($_REQUEST['thematic_id']);
46
        $thematic_advance_id = isset($_REQUEST['thematic_advance_id']) ? (int) $_REQUEST['thematic_advance_id'] : null;
47
        $thematic_advance_data = [];
48
        switch ($action) {
49
            case 'thematic_advance_delete':
50
51
                break;
52
            case 'thematic_advance_list':
53
                if (!api_is_allowed_to_edit(null, true)) {
54
                    echo '';
55
                    exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
56
                }
57
58
                $data['action'] = $_REQUEST['action'];
59
                $data['thematic_id'] = $_REQUEST['thematic_id'];
60
                $data['attendance_select'] = $attendance_select;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $attendance_select does not exist. Did you maybe mean $attendance?
Loading history...
61
                if (isset($_REQUEST['thematic_advance_id'])) {
62
                    $data['thematic_advance_id'] = $_REQUEST['thematic_advance_id'];
63
                    $thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']);
64
                    $data['thematic_advance_data'] = $thematic_advance_data;
65
                }
66
                break;
67
            default:
68
                $thematic_advance_data = $thematic->get_thematic_advance_list($thematic_advance_id);
69
                break;
70
        }
71
72
        // get calendar select by attendance id
73
        $calendar_select = [];
74
        if (!empty($thematic_advance_data)) {
75
            if (!empty($thematic_advance_data['attendance_id'])) {
76
                $attendance_calendar = $attendance->get_attendance_calendar($thematic_advance_data['attendance_id']);
77
                if (!empty($attendance_calendar)) {
78
                    foreach ($attendance_calendar as $calendar) {
79
                        $calendar_select[$calendar['date_time']] = $calendar['date_time'];
80
                    }
81
                }
82
            }
83
        }
84
85
        $data['action'] = $action;
86
        $data['thematic_id'] = $thematic_id;
87
        $data['thematic_advance_id'] = $thematic_advance_id;
88
        $data['attendance_select'] = $attendance_select;
89
        $data['thematic_advance_data'] = $thematic_advance_data;
90
        $data['calendar_select'] = $calendar_select;
91
        $layoutName = $displayHeader ? 'layout' : 'layout_no_header';
92
93
        // render to the view
94
        $this->view->set_data($data);
95
        $this->view->set_layout($layoutName);
96
        $this->view->set_template('thematic_advance');
97
        $this->view->render();
98
    }
99
}
100