-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourse.api.php
226 lines (215 loc) · 7.25 KB
/
course.api.php
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/**
* @file
* Hooks provided by Course module.
*
* These entity types provided by Course also have entity API hooks.
*
* course_report
* course_object
* course_object_fulfillment
* course_enrollment
*
* So for example
*
* hook_course_report_presave(&$course_report)
* hook_course_object_fulfillment_insert($course_object_fulfillment)
*
* Enjoy :)
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Allow modules to define handlers that extend Course functionality.
*
* @return array
* A associative array of handler declarations, keyed by type:
* - object: An associative array of course object types, keyed by type:
* - name: A string to reference this type on administrative forms.
* - description: A string to display more information to administrators.
* - class: (optional) A class name which will override the default
* CourseObject class.
* - fulfillment class: (optional) A class name which will override the
* default CourseObjectFulfillment class.
* - outline: An asociative array of outline handlers, keyed by type:
* - name: A string to reference this type on administrative forms.
* - description: A string to display more information to administrators.
* - callback: A function name that will return themed course outline HTML.
* - file: (optional) A string to locate the callback file. This should be
* specified if not located in the implementing module's .module file.
* - file path: (optional) The path to the directory containing the file
* specified in 'file'. Defaults to the implementing module path.
* - settings: An associative array of configurations, which will be available
* as secondary tabs from the Course sitewide settings form:
* - name: A string to reference this type on administrative forms.
* - description: A string to display more information to administrators.
* - callback: A function name that will return a Drupal form API array.
* - file: (optional) A string to locate the callback file. This should be
* specified if not located in the implementing module's .module file.
* - file path: (optional) The path to the directory containing the file
* specified in 'file'. Defaults to the implementing module path.
* - package: (optional) The key of the settings package this form should be
* grouped with.
*/
function hook_course_handlers() {
// Example: a custom module definition.
return array(
'object' => array(
'custom' => array(
'name' => t('Custom'),
'class' => 'CustomCourseObject',
'description' => t('A custom course object.'),
),
),
'outline' => array(
'custom' => array(
'name' => t('Custom'),
'description' => t('Custom outline display.'),
'callback' => 'custom_outline',
),
),
'settings' => array(
'custom' => array(
'name' => t('Custom'),
'description' => t('Course custom configurations.'),
'callback' => 'custom_course_settings',
),
'followup' => array(
'name' => t('Follow up'),
'description' => t('Course custom followup configurations.'),
'callback' => 'custom_course_followup_settings',
'file' => 'includes/another_module.followup.inc',
'file path' => drupal_get_path('module', 'another_module'),
'package' => 'custom',
),
),
);
}
/**
* Allow modules to alter each other's list of handlers.
*
* @param array $handlers
* By reference. The return value from each module that implements
* hook_course_handlers().
* @param type $module
*
* @see course_get_handlers()
*/
function hook_course_handlers_alter(&$handlers, $module) {
// Example: alter the class of a course object handler.
$is_quiz_type = isset($handlers['object']) && isset($handlers['object']['quiz']);
if ($module == 'course_quiz' && $is_quiz_type) {
// Change which class should be used.
$handlers['object']['quiz']['class'] = 'CustomQuizCourseObject';
}
}
/**
* Allow modules to add links to the course completion landing page, such as
* post-course actions.
*
* @param array $links
* By reference. Currently an array of three elements:
* - 0: $path param for l().
* - 1: $text param for l().
* - 2: A description, suitable for theme_form_element().
* @param object $course_node
* The course node object.
* @param object $account
* The user who just took the course.
*
* @see course_completion_page()
*/
function hook_course_outline_completion_links_alter(&$links, $course_node, $account) {
// Example: add a link.
$links['gohome'] = array(t('Go home!'), '<front>', t('If you got this far, you
deserve a link back home'));
}
/**
* Allow modules to alter remaining incomplete links on the course completion
* landing page.
*
* @param array $links
* Same as $links param for hook_course_outline_completion_links().
* @param object $course_node
* The course node object.
* @param object $account
* The user who just took the course.
*
* @see course_completion_page()
*/
function hook_course_outline_incomplete_links_alter(&$links, $course_node, $account) {
// Example: change the default link.
$links['course'] = array(t("Let's try that again"), "node/$course_node->nid/takecourse", t('Looks like you missed something.'));
}
/**
* Allow modules to restrict menu access to the take course tab.
*
* @param object $node
* The course node.
* @param object $user
* The user to check access.
*
* @return boolean
* Any hook returning FALSE will restrict access to the take course tab.
*/
function hook_course_has_takecourse($node, $user) {
if ($node->type == 'imported_course') {
// Users cannot take imported courses.
return FALSE;
}
}
/**
* Allow modules to determine if this course should be restricted.
*
* If any module implementing this hook returns FALSE or an array containing
* 'success' => FALSE, the course will be restricted.
*
* @param string $op
* Either 'enroll' or 'take'.
* @param object $node
* The course node.
* @param object $user
* The user who may or may not enroll/take the course.
*
* @return boolean|array
* Either FALSE, or an array containing:
* - success: Boolean. Indicates whether or not the user has permission to
* enroll or take this course.
* - message: String. If success is FALSE, a message to display to the user.
*
* @see course_take_course_access()
* @see course_enroll_access()
*/
function hook_course_access($op, $node, $user) {
if ($op == 'take') {
// Example: do not allow users to take courses on Wednesdays.
if (date('L') == 'wednesday') {
$hooks[] = array(
'success' => FALSE,
'message' => t('Courses are closed on Wednesdays.'),
);
}
// Example: however allow users to bypass enrollment restriction on Christmas.
elseif ((date('m') == 12) && (date('d') == 25)) {
$hooks[] = array('success' => TRUE);
}
return $hooks;
}
if ($op == 'enroll') {
// Same usage as $op == 'take'.
}
}
/**
* Implements hook_course_access_alter().
*/
function hook_course_access_alter(&$hooks, $op, $node, $account) {
if ($op == 'enroll') {
$hooks['wait_a_minute'] = array(
'message' => t('You cannot take this course.'),
'weight' => 5,
'success' => FALSE,
);
}
}