From: maxious Date: Tue, 03 Jan 2012 13:42:56 +0000 Subject: includes/nav cleanup X-Git-Url: https://maxious.lambdacomplex.org/git/?p=disclosr.git&a=commitdiff&h=57d9a0f93d6c9e6f91f471996f1b530175ba7709 --- includes/nav cleanup Former-commit-id: 814e610d82c2640010ae9ead51310519574f6adb --- --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,7 @@ -[submodule "sag"] - path = sag - url = https://github.com/sbisbee/sag.git [submodule "couchdb/couchdb-lucene"] path = couchdb/couchdb-lucene url = https://github.com/rnewson/couchdb-lucene.git +[submodule "couchdb/settee"] + path = couchdb/settee + url = https://github.com/inadarei/settee.git --- a/about.php +++ b/about.php @@ -1,3 +1,4 @@ + Organisational Data Sources http://www.comlaw.gov.au/Browse/Results/ByTitle/AdministrativeArrangementsOrders/Current/Ad/0 defines departments --- a/common.inc.php +++ /dev/null @@ -1,133 +1,1 @@ -head('_design/app')->headers->_HTTP->status != "404") - return true; - } catch (Exception $e) { - //database issue - return false; - } - $ddoc = new StdClass(); - $ddoc->_id = '_design/app'; - $ddoc->views = new StdClass(); - // by abn, by name - $ddoc->views->byABN = new StdClass(); - $ddoc->views->byABN->map = "function(doc) { emit(doc.abn, doc); };"; - $ddoc->views->byName = new StdClass(); - $ddoc->views->byName->map = "function(doc) { emit(doc.name, doc); };"; - $ddoc->views->getActive = new StdClass(); - $ddoc->views->getActive->map = 'function(doc) { if (doc.status == "active") { emit(doc._id, doc); } };'; - $ddoc->views->getSuspended = new StdClass(); - $ddoc->views->getSuspended->map = 'function(doc) { if (doc.status == "suspended") { emit(doc._id, doc); } };'; - $ddoc->views->getScrapeRequired = new StdClass(); - $ddoc->views->getScrapeRequired->map = "function(doc) { emit(doc.abn, doc); };"; - try { - $sag->put('_design/app', $ddoc); - } catch (Exception $e) { - /* - * A 409 status code means there was a conflict, so another client - * already created the design doc for us. This is fine. - */ - if ($e->getCode() != 409) - return false; - } - return true; -} -error_reporting(0); -require_once('sag/src/SagException.php'); -require_once('sag/src/SagCouchException.php'); -require_once('sag/src/SagConfigurationCheck.php'); -require_once('sag/src/httpAdapters/SagHTTPAdapter.php'); -require_once('sag/src/httpAdapters/SagNativeHTTPAdapter.php'); -require_once('sag/src/httpAdapters/SagCURLHTTPAdapter.php'); -require_once 'sag/src/Sag.php'; -error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE); -$sag = new Sag(); - -// createAgencyDesignDoc(); - -function include_header() { - ?> - - - - - - - - - - - - - - Welcome to Foundation - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - - - - - - - - - - - --- /dev/null +++ b/couchdb/settee --- a/getAgency.php +++ b/getAgency.php @@ -1,24 +1,127 @@ setDatabase("disclosr-agencies", true); -//get an agency record as json/html, search by name/abn/id +function displayValue($key, $value, $mode) { + if ($mode == "view") { + if (is_array($value)) { + echo "$key
    "; + foreach ($value as $subkey => $subvalue) { + echo "
  1. $subvalue
  2. "; + } + echo "
"; + } else { + echo "$key$value"; + } + } + if ($mode == "edit") { + if (is_array($value)) { + echo '
+
+
+
' . $key . '
'; + foreach ($value as $subkey => $subvalue) { + echo ""; + } + echo "
+
+
"; + } else { + if (strpos($key, "_") === 0) { + echo""; + } if (strpos($key, "has") === 0) { + echo ""; + } else { + echo ""; + } + } + } + // +} + +function addDefaultFields($row) { + $defaultFields = Array("name"); + foreach ($defaultFields as $defaultField) { + if (!isset($row[$defaultField])) + $row[$defaultField] = ""; + } + return $row; +} + +$db = $server->get_db('disclosr-agencies'); + +if (isset($_REQUEST['id'])) { + //get an agency record as json/html, search by name/abn/id // by name = startkey="Ham"&endkey="Ham\ufff0" // edit? -$rows = $sag->get('/_design/app/_view/byABN?include_docs=true')->body->rows; // &endkey='.$searchVar -foreach ($rows as $row) { - echo ""; - echo '"; - echo ""; -foreach ($row->doc as $key => $value) { - if (is_a($value, 'stdClass')) { - echo ""; - } else echo ""; - } // also show documents/URLs available - echo "

' . $row->doc->agencyName . "

