Permalink
Browse files

FusionTables / re-enable state filters.

  • Loading branch information...
1 parent 9a7f066 commit d37cf38f6b027a012a4a4af0d1efb477855ab0ca @radgeek radgeek committed Nov 17, 2012
Showing with 50 additions and 26 deletions.
  1. +0 −1 card.php
  2. +39 −17 extensions/fusion/occupysandycard.class.php
  3. +11 −8 page-show-cards.php
View
@@ -2,7 +2,6 @@
// Prepare data for use in template.
$card = get_the_occupy_sandy_card();
$classes = array('card', $card->get_card_class());
- $classes[] = "state-".$card->get_state();
$state = $card->get_state();
$address = $card->get_address();
$timestamp = $card->get_timestamp('U');
@@ -3,30 +3,29 @@ class OccupySandyCard {
private $row = array();
private $cols = array();
private $cardTitle;
- private $cardClasses;
- private $regionClasses;
+ private $htmlClasses;
function __construct ($row = array(), $cols = array()) {
$this->row = $row;
$this->cols = $cols;
$this->parseData();
- $this->cardClasses = apply_filters('occupysandy_card_classes', $this->cardClasses, $this);
+ $this->htmlClasses = apply_filters('occupysandy_card_classes', $this->htmlClasses, $this);
$this->cardTitle = apply_filters('occupysandy_card_title', $this->cardTitle, $this);
}
function parseData () {
- $this->cardClass = array();
+ $this->htmlClasses = array('type' => array(), 'region' => array(), 'state' => array());
$this->cardTitle = '';
if ($this->is_distro_center()) :
- $this->cardClasses[] = 'hub';
+ $this->htmlClasses['type'][] = 'hub';
$this->cardTitle = 'Main Distribution Center';
endif;
if ($this->is_drop_off()) :
- $this->cardClasses[] = 'dropoff';
+ $this->htmlClasses['type'][] = 'dropoff';
// We may have already gotten a title, if this is a distro center.
if (strlen($this->cardTitle) < 1) :
@@ -35,7 +34,7 @@ function parseData () {
endif;
if ($this->is_volunteer()) :
- $this->cardClasses[] = 'volunteer';
+ $this->htmlClasses['type'][] = 'volunteer';
// We may have already gotten a title, if this is a distro center or a drop-off+volunteer location
if (strlen($this->cardTitle) < 1) :
@@ -51,20 +50,40 @@ function parseData () {
endif;
endif;
- if (count($this->cardClasses) == 0) :
- $this->cardClasses[] = 'unknown';
+ if (count($this->htmlClasses['type']) == 0) :
+ $this->htmlClasses['type'][] = 'unknown';
endif;
- $this->regionClasses = array();
+ $this->htmlClasses['region'] = array();
$region = $this->field('Region');
if (strlen($region) > 0) :
- $this->regionClasses[$region] = 'region-'.sanitize_title($region);
+ $this->htmlClasses['region'][$region] = 'region-'.sanitize_title($region);
else :
- $this->regionClasses['Other'] = 'region-other';
+ $this->htmlClasses['region']['Other'] = 'region-other';
+ endif;
+
+ $state = $this->get_state();
+ if (strlen($state) > 0) :
+ $this->htmlClasses['state'][$state] = 'state-'.strtoupper(sanitize_title($state));
+ else :
+ $this->htmlClasses['state']['NY'] = 'state-NY';
endif;
}
+ function normalize_state ($state) {
+ $map = array(
+ "new-york" => 'NY',
+ 'new-jersey' => 'NJ',
+ 'pennsylvania' => 'PA',
+ );
+
+ // Normalize key.
+ $key = sanitize_title(preg_replace('/\s+/', ' ', $state));
+
+ return (isset($map[$key]) ? $map[$key] : $state);
+ }
+
function columns () {
return $this->cols;
}
@@ -114,7 +133,7 @@ function get_state () {
global $os_regionToState;
$ret = $this->field('State');
- if (is_null($ret)) :
+ if (is_null($ret) or (strlen($ret) == 0)) :
$region = $this->field('Region');
if (preg_match('/\b(New Jersey|NJ)\b/i', $region)) :
$ret = 'NJ';
@@ -126,12 +145,15 @@ function get_state () {
endif;
endif;
endif;
- return $ret;
+
+ // Normalize state names
+ return $this->normalize_state($ret);
}
- function get_type_classes () { return $this->cardClasses; }
- function get_region_classes () { return $this->regionClasses; }
- function get_card_class () { return implode(" ", array_merge($this->get_type_classes(), $this->get_region_classes())); }
+ function get_type_classes () { return $this->htmlClasses['type']; }
+ function get_region_classes () { return $this->htmlClasses['region']; }
+ function get_state_classes () { return $this->htmlClasses['state']; }
+ function get_card_class () { return implode(" ", array_merge($this->get_type_classes(), $this->get_region_classes(), $this->get_state_classes())); }
function get_card_heading () { return $this->cardTitle; }
function get_title () { return $this->field('Title'); }
function get_address () { return $this->field('Address'); }
View
@@ -103,18 +103,19 @@ function options_filter_ul ($filters, $axis) {
// FILTERING: PREPARE OPTIONS FOR FILTERING LISTS. //
/////////////////////////////////////////////////////
-/* $filters['state'] = array(
- "values" => get_occupy_sandy_possible_values_for('get_state'),
- "prefix" => 'state-',
- "label-filter" => 'strtoupper',
- 'default' => 'Unlisted',
-); */
$filters['type'] = array(
'values' => get_occupy_sandy_possible_values_for('get_type_classes'),
'prefix' => '',
'label-filter' => 'ucfirst',
'label-text' => array('all' => 'All Types', 'hub' => 'Distribution Centers', 'unknown' => 'Other'),
);
+$filters['state'] = array(
+ "values" => get_occupy_sandy_possible_values_for('get_state_classes'),
+ "prefix" => '',
+ 'label-text' => array('all' => 'All States'),
+ "label-filter" => 'strtoupper',
+ 'default' => 'Unlisted',
+);
$filters['region'] = array(
'values' => get_occupy_sandy_possible_values_for('get_region_classes'),
'prefix' => '',
@@ -126,11 +127,13 @@ function options_filter_ul ($filters, $axis) {
$filterMap['type']['text'] = array('unknown' => 'Other');
// Force the unknown / other settings to bottom.
-//$filters['state']['values'][''] = 0;
+if (isset($filters['state']['values'][''])) :
+ $filters['state']['values'][''] = 0;
+endif;
$filters['type']['values']['unknown'] = 0;
$filters['region']['values']['Other/region-other'] = 0;
-//arsort($filters['state']['values']);
+arsort($filters['state']['values']);
arsort($filters['type']['values']);
arsort($filters['region']['values']);

0 comments on commit d37cf38

Please sign in to comment.