Skip to content

Commit edbf300

Browse files
committed
better sorting before generating, better local override for generating data files
1 parent 7c25842 commit edbf300

File tree

6 files changed

+24
-28
lines changed

6 files changed

+24
-28
lines changed

config/config.sample.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

includes/build-agencies.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
require_once 'config/agencies.php';
88
require_once 'load.php';
99

10+
//sort agencies by name alpha ascending
11+
dgs_sort( $dgs_agencies, 'name' );
12+
1013
//output JSON
1114
file_put_contents( DGS_BASE_DIR . '/data/agencies.json', json_encode( $dgs_agencies ) );
1215

includes/build-items.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
require_once 'config/items.php';
88
require_once 'load.php';
99

10+
//sort action items by ID ascending
11+
dgs_sort( $dgs_items );
12+
1013
//JSON encode the action items array into the json file
1114
file_put_contents( DGS_BASE_DIR .'/data/items.json', json_encode( $dgs_items ) );
1215

includes/functions.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,18 @@ function dgs_max_values( $item, $import ) {
344344
return $max;
345345

346346
}
347-
function dgs_sort(&$items) {
348-
foreach ($items as $obj) {
349-
$order[$obj->id] = $obj;
350-
}
351-
array_multisort($order, SORT_ASC, $items);
347+
348+
/**
349+
* Helper function to sort items and agencies before generating
350+
* @param array $items array of agency objects
351+
* @param string $field field to sort by (optional, default ID)
352+
* @param int $dir sort direction, either SORT_ASC or SORT_DESC (optional, default ASC)
353+
*/
354+
function dgs_sort( &$items, $field = 'id' , $dir = SORT_ASC ) {
355+
356+
foreach ($items as $obj)
357+
$order[ $obj->$field ] = $obj;
358+
359+
array_multisort( $order, $dir, $items );
360+
352361
}

index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
//output header
1414
dgs_header();
15-
dgs_sort($dgs_items);
1615
?>
1716

1817
<h1>Slash Digital Strategy Generator</h1>

load.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,26 @@
3434
// (3) Local /data/ directory, for non-expired cached files
3535
// (4) GSA GitHub Repo
3636
// (5) /config/ directory
37+
// Note: change DGS_SCHEMA_BASE to FALSE and DGS_TTL to 0 in config.php to force local refresh
3738

3839
//look for global var already established, no need to re-parse
3940
if ( isset( $$global_var ) )
4041
continue;
4142

4243
//check APC Cache, if it's installed
43-
if ( DGS_REPORT_DIR && function_exists( 'apc_fetch' ) && $cache = apc_fetch ( $global_var ) ) {
44+
if ( function_exists( 'apc_fetch' ) && $cache = apc_fetch ( $global_var ) ) {
4445
$$global_var = $cache->$plural;
4546
continue;
4647
}
4748

4849
//look for /data/ files and parse (disk cache)
49-
if ( DGS_REPORT_DIR && $file = dgs_get_disk_cache( $plural ) ) {
50+
if ( $file = dgs_get_disk_cache( $plural ) ) {
5051
$$global_var = $file->$plural;
5152
continue;
5253
}
5354

5455
//try GitHub (mmm... dogfood)
55-
if ( DGS_REPORT_DIR && $file = dgs_get_live( $plural ) ) {
56+
if ( DGS_SCHEMA_BASE && $file = dgs_get_live( $plural ) ) {
5657
$$global_var = $file->$plural;
5758
continue;
5859
}

0 commit comments

Comments
 (0)