GENERAL INFORMATION: DO NOT MODIFY ANY FILES IN THE "generated" folder created in "/path/to/lib/". These files will be completely overwritten the next time the program is run. Add any custom functions to the main classes generated directly within "/path/to/lib/". All code written under the specified line will be saved if the program is re-run. You can also add any custom "SITE WIDE" variables/arrays/functions to the "/path/to/lib.php" file to be used throughout your site. This could include things like the web path to the directory you upload pictures to as well as the absolute path of the directory you upload pictures to. Since this file should be included on every page anyway, it makes it logical to use it for these variables as well. Initial Setup: First, create the database. When creating the tables, the table name cannot equal "class_functions". Make sure to set the tables primary key(s) and foreign key(s) if they exist. The keys are used in numerous places. Tables with no primary key and tables with multi-column primary keys are handled differently from tables with single column primary keys. Tables with foreign keys have additional functions as well. To create the code, you need to create a setup file that includes some basic parameters. An example setup file will look something like this: (filename: ddataobjects.php)
then, from the command line, run setup: root@localhost [/var/www/html]# php ddataobjects.php This will create a folder called "/path/to/lib" with all of the library files included. It will also create "/path/to/lib.php" which is the file that should be included on every page of your site. All paths within the generated files are ABSOLUTE (unless you change pathinfo to relative). You cannot move this folder without modifying the setup file and re-running the script. Variables Created: The php code generated from this program will be based on the database being read. A class will be created for each table of the database with one variable for each column of the database. An example table named "person" with columns "person_id" "name" "address" "city" "state" "age" "birthdate" "person_created": ###################################################
*note - if a variable is a timestamp, a class variable will be created with the variable name to store the timestamp. Another variable will be created as the variable name appended by "_display" which will be a display friendly version of the timestamp in "mm/dd/yyyy hh:mm" format. - if a variable is a date, a class variable will be created with the variable name to store the date. Another variable will be created as the variable name appended by "_display" which will be a display friendly version of the date in "mm/dd/yyyy" format. - if a variable is a time, a class variable will be created with the variable name to store the time. Another variable will be created as the variable name appended by "_display" which will be a display friendly version of the time in "hh:mm am/pm" format * "_lookup" variables - if any fields in this table are foreign keys in another table (and this table links to the other table exactly 1 time), another variable can be created as the name of the other table appended by "_lookup" which will store an array of arrays containing the values of the other table. A label variable will also be created. If the linked table is a lookup table, the value of the label variable with be the table name of the column referenced from the lookup table, otherwise, it will be the name of the table linked to. This feature is enabled by adding the text "create_linked_variables" somewhere in the comments section of the table. *THERE IS A CHANCE OF A CONFLICT HERE if this table links to a lookup table that references a table, and another element of this table references the referenced table directly. I consider the chance of this happenening remote enough to not work around, but I do want to mention it. Loading Classes By default classes are loaded with PHP's __autoload() function in lib.php. Two additional functions are created if this doesn't work. The "load_all()" function will load all classes, and the "load($class) function can load the individual classes, for example, "load('person')" Constructor: A class constructor will be created which (optionally) takes as input the primary key of the table (if one exists, does not work with tables with multiple primary key fields). If the primary key is entered, the record will be selected from the table and the values will be set in the class.
<?php Also, there is an optional query string that can be entered to get a single record from the database. This is most useful when a primary key doesn't exist, but has been relevant in other situations as well. If more than one record is returned by the search, no records will be set. Search must return exactly one record. IMPORTANT: YOU MUST USE pg_escape_string ON USER GENERATED CONTENT HERE
<?php If there is no primary key (or multiple primary keys):.
<?php -------------------------------------------------------------------------------------------------------- Parameters that can be passed through Postgresql comments are: regexp, label (l), field_type (ft), input_type (it), size (s), default_value (dv), rows (r), columns(c), elements (e), spacer, multiple, additional_params (ap), foreign_DISPLAY_columns (fdc), foreign_SORT_columns (fsc), foreign_DISPLAY_columns_comma (fdcc) Comments are passed through with the following syntax: "regular comments|||param1|value1||param2|value2||.... -------------------------------------------------------------------------------------------------------- The "regular comments" value will create the class variable ${field_name}_regular_comments that can be returned on error. The regexp (regular expression) will be added to the variables setter to validate the variable The label will create the class variable ${field_name}_label with the value of "Label". If "Label" is not set, the value will be the value of the field with the first letter of each word capitalized and "_"'s replaced by " "'s. The field_type can be used to denote special fields that have their own unique error checking and formatting. This only works with "text" type fields. Current Field Types: phone_number: all non-digit chars will be stripped, 9 digit chars must exist and will be formatted as (xxx) xxx-xxxx zip_code: must be 5 digits or 9 digits email: validated against the regexp ^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$ currency: creates a "_display" variable and formats it as number_format($value, 2, '.', ',') ssn: all non-digit chars will be stripped. must be 9 digits, formatted xxx-xx-xxxx mmdd: A date without the year. Internally the year will be set to 9999, but will display as mm/dd not setup yet credit_card_number: all non-digit chars will be stripped. then must be 16 digits. formatted as xxxx-xxxx-xxxx-xxxx not setup yet month_year: must be 2 sets of digits seperated by - or /. must pass a date check for m/1/y. The input_type can be used to change the default input element of the field from textbox to something else. (use the size parameter to set default textbox size) Current Input Types: password displayed value will be ******** textarea use this with the rows and columns parameters select use this with the elements and multiple parameters radio use this with the elements and spacer parameters Use additional_params and default_value with any of the input_types The foreign_DISPLAY_columns are used when the field is a foreign key to another table. This tells internal functions what to link to The foreign_DISPLAY_columns_comma is used to tell internal functions to put a comma between columns when auto-pulling data out of linked tables The foreign_SORT_columns are used when the field is a foreign key to another table. This tells internal functions how to sort the DISPLAY columns NOTE ON FOREIGN KEYS: A setter method will also be generated for the "_lookup" variables. Input will be a one-dimensional array, either the referenced column from the lookup table will be used, or the primary key of the table will be set if it isn't a lookup table will be used. |