-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomm-list.php
168 lines (137 loc) · 5.6 KB
/
comm-list.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
<?php
#By Zachary Spalding @Southeastern New York Library Resources Council
#https://airtable.com/<YOUR BASE ID>/api/docs
#https://codepen.io/airtable/full/MeXqOg
#Mkae sure to put in your API key from Airtable along with your CSS for the DIV tags and table and base ID
$api_key = '<ADD YOUR API KEY>';
$base_id = '<YOUR BASE ID>';
$table_id = '<YOUR TABLE ID>';
$apiUrl = "https://api.airtable.com/v0/{$baseId}/{$tableId}";
// Set up cURL options
function fetchData($url, $apiKey, $params = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
die();
}
curl_close($ch);
return json_decode($response, true);
}
// Replace this function with your actual implementation to fetch organization details
function fetchOrganizationDetails($organizationId, $baseid, $apikey, $tableid)
{
// Implement your logic to fetch organization details based on the provided ID
// Make an additional API request to Airtable using $organizationId
// For now, I'll just return a placeholder value
$apiUrl = "https://api.airtable.com/v0/{$baseid}/{$tableid}/{$organizationId}";
// Set up cURL options
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apikey,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
die();
}
curl_close($ch);
$organizationDetails = json_decode($response, true);
//for testing
//print_r($organizationDetails);
// echo $organizationDetails['fields']['Organization'];
// Return the organization details (modify as needed based on your Airtable structure)
$org = $organizationDetails['fields']['Organization'];
return $org;
}
// Initial request without offset
$params = [
'fields' => ['Organization (from People)', 'Last Name (from People)', 'Full Name', 'Tags'], // Update with the correct field names
'filterByFormula' => '',
'sort' => [['field' => 'Last Name (from People)', 'direction' => 'asc']],
'pageSize' => 100, // Maximum page size
];
// Set the operating year start date (July 1)
$operatingYearStart = date('Y') . '-07-01';
// Get the current date
$currentDate = date('Y-m-d');
// Check if the current date is on or after the operating year start
if (strtotime($currentDate) >= strtotime($operatingYearStart)) {
// If on or after the operating year start, use the current year
$operatingYear = date('Y');
} else {
// If before the operating year start, decrement the year by 1
$operatingYear = date('Y') - 1;
}
// Calculate the next year for display
$nextYear = $operatingYear + 1;
// Echo the operating year in the desired format
echo "The " . $operatingYear . '/' . $nextYear . " committee members are:<br><br><ul>";
//Storeing data in array so i can put the names in the correct part of the page
$chairArray = array();
$boardArray = array();
$nothingArray = array();
// Loop through records and print information
do {
$data = fetchData($apiUrl, $apiKey, $params);
//for testing
//print_r($data);
if (isset($data['records'])) {
foreach ($data['records'] as $record) {
$organizationId = $record['fields']['Organization (from People)'][0];
$name = '<strong>' . htmlspecialchars($record['fields']['Full Name']) . '</strong>';
if (isset($record['fields']['Tags'])) {
// Get and print the value of the 'Tags' field
$tags = $record['fields']['Tags'];
} else {
$tags = '';
}
// Fetch organization details based on the provided ID
// The inital value is just an ID number we have to use this function to translate it to a name
$organizationDetails = fetchOrganizationDetails($organizationId, $baseId, $apiKey, $tableId);
//for testing
//echo "my data" . $name . " " . $tags[0] . " " . $organizationDetails . "<br>";
// Check the value of 'tags' and assign the name with organization to the corresponding array
if ($tags[0] === 'chair') {
$chairArray[] = $name . ', ' . $organizationDetails;
} elseif ($tags[0] === 'Board Liaison') {
$boardArray[] = $name . ', ' . $organizationDetails;
} elseif ($tags[0] === 'Council Liaison') {
$councilArray[] = $name;
} else {
$groupArray[] = $name . ', ' . $organizationDetails;
}
} //end foreach loop
} //end if isset
// Set the offset for the next request
$params['offset'] = $data['offset'] ?? null;
} while (isset($data['offset']));
if (!isset($data['records'])) {
echo 'No records found.';
}
echo '<ul>';
foreach ($chairArray as $chairName) {
echo '<li style="list-style:square;">' . $chairName . ' (Chair)</li>';
}
foreach ($groupArray as $groupName) {
echo '<li style="list-style:square;">' . $groupName . ' </li>';
}
echo '</ul><br>';
echo "<p>Southeastern Staff Liaison:</p><ul>";
foreach ($councilArray as $councilName) {
echo '<li style="list-style:square;">' . $councilName . ' </li>';
}
echo '</ul><br>';
echo "<p>Southeastern Board Liaisons:</p><ul>";
foreach ($boardArray as $boardName) {
echo '<li style="list-style:square;">' . $boardName;
}
echo '</ul>';