Skip to content

Commit

Permalink
better sorting before generating, better local override for generatin…
Browse files Browse the repository at this point in the history
…g data files
  • Loading branch information
benbalter committed Aug 13, 2012
1 parent 7c25842 commit edbf300
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
19 changes: 0 additions & 19 deletions config/config.sample.php

This file was deleted.

3 changes: 3 additions & 0 deletions includes/build-agencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
require_once 'config/agencies.php';
require_once 'load.php';

This comment has been minimized.

Copy link
@DSzshine

DSzshine Sep 8, 2024

great


//sort agencies by name alpha ascending
dgs_sort( $dgs_agencies, 'name' );

//output JSON

This comment has been minimized.

Copy link
@DSzshine

DSzshine Sep 8, 2024

great

file_put_contents( DGS_BASE_DIR . '/data/agencies.json', json_encode( $dgs_agencies ) );

Expand Down
3 changes: 3 additions & 0 deletions includes/build-items.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );

Expand Down
19 changes: 14 additions & 5 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

This comment has been minimized.

Copy link
@DSzshine

DSzshine Sep 8, 2024

great

*/
function dgs_sort( &$items, $field = 'id' , $dir = SORT_ASC ) {

foreach ($items as $obj)
$order[ $obj->$field ] = $obj;

array_multisort( $order, $dir, $items );

}
1 change: 0 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

//output header
dgs_header();
dgs_sort($dgs_items);
?>

<h1>Slash Digital Strategy Generator</h1>
Expand Down
7 changes: 4 additions & 3 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

1 comment on commit edbf300

@DSzshine
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

Please sign in to comment.