+++ /dev/null
-GlmDataAbstract.php Documentation
--------------------------------------------
-
-
-**** Need to add 'PreDelete" and "PostDelete" capability for things like images and other related stuff ****
-
-
-
-This file is an abstract layer for all standard database operations. It
-provides the following.
-
-* Standardized method for database use definition
-* Standardized methods for database access
-* Standardized data input and output processing
-* Standardized response data structure for use with applications or directly with templates
-
-This abstraction layer is primarily driven by a dabase field definitions
-array. The array defines both real and virtual database fields, the type
-of those fields, how input to those fields is filtered and validated,
-whether the fields are required, if those fields must be unique, and
-for which database access methods the fields should be used. A specification
-of that array is defined below under "Field Definitions Array Specification".
-
-Virtual fields are either modified copies of a real database field using
-an alternative name and alternative parameters, or are the result of more
-complex operations related to a single or multiple specific real database
-fields (such as pointer field options, possibly with selection criteria).
-
-
-Summary of Standard Database Access Methods
--------------------------------------------
-
-getStats() Collects and returns statistics from the database according
- to the field definitions array.
-
-getList() Builds and returns a list of database entries according to
- the field definitions array.
-
- Parameters:
- $where Optional SQL "WHERE" clause
- $order Optional SQL "ORDER BY" clause
-
-getEntry() Builds and returns a single simple database table entry or
- optionally a single instance of a composite of multiple
- related table entries.
-
-newEntry() Prepairs for the creation of a new simple or composite database
- entry and returns information sufficient to create the
- necessary user input requests through a template.
-
-insertEntry() Checks for and compiles input data from the $_REQUEST array,
- tests for all requirements to be met, and if possible inserts
- the data into a single database table or if a composite into
- multiple related tables.
-
-cloneEntry() Makes a copy of the entry with the specified ID and if
- successful returns the ID of the cloned copy. Also makes
- duplicates of any images and updates the image names.
-
-editEntry() Builds and returns a single simple database table entry or
- optionally a single instance of a composite of multiple
- related table entries and includes the information necessary
- to build a user input request through a template.
-
-updateEntry() Checks for and compiles input data from the $_REQUEST array,
- tests for all requirements to be met, if possible updates
- the specified database table entry/entries, and returns the
- stored data for display back to the user (similar to the
- getEntry method). If the update fails, it returns the data
- submitted and flags/information indicating the field(s)
- and nature of the failure so that the user input form can
- be redisplayed with such notices.
-
-deleteEntry() Checks for the deletion of a simple or composite database
- entry, deletes that entry if possible, and returns information
- on the success or failure of that operation.
-
-checkOther() Permits other checks before submission of data with insert
- and update. This is a hook back into DataAbstract.php that
- can be used to intercept the insert and update process, run
- checks on data that was submitted, alter data, add fieldFail
- data, and chage the result status. The function is passed the
- entire result array ($r) and the action character ($a)
- and should return the same when done
- performing checks and updates. This is not required when calling
- DataAbstract since there is a stub checkOther() method there.
-
- An example follows showing how to hook into checkOther() in
- DataAbstract and make additional checks ...
-
- function checkOther($r, $a)
- {
- // Required
- parent::checkOther($r, $a);
-
- // ---- Perform test and changes ----
-
- // Sample field checks and status updates
- if ($r['fieldData']['date_specific']['value'] && $r['fieldData']['cart_sticky']['value']) {
- $r['status'] = false;
- $r['fieldFail']['cart_sticky'] = 'Sticky may not be used when "Specified Dates" is checked.';
- $r['fieldFail']['date_specific'] = 'Specified dates may not be used when "Sticky" is checked.';
- }
-
- // ---- End tests and changes ----
-
- // Required
- return $r;
- }
-
-
-Summary of Additional Methods Supporing the Methods Above
----------------------------------------------------------
-
-{fieldtype}Field() Returns a field name as needed for use in an SQL query
- for an individual field.
-
-{fieldtype}Options() Returns an SQL query segment needed to implement specific
- field options for an individual field.
-
-{fieldtype}Output() Returns data for an individual real or virtual field.
-
-{fieldtype}Input() Processes input for an individual real or composite field
- and returns a copy of the field information.
-
-{fieldtype}Store() Returns and SQL query segment representing the "VALUE"
- parameter for an individual field.
-
-buildFieldsList() Parses the definitions array and builds a list of fields
- and fields parameters that need to be processed for the
- current operation.
-
-processOutputData() Processes a fields list and returns a set of output data
- for all fields used for the current operation.
-
-processInputData() Processes a fields list and collects input data
- for all fields used for the current operation.
-
-f2LatLon() Performs various types of Latitude/Longitude conversions.
-
-
-Summary of Available Field Types
---------------------------------
-
-integer Standard integer value.
-
-Float Standard float value.
-
-money A float value processed for monitary input or display stripping
- any supplied "$" or "," characters and properly formatting for output.
-
-percent A float value processed for percentile input and display stripping
- any supplied "%" characters and properly formatting for output.
-
-pointer An integer field being used as a pointer to other table entries.
- NOTE: Pointer processing is performed after the table data is
- queried. Because of this, it's not possible to use a 'where' option
- to select those results. The 'where' option would only operate
- on the value of the pointer, not what it's pointing to.
-
-list An integer field being used as a pointer to a list of possible
- values useable for radio buttons and picklists.
-
-text A standard text field.
-
-checkbox A boolean field represented in any standard boolean form (i.e.
- Yes/No, 0/1, true/false).
-
-email A text field expecting and returning text formatted as an E-Mail
- address.
-
-date A timestamp field represented as a date, timestamp, or date list.
-
-time A timestamp field represented as a time value.
-
-datetime A timestamp filed represented as a date AND time value.
-
-phone A text field expecting and returning text formatted as a Phone
- number.
-
-image A field expecting and returning an image file to be stored and
- retrieved from the Image Server and represented in a text field
- as the Image Server file name.
-
-latitude A float field expecting and returning text formatted as a
- latitude.
-
-longitude A float field expecting and returning text formatted as a
- longitude.
-
-password A string field that uses crypt() to generate the stored value.
- Consider using the 'no_update_when_blank' option with this type of field.
-
-
-Field Definitions Array Specification
--------------------------------------
-
-Fields are specified using an array of field specification arrays.
-
-Sample:
-
- $this->fields = array(
-
- // Record ID
- 'id' => array(
- 'field' => 'id',
- 'as' => false,
- 'type' => 'integer',
- 'filter' => 'int',
- 'required' => true,
- 'unique' => true,
- 'default' => false,
- 'use' => 'a'
- ),
-
- // Name of event
- 'name' => array(
- 'field' => 'name',
- 'as' => false,
- 'type' => 'text',
- 'filter' => 'string',
- 'required' => true,
- 'unique' => true,
- 'default' => false,
- 'use' => 'a'
- )
-
- );
-
-
-The index for fields must be unique, but three may be multiple entries for a
-single field ('field') in the database table.
-
-
-Field Specifications:
-
-(array index) The array index is only used to permit multiple entries for the
- same database field. This permits including the field several
- times so it can be processed differently based on the operation
- being performed or can be displayed multiple time but each in a
- different way.
-
-'field' Name of field in database table
-
-'as' Name to use for this field for all operations other than for talking
- with the database. Doing this keeps any possible multiple instances
- of use of a single database field separate. (see array index above)
-
- If this is not specified, then the actual database field name is
- used for these purposes.
-
-
-'type' Type of field - Possible field types are...
-
- 'integer',
- 'float',
- 'money',
- 'percent',
- 'pointer',
- 'list',
- 'text',
- 'password',
- 'checkbox',
- 'email',
- 'date',
- 'time',
- 'phone',
- 'image',
- 'latitude', Data is an array of (dir,deg,min,sec);
- 'longitude' " " "
- "dir" is - for West and South
-
-'filter' Optional filter - See PHP filter_input() "filter" parameter.
- Currently only for type "text"
- FILTER_SANITIZE_FULL_SPECIAL_CHARS does not seem to be defined at this time.
- FILTER_SANITIZE_MAGIC_QUOTES seems to be good for permitting HTML
-
-'filter_options' Optional filter options - See PHP filter_input() "options" parameter.
- Currently only for type "text".
-
-'required' If set and true, field data must be supplied
-
-'unique' If set and true, must be a unique value
-
-'default' If set and true use this value as the default for input fields.
- Dates/times are expected to be timestamps
- There is no default image capability
-
-'use' Character(s) that indicate which operations to use this field with.
-
- l = Listing records
- g = Get - Displaying a record
- n = Setup input for a new record
- i = Insert new record
- e = Edit an existing record
- u = Update an edited record
- d = Ask for verification of deletion of a record
- c = Confirm delete and delete record.
- a = All above operations
-
-'minValue' Minimum acceptable value (numeric)
- Dates are specified as timestamp
-
-'maxValue' Maximum acceptable value (numeric)
- Dates are specified as timestamp
-
-'minLength' Minimum length for an input field
-'maxLength' Maximum length for an input field
-
-'force_list' Always provide the picklist tables (p_static overrides)
-
-'p_table' Table to get related data from for pointer types
-
-'p_field' Field to get related data from for pointer types
-
-'p_id' name of ID field in related data table
-
-'p_where' Additional WHERE clause for getting possible values from related table.
- "T." refers to the primary table
-
-'p_from' Additional FROM tables for getting possible values from related table.
- See example in dataMembers.php
-
-'p_blank' If set or true provide a "blank" option for pointer input
-
-'p_blank_text' If set, use this as the text for the 'p_blank' option
-
-'p_sort' Optional ORDER BY sort clause (i.e. "name, age DESC") - May not be functional yet.
-
-'p_orderby' Optional "ORDER BY" clause for results from table pointed to by pointer
-
-'p_autoadd' Option to permit the addition of a new entry using a text input field
-
-'p_sum' If true causes a numeric sum of all returned values from the target table/column
-
-'p_static' A static pointer that does not do a lookup for a list of values, only a single value reference
-
-'output_type' Optional type to use for output. Useful with pointers.
-
-'latlon_type' Optional specification for lat/lon output (DMS, DM, or D)
-
-'view_only' View only field, do not check for input or store, only provide data from record.
-
-'list' Required with field type 'list' - includes simple array where...
- array key is value for option
- array value is name for option
-
-'l_blank] Provide a blank entry for type 'list'.
-
-'list_keytype' Type of key field (default is 'text')
- 'text' A Text key - expects a text field in the database
- 'int' An Integer key - expects a numeric field in the database
-
-'output_format' Optional output format specification as would be used in printf()
- Use only the actual format and not the type identifier (i.e. "02.2" rather than "%f02.2")
-
-'no_stripslashes' Don't strip slashes when recalling this field from the database.
-
-'quicktip' Text description of this field and its use.
-
-'no_update_when_blank' Do not store a new value if the submitted data is blank
- Used particularly for password fields where you only want them updated when the user puts something in
-
-'pw_type' Type of password to require for password fields. (default is normal, 'strong' is for strong passwords with a mix of character types)
-
-'i_prefix' Optional string prefix to be attached to the beginning of a stored image. May be used to categorize images
- or associate an image with a particular entity. Note that no delimiter is added, so if you want want (i.e. '_'), you need to include that.
-
-Data specification for various types
-------------------------------------
-
-Type 'list'
-
- Return data
-
- array(
- 'list' => array(
- array('name' => {name}, 'value' => {value}, 'default' => {true if default or selected},
- ....
- ),
- 'value' => {value of selected option},
- 'name' => {name of selected option}
- )
-
-Type 'date'
-
- Input data fields
-
- When using single input text field, input field is name of field
-
- When using separate M, D, Y picklist or input fields
-
- '{field}_month'
- '{field}_day'
- '{field}_year'
-
- Return data
-
- array(
- 'date' => {text date},
- 'timestamp' => {timestamp},
- 'date_list' => array(
- 'month' => {picklist array},
- 'day' => {picklist array},
- 'year' => {picklist array}
- ),
- )
-
-Type 'time'
-
- Input data fields
-
- When using single input text field, input field is name of field
-
- When using separate H, M picklist or input fields
-
- '{field}_hour'
- '{field}_min'
- '{field}_ampm'
-
-
- Return data
-
- array(
- 'time' => {text time},
- 'time_list' => array(
- 'hour' => {picklist array},
- 'min' => {picklist array},
- 'ampm' => {picklist array}
- ),
- )
-
-
-Types 'lat' & 'lon'
-
- Return data
-
- array(
- 'dir' => {direction: -1 = S or W, +1 = N or E},
- 'dir_list' => array(
- array('name' => 'N', 'value' => 1, 'default' => {true if default or selected}),
- array('name' => 'S', 'value' => -1, 'default' => {true if default or selected})
- ),
- 'deg' => {degrees},
- 'min' => {minutes},
- 'sec' => {seconds}
- )
-
-
-Type 'image'
-
- Input fields
-
- '{field}_delete' Name of checkbox field to delete image
- '{field}_new' Name of file input field to save new image
-
-
-Type 'picklist'
-
- Parameters for {picklist array}
-
- 'name' Name to use for this option
- 'value' Value to return when this option is selected
- 'default' True if this option is currently selected
-
-
-
settype($dbVersion, 'string');
$resultMessage = '';
+ $importData = array(
+ 'success' => false,
+ 'haveNotices' => false,
+ 'notices' => array(),
+ 'haveMembers' => false,
+ 'members' => false
+ );
// Load database activation class to get access to database version information
require_once (GLM_MEMBERS_PLUGIN_PATH . '/activate.php');
switch($option) {
+ case 'import_connections':
+
+ // Load Member Info Data Class and get info data for later use
+ require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/glmMemberImportFromConnections.php');
+ $Connections = new GlmMemberImportFromConnections($this->wpdb, $this->config);
+
+ // Check if Connections is not installed or not active. If active, gets count of entries.
+ $c = $Connections->checkConnections();
+ if ($c === false) {
+ $importaData['notices'][] = 'Connections Business Directory plugin is not installed or not active!<br>'.print_r($c,1);
+ break;
+ }
+ $importData['numbEntries'] = $c;
+ $importData['notices'][] = 'Connections Business Directory plugin is active.<br>Number of businesses listed: '.$c.'<br>';
+
+ // Get the basic business data for review.
+ $importData['members'] = $Connections->getList();
+ if ($importData['members'] === false) {
+ $importaData['notices'][] = 'No businesses were retieved.';
+ break;
+ }
+
+ $importData['haveMembers'] = true;
+
+ if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ glmMembersAdmin::addNotice($importData['members'], 'DataBlock', 'Base Members Data');
+ }
+
+
+ break;
+
case 'drop':
case 'reset':
// Replace {prefix} with table name prefix
$sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
+ if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ glmMembersAdmin::addNotice('Dropping all database tables', 'Process');
+ glmMembersAdmin::addNotice($sql, 'DataBlock', 'Drop Tables SQL');
+ }
+
// Removing the tables using the script
$this->wpdb->query($sql);
+ // If there's been an error, display in debug Alert
+ $queryError = $this->wpdb->last_error;
+ if ($queryError) {
+ if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ glmMembersAdmin::addNotice('<b>Error when deleting database:</b><br>'.$queryError, 'Alert');
+ }
+ }
+
$resultMessage .= 'Database deleted<br>';
if ($option != 'reset') {
$queries = preg_split('/^----$/m', $sql);
// Try executing all queries to build database
+ $qForDebug = '';
do {
$q = current($queries);
$this->wpdb->query($q);
$queryError = $this->wpdb->last_error;
+
+ if ($queryError) {
+ glmMembersAdmin::addNotice('<b>Error when creating database:</b> <br>'.$queryError, 'Alert');
+ }
+ $qForDebug .= $queryError.$q;
+
} while ($queryError == '' && next($queries));
+ if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ glmMembersAdmin::addNotice('Creating database tables', 'Process');
+ glmMembersAdmin::addNotice($qForDebug, 'DataBlock', 'Create Tables SQL');
+ }
+
// If there were no errors
if (trim($queryError) == '') {
} else {
$resultMessage .= 'Failure installing database tables for the '.GLM_MEMBERS_PLUGIN_NAME.' plugin.<br>';
- $resultMessage .= '<b>Database Installation Error:</b> <br>';
+ $resultMessage .= '<b>Database Installation Error:</b> '.$queryError.'<br>';
}
break;
}
+ if (count($importData['notices'] > 0)) {
+ $importData['haveNotices'] = true;
+ }
+
$templateData = array(
- 'resultMessage' => $resultMessage
+ 'resultMessage' => $resultMessage,
+ 'importData' => $importData
);
// Return status, suggested view, and data to controller