achhunna / client-revenue-schedule-t201610

Billing system management app
Other
0 stars 0 forks source link

data structures for tables #2

Open caleb99 opened 8 years ago

caleb99 commented 8 years ago

https://github.com/achhunna/Tally/blob/master/tally-functions.php#L15-L19

I'm wondering if we can't create more of a data structure for the purposes of defining tables.

We'll need to do strong type casting / validations. i.e. every input validated before being passed to an insert table helper function.

Maybe something like (pseudo code):

$tables = array(
  invoice_clients => array( 
       table=>acctg_invoice_clients,
       fields=> array(  acctg_invoice_clients_id => array( type=> int ), date_signed=>array(type=>date) ),
  client_transactions => array(
      table =>acctg_client_transactions,
      fields=> array(  acctg_client_transactions_id => array( type=> int ), date_of_transaction=>array(type=>date) ),

);

Then we can make helper functions to reference the tables and their attributes:

if( valid_input("invoice_clients","date_signed", $user_input_from_csv_or_UI ) )
  echo "it's valid input";
achhunna commented 8 years ago

Ya makes sense. I had similar thought as well, but wanted to first get a working version first.

caleb99 commented 8 years ago

We could also switch to embedded wpdb functions for table manipulation.

https://codex.wordpress.org/Class_Reference/wpdb

$wpdb->insert( 
    'table', 
    array( 
        'column1' => 'value1', 
        'column2' => 123 
    ), 
    array( 
        '%s', 
        '%d' 
    ) 
);

Could be something like:

$wpdb->insert( 
    tn('client_transactions'), 
    fields('client_transactions', $user_input), // fields could be array_mapped somehow
    input_types('client_transactions') // returns the wpdb->prepare specific input types
);