1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once('common.inc.php'); |
4
|
|
|
|
5
|
|
|
use Battis\DataUtilities; |
6
|
|
|
use Battis\BootstrapSmarty\NotificationMessage; |
7
|
|
|
|
8
|
|
|
define('STEP_INSTRUCTIONS', 1); |
9
|
|
|
define('STEP_CONFIRM', 2); |
10
|
|
|
define('STEP_TEMPLATE', 3); |
11
|
|
|
|
12
|
|
|
$step = (empty($_REQUEST['step']) ? STEP_INSTRUCTIONS : $_REQUEST['step']); |
13
|
|
|
|
14
|
|
|
switch ($step) { |
15
|
|
|
case STEP_CONFIRM: |
16
|
|
|
case STEP_TEMPLATE: |
17
|
|
|
try { |
18
|
|
|
$source = array(); |
19
|
|
|
$template = false; |
20
|
|
View Code Duplication |
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
|
|
|
|
73
|
|
|
if ($step == STEP_CONFIRM) { |
74
|
|
|
if (empty($courses)) { |
75
|
|
|
$toolbox->smarty_addMessage( |
76
|
|
|
'Courses', |
77
|
|
|
'No courses found in uploaded list.', |
78
|
|
|
NotificationMessage::ERROR |
|
|
|
|
79
|
|
|
); |
80
|
|
|
$step = STEP_INSTRUCTIONS; |
81
|
|
|
} else { |
82
|
|
|
foreach ($courses as $course) { |
83
|
|
|
/* duplicate course settings */ |
84
|
|
|
$course = $toolbox->api_put("courses/sis_course_id:{$course['course_id']}", $source); |
85
|
|
|
|
86
|
|
|
/* duplicate course navigation */ |
87
|
|
View Code Duplication |
foreach ($navigation as $id => $tab) { |
88
|
|
|
$toolbox->api_put( |
89
|
|
|
"courses/{$course['id']}/tabs/$id", |
90
|
|
|
[ |
91
|
|
|
'position' => $tab['position'], |
92
|
|
|
'visibility' => $tab['visibility'] |
93
|
|
|
] |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/* duplicate course content */ |
98
|
|
|
$migration = $toolbox->api_post( |
99
|
|
|
"courses/{$course['id']}/content_migrations", |
100
|
|
|
array( |
101
|
|
|
'migration_type' => 'course_copy_importer', |
102
|
|
|
'settings[source_course_id]' => $template |
103
|
|
|
) |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$toolbox->smarty_addMessage( |
107
|
|
|
"<a target=\"_parent\" href=\"{$_SESSION[CANVAS_INSTANCE_URL]}/courses/{$course['id']}\">{$course['name']}</a>", |
108
|
|
|
"has been templated as a clone of <a target=\"_parent\" href=\"{$_SESSION[CANVAS_INSTANCE_URL]}/courses/$sourceId\">$sourceName</a>. Course content is being <a target=\"_parent\" href=\"{$_SESSION[CANVAS_INSTANCE_URL]}/courses/{$course['id']}/content_migrations\">migrated</a> right now.", |
109
|
|
|
NotificationMessage::GOOD |
|
|
|
|
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} catch (Exception $e) { |
115
|
|
|
$toolbox->exceptionErrorMessage($e); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/* flows into STEP_INSTRUCTIONS */ |
119
|
|
|
|
120
|
|
|
case STEP_INSTRUCTIONS: |
121
|
|
|
default: |
122
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_CONFIRM)); |
123
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
124
|
|
|
} |
125
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.