From 299e7095735b00bdf5a8bfefd18b5b8455342035 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 4 Sep 2015 12:12:18 -0400 Subject: [PATCH] Added member info amenities mangement, selection, and display --- classes/data/dataAmenities.php | 95 ++++++++++++++++++- classes/data/dataCategoryMemberInfo.php | 4 +- classes/data/dataMemberInfo.php | 11 +++ config/plugin.ini | 12 ++- glm-member-db.php | 1 + misc/databaseScripts/create_database_V0.1.sql | 2 +- misc/notes.txt | 2 + models/admin/member/memberInfo.php | 52 +++++++++- models/front/members/list.php | 40 ++++++++ views/admin/configure/amenities.html | 24 ++--- views/admin/member/memberInfo.html | 70 +++++++++++++- views/front/members/detail.html | 13 ++- views/front/members/list.html | 42 ++++++-- 13 files changed, 332 insertions(+), 36 deletions(-) diff --git a/classes/data/dataAmenities.php b/classes/data/dataAmenities.php index ce8d06c0..a8b20548 100644 --- a/classes/data/dataAmenities.php +++ b/classes/data/dataAmenities.php @@ -116,10 +116,10 @@ class GlmDataAmenities extends GlmDataAbstract ), // Facility Type - 'facility_type' => array ( - 'field' => 'facility_type', + 'ref_type' => array ( + 'field' => 'ref_type', 'type' => 'list', - 'list' => $this->config['facility_type'], + 'list' => $this->config['ref_type'], 'required' => true, 'use' => 'a' ), @@ -162,6 +162,95 @@ class GlmDataAmenities extends GlmDataAbstract } } + + + /* + * Get the amenitities for a particular reference and destination + * + * @param integer $ref Reference Type (i.e. member, member_info, location, ...) + * @param integer $dest Destination ID (i.e. ID of member info record) + * + * @return array Array of amenities + */ + 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'])) { + return false; + } + + // Now check for positive integer for destination (record ID) + if ($ref_dest == false || ($ref_dest-0) <= 0) { + return false; + } + + // + $sql = " + SELECT A.* + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenity_ref AS R, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenities AS A + WHERE R.ref_type = $ref_type + AND R.ref_dest = $ref_dest + AND A.id = R.amenity + ORDER BY A.name + ;"; + $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, ...) + * @param integer $dest Destination ID (i.e. ID of member info record) + * + * @return array Array of amenities + */ + 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'])) { + return false; + } + + // Now check for positive integer for destination (record ID) + 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); + + // If no amenities supplied, return now with no list + if ($amenities == false) { + return false; + } + + // Since we seem to have a list, add all of these + foreach ($amenities as $a) { + + $sql = " + INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref + ( amenity, ref_type, ref_dest) + VALUES + ( $a, $ref_type, $ref_dest ) + ;"; + + $this->wpdb->query($sql); + + } + + return $this->getAmenityRef($ref_type, $ref_dest); + + } + } ?> \ No newline at end of file diff --git a/classes/data/dataCategoryMemberInfo.php b/classes/data/dataCategoryMemberInfo.php index 23b30fc0..10f5c198 100644 --- a/classes/data/dataCategoryMemberInfo.php +++ b/classes/data/dataCategoryMemberInfo.php @@ -10,7 +10,7 @@ * @package GLM Member-DB * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: dataMemberType.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @release SVN: $Id: dataCategoryMemberInfo.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ */ /** @@ -22,7 +22,7 @@ * @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 + * @release SVN: $Id: dataCategoryMemberInfo.php,v 1.0 2011/01/25 19:31:47 cscott * Exp $ */ class GlmDataCategoryMemberInfo extends GlmDataAbstract diff --git a/classes/data/dataMemberInfo.php b/classes/data/dataMemberInfo.php index 2c75c6af..f9f1fced 100644 --- a/classes/data/dataMemberInfo.php +++ b/classes/data/dataMemberInfo.php @@ -393,6 +393,17 @@ class GlmDataMemberInfo extends GlmDataAbstract ;"; $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A); + // Get Amenity Data for this entry + $sql = " + SELECT A.* + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX. "amenities AS A, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX. "amenity_ref AS R + WHERE R.ref_type = ".$this->config['ref_type_numb']['MemberInfo']." + AND R.ref_dest = ".$r['id']." + AND A.id = R.amenity + ;"; + $r['amenities'] = $this->wpdb->get_results($sql, ARRAY_A); + return $r; } diff --git a/config/plugin.ini b/config/plugin.ini index 249f07f6..36a97cac 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -70,8 +70,8 @@ front-config['list_show_map'] = true front-config['list_show_list'] = true front-config['list_show_search'] = true front-config['list_search_text'] = true -front-config['list_search_category'] = false -front-config['list_search_amenities'] = false +front-config['list_search_category'] = true +front-config['list_search_amenities'] = true front-config['list_search_alpha'] = true ; Front-end Member Listing Options front-config['list_show_detaillink'] = true @@ -88,6 +88,7 @@ front-config['list_show_phone'] = true front-config['list_show_tollfree'] = true front-config['list_show_url'] = true front-config['list_show_url_newtarget'] = true +front-config['list_show_email'] = true front-config['list_show_categories'] = false front-config['list_show_creditcards'] = false front-config['list_show_amenities'] = false @@ -106,9 +107,10 @@ front-config['list_map_show_phone'] = true front-config['list_map_show_tollfree'] = true front-config['list_map_show_url'] = true front-config['list_map_show_url_newtarget'] = true +front-config['list_map_show_email'] = true front-config['list_map_show_categories'] = true front-config['list_map_show_creditcards'] = true -front-config['list_map_show_amenities'] = false +front-config['list_map_show_amenities'] = true ; Front-end Member Detail Options front-config['detail_show_map'] = true front-config['detail_show_directions'] = true @@ -125,6 +127,7 @@ front-config['detail_show_phone'] = true front-config['detail_show_tollfree'] = true front-config['detail_show_url'] = true front-config['detail_show_url_newtarget'] = true +front-config['detail_show_email'] = true front-config['detail_show_categories'] = true front-config['detail_show_creditcards'] = true front-config['detail_show_amenities'] = true @@ -198,11 +201,13 @@ ref_type_numb['Contact'] = 80 ; ; Facility Type ; +facility_type[1] = 'Member' facility_type[10] = 'Hotel - Motel' facility_type[20] = 'Bed and Breakfast' facility_type[30] = 'Restaurant' facility_type[40] = 'Golf' +facility_type_numb['Member'] = 1 facility_type_numb['HotelMotel'] = 10 facility_type_numb['BedAndBreakfast'] = 20 facility_type_numb['Restaurant'] = 30 @@ -338,6 +343,7 @@ phrase['phrase_test'] = 'test' admin_debug = true admin_debug_verbose = true front_debug = true +front_debug_verbose = true googleMapsApiKey = '' diff --git a/glm-member-db.php b/glm-member-db.php index 43b2afd7..227e7d14 100644 --- a/glm-member-db.php +++ b/glm-member-db.php @@ -47,6 +47,7 @@ require_once('defines.php'); // Get plugin configuration $configData = parse_ini_file(GLM_MEMBERS_PLUGIN_PATH.'/config/plugin.ini', true); $config = $configData['common']; + // Override parameters according to GLM_HOST_ID $hostSection = strtolower(GLM_MEMBER_PLUGIN_HOST).':common'; if (isset($configData[$hostSection])) { diff --git a/misc/databaseScripts/create_database_V0.1.sql b/misc/databaseScripts/create_database_V0.1.sql index 78abc134..e5289cd4 100644 --- a/misc/databaseScripts/create_database_V0.1.sql +++ b/misc/databaseScripts/create_database_V0.1.sql @@ -83,7 +83,7 @@ CREATE TABLE {prefix}amenities ( name TINYTEXT NULL, descr TEXT NULL, short_descr TINYTEXT NULL, - facility_type INT NULL, + ref_type INT NULL, uses_value BOOLEAN NULL, PRIMARY KEY (id), INDEX(name(20)) diff --git a/misc/notes.txt b/misc/notes.txt index 703863df..1595498e 100644 --- a/misc/notes.txt +++ b/misc/notes.txt @@ -6,6 +6,8 @@ Database Updates * Added table settings_general * Added table settings_terms * ALTER TABLE wp_glm_members_images CHANGE pending status tinyint; +* alter table wp_2_glm_members_amenities change column facility_type ref_type integer; + TO-DO diff --git a/models/admin/member/memberInfo.php b/models/admin/member/memberInfo.php index 64840440..3ca0c2fe 100644 --- a/models/admin/member/memberInfo.php +++ b/models/admin/member/memberInfo.php @@ -109,6 +109,10 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo $noActive = false; $categories = false; $haveCategories = false; + $amenities = false; + $haveAmenities = false; + $memberAmenities = false; + $haveMemberAmenities = false; $regions = false; $haveRegions = false; $error = false; @@ -337,7 +341,6 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo ); } - /* * Get a sorted list of categories. * These will be sorted so sub-categories fall under their @@ -350,6 +353,20 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo $haveCategories = true; } + // Get list of Available Member Amenities + require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataAmenities.php'); + $Amenities = new GlmDataAmenities($this->wpdb, $this->config); + $amenities = $Amenities->getList("T.ref_type = ".$this->config['ref_type_numb']['MemberInfo']); + if (is_array($amenities) && count($amenities) > 0) { + $haveAmenities = true; + } + + // Get list of Amenities selected for this Member + $memberAmenities = $Amenities->getAmenityRef($this->config['ref_type_numb']['MemberInfo'], $memberID); + if (is_array($memberAmenities) && count($memberAmenities) > 0) { + $haveMemberAmenities = true; + } + // Lastly, if we have member info, and if this record is active, we need to check for other active records and other things $categoryMemberInfo = false; if ($haveMemberInfo) { @@ -460,6 +477,35 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo // Now get the (possibly updated) category list for this member info record $categoryMemberInfo = $CategoryMemberInfo->getListWithParents($memberInfoID); + + /* + * Get and store any selected amenities + * + * Makes an array of amenities IDs then stores that + */ + $selectedAmenities = array(); + $newAmenity = false; + if (isset($_REQUEST['amenity']) && is_array($_REQUEST['amenity']) && count($_REQUEST['amenity']) > 0) { + + // For each selected amenity + foreach ($_REQUEST['amenity'] as $key) { + + // Make sure key is an integer + $key = intval($key -0); + + // Add to selected amenities list + $selectedAmenities[$key] = $key; + + } // For each amityy being submitted + + // Update the selected amenities for this member information record, returns new list + $memberAmenities = $Amenities->updateAmenityRef($this->config['ref_type_numb']['MemberInfo'], $memberID, $selectedAmenities); + + // Otherwise if this is a submission and there's no categories submitted, so make sure there's none stored + } elseif (isset($_REQUEST['option']) && $_REQUEST['option'] == 'submit') { + $memberAmenities = $Amenities->updateAmenityRef($this->config['ref_type_numb']['MemberInfo'], $memberID); + } + } // Have member info // If we have a member record @@ -495,6 +541,10 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo 'haveCategories' => $haveCategories, 'categories' => $categories, 'categoryMemberInfo' => $categoryMemberInfo, + 'haveAmeenities' => $haveAmenities, + 'amenities' => $amenities, + 'haveMemberAmenities' => $haveMemberAmenities, + 'memberAmenities' => $memberAmenities, 'haveImageGallery' => $haveImageGallery, 'imageGallery' => $imageGallery, 'noActive' => $noActive, diff --git a/models/front/members/list.php b/models/front/members/list.php index 46a59747..0534b102 100644 --- a/models/front/members/list.php +++ b/models/front/members/list.php @@ -164,6 +164,44 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo } + // Get amenity filter data + $amenityData = false; + $amenSelected = ''; + if ($this->config['front-config']['list_search_amenities']) { + + // Get amenity data for search pick list + require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataAmenities.php'); + $Amenities = new GlmDataAmenities($this->wpdb, $this->config); + $amenityData = $Amenities->getList('T.ref_type = '.$this->config['ref_type_numb']['MemberInfo']); + + // Add default flag as false to all entries + foreach ($amenityData as $k=>$v) { + $amenityData[$k]['default'] = false; + } + + // Check if an amenity has been submitted + if (isset($_REQUEST['amenitySearch'])) { + $amenSelected = $_REQUEST['amenitySearch'] - 0; + + // If we have an amenity ID + if ($amenSelected > 0) { + + // Build query to get the member ID's that have the selected amenity + $where .= $whereSep." T.id in ( + SELECT DISTINCT(ref_dest) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref + WHERE amenity = $amenSelected + AND ref_type = ".$this->config['ref_type_numb']['MemberInfo']." + )"; + $whereSep = ' AND '; + + // Set default to true for the selected category + $amenityData[$amenSelected]['default'] = true; + + } // If we have a sane amenity ID + } // If an amenity search has been selected + } // it doing amenity search + // Only look at active member information $where .= $whereSep." T.status = ".$this->config['status_numb']['Active']; @@ -220,6 +258,8 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo 'textSearch' => $textSearch, 'categories' => $categoryData, 'catSelected' => $catSelected, + 'amenities' => $amenityData, + 'amenSelected' => $amenSelected, 'alphaList' => $alphaList, 'alphaSelected' => $alphaSelected ); diff --git a/views/admin/configure/amenities.html b/views/admin/configure/amenities.html index ea5088c0..b1b9a68f 100644 --- a/views/admin/configure/amenities.html +++ b/views/admin/configure/amenities.html @@ -14,11 +14,11 @@ - Facility Type: + Used With: - - {foreach from=$newAmenity.fieldData.facility_type.list item=v} + {foreach from=$newAmenity.fieldData.ref_type.list item=v} {/foreach} @@ -71,11 +71,11 @@ - Facility Type: + Used With: - - {foreach from=$newAmenity.fieldData.facility_type.list item=v} + {foreach from=$newAmenity.fieldData.ref_type.list item=v} {/foreach} @@ -112,7 +112,7 @@ Amenity - Facility Type + Used With Uses Value Description Short Description @@ -129,10 +129,10 @@ {/if} - {$t.name} + {$t.name} - - {$t.facility_type.name} + + {$t.ref_type.name} {$t.uses_value.name} @@ -179,13 +179,13 @@ $('.editAmenity').click( function() { var amenityID = $(this).attr('data-amenityID'); var amenityName = $(this).text(); - var amenityFacilityTypeID = $(this).attr('data-facilityTypeID'); + var amenityRefTypeID = $(this).attr('data-refTypeID'); var amenityUsesValue = parseInt($(this).attr('data-amenityUsesValue')); var amenityDescr = $('#editAmenityDescr_' + amenityID).html(); var amenityShortDescr = $('#editAmenityShortDescr_' + amenityID).html(); $('#editAmenityID').val(amenityID); $('#editAmenityName').val(amenityName.trim()); - $('#editAmenityFacility').val(amenityFacilityTypeID); + $('#editAmenityRef').val(amenityRefTypeID); $('#editAmenityUsesValue').prop('checked', amenityUsesValue); $('#editAmenityDescr').val(amenityDescr.trim()); $('#editAmenityShortDescr').val(amenityShortDescr.trim()); diff --git a/views/admin/member/memberInfo.html b/views/admin/member/memberInfo.html index e7a4aeda..9319bc57 100644 --- a/views/admin/member/memberInfo.html +++ b/views/admin/member/memberInfo.html @@ -272,6 +272,31 @@ {/foreach} + {/if} + + + + + Amenities + + +    Select an amenity to add to box below.
+
+ {if $haveMemberAmenities} + {foreach from=$memberAmenities item=c} +
+ {$c.name} + X + +
+ {/foreach} {/if}
@@ -516,7 +541,7 @@ if (!found) { $('#activeCategories').append('
' - + parentName + catName.trim() + ' X' + + parentName + catName.trim() + ' X' + '
'); } @@ -527,8 +552,7 @@ // Action to de-select a category $('.catDelete').live('click', function() { - var id = $(this).attr('data-id'); - $(".glm-members-category, [data-id='" + id + "']").remove(); + $(this).parent().remove(); }); /* @@ -605,6 +629,46 @@ dialogClass: "glm-dialog-no-close" }); + /* + * Action to select an Amenity + */ + $('#amenitySelect').change( function() { + + // Get the ID, name + var amenValue = $('#amenitySelect').val(); + var amenName = $('#amenitySelect').find(':selected').text(); + + if (amenValue == '') { + return; + } + + // Check if the amenity has already been added + var found = false; + $(".glm-members-amenity").each( function() { + var id = $(this).attr('data-id'); + if (id == amenValue) { + found = true; + } + }); + + // If not found, Add the category + if (!found) { + $('#activeAmenities').append('
' + amenName + + ' X' + + '
'); + } + + // Reset picklist + $('#amenitySelect').val(''); + + }); + + // Action to de-select an Amenity + $('.amenityDelete').live('click', function() { + $(this).parent().remove(); + }); + /* * New City Dialog */ diff --git a/views/front/members/detail.html b/views/front/members/detail.html index edc0e16e..0c1778d4 100644 --- a/views/front/members/detail.html +++ b/views/front/members/detail.html @@ -70,7 +70,7 @@ {if $member.phone && $detail_show_phone}
Phone: {$member.phone}{/if} {if $member.toll_free && $detail_show_tollfree}
Toll Free: {$member.toll_free}{/if} {if $member.url && $detail_show_url}
Web site: {$member.url}{/if} - {if $member.email}
E-Mail Address: {$member.email}{/if} + {if $member.email && $detail_show_email}
E-Mail Address: {$member.email}{/if} {if $member.region.value && $detail_show_region}
Region: {$member.region.name}{/if} @@ -107,9 +107,16 @@

{/if} - {if $detail_show_amenities} + {if $member.amenities && $detail_show_amenities}

- Amenities go here + {$term_member_cap} Amenities +

    + {foreach $member.amenities as $a} +
  • + {$a.name} +
  • + {/foreach} +

{/if} diff --git a/views/front/members/list.html b/views/front/members/list.html index 7e76e0d7..d250ef4b 100644 --- a/views/front/members/list.html +++ b/views/front/members/list.html @@ -31,7 +31,21 @@ {/if} {if $list_search_amenities} -
Amenity search goes here
+ +
+
+ {$term_member_cap} Amenity: + +
+
+ {/if}
@@ -83,11 +97,11 @@ {if $m.city.name}{$m.city.name}{if $m.state.name}, {/if}{/if}{if $m.state.name}{$m.state.name}{/if}{if $m.zip} {$m.zip}{/if} {/if} {if $m.country.name && $list_show_country}
{$m.country.name}{/if} - {/if} {*list_show_address*} + {/if} {if $m.phone && $list_show_phone}
Phone: {$m.phone}{/if} {if $m.toll_free && $list_show_tollfree}
Toll Free: {$m.toll_free}{/if} {if $m.url && $list_show_url}
Web site: {$m.url}{/if} - {if $m.email}
E-Mail Address: {$m.email}{/if} + {if $m.email && $list_show_email}
E-Mail Address: {$m.email}{/if} {if $m.region.value && $list_show_region}

Region: {$m.region.name}{/if} @@ -124,9 +138,16 @@

{/if} - {if $list_show_amenities} + {if $m.amenities && $list_show_amenities}

-

Amenities go here

+ {$term_member_cap} Amenities +
    + {foreach $m.amenities as $A} +
  • + {$A.name} +
  • + {/foreach} +

{/if} @@ -163,7 +184,7 @@ {if $m.phone && $list_map_show_phone}Phone: {$m.phone}
{/if} {if $m.toll_free && $list_map_show_tollfree}Toll Free: {$m.toll_free}
{/if} {if $m.url && $list_map_show_url}Web site: {$m.url}
{/if} - {if $m.email}E-Mail Address: {$m.email}
{/if} + {if $m.email && $list_map_show_email}E-Mail Address: {$m.email}
{/if} {if $m.region.value && $list_map_show_region}

Region: {$m.region.name}

{/if}

{if $m.descr && $list_map_show_description}{$m.descr}
{/if} @@ -191,8 +212,13 @@ {/if} {if $list_map_show_amenities} -
-

Amenities go here

+
+ Amenities: +
    + {foreach $m.amenities as $a} +
  • {$a.name}
  • + {/foreach} +
{/if}
-- 2.17.1