/
ACSSync.module
150 lines (125 loc) · 3.9 KB
/
ACSSync.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
<?php
function acssync_menu() {
$items = array();
$items['admin/config/content/acs-sync'] = array(
'title' => 'AccessACS Sync Administration',
'description' => 'Configuration for AccessACS Sync',
'page callback' => 'drupal_get_form',
'page arguments' => array('acssync_admin_form'),
'access arguments' => array('administer accessacs'),
'type' => MENU_NORMAL_ITEM,
);
$items['acs-sync'] = array(
'title' => 'Sync AccessACS',
'description' => 'Sync AccessACS to Drupal Tables',
'page callback' => 'acssync_sync',
'access arguments' => array('administer accessacs'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function acssync_permission() {
return array(
'administer accessacs' => array(
'title' => t('Change core settings for AccessACS integration.'),
)
);
}
function acssync_admin_form($form, &$form_state) {
$form['acs_site_number'] = array(
'#type' => 'textfield',
'#title' => t('Site Number'),
'#default_value' => variable_get('acs_site_number', ''),
// '#description' => t('The AccessACS site number'),
'#required' => TRUE,
);
$form['acs_username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => variable_get('acs_username', ''),
// '#description' => t('The AccessACS site number'),
'#required' => TRUE,
);
$form['acs_password'] = array(
'#type' => 'textfield',
'#title' => t('Password'),
'#default_value' => variable_get('acs_password', ''),
// '#description' => t('The AccessACS site number'),
'#required' => TRUE,
);
return system_settings_form($form);
}
function acssync_sync()
{
echo '<pre>';
$site_number = variable_get('acs_site_number');
$username = variable_get('acs_username');
$password = variable_get('acs_password');
if (empty($site_number) || empty($username) || empty($password)) {
drupal_set_message(t('ACS auth settings not set.'), 'error');
return;
}
$acsAPI = new Drupal\ACSSync\API($site_number, $username, $password);
try {
$result = $acsAPI->get_all_people(200);
// $result = $acsAPI->get_person(271);
} catch (Exception $e) {
drupal_set_message(t('ACS API returned an error: ' . $e->message, 'error'));
return;
}
db_truncate('accessacs_individuals')->execute();
foreach ($result->Page as $simple_person) {
$individual = $acsAPI->get_person($simple_person->IndvId);
// var_dump($individual);
$nid = db_insert('accessacs_individuals')
->fields(array(
'IndvId' => $individual->IndvId,
'PrimFamily' => $individual->PrimFamily,
'MiddleName' => $individual->MiddleName,
'Title' => $individual->Title,
'LastName' => $individual->LastName,
'FirstName' => $individual->FirstName,
'PictureUrl' => $individual->PictureUrl,
'FamilyPosition' => $simple_person->FamilyPosition,
'Suffix' => $individual->Suffix,
'FullName' => $individual->FullName,
'FriendlyName' => $individual->FriendlyName,
'FamilyPictureUrl' => $individual->FamilyPictureUrl,
'DateOfBirth' => $individual->DateOfBirth,
'MemberStatus' => $individual->MemberStatus,
))
->execute();
return;
}
// $query = db_insert('accessacs_individuals')
// ->fields(array(
// 'IndvId',
// 'FamId',
// 'MiddleName',
// 'GoesByName',
// 'Title',
// 'LastName',
// 'FirstName',
// 'PictureUrl',
// 'FamilyPosition',
// 'Suffix',
// ));
// foreach ($result->Page as $individual) {
// $query->values(array(
// 'IndvId' => $individual->IndvId,
// 'FamId' => $individual->FamId,
// 'MiddleName' => $individual->MiddleName,
// 'GoesByName' => $individual->GoesByName,
// 'Title' => $individual->Title,
// 'LastName' => $individual->LastName,
// 'FirstName' => $individual->FirstName,
// 'PictureUrl' => $individual->PictureUrl,
// 'FamilyPosition' => $individual->FamilyPosition,
// 'Suffix' => $individual->Suffix,
// ));
// }
// $out = $query->execute();
var_dump($result);
}
// TODO: Sync Tables
// TODO: Views Integration