From: Steve Sutton Date: Tue, 14 Jun 2016 17:10:40 +0000 (-0400) Subject: Updating the settings for amenities X-Git-Tag: v2.1^2~3^2^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=eefbcc311312b930dcf0a8159524461453802117;p=WP-Plugins%2Fglm-member-db.git Updating the settings for amenities Updating the view file and processing for getting the amenities into groups. WIP: Does not bring old groups into the edit form yet. --- diff --git a/classes/data/dataAmenities.php b/classes/data/dataAmenities.php index 8c9f2bd2..60ace161 100644 --- a/classes/data/dataAmenities.php +++ b/classes/data/dataAmenities.php @@ -84,11 +84,11 @@ class GlmDataAmenities extends GlmDataAbstract * @return void * @access public */ - function __construct ($wpdb, $config) + function __construct ( $wpdb, $config ) { // If this class is not being extended along with existing $wpdb and $config - if (!$this->wpdb) { + if ( !$this->wpdb ) { // Save WordPress Database object $this->wpdb = $wpdb; @@ -109,62 +109,97 @@ class GlmDataAmenities extends GlmDataAbstract $this->fields = array( 'id' => array( - 'field' => 'id', - 'type' => 'integer', - 'view_only' => true, - 'use' => 'a' + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a', ), // Facility Type - 'ref_type' => array ( - 'field' => 'ref_type', - 'type' => 'list', - 'list' => $this->config['ref_type'], - 'required' => true, - 'use' => 'a' + 'ref_type' => array ( + 'field' => 'ref_type', + 'type' => 'list', + 'list' => $this->config['ref_type'], + 'required' => true, + 'use' => 'a', ), // Name 'name' => array( - 'field' => 'name', - 'type' => 'text', - 'required' => true, - 'unique' => true, - 'use' => 'a' + 'field' => 'name', + 'type' => 'text', + 'required' => true, + 'unique' => true, + 'use' => 'a', ), // Uses Value 'uses_value' => array( - 'field' => 'uses_value', - 'type' => 'checkbox', - 'use' => 'a' + 'field' => 'uses_value', + 'type' => 'checkbox', + 'use' => 'a', ), // Description 'descr' => array( - 'field' => 'descr', - 'type' => 'text', - 'use' => 'a' + 'field' => 'descr', + 'type' => 'text', + 'use' => 'a', ), // Short Description 'short_descr' => array( - 'field' => 'short_descr', - 'type' => 'text', - 'use' => 'a' - ) + 'field' => 'short_descr', + 'type' => 'text', + 'use' => 'a', + ), ); - if (is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { - glmMembersAdmin::addNotice($this->fields, 'DataBlock', 'Table Fields: '.$this->table); + if ( is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) { + glmMembersAdmin::addNotice( $this->fields, 'DataBlock', 'Table Fields: '.$this->table ); } } + /** + * Entry Post Processing Call-Back Method + * + * Perform post-processing for all result entries. + * + * In this case we're using it to append an array of category + * data to each member result and also sort by member name. + * + * @param array $r Array of field result data for a single entry + * @param string $a Action being performed (l, i, g, ...) + * + * @return object Class object + * + */ + public function entryPostProcessing( $result_data, $action ) + { + switch ( $action ) { + case 'l': + case 'g': + $sql = " + SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "grouped_amenities + WHERE amenity_id = " . $result_data['id']; + $result_data['groups'] = $this->wpdb->get_results( $sql, ARRAY_A ); + $result_data['groups_json'] = json_encode($result_data['groups']); + break; + case 'i': + echo '
INSERT: $result_data: ' . print_r($result_data, true) . '
'; + echo '
$_REQUEST: ' . print_r($_REQUEST, true) . '
'; + break; + case 'd': + break; + } + return $result_data; + } - /* + /** * Get the amenitities for a particular reference and destination * * @param integer $ref Reference Type (i.e. member, member_info, location, ...) @@ -172,15 +207,18 @@ class GlmDataAmenities extends GlmDataAbstract * * @return array Array of amenities */ - public function getAmenityRef($ref_type = false, $ref_dest = false) { + public function getAmenityRef( $ref_type = false, $ref_dest = false ) { // Check input for sanity - Refernce type first - if ($ref_type == false || ($ref_type-0) <= 0 || !in_array($ref_type, $this->config['ref_type_numb'])) { + if ( $ref_type === false + || ( $ref_type - 0 ) <= 0 + || !in_array( $ref_type, $this->config['ref_type_numb'] ) + ) { return false; } // Now check for positive integer for destination (record ID) - if ($ref_dest == false || ($ref_dest-0) <= 0) { + if ( $ref_dest == false || ( $ref_dest - 0 ) <= 0 ) { return false; } @@ -195,13 +233,13 @@ class GlmDataAmenities extends GlmDataAbstract ORDER BY A.name ;"; - $amenList = $this->wpdb->get_results($sql, ARRAY_A); + $amenList = $this->wpdb->get_results( $sql, ARRAY_A ); return $amenList; } - /* + /** * Get the amenitities for a particular reference and destination * * @param integer $ref Reference Type (i.e. member, member_info, location, ...) @@ -209,49 +247,49 @@ class GlmDataAmenities extends GlmDataAbstract * * @return array Array of amenities */ - public function updateAmenityRef($ref_type = false, $ref_dest = false, $amenities = false) { + public function updateAmenityRef( $ref_type = false, $ref_dest = false, $amenities = false ) { // Check input for sanity - Refernce type first - if ($ref_type == false || ($ref_type-0) <= 0 || !in_array($ref_type, $this->config['ref_type_numb'])) { + if ( $ref_type == false + || ( $ref_type - 0 ) <= 0 + || !in_array( $ref_type, $this->config['ref_type_numb'] ) ) { return false; } // Now check for positive integer for destination (record ID) - if ($ref_dest == false || ($ref_dest-0) <= 0) { + if ( $ref_dest == false || ( $ref_dest - 0 ) <= 0 ) { return false; } // Start by deleting all amenities for this destination $sql = " - DELETE FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref - WHERE ref_type = $ref_type - AND ref_dest = $ref_dest - ;"; - $this->wpdb->query($sql); + DELETE + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref + WHERE ref_type = $ref_type + AND ref_dest = $ref_dest"; + $this->wpdb->query( $sql ); // If no amenities supplied, return now with no list - if ($amenities == false) { + if ( $amenities == false ) { return false; } // Since we seem to have a list, add all of these - foreach ($amenities as $a) { + foreach ( $amenities as $a ) { $sql = " - INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref + INSERT INTO " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenity_ref ( amenity, ref_type, ref_dest) VALUES ( $a, $ref_type, $ref_dest ) ;"; - $this->wpdb->query($sql); + $this->wpdb->query( $sql ); } - $amen = $this->getAmenityRef($ref_type, $ref_dest); + $amen = $this->getAmenityRef( $ref_type, $ref_dest ); return $amen; } } - -?> \ No newline at end of file diff --git a/classes/data/dataGroups.php b/classes/data/dataGroups.php new file mode 100644 index 00000000..63958bf9 --- /dev/null +++ b/classes/data/dataGroups.php @@ -0,0 +1,130 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMemberType.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * EventManagementDataGroups class + * + * PHP version 5 + * + * @category Data + * @package EventManagement + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmDataGroups extends GlmDataAbstract +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Field definitions + * + * @var $ini + * @access public + */ + public $table; + + /** + * Field definitions + * + * 'type' is type of field as defined by the application + * text Regular text field + * pointer Pointer to an entry in another table + * 'filters' is the filter name for a particular filter ID in PHP filter + * functions + * See PHP filter_id() + * + * 'use' is when to use the field + * l = List + * g = Get + * n = New + * i = Insert + * e = Edit + * u = Update + * d = Delete + * a = All + * + * @var $ini + * @access public + */ + public $fields = false; + + /** + * Constructor + * + * @param object $d + * database connection + * + * @return void + * @access public + */ + function __construct ( $wpdb, $config ) + { + + // If this class is not being extended along with existing $wpdb and $config + if ( !$this->wpdb ) { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + } + + /* + * Table Name + */ + $this->table = GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenity_groups'; + + /* + * Table Data Fields + */ + $this->fields = array( + 'id' => array( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Name + 'name' => array( + 'field' => 'name', + 'type' => 'text', + 'required' => true, + 'unique' => true, + 'use' => 'a' + ), + ); + + if ( is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) { + glmMembersAdmin::addNotice( $this->fields, 'DataBlock', 'Table Fields: '.$this->table ); + } + } +} diff --git a/models/admin/settings/amenities.php b/models/admin/settings/amenities.php index 9c154491..cc917dc7 100644 --- a/models/admin/settings/amenities.php +++ b/models/admin/settings/amenities.php @@ -14,7 +14,8 @@ */ // Load Amenities data abstract -require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataAmenities.php'); +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataAmenities.php'; +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataGroups.php'; /* * This class performs the work for the default action of the "Members" menu @@ -48,7 +49,7 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities * @return object Class object * */ - public function __construct ($wpdb, $config) + public function __construct ( $wpdb, $config ) { // Save WordPress Database object @@ -58,7 +59,7 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities $this->config = $config; // Run constructor for members data class - parent::__construct(false, false); + parent::__construct( false, false ); } @@ -96,143 +97,158 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities * produce output. * */ - public function modelAction ($actionData = false) + public function modelAction ( $actionData = false ) { - $success = true; + $success = true; $haveAmenities = false; - $amenities = false; - $error = false; - - - $newAmenity = $this->newEntry(); + $haveGroups = false; + $amenities = false; + $error = false; + $newAmenity = $this->newEntry(); // Check if a category ID is supplied $id = 0; - if (isset($_REQUEST['id'])) { - $id = $_REQUEST['id']-0; + if ( isset( $_REQUEST['id'] ) ) { + $id = $_REQUEST['id'] - 0; } - // If there's an action option - if (isset($_REQUEST['option'])) { - - switch($_REQUEST['option']) { + $groupData = new GlmDataGroups( $this->wpdb, $this->config ); + // If there's an action option + if ( isset( $_REQUEST['option'] ) ) { + switch( $_REQUEST['option'] ) { case 'addNew': $this->insertEntry(); break; case 'update': - if ($id > 0) { - $this->updateEntry($id); + if ( $id > 0 ) { + $this->updateEntry( $id ); + } + echo '
$id: ' . print_r($id, true) . '
'; + echo '
$_REQUEST: ' . print_r($_REQUEST, true) . '
'; + // Delete the current entries for the grouped amenities + $this->wpdb->delete( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'grouped_amenities', + array( 'amenity_id' => $id ), + array( '%d' ) + ); + if ( isset( $_REQUEST['grouped']['group'] ) ) { + foreach ( $_REQUEST['grouped']['group'] as $group_id => $group_value ) { + if ( $group_value == 1 ) { + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'grouped_amenities', + array( + 'group_id' => $group_id, + 'amenity_id' => $id, + 'searchable' => $_REQUEST['grouped']['searchable'][$group_id] + ), + array( + '%d', + '%d', + '%s' + ) + ); + } + } } break; case 'delete': - if ($id > 0) { - $this->deleteEntry($id, true); + if ( $id > 0 ) { + $this->deleteEntry( $id, true ); } break; - } - - } - - -/* - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { - glmMembersAdmin::addNotice($newAmenity, 'DataBlock', 'New Amenity Data'); - } - - if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'addNew') { - - $amenities = $this->insertEntry(); - - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { - glmMembersAdmin::addNotice('  New Entry Added ', 'Process'); - } - } - - if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'delete' && isset($_REQUEST['amenityID'])) { + case 'addNewGroup': + $groupData->insertEntry(); + break; - $id = $_REQUEST['amenityID']-0; - if ($id > 0) { - $this->deleteEntry($id, true); - } + case 'updateGroup': + if ( $id > 0 ) { + $groupData->updateEntry( $id ); + } + break; - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { - glmMembersAdmin::addNotice('  Entry Deleted: id = '.$id, 'Process'); + case 'deleteGroup': + if ( $id > 0 ) { + $groupData->deleteEntry( $id ); + } + break; } - - } - - // Check if a amenity ID is supplied - if (isset($_REQUEST['amenity_id'])) { - // Make sure it's a number - $amenityID = $_REQUEST['amenity_id']-0; - } - - // Check for action option - $option = false; - if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') { - $option = $_REQUEST['option']; } -*/ // Get a current list of amenities $amenities = $this->getList(); + echo '
$amenities: ' . print_r($amenities, true) . '
'; - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { - glmMembersAdmin::addNotice($amenities, 'DataBlock', 'Amenities Data'); + if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) { + glmMembersAdmin::addNotice( $amenities, 'DataBlock', 'Amenities Data' ); } // If we have list entries - even if it's an empty list $success = true; $haveAmenities = false; - if ($amenities !== false) { + if ( $amenities !== false ) { $success = true; // If we have any entries - if (count($amenities) > 0) { + if ( count( $amenities ) > 0 ) { $haveAmenities = true; } } + $groups = $groupData->getList(); + + if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) { + glmMembersAdmin::addNotice( $groups, 'DataBlock', 'Amenity Groups Data' ); + } + + if ( $groups !== false ) { + $success = true; + + // If we have any entries. + if ( count( $groups ) > 0 ) { + $haveGroups = true; + } + } + // If we had a fatal error, redirect to the error page if ($error) { return array( - 'status' => $success, - 'menuItemRedirect' => 'error', - 'modelRedirect' => 'index', - 'view' => 'admin/error/index.html', - 'data' => false + 'status' => $success, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => false, ); } if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { - glmMembersAdmin::addNotice($amenities, 'DataBlock', 'Amenities Data'); + glmMembersAdmin::addNotice( $amenities, 'DataBlock', 'Amenities Data' ); } // Compile template data $templateData = array( 'haveAmenities' => $haveAmenities, - 'amenities' => $amenities, - 'newAmenity' => $newAmenity + 'haveGroups' => $haveGroups, + 'amenities' => $amenities, + 'groups' => $groups, + 'newAmenity' => $newAmenity, ); // Return status, suggested view, and data to controller return array( - 'status' => $success, + 'status' => $success, 'menuItemRedirect' => false, - 'modelRedirect' => false, - 'view' => 'admin/settings/amenities.html', - 'data' => $templateData + 'modelRedirect' => false, + 'view' => 'admin/settings/amenities.html', + 'data' => $templateData, ); } } - -?> \ No newline at end of file diff --git a/setup/validActions.php b/setup/validActions.php index 651e9545..8e4dee80 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -33,58 +33,58 @@ $glmMembersValidActions = array( 'adminActions' => array( 'ajax' => array( - 'imageUpload' => 'glm-member-db' + 'imageUpload' => 'glm-member-db', ), 'dashboardWidget' => array( - 'index' => 'glm-member-db' + 'index' => 'glm-member-db', ), 'members' => array( - 'index' => 'glm-member-db', // member list - 'list' => 'glm-member-db', - 'reports' => 'glm-member-db', - 'other' => 'glm-member-db' + 'index' => 'glm-member-db', // member list + 'list' => 'glm-member-db', + 'reports' => 'glm-member-db', + 'other' => 'glm-member-db', ), 'member' => array( - 'index' => 'glm-member-db', // Member Dashboard - 'memberInfo' => 'glm-member-db', - 'memberEdit' => 'glm-member-db', - 'locations' => 'glm-member-db' + 'index' => 'glm-member-db', // Member Dashboard + 'memberInfo' => 'glm-member-db', + 'memberEdit' => 'glm-member-db', + 'locations' => 'glm-member-db', ) , 'settings' => array( - 'index' => 'glm-member-db', // Member Types - 'categories' => 'glm-member-db', - 'cities' => 'glm-member-db', - 'regions' => 'glm-member-db', - 'amenities' => 'glm-member-db' + 'index' => 'glm-member-db', // Member Types + 'categories' => 'glm-member-db', + 'cities' => 'glm-member-db', + 'regions' => 'glm-member-db', + 'amenities' => 'glm-member-db', ), 'management' => array( - 'index' => 'glm-member-db', // General Options - 'terms' => 'glm-member-db', - 'development' => 'glm-member-db', - 'theme' => 'glm-member-db', - 'import' => 'glm-member-db', - 'addons' => 'glm-member-db', - 'hooks' => 'glm-member-db' + 'index' => 'glm-member-db', // General Options + 'terms' => 'glm-member-db', + 'development' => 'glm-member-db', + 'theme' => 'glm-member-db', + 'import' => 'glm-member-db', + 'addons' => 'glm-member-db', + 'hooks' => 'glm-member-db', ), 'shortcodes' => array( - 'index' => 'glm-member-db' + 'index' => 'glm-member-db' ), 'error' => array( - 'index' => 'glm-member-db', - 'badAction' => 'glm-member-db' + 'index' => 'glm-member-db', + 'badAction' => 'glm-member-db', ) ), 'frontActions' => array( 'members' => array( - 'list' => 'glm-member-db', - 'detail' => 'glm-member-db' + 'list' => 'glm-member-db', + 'detail' => 'glm-member-db', ), 'error' => array( - 'index' => 'glm-member-db', - 'badAction' => 'glm-member-db' + 'index' => 'glm-member-db', + 'badAction' => 'glm-member-db', ) ) ); -?> \ No newline at end of file +?> diff --git a/views/admin/settings/amenities.html b/views/admin/settings/amenities.html index 8ba15e7d..008dc86a 100644 --- a/views/admin/settings/amenities.html +++ b/views/admin/settings/amenities.html @@ -1,233 +1,422 @@ {include file='admin/settings/header.html'} - -
Add an Amenity
-
-
- - + - - + + + {if $haveAmenities} + {assign var="i" value="0"} + {foreach $amenities as $t} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + + + + + {/foreach} + {else} + + {/if} + +
+ +
Add an Amenity
+
+ + + - - - - - - - - - - - + + + +
Amenity Name: - -
Description: - -
+ + + + + + + + + + + + + + + +
Amenity Name: + +
Description: + +
Short Description: + +
+ + {foreach $groups as $group} + + + + + {/foreach} +
+ + + +
+
+

* Required

+ Cancel + + + +
+ + +
+
+

Are you sure you want to delete this amenity?

+

Yes, delete this amenity

+

Cancel

+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
Amenity Name: + +
Description: + +
Short Description: + +
+ + {foreach $groups as $group} + + + + + {/foreach} +
+ + + +
+
+

* Required

+ Cancel + + +
+
+ + +

Amenities

+ + + - - + + + + + + -
Short Description: - - AmenityUsed WithDescriptionShort DescriptionUses Value 
-

* Required

- Cancel - + +
+ {$t.name} + + {$t.ref_type.name} + + {$t.descr} + + {$t.short_descr} + + {foreach $t.groups as $group} + + {/foreach} + +
Delete
+
(no amenities listed)
+ + + + + + + {if $haveGroups} + {assign var="i" value="0"} + {foreach $groups as $t} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + {/foreach} + {else} + + {/if} + +
+ +
Add a Group
+
+
+ + + + + + + + + + + +
Group Name: + +
+

* Required

+ Cancel + + +
+
+ + +
+
+

Are you sure you want to delete this group?

+

Yes, delete this group

+

Cancel

+
+
+ + +
+
+ + + + + + + + + + + + +
Group Name: + +
+

* Required

+ Cancel + + +
+
+ +

Groups

+ + - - + + -
Short Description: - - Group 
-

* Required

- Cancel - - - - - + +
+ {$t.name} + +
Delete
+
(no groups listed)
+ + + + -

Amenities

- - - - - - - - - - - - - -{if $haveAmenities} - {assign var="i" value="0"} - {foreach $amenities as $t} - {if $i++ is odd by 1} - - {else} - - {/if} - - - - - - - - {/foreach} -{else} - -{/if} - -
AmenityUsed WithUses ValueDescriptionShort Description 
- {$t.name} - - {$t.ref_type.name} - - {$t.uses_value.name} - - {$t.descr} - - {$t.short_descr} - -
Delete
-
(no amenities listed)
- - {include file='admin/footer.html'}