--- a/admin/importRTKbodies.php +++ b/admin/importRTKbodies.php @@ -12,9 +12,10 @@ function extractCSVAccounts($url, $nameField, $accountField, $filter) { global $accounts, $nametoid; - $request = Requests::get($url); + // $request = Requests::get($url); echo $url; - $Data = str_getcsv($request->body, "\n"); //parse the rows +// $Data = str_getcsv($request->body, "\n"); //parse the rows + $Data = str_getcsv(file_get_contents("all-authorities.csv"), "\n"); //parse the rows $headers = Array(); foreach ($Data as $num => $line) { $Row = str_getcsv($line, ","); @@ -29,6 +30,7 @@ } else { echo $Row[array_search($nameField, $headers)] . PHP_EOL; $accounts[$nametoid[trim($agencyName)]]["rtkURLs"][$agencyName] = 'http://www.righttoknow.org.au/body/'.$Row[array_search($accountField, $headers)]; + $accounts[$nametoid[trim($agencyName)]]["rtkDescriptions"][$agencyName] = $Row[array_search("Notes", $headers)]; } } else { echo "error finding any agency" . $line . PHP_EOL; @@ -37,20 +39,28 @@ } } -extractCSVAccounts("http://www.righttoknow.org.au/body/all-authorities.csv","Agency","URL name"); -print_r($accounts); -/* foreach ($accounts as $id => $accountTypes) { +extractCSVAccounts("http://www.righttoknow.org.au/body/all-authorities.csv","Agency","URL name",""); +//print_r($accounts); + foreach ($accounts as $id => $allvalues) { echo $id . "
" . PHP_EOL; $doc = object_to_array($db->get($id)); // print_r($doc); - foreach ($accountTypes as $accountType => $accounts) { - if (!isset($doc["has" . $accountType]) || !is_array($doc["has" . $accountType])) { - $doc["has" . $accountType] = Array(); + foreach ($allvalues as $valueType => $values) { + if (!isset($doc[ $valueType]) || !is_array($doc[ $valueType])) { + $doc[ $valueType] = Array(); } - $doc["has" . $accountType] = array_unique(array_merge($doc["has" . $accountType], $accounts)); + $doc[ $valueType] = array_unique(array_merge($doc[ $valueType], $values)); + if ( $valueType == "rtkDescriptions") { + foreach ($values as $descriptionAgency => $descriptionValue) { + if ($descriptionAgency == $doc->name) { + $doc->description = $descriptionValue; + } + } + } } + if (isset($doc->value->rtkDescriptions[$doc->value->name])) $doc->value->description = $doc->value->rtkDescriptions[$doc->value->name]; $db->save($doc); -}*/ +} ?>