Adding Accommodations to the front end member detail page
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 26 Jun 2019 17:18:17 +0000 (13:18 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 26 Jun 2019 17:18:17 +0000 (13:18 -0400)
Add Rooms/Cabins and Year Round output to new expandable section on
member detail pages.

classes/data/dataAccommodations.php [new file with mode: 0644]
classes/data/dataMemberInfo.php
models/admin/member/memberInfo.php
views/admin/management/index.html
views/admin/member/memberInfo/editAccommodations.html [new file with mode: 0644]
views/admin/member/memberInfo/editProfile.html
views/front/members/detail.html

diff --git a/classes/data/dataAccommodations.php b/classes/data/dataAccommodations.php
new file mode 100644 (file)
index 0000000..f2a7dad
--- /dev/null
@@ -0,0 +1,438 @@
+<?php
+
+/**
+ * GLM Member-DB WordPress Plugin
+ * Categories data class
+ *
+ * PHP version 5.3
+ *
+ * @category Data
+ * @package  GLM Member-DB
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 <cscott@gaslightmedia.com>
+ * @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;
+    }
+
+}
+
+?>
index 6ec1ec1..80c0e40 100755 (executable)
@@ -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;
     }
 
index 22b0f48..3c886ff 100755 (executable)
@@ -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 '<pre>' . print_r( $accommodation, true ) . '</pre>';
+        // exit;
+    }
 
     /**
      * Check for new Cities being submitted
index b012817..71bef57 100755 (executable)
                         <tr><th>Show Live Cam Feed:</th><td><input type="checkbox" name="detail_show_live_cam"{if $genSettings.fieldData.detail_show_live_cam.value} checked="checked"{/if}></td></tr>
                         <tr><th>Autoscroll Offset From Top (height of sticky nav):</th><td><input type="text" pattern="[0-9]{literal}{0,4}{/literal}" name="detail_top_offset_autoscroll" value="{$genSettings.fieldData.detail_top_offset_autoscroll}" class="glm-form-numeric-input" placeholder="0" maxlength="4">px</td></tr>
                         <tr><th>Accommodations:</th><td><input type="checkbox" name="profile_accommodation"{if $genSettings.fieldData.profile_accommodation.value} checked="checked"{/if}></td></tr>
+                        {*
                         <tr><th>Restaurants:</th><td><input type="checkbox" name="profile_restaurant"{if $genSettings.fieldData.profile_restaurant.value} checked="checked"{/if}></td></tr>
                         <tr><th>Golf:</th><td><input type="checkbox" name="profile_golf"{if $genSettings.fieldData.profile_golf.value} checked="checked"{/if}></td></tr>
+                        *}
                     </table>
                 </td>
                 <td>
diff --git a/views/admin/member/memberInfo/editAccommodations.html b/views/admin/member/memberInfo/editAccommodations.html
new file mode 100644 (file)
index 0000000..8229cc1
--- /dev/null
@@ -0,0 +1,41 @@
+<br>
+<h2>Accommodations Info</h2>
+<div class="glm-admin-table glm-admin-table-inner-wrapper">
+    <div class="glm-admin-table glm-admin-table-inner">
+
+        <div class="glm-row">
+            <div>
+                <label>
+                    <input type="checkbox" name="accommodations"{if $memberInfo.fieldData.accommodations} checked{/if}>
+                    Accommodations enabled
+                </label>
+            </div>
+        </div>
+
+        <div class="glm-row">
+            <h4>Rooms/Cabins:</h4>
+            <div>
+                <input type="text" name="num_rooms" value="{$memberInfo.fieldData.num_rooms}" class="glm-form-text-input-short">
+            </div>
+        </div>
+
+        {*
+        <div class="glm-row">
+            <h4>Reservation URL:</h4>
+            <div>
+                <input type="text" name="reservation_url" value="" class="glm-form-text-input-short">
+            </div>
+        </div>
+        *}
+
+        <div class="glm-row">
+            <div>
+                <label>
+                    <input type="checkbox" name="year_round"{if $memberInfo.fieldData.year_round} checked{/if}>
+                    Year Round
+                </label>
+            </div>
+        </div>
+
+    </div>
+</div>
index a0c7bb6..7f02144 100644 (file)
                 <div class="glm-small-12 glm-medium-6 glm-left">
                     <div class="glm-row">
                         {if $settings.memb_info_contact}
-                        <div class="glm-small-12">
-                            {include file='admin/member/memberInfo/editProfileContact.html'}
-                        </div>
-                        <br>
+                            <div class="glm-small-12">
+                                {include file='admin/member/memberInfo/editProfileContact.html'}
+                            </div>
+                            <br>
                         {/if}
                         <div class="glm-small-12">
                             {include file='admin/member/memberInfo/editProfileDescription.html'}
                         </div>
-                        <div class="glm-small-12">
-                            <div class="glm-admin-table glm-admin-table-inner">
-                                <div class="glm-row">
-                                    <label><input type="checkbox" name="accommodations" />Accommodations</label>
-                                    <label for="">Rooms/Cabins</label>
-                                    <input type="text" name="num_rooms" />
-                                    <label for="">Reservation URL</label>
-                                    <input type="text" name="reservation_url">
-                                    <label>
-                                        <input type="checkbox" name="reservation_url">
-                                        Year Round
-                                    </label>
-                                </div>
+                        {if $settings.profile_accommodation == 1}
+                            <div class="glm-small-12">
+                                {include file='admin/member/memberInfo/editAccommodations.html'}
                             </div>
-                        </div>
-                        <div class="glm-small-12">
-                            <label><input type="checkbox" name="restaurants" />Restaurants</label>
-                        </div>
-                        <div class="glm-small-12">
-                            <label><input type="checkbox" name="golf" />Golf</label>
-                        </div>
+                            <br>
+                        {/if}
                     </div>
                 </div>
             </div>
index b84b18b..bf9e5ff 100755 (executable)
                     </div>
                     {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}
+                        <div id="glm-member-detail-accommodations-toggle" class="glm-member-detail-content-toggle">Accommodations Info</div>
+                        <div id="glm-member-detail-accommodations-container" class="glm-member-detail-content-data">
+                            <div id="glm-member-detail-accommodations" >
+                                <ul>
+                                    {if $member.num_rooms}<li>{$member.num_rooms} Rooms/Cabins</li>{/if}
+                                    {if $member.year_round}<li>Open Year Round</li>{/if}
+                                </ul>
+                            </div>
+                            <div class="glm-member-detail-sub-data-links glma-row">
+                                <a class="glm-member-detail-content-toggle glma-columns glma-small-6">Collapse</a>
+                                <a class="glm-member-detail-link-to-top glma-columns glma-small-6">Back to top</a>
+                            </div>
+                        </div>
+                    {/if}
+
+
                     {if $settings.detail_show_imagegallery && $haveImageGallery}
                     <div id="glm-member-detail-images-toggle" class="glm-member-detail-content-toggle">Photos</div>
                     <div id="glm-member-detail-images-container" class="glm-member-detail-content-data">
                         {apply_filters('glm-member-db-front-members-detail-galleryTop', '', $member.id)}
-<!--                        <h2>Photo Gallery</h2>-->
-
                             <ul class="glma-row">
                         {foreach $imageGallery as $i}
                                 <li class="glma-small-12 glma-medium-6 glma-large-4 glma-columns">