-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_course_cats.php
More file actions
115 lines (105 loc) · 2.57 KB
/
create_course_cats.php
File metadata and controls
115 lines (105 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
// Create our course categories for a semester, which you are prompted to
// provide by the script. So, for instance, creates the (parent) 2020FA,
// 2020FA > Metacourses, 2020FA > ANIMA, etc. categories, one per CCA program.
// Can run interactively with no arguments or accept a single argument that is
// the parent semester category: `php create_course_cats.php 2021FA`
/**
*
* @package core
* @subpackage cli
* @copyright 2025 CCA (https://cca.edu)
* @license https://opensource.org/licenses/ECL-2.0 ECL 2.0
*/
define('CLI_SCRIPT', true);
// Bitnami container config is in a consistent place
require('/bitnami/moodle/config.php');
// https://github.com/moodle/moodle/blob/MOODLE_404_STABLE/lib/clilib.php
require_once($CFG->libdir.'/clilib.php');
$categories = array(
'Metacourses',
'ADSTU',
'ANIMA',
'ARCHT',
'ARTED',
'CERAM',
'CMDSN',
'COMAR',
'COMIC',
'COMIX',
'CRAFT',
'CRITI',
'CRTSD',
'CURPR',
'DESGN',
'DSMBA',
'ETHSM',
'ETHST',
'EXCHG',
'EXTED',
'FASHN',
'FILMG',
'FILMS',
'FINAR',
'FNART',
'FURNT',
'FYCST',
'GAMES',
'GELCT',
'GLASS',
'GRAPH',
'HAAVC',
'ILLUS',
'INDIV',
'INDUS',
'INTDS',
'INTER',
'IXDGR',
'IXDSN',
'KADZE',
'LITPA',
'MAARD',
'MARCH',
'METAL',
'MOBIL',
'PHCRT',
'PHOTO',
'PNTDR',
'PRECO',
'PRINT',
'SCIMA',
'SCULP',
'SSHIS',
'TEXTL',
'TRAVL',
'UDIST',
'VISCR',
'WRITE',
'WRLIT'
);
if (isset($argv[1])) {
$semester_str = trim($argv[1]);
} else {
$prompt = "Semester category (e.g. 2020FA)";
$semester_str = trim(cli_input($prompt));
if (!strlen($semester_str)) {
cli_error('Empty semester string, exiting without creating any course categories.');
}
}
cli_writeln('Creating course categories for ' . $semester_str . ' semester');
// create semester, we need to know its ID to create its children
$data = new stdClass();
$data->name = $semester_str;
$data->idnumber = $semester_str;
$semester = \core_course_category::create($data);
cli_writeln($semester->id . ' ' . $semester->name . ' (' . $semester->idnumber . ')');
// position department children under semester parent
foreach ($categories as $category) {
$data = new stdClass();
$data->name = $category;
$data->idnumber = $semester_str . '-' . $category;
$data->parent = $semester->id;
$childcat = \core_course_category::create($data);
cli_writeln($childcat->id . ' ' . $childcat->name . ' (' . $childcat->idnumber .') ');
}
exit(0);