--- a/alaveteli/exportAgencies.csv.php +++ b/alaveteli/exportAgencies.csv.php @@ -12,7 +12,18 @@ $rows = $db->get_view("app", "byDeptStateName", null, true)->rows; //print_r($rows); foreach ($rows as $row) { - $tag[$row->value] = phrase_to_tag(dept_to_portfolio($row->key)); + $tag[$row->id] = phrase_to_tag(dept_to_portfolio($row->key)); + } +} catch (SetteeRestClientException $e) { + setteErrorHandler($e); +} + +$foiEmail = Array(); +try { + $rows = $db->get_view("app", "foiEmails", null, true)->rows; + //print_r($rows); + foreach ($rows as $row) { + $foiEmail[$row->key] = $row->value; } } catch (SetteeRestClientException $e) { setteErrorHandler($e); @@ -29,39 +40,45 @@ $agencies = $db->get_view("app", "byCanonicalName", null, true)->rows; //print_r($rows); foreach ($agencies as $agency) { - // print_r($agency); - $row = Array(); - $row["#id"] = $agency->value->_id; - $row["name"] = $agency->value->name; - if (isset($agency->value->foi_email)) { - $row["request_email"] = $agency->value->foiEmail; - } else { - $row["request_email"] = "foi@".GetDomain($agency->value->website); - // - } - if (isset($agency->value->shortName)) { - $row["short_name"] = $agency->value->shortName; - } else { - $out = Array(); - preg_match_all('/[A-Z]/', $agency->value->name, $out); - $row["short_name"] = implode("",$out[0]); - } - $row["notes"] = ""; - $row["publication_scheme"] = $agency->value->infoPublicationSchemeURL; - $row["home_page"] = $agency->value->website; - if ($agency->value->orgType == "FMA-DepartmentOfState") { - $row["tag_string"] = $tag[$agency->value->_id]; - } else { - $row["tag_string"] = $tag[$agency->value->parentOrg];; - } - - fputcsv($fp, array_values($row)); - - if (isset($agency->value->foiBodies)) { - foreach ($agency->value->foiBodies as $foiBody) { - $row['name'] = $foiBody; - $row['short_name'] = ""; - fputcsv($fp, array_values($row)); + // print_r($agency); + + if (isset($agency->value->foiEmail) && $agency->value->foiEmail != "null" && !isset($agency->value->status)) { + $row = Array(); + $row["#id"] = $agency->id; + $row["name"] = trim($agency->value->name); + if (isset($agency->value->foiEmail)) { + $row["request_email"] = $agency->value->foiEmail; + } else { + if ($agency->value->orgType == "FMA-DepartmentOfState") { + $row["request_email"] = "foi@" . GetDomain($agency->value->website); + } else { + $row["request_email"] = $foiEmail[$agency->value->parentOrg]; + } + } + if (isset($agency->value->shortName)) { + $row["short_name"] = $agency->value->shortName; + } else { + $out = Array(); + preg_match_all('/[A-Z]/', trim($agency->value->name), $out); + $row["short_name"] = implode("", $out[0]); + } + $row["notes"] = ""; + $row["publication_scheme"] = (isset($agency->value->infoPublicationSchemeURL) ? $agency->value->infoPublicationSchemeURL : ""); + $row["home_page"] = (isset($agency->value->website) ? $agency->value->website : ""); + if ($agency->value->orgType == "FMA-DepartmentOfState") { + $row["tag_string"] = $tag[$agency->value->_id] . " " . $agency->value->orgType; + } else { + $row["tag_string"] = $tag[$agency->value->parentOrg] . " " . $agency->value->orgType; + } + + fputcsv($fp, array_values($row)); + + if (isset($agency->value->foiBodies)) { + foreach ($agency->value->foiBodies as $foiBody) { + $row['name'] = $foiBody; + $row['short_name'] = ""; + fputcsv($fp, array_values($row)); + } } } }