Permalink
Browse files

better sorting before generating, better local override for generatin…

…g data files
  • Loading branch information...
1 parent 7c25842 commit edbf30006fe4b6403c7a165709b31a2c474782ae @benbalter benbalter committed Aug 13, 2012
Showing with 24 additions and 28 deletions.
  1. +0 −19 config/config.sample.php
  2. +3 −0 includes/build-agencies.php
  3. +3 −0 includes/build-items.php
  4. +14 −5 includes/functions.php
  5. +0 −1 index.php
  6. +4 −3 load.php
View
@@ -1,19 +0,0 @@
-<?php
-/**
- * Main config file for digital strategy report generator
- * Copy this file to config.php and edit as needed for your installation
- */
-
-//base dir for includes, leave at default for same directory as this file`
-define( 'DGS_BASE_DIR', dirname( __FILE__ ) );
-
-//directory where reports will reside afer generation, FALSE to delete after sending to user
-define( 'DGS_REPORT_DIR', FALSE );
-
-//base url for schema, change to false to use local information only
-define( 'DGS_SCHEMA_BASE', 'https://raw.github.com/GSA/digital-strategy/1/' );
-
-//TTL of disk / in-memory cache ( default is 1 hour )
-define( 'DGS_TTL', 3600 );
-
-//that's it!
@@ -7,6 +7,9 @@
require_once 'config/agencies.php';
require_once 'load.php';
+//sort agencies by name alpha ascending
+dgs_sort( $dgs_agencies, 'name' );
+
//output JSON
file_put_contents( DGS_BASE_DIR . '/data/agencies.json', json_encode( $dgs_agencies ) );
View
@@ -7,6 +7,9 @@
require_once 'config/items.php';
require_once 'load.php';
+//sort action items by ID ascending
+dgs_sort( $dgs_items );
+
//JSON encode the action items array into the json file
file_put_contents( DGS_BASE_DIR .'/data/items.json', json_encode( $dgs_items ) );
View
@@ -344,9 +344,18 @@ function dgs_max_values( $item, $import ) {
return $max;
}
-function dgs_sort(&$items) {
- foreach ($items as $obj) {
- $order[$obj->id] = $obj;
- }
- array_multisort($order, SORT_ASC, $items);
+
+/**
+ * Helper function to sort items and agencies before generating
+ * @param array $items array of agency objects
+ * @param string $field field to sort by (optional, default ID)
+ * @param int $dir sort direction, either SORT_ASC or SORT_DESC (optional, default ASC)
+ */
+function dgs_sort( &$items, $field = 'id' , $dir = SORT_ASC ) {
+
+ foreach ($items as $obj)
+ $order[ $obj->$field ] = $obj;
+
+ array_multisort( $order, $dir, $items );
+
}
View
@@ -12,7 +12,6 @@
//output header
dgs_header();
-dgs_sort($dgs_items);
?>
<h1>Slash Digital Strategy Generator</h1>
View
@@ -34,25 +34,26 @@
// (3) Local /data/ directory, for non-expired cached files
// (4) GSA GitHub Repo
// (5) /config/ directory
+ // Note: change DGS_SCHEMA_BASE to FALSE and DGS_TTL to 0 in config.php to force local refresh
//look for global var already established, no need to re-parse
if ( isset( $$global_var ) )
continue;
//check APC Cache, if it's installed
- if ( DGS_REPORT_DIR && function_exists( 'apc_fetch' ) && $cache = apc_fetch ( $global_var ) ) {
+ if ( function_exists( 'apc_fetch' ) && $cache = apc_fetch ( $global_var ) ) {
$$global_var = $cache->$plural;
continue;
}
//look for /data/ files and parse (disk cache)
- if ( DGS_REPORT_DIR && $file = dgs_get_disk_cache( $plural ) ) {
+ if ( $file = dgs_get_disk_cache( $plural ) ) {
$$global_var = $file->$plural;
continue;
}
//try GitHub (mmm... dogfood)
- if ( DGS_REPORT_DIR && $file = dgs_get_live( $plural ) ) {
+ if ( DGS_SCHEMA_BASE && $file = dgs_get_live( $plural ) ) {
$$global_var = $file->$plural;
continue;
}

0 comments on commit edbf300

Please sign in to comment.