Skip to content
This repository has been archived by the owner on Feb 6, 2021. It is now read-only.

Commit

Permalink
converted mailing labels to use JSON instead of SQLite database, refs:
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Little committed Nov 24, 2015
1 parent 4781181 commit aa88be9
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions php/mailing_labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,26 @@
array_push($lineTemplate, $CONFIGURATION['label_line_'.$i]);
}

# connect to the sqlite db
$sqlite = new PDO('sqlite:'.$tempDirectory.'/'.$query_id.'.db');
# new caching format uses JSON.
$cache_filename = $tempDirectory.'/'.$query_id.'.json';
$cache = json_decode(file_get_contents($cache_filename), true);

# put the labels into a larger array
$allAddresses = array();

# this is added to support a more elaborate CSV format
$csv_addresses = array();

foreach ($sqlite->query('select * from features') as $rec) {
error_log('cache filename '.$cache_filename);

foreach($cache['results']['features'] as $feature) {
error_log('In cache: '.$feature);
$address = array();
for($line = 0; $line < $labelLines; $line++) {
$address[$line] = $lineTemplate[$line];
foreach($rec as $k=>$v) {
$address[$line] = str_replace('%'.$k.'%', trim($v), $address[$line]);
foreach($feature['properties'] as $k=>$v) {
$key = strtoupper($k);
$address[$line] = str_replace('%'.$key.'%', trim($v), $address[$line]);
}
$address[$line] = trim($address[$line]);
}
Expand All @@ -74,8 +79,9 @@

# build the virtual csv file
$current_address = $CONFIGURATION['csv_record'];
foreach($rec as $k=>$v) {
$current_address = str_replace('%'.$k.'%', trim($v), $current_address);
foreach($feature['properties'] as $k=>$v) {
$key = strtoupper($k);
$current_address = str_replace('%'.$key.'%', trim($v), $current_address);
}

$csv_addresses[] = $current_address;
Expand Down

0 comments on commit aa88be9

Please sign in to comment.