Skip to content

Commit

Permalink
Initial compliance for Open311 GeoReport v2 service definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Ashlock authored and Philip Ashlock committed Aug 29, 2012
1 parent 548d9db commit c0929c6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
61 changes: 54 additions & 7 deletions Formbuilder/Formbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,68 @@ public function open311_form(){
$new_attributes['variable'] = true;

// this should be user provided, just faking it now
$new_attributes['code'] = str_replace(' ', '-', strtolower($attributes['title']));
$code_temp = (strlen($attributes['title'])) ? $attributes['title'] : $attributes['values'];
$new_attributes['code'] = str_replace(' ', '-', strtolower($code_temp));

$new_attributes['order'] = $count;

// these two need to be filtered more
$new_attributes['datatype'] = $attributes['cssClass'];
$new_attributes['datatype-multiple'] = $attributes['multiple'];
$datatype = $attributes['cssClass'];

switch ($datatype) {
case 'select':
if ($attributes['multiple'] == 'checked') {
$new_attributes['datatype'] = 'multivaluelist';
$new_attributes['datatype_description'] = 'Select an option';
} else {
$new_attributes['datatype'] = 'singlevaluelist';
$new_attributes['datatype_description'] = 'Select one or more options';
}
break;
case 'radio':
$new_attributes['datatype'] = 'singlevaluelist';
$new_attributes['datatype_description'] = 'Select an option';
break;
case 'checkbox':
$new_attributes['datatype'] = 'multivaluelist';
$new_attributes['datatype_description'] = 'Select one or more options';
break;
case 'input_text':
$new_attributes['datatype'] = 'string';
$new_attributes['datatype_description'] = 'Short text response';
break;
case 'textarea':
$new_attributes['datatype'] = 'text';
$new_attributes['datatype_description'] = 'Long text response';
break;
}

// this should be user provided, just faking it now
$new_attributes['datatype_description'] = '';

$new_attributes['description'] = $attributes['title'];
//$new_attributes['datatype_description'] = '';

$new_attributes['required'] = ($attributes['required'] == 'checked') ? true : false;
$new_attributes['description'] = ($new_attributes['datatype'] == 'text' || $new_attributes['datatype'] == 'string') ? $attributes['values'] : $attributes['title'];

// this needs to be restructured
$new_attributes['values'] = $attributes['values'];
$option_values = $attributes['values'];

$new_attributes['values'] = null;


if ($new_attributes['datatype'] !== 'text' && $new_attributes['datatype'] !== 'string') {
foreach ($option_values as $option) {

// should be user provided, just faking it now
$key = null;
$key = str_replace(' ', '-', strtolower($option['value']));

$new_attributes['values'][] = array('key' => $key, 'name' => $option['value']);


}
}

//$new_attributes['values']

$new_structure[$keys] = $new_attributes;

Expand Down
12 changes: 9 additions & 3 deletions Formbuilder/Formbuilder_pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,25 @@ public function connect(){
* Save the data to the database, but still returns the $for_db array.
*/
public function save_form(){
//$for_db = parent::get_encoded_form_array();
$for_db = parent::get_encoded_form_array();

$for_db = parent::open311_form();
$for_db_open311 = parent::open311_form();
$for_db['form_structure_open311'] = $for_db_open311['form_structure'];

if($for_db['form_id']){
$stmt = $this->_db->prepare("UPDATE fb_savedforms SET form_structure = :struct WHERE id = :id");
$stmt->bindParam(':id', $for_db['form_id'], PDO::PARAM_INT);
} else {
$stmt = $this->_db->prepare("INSERT INTO fb_savedforms (form_structure) VALUES (:struct)");
$stmt = $this->_db->prepare("INSERT INTO fb_savedforms (form_structure, form_structure_open311) VALUES (:struct, :struct311)");
}
$stmt->bindParam(':struct', $for_db['form_structure'], PDO::PARAM_STR);
$stmt->bindParam(':struct311', $for_db['form_structure_open311'], PDO::PARAM_STR);
$stmt->execute();


}




/**
Expand Down
1 change: 1 addition & 0 deletions Formbuilder/sql/mysql.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE TABLE IF NOT EXISTS `fb_savedforms` (
`id` int(11) NOT NULL auto_increment,
`form_structure` longtext NOT NULL,
`form_structure_open311` longtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

Expand Down
8 changes: 4 additions & 4 deletions example-save.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

$form_data = isset($_POST['frmb']) ? $_POST : false;
$form = new Formbuilder($form_data);
//$for_db = $form->get_encoded_form_array();
$for_db = $form->get_encoded_form_array();

$for_db = $form->open311_form();
$for_db_raw = $form->open311_form();

//------------------------------------------------------------------------------

Expand All @@ -29,13 +29,13 @@
$form = new Formbuilder_pdo($for_db);
$form->connect();
$form->save_form();

//$form->save_form_open311();

//------------------------------------------------------------------------------

// Here's the example output of get_encoded_form_array()

print_r($for_db);
print_r($for_db_raw);
//Array
//(
// [form_id] => 1
Expand Down
2 changes: 1 addition & 1 deletion fake-form-db-vals.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

$form = new Formbuilder_pdo();
$form->connect();
$fake_db_vals = $form->loadFormRecord('6');
$fake_db_vals = $form->loadFormRecord('49');

?>

0 comments on commit c0929c6

Please sign in to comment.