-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.drush.inc
77 lines (67 loc) · 1.88 KB
/
registration.drush.inc
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
<?php
/**
* @file
* Install, update and uninstall functions for the registration module.
*/
/**
* Implements hook_drush_command().
*/
function registration_drush_command() {
$commands['reg-student-list'] = array(
'callback' => 'drush_registration_reg_student_list',
'description' => 'Get a list of students signed up for this course.',
'aliases' => array('rsl'),
'arguments' => array(),
'options' => array(),
'examples' => array(
'drush rsl' => 'Print a list of students registered for a given class.',
),
);
return $commands;
}
/**
* Drush command logic.
*
* Drush_[MODULE_NAME]_[COMMAND_NAME]().
*/
function drush_registration_reg_student_list() {
$reg_list = drush_registration_get_list();
drush_print(dt(''));
drush_print(dt('**STUDENTS REGISTERED - ' . REGISTRATION_COURSE_TITLE));
drush_print(dt(''));
if (!empty($reg_list)) {
// Sort alphabetically, ascending. Sort by last name first,
// then by first name.
uasort($reg_list, function ($a, $b) {
$i = strnatcasecmp($a['surname'], $b['surname']);
if ($i == 0) {
$i = strnatcasecmp($a['name'], $b['name']);
}
return $i;
});
foreach ($reg_list as $reg) {
drush_print(dt('@last, @first',
['@last' => $reg['surname'], '@first' => $reg['name']])
);
}
}
else {
drush_print(dt('No students have registered yet.'));
}
drush_print(dt(''));
}
/**
* Gets list from db 'registration' table for output by drush command.
*/
function drush_registration_get_list() {
$rows = array();
// Get all entries in the registration table.
if ($entries = registration_selective_list(array('surname', 'name'))) {
$rows = array();
foreach ($entries as $entry) {
// Sanitize the data before handing it off to the theme layer.
$rows[] = array_map('check_plain', (array) $entry);
}
}
return $rows;
}