Code Duplication    Length = 50-53 lines in 2 locations

courses/create-courses.php 1 location

@@ 64-116 (lines=53) @@
61
        }
62
63
        $templated = false;
64
        if (empty($_REQUEST['template'])) {
65
            $toolbox->smarty_addMessage(
66
                'Template',
67
                'was not entered, courses are in default configuration.'
68
            );
69
        } else {
70
            $templated = true;
71
            $template = (is_int($_REQUEST['template']) ? $_REQUEST['template'] : "sis_course_id:{$_REQUEST['template']}");
72
73
            /* pull course settings as completely as possible */
74
            try {
75
                $source = $toolbox->api_get("courses/$template/settings");
76
                $source = array_merge(
77
                    $source->getArrayCopy(),
78
                    $toolbox->api_get("courses/$template")->getArrayCopy()
79
                );
80
81
                /* save ID and name to create a nice link later */
82
                $sourceId = $source['id'];
83
                $sourceName = $source['name'];
84
85
                /* clear settings that are provided form entry */
86
                unset($source['id']);
87
                unset($source['sis_course_id']);
88
                unset($source['integration_id']);
89
                unset($source['name']);
90
                unset($source['course_code']);
91
                unset($source['account_id']);
92
                unset($source['enrollment_term_id']);
93
                unset($source['start_at']);
94
                unset($source['end_at']);
95
                unset($source['enrollments']);
96
97
                /* why nest this, I mean... really? */
98
                $source = array('course' => $source);
99
100
                /* pull course navigation */
101
                $tabs = $toolbox->api_get("courses/$template/tabs", [
102
                    'include[]' => 'external'
103
                ]);
104
                $navigation = [];
105
                foreach ($tabs as $tab) {
106
                    if ($tab['id'] != 'home' && $tab['id'] != 'settings') {
107
                        $navigation[$tab['id']] = $tab;
108
                    }
109
                }
110
                uasort($navigation, function ($left, $right) {
111
                    return $left['position'] - $right['position'];
112
                });
113
            } catch (Exception $e) {
114
                $toolbox->exceptionErrorMessage($e);
115
            }
116
        }
117
118
        $csv = DataUtilities::loadCsvToArray('csv');
119
        if ($csv) {

courses/template-courses.php 1 location

@@ 20-69 (lines=50) @@
17
        try {
18
            $source = array();
19
            $template = false;
20
            if (empty($_REQUEST['template'])) {
21
                $toolbox->smarty_addMessage(
22
                    'Template',
23
                    'was not entered, courses are in default configuration.'
24
                );
25
                $step = STEP_INSTRUCTIONS;
26
            } else {
27
                $templated = true;
28
                $template = (is_int($_REQUEST['template']) ? $_REQUEST['template'] : "sis_course_id:{$_REQUEST['template']}");
29
30
                /* pull course settings as completely as possible */
31
                $source = $toolbox->api_get("courses/$template/settings");
32
                $source = array_merge(
33
                    $source->getArrayCopy(),
34
                    $toolbox->api_get("courses/$template")->getArrayCopy()
35
                );
36
37
                /* save ID and name to create a nice link later */
38
                $sourceId = $source['id'];
39
                $sourceName = $source['name'];
40
41
                /* clear settings that are provided form entry */
42
                unset($source['id']);
43
                unset($source['sis_course_id']);
44
                unset($source['integration_id']);
45
                unset($source['name']);
46
                unset($source['course_code']);
47
                unset($source['account_id']);
48
                unset($source['enrollment_term_id']);
49
                unset($source['start_at']);
50
                unset($source['end_at']);
51
                unset($source['enrollments']);
52
53
                /* why nest this, I mean... really? */
54
                $source = array('course' => $source);
55
56
                /* pull course navigation */
57
                $tabs = $toolbox->api_get("courses/$template/tabs", [
58
                    'include[]' => 'external'
59
                ]);
60
                $navigation = [];
61
                foreach ($tabs as $tab) {
62
                    if ($tab['id'] != 'home' && $tab['id'] != 'settings') {
63
                        $navigation[$tab['id']] = $tab;
64
                    }
65
                }
66
                uasort($navigation, function ($left, $right) {
67
                    return $left['position'] - $right['position'];
68
                });
69
            }
70
71
            $courses = DataUtilities::loadCsvToArray('csv');
72