From: Steve Sutton Date: Wed, 26 Jun 2019 17:18:17 +0000 (-0400) Subject: Adding Accommodations to the front end member detail page X-Git-Tag: v2.12.4~1^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=7459560d273532e6638cadf279e30c7e5a3ce76a;p=WP-Plugins%2Fglm-member-db.git Adding Accommodations to the front end member detail page Add Rooms/Cabins and Year Round output to new expandable section on member detail pages. --- diff --git a/classes/data/dataAccommodations.php b/classes/data/dataAccommodations.php new file mode 100644 index 00000000..f2a7dade --- /dev/null +++ b/classes/data/dataAccommodations.php @@ -0,0 +1,438 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMemberType.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * EventManagementDataCategories 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 GlmDataAccommodations 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 . 'accommodations'; + + /* + * Table Data Fields + */ + $this->fields = array( + + 'id' => array( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Rooms/Cabins + 'num_rooms' => array( + 'field' => 'num_rooms', + 'type' => 'text', + 'required' => true, + 'unique' => true, + 'use' => 'a' + ), + + // Year Round + 'year_round' => array( + 'field' => 'year_round', + 'type' => 'checkbox', + 'use' => 'a' + ), + + // Short Description + 'ref_dest' => array( + 'field' => 'ref_dest', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info', + 'p_field' => 'member_name', + 'use' => 'a' + ) + + + ); + + } + + /** + * Add a category using supplied parameters + * + * @param string $name Category Name + * @param mixed $parent Existing Parent ID or name of parent to add + * + * @return integer ID of new category or false if failed + * + * @access public + */ + + public function addCategory($name, $parent) { + + $categoryID = false; + $parentID = false; + + // Filter new category name + $name = filter_var($name); + if ($name == false || trim($name) == '') { + return false; + } + + // Determine parent supplied as an ID + + $parentInt = $parent - 0; + if (is_int($parent) && $parentInt > 0) { + + // If it's not positive, then fail + if ($parent <= 0) { + return false; + } + + // Check that parent exists + $sql = " + SELECT COUNT(id) AS count + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories + WHERE id = $parent + ;"; + $test = $this->wpdb->get_row($sql, ARRAY_A); + + // Should be only one entry if the parent category exists + if ($test['count'] != 1) { + return false; + } + + $parentID = $parent; + + // Else check to see if parent was supplied as a name + } elseif ($parent != '') { + + $parent = filter_var($parent); + + // If the name didn't pass the filer then fail + if ($parent == false) { + return false; + } + + // Check if the name already exists + $sql = " + SELECT id + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories + WHERE name = '$parent' + ;"; + $parentCategory = $this->wpdb->get_row($sql, ARRAY_A); + + // If we found the parent ID + if ($parentCategory['id']) { + + // Set that as the parent ID for the new category + $parentID = $parentCategory['id']; + + // Otherwise, try to add the parent category + } else { + + // Add the parent as a new category + $sql = " + INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories + ( name, parent ) + VALUES + ( '".addslashes($parent)."', 0 ) + ;"; + $this->wpdb->query($sql); + $parentID = $this->wpdb->insert_id; + + // Check if it didn't store properly + if (!$parentID) { + return false; + } + + } + + // Otherwise the categroy being added has no parent + } else { + $parentID = 0; + } + + // Check if the new category name/parent already exists + $sql = " + SELECT id + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories + WHERE name = '$name' + AND parent = $parentID + ;"; + $existing = $this->wpdb->get_row($sql, ARRAY_A); + + if ($existing['id']) { + + $categoryID = $existing['id']; + + } else { + + // Try to add the new category + $sql = " + INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories + ( name, parent ) + VALUES + ( '".addslashes($name)."', $parentID ) + ;"; + $this->wpdb->query($sql); + $categoryID = $this->wpdb->insert_id; + + } + + return $categoryID; + + } + + /** + * Get categories list sorted by parent/child then alpha + * + * @param boolean $forEdit If true include list of options for each parent field + * @param boolean $forActiveMembers Return only categories that are referenced in active members + * + * @return array Array of categories + * @access public + */ + + public function getListSortedParentChild($forEdit = true, $forActiveMembers = false, $regionList = false, $countyList = false) { + + $regionWhere = ''; + if ($regionList !== false && trim($regionList) != '') { + $regionWhere = " AND MI.region in ($regionList)"; + } + $countyWhere = ''; + if ( $countyList !== false && trim( $countyList ) != '' ) { + $countyWhere = " AND MI.county in ($countyList) "; + } + $where = ''; + + // If we only want categories for active and visible members - and we want any of their parents (i know it's messy) + if ($forActiveMembers) { + $where = " + ( + T.id in ( + SELECT DISTINCT(C.parent) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C + WHERE C.id in ( + SELECT DISTINCT(CMI.category) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info CMI, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M + WHERE MI.id = CMI.member_info + AND MI.status = 10 + AND M.id = MI.member + $regionWhere + $countyWhere + AND M.access IN ( + ".$this->config['access_numb']['NoAccess'].", + ".$this->config['access_numb']['Moderated'].", + ".$this->config['access_numb']['Full']." + ) + ) + ) + OR + T.id in ( + SELECT DISTINCT(CMI.category) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info CMI, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M + WHERE MI.id = CMI.member_info + AND MI.status = 10 + AND M.id = MI.member + $regionWhere + $countyWhere + AND M.access IN ( + ".$this->config['access_numb']['NoAccess'].", + ".$this->config['access_numb']['Moderated'].", + ".$this->config['access_numb']['Full']." + ) + ) + + ) + "; + } + + // Get a list of all categories (optionally for active members only) + $categories = $this->getList($where); + $categoriesSorted = $this->sortParentChild($categories); + + if (!$forEdit && is_array($categoriesSorted)) { + foreach ( $categoriesSorted as $k => $v ) { + $categoriesSorted[$k]['parent_id'] = $v['parent']['value']; + $categoriesSorted[$k]['parent'] = $v['parent']['name']; + } + } + + return $categoriesSorted; + + } + + /* + * Check other requirements + * + * When deleteing categories, check for references in sub-categories and set them to no parent. + * + */ + function checkOther($r, $a) + { + // Required + parent::checkOther($r, $a); + + // If there's a valid category ID + if (isset($r['id']) && $r['id'] > 0) { + + // Set any parent references with this ID to 0 + $sql = " + UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories + SET parent = 0 + WHERE parent = ".$r['id']." + ;"; + $this->wpdb->query($sql); + + } + + return $r; + } + + /* + * Sort a database result array (from DataAbstract.php) by parent, child relationships + * + * @param array $array Array to be sorted + * @param string $name Name of array element that represents the text to sort on + * @param string $parent Name of the array element that represents the parent ID to sort on + * + * @return array Sorted array + */ + public static function sortParentChild($array, $name = 'name', $parent = 'parent') + { + + if (!is_array($array) || count($array) == 0) { + return false; + } + + // Do a sort by custom function with it included in the call + // This lets me directly use $name and $parent in the sort function + uasort($array, function ($a, $b) use ($name, $parent) { + + // If there's a parent, append the name of this entry to the parent + // The '~~~' simply keeps appended strings from any chance of a match with something else + if ($a[$parent]['value']) { + $aVal = $a[$parent]['name'].'~~~'.$a['name']; + } else { + // Otheriwse just use the name. + $aVal = $a['name'].'~~~'; + } + + // Same for b value + if ($b[$parent]['value']) { + $bVal = $b[$parent]['name'].'~~~'.$b['name']; + } else { + $bVal = $b['name'].'~~~'; + } + + if ($aVal > $bVal) { + return 1; + } + + if ($aVal < $bVal) { + return -1; + } + + return 0; + + }); + + return $array; + } + +} + +?> diff --git a/classes/data/dataMemberInfo.php b/classes/data/dataMemberInfo.php index 6ec1ec1f..80c0e400 100755 --- a/classes/data/dataMemberInfo.php +++ b/classes/data/dataMemberInfo.php @@ -688,6 +688,30 @@ class GlmDataMemberInfo extends GlmDataAbstract } } + // If post processing and Accommodations + if ( $this->doPostProcessing ) { + + $accommodationData = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "accommodations + WHERE ref_dest = %d", + $r['member_pointer'] + ), + ARRAY_A + ); + if ( $accommodationData ) { + $r['accommodations'] = true; + $r['num_rooms'] = $accommodationData['num_rooms']; + $r['year_round'] = $accommodationData['year_round']; + } else { + $r['accommodations'] = false; + $r['num_rooms'] = false; + $r['year_round'] = false; + } + + } + return $r; } diff --git a/models/admin/member/memberInfo.php b/models/admin/member/memberInfo.php index 22b0f48d..3c886ff3 100755 --- a/models/admin/member/memberInfo.php +++ b/models/admin/member/memberInfo.php @@ -324,6 +324,9 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo // Update submitted categories $this->updateCategories(); + // Update submitted accommodations + $this->updateAccommodations(); + // Update submitted amenities $this->updateAmenities(); @@ -560,6 +563,68 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo } + public function updateAccommodations() + { + if ( !$this->config['settings']['profile_accommodation'] ) { + return false; + } + if ( isset( $_REQUEST['accommodations'] ) && $hasAccommodations = filter_var( $_REQUEST['accommodations'], FILTER_VALIDATE_BOOLEAN ) ) { + $accommodationId = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "accommodations + WHERE ref_dest = %d", + $this->memberInfoID + ) + ); + $yearRound = isset( $_REQUEST['year_round'] ) ? filter_var( $_REQUEST['year_round'], FILTER_VALIDATE_BOOLEAN ) : false; + $numRooms = isset( $_REQUEST['num_rooms'] ) ? filter_var( $_REQUEST['num_rooms'], FILTER_VALIDATE_INT ) : false; + if ( $accommodationId ) { + $this->wpdb->update( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'accommodations', + array( + 'ref_type' => $this->config['ref_type_numb']['MemberInfo'], + 'ref_dest' => $this->memberInfoID, + 'num_rooms' => $numRooms, + 'year_round' => $yearRound + ), + array( 'id' => $accommodationId ), + array( + '%d', + '%d', + '%d', + '%s' + ), + array( '%d' ) + ); + } else { + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'accommodations', + array( + 'ref_type' => $this->config['ref_type_numb']['MemberInfo'], + 'ref_dest' => $this->memberInfoID, + 'num_rooms' => $numRooms, + 'year_round' => $yearRound + ), + array( + '%d', + '%d', + '%d', + '%s' + ) + ); + } + } else { + // Delete Accommodation record + $this->wpdb->query( + "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "accommodations + WHERE ref_dest = " . $this->memberInfoID + ); + } + + // echo '
' . print_r( $accommodation, true ) . '
'; + // exit; + } /** * Check for new Cities being submitted diff --git a/views/admin/management/index.html b/views/admin/management/index.html index b0128177..71bef575 100755 --- a/views/admin/management/index.html +++ b/views/admin/management/index.html @@ -578,8 +578,10 @@ Show Live Cam Feed: Autoscroll Offset From Top (height of sticky nav):px Accommodations: + {* Restaurants: Golf: + *} diff --git a/views/admin/member/memberInfo/editAccommodations.html b/views/admin/member/memberInfo/editAccommodations.html new file mode 100644 index 00000000..8229cc11 --- /dev/null +++ b/views/admin/member/memberInfo/editAccommodations.html @@ -0,0 +1,41 @@ +
+

Accommodations Info

+
+
+ +
+
+ +
+
+ +
+

Rooms/Cabins:

+
+ +
+
+ + {* +
+

Reservation URL:

+
+ +
+
+ *} + +
+
+ +
+
+ +
+
diff --git a/views/admin/member/memberInfo/editProfile.html b/views/admin/member/memberInfo/editProfile.html index a0c7bb6d..7f02144f 100644 --- a/views/admin/member/memberInfo/editProfile.html +++ b/views/admin/member/memberInfo/editProfile.html @@ -22,35 +22,20 @@
{if $settings.memb_info_contact} -
- {include file='admin/member/memberInfo/editProfileContact.html'} -
-
+
+ {include file='admin/member/memberInfo/editProfileContact.html'} +
+
{/if}
{include file='admin/member/memberInfo/editProfileDescription.html'}
-
-
-
- - - - - - -
+ {if $settings.profile_accommodation == 1} +
+ {include file='admin/member/memberInfo/editAccommodations.html'}
-
-
- -
-
- -
+
+ {/if}
diff --git a/views/front/members/detail.html b/views/front/members/detail.html index b84b18ba..bf9e5ff7 100755 --- a/views/front/members/detail.html +++ b/views/front/members/detail.html @@ -198,12 +198,28 @@ {apply_filters('glm-member-db-front-members-detail-descriptionAfter', '', $member.id)} {apply_filters('glm-member-db-front-members-detail-imageGalleryBefore', '', $member.id)} + + {if $settings.profile_accommodation && $member.accommodations} +
Accommodations Info
+
+
+
    + {if $member.num_rooms}
  • {$member.num_rooms} Rooms/Cabins
  • {/if} + {if $member.year_round}
  • Open Year Round
  • {/if} +
+
+ +
+ {/if} + + {if $settings.detail_show_imagegallery && $haveImageGallery}
Photos
{apply_filters('glm-member-db-front-members-detail-galleryTop', '', $member.id)} - -
    {foreach $imageGallery as $i}