Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Backend / Generic DataSource parent class. Implement raw/non-raw flag…

… for Sahana JSONP.
  • Loading branch information...
commit decfb749564d1c7facfe1dfdf138976a7e2ec5e2 1 parent 7b5a6f8
@radgeek authored
View
17 extensions/fusion/fusiontable.class.php
@@ -1,6 +1,7 @@
<?php
+require_once('occupysandydatasource.class.php');
-class FusionTable {
+class FusionTable extends OccupySandyDataSource {
private $apikey;
private $defaultTable;
private $apiQs = 0;
@@ -165,21 +166,11 @@ function data ($params = array()) {
endif;
$data = $this->select('SELECT '.$params['cols'].$fromClause.$whereClause.$limitClause, $params);
+
if (is_wp_error($data) or $params['raw']) :
$ret = $data;
else :
- $ret = array();
- foreach ($data->rows as $row) :
- $aRow = array();
- foreach ($row as $idx => $col) :
- $i = $idx;
- if (isset($data->columns[$idx])) :
- $i = $data->columns[$idx];
- endif;
- $aRow[$i] = $col;
- endforeach;
- $ret[] = $aRow;
- endforeach;
+ $ret = $this->to_table_hash($data);
endif;
return $ret;
}
View
30 extensions/fusion/occupysandydatasource.class.php
@@ -0,0 +1,30 @@
+<?php
+class OccupySandyDataSource {
+
+ public function __construct () {
+ // NOOP.
+ }
+
+ public function data ($params) {
+ return NULL;
+ }
+
+ public function to_table_hash ($data) {
+ $ret = array();
+ foreach ($data->rows as $row) :
+ $aRow = array();
+ foreach ($row as $idx => $col) :
+ $i = $idx;
+ if (isset($data->columns[$idx])) :
+ $i = $data->columns[$idx];
+ endif;
+ $aRow[$i] = $col;
+ endforeach;
+ $ret[] = $aRow;
+ endforeach;
+ return $ret;
+ }
+
+} /* class OccupySandyDataSource */
+
+
View
10 extensions/fusion/sahanageojsonp.class.php
@@ -1,5 +1,6 @@
<?php
require_once('sahanageofeature.class.php');
+require_once('occupysandydatasource.class.php');
class SahanaInvalidQuery extends Exception {
function __construct ($q, $message) {
@@ -15,7 +16,7 @@ function __construct ($f) {
}
}
-class SahanaGeoJSONP {
+class SahanaGeoJSONP extends OccupySandyDataSource {
private $url;
private $text;
private $data;
@@ -108,7 +109,7 @@ function get_features () {
return $feat;
} /* SahanaGeoJSONP::get_features () */
- function data ($params = array()) {
+ public function data ($params = array()) {
$params = wp_parse_args($params, array(
"cols" => '*',
"limit" => null,
@@ -238,6 +239,11 @@ function ($running, $v) use ($cell) {
endif;
endif;
+ if (is_wp_error($data) or $params['raw']) :
+ $data = $data;
+ else :
+ $data = $this->to_table_hash($data);
+ endif;
return $data;
} /* SahanaGeoJSONP::data () */
Please sign in to comment.
Something went wrong with that request. Please try again.