-
Notifications
You must be signed in to change notification settings - Fork 0
/
unh_d1_drupal.module
482 lines (428 loc) · 17.2 KB
/
unh_d1_drupal.module
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<?php
/**
* @file
*
* @todo: Update this docblock.
*
* This is the main module file.
*
* This module implements some common Drupal constructs for unh_d1_client.
*
*
*/
/******************************************************************************
* Get 'helper' functions and constants.
******************************************************************************/
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.ajax.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.constants.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.course_node.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.course_search.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.course_utils.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.non_d1_course.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.settings.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.sort.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.utils.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.views_php.inc';
require_once drupal_get_path('module', 'unh_d1_drupal') . '/includes/unh_d1_drupal.admin.inc';
// Allows us to pass variables from php to javascript. We need this in order to make
// calls to the d1 api from javascript (for ajax mapping of course title to course code.
$settings = array(
'd1ClientWebserviceURL' => unh_d1_client_webservice_path(),
'd1ClientDomainFE' => unh_d1_client_settings_fe_domain(),
'd1ClientDomainBE' => unh_d1_client_settings_be_domain(),
'd1ClientDomainPublic' => unh_d1_client_settings_public_domain()
);
drupal_add_js(array('unh_d1_drupal' => $settings), array('type' => 'setting'));
// drupal_add_js(drupal_get_path('module', 'unh_d1_drupal') . '/js/unh_d1_drupal.js');
/*
function unh_d1_drupal_preprocess_node(&$vars) {
// Add JS & CSS by node type
$testvar = 'MAKING MY AJAX CALL!!';
// ddl('got here!');
// ddl($vars, '$vars - pre got here!!');
if( $vars['type'] == 'course') {
drupal_add_js(array('unh_d1_drupal' => array('testvar' => $testvar)), array('type' => 'setting'));
drupal_add_js(drupal_get_path('module', 'unh_d1_drupal') . '/js/unh_d1_drupal.course.js');
}
}
*/
/**
* Implements hook_menu().
*/
function unh_d1_drupal_menu() {
$items = array();
$items['title/autocomplete'] = array(
'page callback' => '_unh_d1_drupal_title_autocomplete',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
$items['certificate_title/autocomplete'] = array(
'page callback' => '_unh_d1_drupal_certificate_title_autocomplete',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
// Admin main page for d1 config.
$items['admin/config/unh-d1'] = array(
'title' => 'UNH DestinyOne',
'description' => 'UNH settings for DestinyOne web services.',
'page callback' => 'system_admin_menu_block_page',
//'access arguments' => array('administer site configuration'),
'access callback' => TRUE,
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
// Admin config page for d1_drupal module.
$items['admin/config/unh-d1/unh-d1-drupal-settings'] = array(
'title' => 'UNH D1: Drupal Settings',
'description' => 'Configuration UNH DestinyOne Drupal module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('unh_d1_drupal_settings_form'),
//'access callback' => TRUE,
'access arguments' => array('administer unh_d1_drupal module'),
'type' => MENU_NORMAL_ITEM,
);
// Admin config page for d1_drupal reports.
$items['admin/config/unh-d1/unh-d1-drupal-reports-orphan-d1-courses'] = array(
'title' => 'UNH D1: Reports - Orphan D1 Courses',
'description' => 'Reports DestinyOne (D1) Courses that are visible to the UNH web app through the D1 Client, but have no corresponding Drupal course node.',
'page callback' => 'unh_d1_drupal_reports_orphan_d1_courses',
//'page arguments' => array('d1pdt_reports_orphans'),
//'access callback' => TRUE,
'access arguments' => array('view unh_d1_drupal reports'),
'type' => MENU_NORMAL_ITEM,
);
// Add callback for non-cached loading of status (ajax).
$items['unh_d1_drupal/ajax/get_section_status/%/%/%'] = array(
//$items['unh_d1_drupal/ajax/get_section_status'] = array(
'page callback' => 'unh_d1_drupal_ajax_get_section_status', // Render HTML.
'page arguments' => array(3, 4, 5, 6),
//page arguments' => array('abc'),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
'delivery callback' => 'unh_d1_drupal_ajax_get_section_status_callback', // Magic goes here.
);
$items['course-search-bar'] = array(
'title' => 'Course Search Bar',
'page callback' => 'drupal_get_form',
'page arguments'=>array('unh_d1_drupal_courseSearchBar'),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
$items['course-search-by-text'] = array(
'title' => 'Course Search - Textual',
'page callback' => 'drupal_get_form',
'page arguments'=>array('unh_d1_drupal_courseSearchByText'),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
// All search form results are forwarded here for display
$items['course-search-results/%'] = array(
'title' => 'Course Search Results',
'page callback' => 'unh_d1_drupal_courseSearch_results',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
}
/**
* Implements hook_permission().
*/
function unh_d1_drupal_permission() {
return array(
'administer unh_d1_drupal module' => array(
'title' => t('Administer UNH D1 Drupal Settings'),
'description' => t('Configure UNH Drupal module settings for this site.'),
),
'view unh_d1_drupal reports' => array(
'title' => t('View UNH D1 Drupal reports'),
'description' => t('View UNH D1 Drupal reports.'),
),
);
}
/**
* Implements hook_form_alter() for the course node edit form.
*
* Adds autocomplete to the 'course code' field.
*
* @todo:
* - Deletes access to the 'location' field???
* - finish bringing in form_alter code from d1pdt, training.
*/
function unh_d1_drupal_form_course_node_form_alter(&$form, &$form_state, $form_id) {
// Autocomplete for course content type (course title)
$form['title']['#attached'] = array(
'library' => array(
array('system', 'ui.autocomplete'),
),
'js' => array(
drupal_get_path('module','unh_d1_drupal') . '/js/unh_d1_drupal.course_node.js',
),
);
$form['title']['#autocomplete_path'] = 'title/autocomplete';
$form['field_course_code']['und'][0]['value']['#attributes']['readonly'] = 'readonly';
// Autocomplete for course content type (certificate title)
foreach($form['field_certificate'][LANGUAGE_NONE] as $delta => $field) {
if(is_array($field) && is_numeric($delta)) {
foreach($field['field_certificate_title'][LANGUAGE_NONE] as $delta_1 => $field_1) {
if(is_array($field_1) && is_numeric($delta_1)) {
$form['field_certificate'][LANGUAGE_NONE][$delta]['field_certificate_title'][LANGUAGE_NONE][$delta_1]['value']['#autocomplete_path'] = 'certificate_title/autocomplete';
}
}
}
}
//
// Supply settings for course certificates.
//
// Make certificate codes readonly.
foreach($form['field_certificate'][LANGUAGE_NONE] as $delta => $field) {
if(is_array($field) && is_numeric($delta)) {
foreach($field['field_certificate_code'][LANGUAGE_NONE] as $delta_1 => $field_1) {
if(is_array($field_1) && is_numeric($delta_1)) {
$form['field_certificate'][LANGUAGE_NONE][$delta]['field_certificate_code'][LANGUAGE_NONE][$delta_1]['value']['#attributes']['readonly'] = 'readonly';
}
}
}
}
// @todo: if you ever delete the location field, get rid of this line.
//$form['field_location']['#access'] = FALSE;
}
/******************************************************************************
* Form constructor for the UNH D1 Drupal admin settings form.
******************************************************************************/
function unh_d1_drupal_settings_form($form, &$form_state) {
$programAreas = unh_d1_client_getprogramAreas();
$options_array = array();
foreach($programAreas as $programArea) {
# the values for the dropdown box
$options_array[$programArea['code']] = $programArea['name'];
}
$form['unh_d1_drupal_program_area'] = array(
'#title' => t('Program Area'),
'#type' => 'select',
'#description' => "Select the applicable program area. Used to limit our set of resources to our particular program.",
//'#options' => $form['unh_d1_drupal_program_area_options']['#value'],
'#options' => $options_array,
'#default_value' => variable_get('unh_d1_drupal_program_area', ''),
'#required' => TRUE,
);
if (_unh_d1_drupal_google_analytics_is_enabled() && _d1_drupal_add_to_head_is_enabled()) {
$title = 'Google Track Enrollments (' . variable_get('googleanalytics_account') . ')';
$disabled = FALSE;
$additional_desc = UNH_D1_DRUPAL_GOOGLE_ET_DESC_ADDL;
} else {
$title = UNH_D1_DRUPAL_GOOGLE_ET_TITLE;
$disabled = TRUE;
$additional_desc = UNH_D1_DRUPAL_GOOGLE_ET_DESC_ADDL;
}
$form['unh_d1_drupal_google_track_enrollments'] = array(
'#type' =>'checkbox',
'#title' => t($title),
'#default_value' => variable_get('unh_d1_drupal_google_track_enrollments', 0),
'#description' => t($additional_desc . UNH_D1_DRUPAL_GOOGLE_ET_DESC),
'#disabled' => $disabled,
);
$form = system_settings_form($form);
$form['#submit'][] = 'unh_d1_drupal_settings_form_custom_submit';
return $form;
}
/**
* Form validation for the UNH D1 Drupal admin settings form.
*/
function unh_d1_drupal_settings_form_validate($form, &$form_state){
}
/**
* Form custom submit for the UNH D1 Drupal admin settings form.
*/
function unh_d1_drupal_settings_form_custom_submit($form, &$form_state){
// Does this even work? (drupal_flush_all_caches)
drupal_flush_all_caches();
drupal_set_message('All caches have been cleared.', 'status', FALSE);
}
/******************************************************************************
*
* Definitions for various content panes (ctools plugins, theme hooks, etc.).
*
******************************************************************************/
/**
* Implements hook_ctools_plugin_directory().
*/
function unh_d1_drupal_ctools_plugin_directory($module, $plugin) {
if (($module == 'ctools' || $module == 'panels') && !empty($plugin)) {
return 'plugins/' . $plugin;
}
}
/**
* Implements hook_theme().
*/
function unh_d1_drupal_theme() {
$module_path = drupal_get_path('module', 'unh_d1_drupal');
$base = array(
'path' => "{$module_path}/theme",
);
$ret = array(
'unh_d1_drupal__d1__course_overview_pane' => $base + array(
'template' => 'unh-d1-drupal--d1--course-overview-pane',
'variables' => array(
'course_nid' => '0',
'course' => NULL,
'course_overview' => '',
'config' => array(),
),
),
'unh_d1_drupal__d1__course_section' => $base + array(
'template' => 'unh-d1-drupal--d1--course-section',
'variables' => array(
'course_nid' => 0,
'course' => NULL,
'section' => NULL,
'config' => array(),
'disp_idx' => 0,
'disp_open' => FALSE,
),
),
'unh_d1_drupal__d1__course_sections_pane' => $base + array(
'template' => 'unh-d1-drupal--d1--course-sections-pane',
'variables' => array(
'course_nid' => '0',
'course' => NULL,
'sections' => array(),
'config' => array(),
),
),
'unh_d1_drupal__non_d1__course_overview_pane' => $base + array(
'template' => 'unh-d1-drupal--non-d1--course-overview-pane',
'variables' => array(
'course_nid' => '0',
'course' => NULL,
'course_overview' => '',
'config' => array(),
),
),
'unh_d1_drupal__non_d1__course_sections_pane' => $base + array(
'template' => 'unh-d1-drupal--non-d1--course-sections-pane',
'variables' => array(
'course_nid' => '0',
'course' => NULL,
'sections' => array(),
'config' => array(),
),
),
'unh_d1_drupal__course_search_results__by_text' => $base + array(
'template' => 'unh-d1-drupal--course-search-results--by-text',
'variables' => array(
'form_state' => array(),
),
),
'unh_d1_drupal__course_search_results__by_topic' => $base + array(
'template' => 'unh-d1-drupal--course-search-results--by-topic',
'variables' => array(
'form_state' => array(),
'filtered' => FALSE,
),
),
'unh_d1_drupal__course_search_results__by_filter' => $base + array(
'template' => 'unh-d1-drupal--course-search-results--by-filter',
'variables' => array(
'form_state' => array(),
),
),
'unh_d1_drupal__course_search_results__course_list_block' => $base + array(
'template' => 'unh-d1-drupal--course-search-results--course-list-block',
'variables' => array(
'course_profiles' => array(),
),
),
'unh_d1_drupal__course_search_results__applicable_certificates_block' => $base + array(
'template' => 'unh-d1-drupal--course-search-results--applicable-certificates-block',
'variables' => array(
'course' => NULL,
),
),
);
return $ret;
}
/**
* Implements hook_theme_registry_alter(). Brings in all of our module theme templates.
*/
function unh_d1_drupal_theme_registry_alter(&$theme_registry) {
// Defined path to the current module.
$module_path = drupal_get_path('module', 'unh_d1_drupal');
// Find all .tpl.php files in this module's folder recursively.
$template_file_objects = drupal_find_theme_templates($theme_registry, '.tpl.php', $module_path);
// Iterate through all found template file objects.
foreach ($template_file_objects as $key => $template_file_object) {
// If the template has not already been overridden by a theme.
if (!isset($theme_registry[$key]['theme path']) || !preg_match('#/themes/#', $theme_registry[$key]['theme path'])) {
// Alter the theme path and template elements.
$theme_registry[$key]['theme path'] = $module_path;
$theme_registry[$key] = array_merge($theme_registry[$key], $template_file_object);
$theme_registry[$key]['type'] = 'module';
}
}
}
/*
function unh_d1_drupal_preprocess_panels_pane(&$vars) {
// ddl($vars, '$vars - preprocess panels pane.');
}
*/
/**
* Implements hook_preprocess() for course sections pane.
*
* Sets up variables for the course sections pane template.
* Makes sure that we are on a course page.
*
* Available variables:
*
* $course_nid = '0', // from page context
* $course = NULL, // from API (course node => course code)
* $sections = array(), // from API (course)
* $config = array() // from pane settings
*
* $course_nid and $body_section_fields already rendered from panel settings.
*/
function unh_d1_drupal_preprocess_unh_d1_drupal__course_sections_pane(&$vars) {
// ddl("YYYY - GOT HERE PREPROCESS COURSE SECTIONS PANE! START!");
// ddl($vars, '$vars - preprocess a section block');
// ddl("YYYY - GOT HERE PREPROCESS COURSE SECTIONS PANE! END!");
}
/**
* Implements hook_preprocess() for course sections pane.
*
* Sets up variables for the course sections pane template.
* Makes sure that we are on a course page.
*
* Available variables:
*
* $course_nid = '0', // from page context
* $course = NULL, // from API (course node => course code)
* $sections = array(), // from API (course)
* $config = array() // from pane settings
*
* $course_nid and $body_section_fields already rendered from panel settings.
*/
function unh_d1_drupal_preprocess_unh_d1_drupal__course_section(&$vars) {
// ddl("ZZZZ - GOT HERE PREPROCESS A SECTION BLOCK! START!");
// ddl($vars, '$vars - preprocess a section block');
// ddl("ZZZZ - GOT HERE PREPROCESS A SECTION BLOCK! END!");
}
/**
* Implements hook_preprocess() for course overview pane.
*
* Sets up variables for the course overview pane template.
* Makes sure that we are on a course page.
*
* Available variables:
*
* $course_nid = '0', // from page context
* $course = NULL, // from API (course node => course code)
* $sections = array(), // from API (course)
* $config = array() // from pane settings
*
* $course_nid and $body_section_fields already rendered from panel settings.
*/
function unh_d1_drupal_preprocess_unh_d1_drupal__course_overview_pane(&$vars) {
// ddl("YYYY - GOT HERE PREPROCESS COURSE OVERVIEW PANE! START!");
// ddl($vars, '$vars - preprocess a section block');
// ddl("YYYY - GOT HERE PREPROCESS COURSE OVERVIEW PANE! END!");
}