--- a/admin/importOAICFOIrequests.php +++ b/admin/importOAICFOIrequests.php @@ -17,13 +17,13 @@ if ($row >= 1) { // print_r($data); $name = trim($data[2]); - echo "$name <br>"; +// echo "$name <br>"; if ($data[0] != "TOTALS" && $data[0] != "") { if (isset($nametoid[$name])) { $id = $nametoid[$name]; $timePeriod = $data[0] . "-Q" . $data[1]; - echo "$timePeriod <br>"; +// echo "$timePeriod <br>"; unset($data[0]); unset($data[1]); unset($data[2]); @@ -38,10 +38,13 @@ $result = Array("source" => "http://data.gov.au/dataset/freedom-of-information-quarterly-request-and-review-statistical-data-2011-12/"); foreach ($data as $key => $datum) { if ($datum != 0) { +// tODO prefix header with "FOI" +if (isset($stats[$id][$timePeriod][$key])) $datum += $stats[$id][$timePeriod][$key]; $result[trim($headers[$key])] = $datum; } } $stats[$id][$timePeriod] = $result; +// TODO merge if already exists //print_r($stats); } else { echo "<br>ERROR NAME MISSING FROM ID LIST<br><bR> $row" . PHP_EOL; @@ -57,21 +60,24 @@ } fclose($handle); } +echo "all stats loaded successfuly"; foreach ($stats as $id => $stat) { echo $id . "<br>" . PHP_EOL; - $doc = $db->get($id); + $doc = $db->get($id); echo $doc->name . "<br>" . PHP_EOL; - print_r($stat); - die(); +// print_r($stat); // print_r($doc); $changed = false; if (!isset($doc->statistics)) { $changed = true; $doc->statistics = Array(); + } else { + $doc->statistics = object_to_array($doc->statistics); } foreach ($stat as $timePeriod => $value) { - if (!isset($doc->statistics->foiRequests->$timePeriod) - || $doc->statistics->foiRequests->$timePeriod != $value) { + if (!isset($doc->statistics["foiRequests"][$timePeriod]) + || $doc->statistics["foiRequests"][$timePeriod] != $value + ) { $changed = true; $doc->statistics["foiRequests"][$timePeriod] = $value; } @@ -81,6 +87,7 @@ } else { echo "not changed" . "<br>" . PHP_EOL; } +//print_r($doc);die(); } ?>