1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once 'common.inc.php'; |
4
|
|
|
|
5
|
|
|
use Battis\BootstrapSmarty\NotificationMessage; |
6
|
|
|
|
7
|
|
|
define('STEP_INSTRUCTIONS', 1); |
8
|
|
|
define('STEP_RENAME', 2); |
9
|
|
|
|
10
|
|
|
$step = (empty($_REQUEST['step']) ? STEP_INSTRUCTIONS : $_REQUEST['step']); |
11
|
|
|
|
12
|
|
|
switch ($step) { |
13
|
|
|
case STEP_RENAME: |
14
|
|
|
/* calculate the proper term prefix/suffix */ |
15
|
|
|
$term = $toolbox->getTermList()[$_REQUEST['term']]; |
16
|
|
|
$isYear = strpos($term['sis_term_id'], 'year') !== false; |
17
|
|
|
preg_match( |
18
|
|
|
'/(\d{4,4}-\d{4,4}) ((St. Mark\'s Saturdays \((Fall|Winter|Spring)\))|' . |
19
|
|
|
'((Fall|Spring) Semester)|(Full Year))/', |
20
|
|
|
$term['name'], |
21
|
|
|
$matches |
22
|
|
|
); |
23
|
|
|
$termPrefix = $matches[1]; |
24
|
|
|
$termSuffix = ''; |
25
|
|
|
if (!empty($matches[3])) { |
26
|
|
|
$termSuffix = $matches[4]; |
27
|
|
|
} elseif (!empty($matches[5])) { |
28
|
|
|
$termSuffix = $matches[6]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$coursesRenamed = 0; |
32
|
|
|
$sectionsRenamed = 0; |
33
|
|
|
|
34
|
|
|
try { |
35
|
|
|
/* get a list of all courses that match account/term and have enrollments */ |
36
|
|
|
$courses = $toolbox->api_get("accounts/{$_REQUEST['account']}/courses", [ |
37
|
|
|
'enrollment_term_id' => $_REQUEST['term'], |
38
|
|
|
'with_enrollments' => true, |
39
|
|
|
'include' => ['teachers'], |
40
|
|
|
]); |
41
|
|
|
foreach ($courses as $course) { |
42
|
|
|
/* calculate specific prefix for this course */ |
43
|
|
|
$teachers = []; |
44
|
|
|
foreach ($course['teachers'] as $teacher) { |
45
|
|
|
$teachers[] = $teacher['display_name']; |
46
|
|
|
} |
47
|
|
|
$teachers = array_unique($teachers); |
48
|
|
|
|
49
|
|
|
/* only rename if the teacher's names aren't already in the name */ |
50
|
|
|
if (strpos($course['name'], implode(', ', $teachers)) === false) { |
51
|
|
|
/* calculate archived course name to include term/teacher metadata */ |
52
|
|
|
$originalName = preg_replace( |
53
|
|
|
'/^(\d{4,4}-\d{4,4} (\((Fall|Spring)\) )?)?(.*)$/', |
54
|
|
|
'$4', |
55
|
|
|
$course['name'] |
56
|
|
|
); |
57
|
|
|
$suffixes = []; |
58
|
|
|
if (!empty($termSuffix)) { |
59
|
|
|
$suffixes[] = $termSuffix; |
60
|
|
|
} |
61
|
|
|
if (preg_match('/ \((Red|Orange|Yellow|Green|Blue|Plum|Brown)\)$/', $originalName)) { |
62
|
|
|
preg_match('/^(.*) \((Red|Orange|Yellow|Green|Blue|Plum|Brown)\)$/', $originalName, $match); |
63
|
|
|
$originalName = $match[1]; |
64
|
|
|
$suffixes[] = $match[2]; |
65
|
|
|
} |
66
|
|
|
if (!empty($teachers)) { |
67
|
|
|
$suffixes[] = implode(', ', $teachers); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$concludedName = "$termPrefix $originalName" . |
71
|
|
|
(empty($suffixes) ? '' : " (" . implode(', ', $suffixes) . ")"); |
72
|
|
|
|
73
|
|
|
/* rename sections to match in single-section courses */ |
74
|
|
|
foreach ($toolbox->api_get("courses/{$course['id']}/sections") as $section) { |
75
|
|
|
if ($section['name'] == $course['name']) { |
76
|
|
|
$toolbox->api_put("sections/{$section['id']}", [ |
77
|
|
|
'course_section[name]' => $concludedName |
78
|
|
|
]); |
79
|
|
|
$sectionsRenamed++; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/* rename course */ |
84
|
|
|
$toolbox->api_put("courses/{$course['id']}", [ |
85
|
|
|
/* also rename any courses named under previous regime that were missing teachers */ |
86
|
|
|
'course[name]' => $concludedName, |
87
|
|
|
'course[course_code]' => $concludedName |
88
|
|
|
]); |
89
|
|
|
$coursesRenamed++; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} catch (Exception $e) { |
93
|
|
|
$toolbox->exceptionErrorMessage($e); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$toolbox->smarty_addMessage( |
97
|
|
|
"{$term['name']} archived and renamed", |
98
|
|
|
"$coursesRenamed courses and $sectionsRenamed sections were renamed to match standard conventions. See " . |
99
|
|
|
"<a target=\"_top\" href=\"{$_SESSION[CANVAS_INSTANCE_URL]}/accounts/{$_REQUEST['account']}" . |
100
|
|
|
"?enrollment_term_id={$_REQUEST['term']}&hide_enrollmentless_courses=1\">" . |
101
|
|
|
'list of affected courses</a>.', |
102
|
|
|
NotificationMessage::GOOD |
|
|
|
|
103
|
|
|
); |
104
|
|
|
$toolbox->smarty_assign([ |
105
|
|
|
'account' => $_REQUEST['account'], |
106
|
|
|
'term' => $_REQUEST['term'] |
107
|
|
|
]); |
108
|
|
|
|
109
|
|
|
/* flows into STEP_INSTRUCTIONS */ |
110
|
|
|
case STEP_INSTRUCTIONS: |
111
|
|
|
default: |
112
|
|
|
$toolbox->smarty_assign([ |
113
|
|
|
'formHidden' => [ |
114
|
|
|
'step' => STEP_RENAME |
115
|
|
|
], |
116
|
|
|
'accounts' => $toolbox->getAccountList(), |
117
|
|
|
'terms' => $toolbox->getTermList() |
118
|
|
|
]); |
119
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
120
|
|
|
} |
121
|
|
|
|
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.