From 0db0a67cdfe310caf59d6367fc464393d6a6c1e0 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Thu, 6 Apr 2017 16:13:29 -0400 Subject: [PATCH] adding models, views and shortcode to add the custon fields data to the member detail page --- classes/data/dataCustomFieldsData.php | 172 ++++++++++++++++++++++++++ models/front/fields/list.php | 108 ++++++++++++++++ setup/frontHooks.php | 8 ++ setup/shortcodes.php | 15 +++ setup/validActions.php | 3 + views/front/fields/list.html | 10 ++ 6 files changed, 316 insertions(+) create mode 100644 classes/data/dataCustomFieldsData.php create mode 100644 models/front/fields/list.php create mode 100644 views/front/fields/list.html diff --git a/classes/data/dataCustomFieldsData.php b/classes/data/dataCustomFieldsData.php new file mode 100644 index 0000000..723e0d3 --- /dev/null +++ b/classes/data/dataCustomFieldsData.php @@ -0,0 +1,172 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataFields.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataEvent class + * + * PHP version 5 + * + * @category Data + * @package GLM Member DB + * @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 GlmDataFieldsCustomFieldsData extends GlmDataAbstract +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Data Table Name + * + * @var $table + * @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; + /** + * MemberInfo DB object + * + * @var $MemberInfo + * @access public + */ + public $MemberInfo; + + /** + * Constructor + * + * @param object $d database connection + * @param array $config Configuration array + * @param bool $limitedEdit Flag to say indicate limited edit requested + * + * @return void + * @access public + */ + public function __construct($wpdb, $config, $limitedEdit = false) + { + + // 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_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_data'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Event ID + 'field_id' => array( + 'field' => 'field_id', + 'type' => 'integer', + 'required' => true, + 'use' => 'a' + ), + + 'ref_dest' => array ( + 'field' => 'ref_dest', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', + 'p_field' => 'name', + 'p_orderby' => 'name', + 'p_blank' => true, + 'use' => 'a' + ), + 'field_data' => array( + 'field' => 'field_data', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + ); + + } + + /* + * 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($r, $a) + { + return $r; + } + +} diff --git a/models/front/fields/list.php b/models/front/fields/list.php new file mode 100644 index 0000000..d0a39ca --- /dev/null +++ b/models/front/fields/list.php @@ -0,0 +1,108 @@ +wpdb, $this->config); + $member_info_id = $member_info->getActiveInfoIdForMember($member_id); + $where = "ref_dest = $member_info_id"; + + $fields_data = new GlmDataFieldsCustomFieldsData($this->wpdb, $this->config); + $field_values = $fields_data->getList($where); + + foreach($field_values as $key=>$value){ + $field_id = $value['field_id']; + $field_value = $value['field_data']; + $sql = "SELECT field_name FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields WHERE id = $field_id;"; + $field_name = $wpdb->get_results($sql); + $field_name = $field_name[0]->field_name; + + if( $field_value ){ + $fields[$field_name] = $field_value; + } else if( $field_value === 'Yes'){ + $slash_price = true; + } + } + } + + // Compile template data + $templateData = array( + 'field_values' => $fields, + 'slash' + ); + error_reporting(E_ALL ^ E_NOTICE); + return array( + 'status' => $status, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'front/fields/list.html', + 'data' => $templateData, + 'settings' => $settings + ); + } + + public function cleanText($text){ + $text = str_replace(' ', ' ', $text); + $text = str_replace('–', '-', $text); + $text = str_replace(''', "'", $text); + $text = str_replace("\n", ' ', $text); + $text = str_replace("\r", '', $text); + return $text; + } +} + diff --git a/setup/frontHooks.php b/setup/frontHooks.php index d8d543d..fbb012c 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -25,3 +25,11 @@ * * *** Also note that parameters will be in the context of the main front controller constructor. *** */ +add_filter('glm-member-db-front-members-detail-descriptionAfter', function($content, $id) { + $eventData = do_shortcode('[glm-members-fields-list member='.$id.', template="detail-sidemenu" order="title"]'); + $content .= $eventData; + return $content; + }, + 10, + 2 +); \ No newline at end of file diff --git a/setup/shortcodes.php b/setup/shortcodes.php index ff31a46..5a07009 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -87,6 +87,21 @@ */ $glmMembersFieldsShortcodes = array( + 'glm-members-fields-list' => array( + 'plugin' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG, + 'menu' => 'fields', + 'action' => 'list', + 'table' => false, + 'attributes' => array( + 'type' => 'all', + 'order' => 'title', + 'member' => false, + 'template' => false, + 'limit' => null, + 'featured' => null, + 'current' => null, + ) + ), ); $glmMembersFieldsShortcodesDescription = ''; diff --git a/setup/validActions.php b/setup/validActions.php index 180782d..4df99c0 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -67,5 +67,8 @@ $glmMembersFieldsAddOnValidActions = array( ), ), 'frontActions' => array( + 'fields' => array( + 'list' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG, + ), ) ); diff --git a/views/front/fields/list.html b/views/front/fields/list.html new file mode 100644 index 0000000..960573e --- /dev/null +++ b/views/front/fields/list.html @@ -0,0 +1,10 @@ +{foreach $field_values as $key=>$value} +
+ {if $value !== 'Yes'} +
{$key}
+ +
{$value}
+ {/if} + +
+{/foreach} -- 2.17.1