Field NameField Value
$key".var_dump($value,true)."
$key$value
"; -} + $row = $db->get($_REQUEST['id']); + //print_r($row); + if (sizeof($_POST) > 0) { + //print_r($_POST); + if (isset($_POST['_id']) && $db->get_rev($_POST['_id']) == $_POST['_rev']) { + echo "Edited version was latest version, continue saving"; + $row = $db->save($_POST); + } else { + echo "ALERT doc revised by someone else while editing."; + } + } -include_footer(); + $mode = "edit"; + $row = addDefaultFields(object_to_array($row)); + if ($mode == "view") { + echo ''; + echo '"; + echo ""; + } + if ($mode == "edit") { + ?> + + + + $value) { + echo displayValue($key, $value, $mode); + } + if ($mode == "view") { + echo "

' . $row['name'] . "

Field NameField Value
"; + } + if ($mode == "edit") { + echo ''; + } + } else { + + try { + $rows = $db->get_view("app", "showNamesABNs")->rows; + //print_r($rows); + foreach ($rows as $row) { + // print_r($row); + echo '
  • ' . + (isset($row->value->name) && $row->value->name != "" ? $row->value->name : "NO NAME " . $row->value->abn) + . '
  • '; + } + } catch (SetteeRestClientException $e) { + setteErrorHandler($e); + } + } + include_footer(); + ?> --- a/import.php +++ b/import.php @@ -1,22 +1,34 @@ setDatabase("disclosr-agencies", true); -//createAgencyDesignDoc(); - $conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost"); - $namesQ = 'select agency.abn, string_agg("agencyName",\',\') as names from agency inner join agency_nametoabn on agency.abn::text = agency_nametoabn.abn group by agency.abn;'; - $abntonames = Array(); - foreach ($conn->query($namesQ) as $row) { - $abntonames[$row['abn']] = explode(",",$row['names']); - } - $result = $conn->query("select * from agency"); - while ($agency = $result->fetch(PDO::FETCH_ASSOC)) { - - $agency['otherNames'] = $abntonames[$agency['abn']]; - if (sizeof($abntonames[$agency['abn']]) == 1) $agency['name'] = $abntonames[$agency['abn']][0]; - $agency["lastScraped"] = "1/1/1970"; - $agency["scrapeDepth"] = 1; - $sag->post($agency); - } +require_once 'include/common.inc.php'; +try { + $server->create_db('disclosr-agencies'); +} catch (SetteeRestClientException $e) { + setteErrorHandler($e); +} +$db = $server->get_db('disclosr-agencies'); +createAgencyDesignDoc(); +$conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost"); +$namesQ = 'select agency.abn, string_agg("agencyName",\'|\') as names from agency inner join agency_nametoabn on agency.abn::text = agency_nametoabn.abn group by agency.abn;'; +$abntonames = Array(); +foreach ($conn->query($namesQ) as $row) { + $abntonames[$row['abn']] = explode("|", $row['names']); +} +$result = $conn->query("select * from agency"); +while ($agency = $result->fetch(PDO::FETCH_ASSOC)) { + $agency['_id'] = md5($agency['abn']); + $agency['otherNames'] = $abntonames[$agency['abn']]; + if (sizeof($abntonames[$agency['abn']]) == 1) + $agency['name'] = $abntonames[$agency['abn']][0]; + $agency["lastScraped"] = "1/1/1970"; + $agency["scrapeDepth"] = 1; + try { + $doc = $db->save($agency); + //print_r($doc); + echo $agency['abn'] . " imported \n
    "; + } catch (SetteeRestClientException $e) { + setteErrorHandler($e); + } +} ?> --- /dev/null +++ b/include/common.inc.php @@ -1,1 +1,39 @@ + array. + $Class = (array) $Class; + + # Iterate through the former properties looking for any stdClass properties. + # Recursively apply (array). + foreach ($Class as $key => $value) { + if (is_object($value) && get_class($value) === 'stdClass') { + $Class[$key] = object_to_array($value); + } + } + return $Class; +} + +# Convert an Array to stdClass. http://www.php.net/manual/en/language.types.object.php#102735 + +function array_to_object(array $array) { + # Iterate through our array looking for array values. + # If found recurvisely call itself. + foreach ($array as $key => $value) { + if (is_array($value)) { + $array[$key] = array_to_object($value); + } + } + + # Typecast to (object) will automatically convert array -> stdClass + return (object) $array; +} +?> + + + --- /dev/null +++ b/include/couchdb.inc.php @@ -1,1 +1,27 @@ +_id = "_design/" . urlencode("app"); + $obj->language = "javascript"; + $obj->views->byABN->map = "function(doc) { emit(doc.abn, doc); };"; + $obj->views->byName->map = "function(doc) { emit(doc.name, doc); };"; + $obj->views->getActive->map = 'function(doc) { if (doc.status == "active") { emit(doc._id, doc); } };'; + $obj->views->getSuspended->map = 'function(doc) { if (doc.status == "suspended") { emit(doc._id, doc); } };'; + $obj->views->getScrapeRequired->map = "function(doc) { emit(doc.abn, doc); };"; + $obj->views->showNamesABNs->map = "function(doc) { emit(doc._id, {name: doc.name, abn: doc.abn}); };"; + // allow safe updates (even if slightly slower due to extra: rev-detection check). + return $db->save($obj, true); +} +require ('couchdb/settee/src/settee.php'); + +$server = new SetteeServer('http://127.0.0.1:5984'); + +function setteErrorHandler($e) { + echo $e->getMessage() . "
    " . PHP_EOL; +} + +?> + --- /dev/null +++ b/include/template.inc.php @@ -1,1 +1,75 @@ + + + + + + + + + + + + + + + Disclosr + + + + + + + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + + + --- a/sag +++ /dev/null --- /dev/null +++ b/schemas/agency.json.php @@ -1,1 +1,19 @@ + "Representation of government agency and online transparency measures", + "type" => "object", + "properties" => Array( + "name" => Array("type" => "string", "required" => true, "description" => "Agency Name, most recent and broadest"), + "othernames" => Array("type" => "array", "required" => true, "description" => "Agency Names", + "items" => Array("type" => "string")), + ), + /*"org":{"type":"object", + "properties":{ + "organizationName":{"type":"string"}, + "organizationUnit":{"type":"string"}}, + } + }*/ +); +?> + --- /dev/null +++ b/schemas/schemas.inc.php @@ -1,1 +1,5 @@ +