* Save the data for the Member Info custom fields.
* Uses the $_REQUEST variable glm_custom_field.
*
- * @param mixed $memberId Id for the member info record
+ * @param mixed $entityID Id for the member info record
*
* @access public
* @return void
*/
-function customFieldsSaveFields( $memberId )
-{
+function customFieldsSaveFields( $entityID )
+{
global $wpdb;
+ echo $entityID;
// If no data for custom field then return
if ( !isset( $_REQUEST['glm_custom_field'] ) ) {
return false;
}
//echo "Trying to save entity of type $uid";
-
+ print_r(customFieldsGetFields($entityID));
// See if this memberInfo has current field data
- $currentCustomFields = customFieldsGetFields( $memberId );
+ $currentCustomFields = customFieldsGetFieldData( $entityID );
// Insert the custom field record
$fieldDataFormat = array(
'%d',
// Loop through the glm_custom_field array
foreach ( $_REQUEST['glm_custom_field'] as $fieldId => $fieldValue ) {
$fieldData =array(
- 'ref_dest' => $memberId,
+ 'entity_id' => $entityID,
'field_id' => $fieldId,
'field_data' => wp_kses_post(stripslashes($fieldValue))
);
GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data",
$fieldData,
array(
- 'ref_dest' => $memberId,
+ 'entity_id' => $entityID,
'field_id' => $fieldId
),
$fieldDataFormat,
if ( isset( $customFields ) ) {
foreach ( $customFields as $fieldId => $fieldData ) {
$fieldData =array(
- 'ref_dest' => $newId,
+ 'entity_id' => $newId,
'field_id' => $fieldId,
'field_data' => $fieldData
);
* Pull the member info custom field data.
* This will be used more for admin side.
*
- * @param mixed $memberId Id for the member info record
+ * @param mixed $entityID Id for the member info record
*
* @access public
* @return void
*/
-function customFieldsGetFields( $memberId )
+function customFieldsGetFieldData( $entityID )
{
global $wpdb;
- if ( !$memberId ) {
+ if ( !$entityID ) {
return false;
}
$data = array();
$sql = "
SELECT *
FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data
- WHERE ref_dest = %d";
- $fieldData = $wpdb->get_results( $wpdb->prepare( $sql, $memberId ), ARRAY_A );
+ WHERE entity_id = %d";
+ $fieldData = $wpdb->get_results( $wpdb->prepare( $sql, $entityID ), ARRAY_A );
if ( $fieldData ) {
foreach ( $fieldData as $key => $val ) {
$data[$val['field_id']] = $val['field_data'];
return false;
}
}
+/**
+ * customFieldsGetFields
+ * Pull the member info custom field data.
+ * This will be used more for admin side.
+ *
+ * @param mixed $entityID Id for the member info record
+ *
+ * @access public
+ * @return void
+ */
+function customFieldsGetFields( $entityID, $where = ' AND true ' )
+{
+ global $wpdb;
+ if ( !$entityID) {
+ return false;
+ }
+ $data = array();
+ $sql = "
+ SELECT *
+ FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+ WHERE id IN (select field_id from ".GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data WHERE entity_id = %d)" . $where;
+ $fieldData = $wpdb->get_results( $wpdb->prepare( $sql, $entityID ), ARRAY_A );
+}
'use' => 'a'
),
- 'ref_dest' => array (
- 'field' => 'ref_dest',
- 'type' => 'pointer',
- 'p_table' => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info',
- 'p_field' => 'member_name',
- 'p_orderby' => 'member_name',
- 'p_blank' => true,
- 'use' => 'a'
- ),
'field_data' => array(
'field' => 'field_data',
'type' => 'text',
if (isset($_REQUEST['id'])) {
$id = $_REQUEST['id']-0;
}
- $memberId = 0;
+ $entityID = 0;
if (isset($actionData)) {
- $memberId = $actionData['memberId'];
+ $entityID = $actionData['entityID'];
$uid = $actionData['uid'];
}
}
require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
- $customFieldsData = customFieldsGetFields( $memberId );
-
+ $customFieldsData = customFieldsGetFieldData( $entityID );
+
// Compile template data
$template_data = array(
'prefix' => 'glm_custom_field',
$member_name = $member_info['member_name'];
$member_name = urlencode($member_name);
- $where = "ref_dest = $member_info_id";
+ $where = "entity_id = $member_info_id";
$fields_data = new GlmDataFieldsCustomFieldsData($this->wpdb, $this->config);
$field_values = $fields_data->getList($where);
if ( isset( $actionData['request']['member'] ) ) {
$member_info_id = $actionData['request']['member'] - 0;
- $where = "ref_dest = $member_info_id";
+ $where = "entity_id = $member_info_id";
$fields_data = new GlmDataFieldsCustomFieldsData($this->wpdb, $this->config);
$field_values = $fields_data->getList($where);
add_filter( 'glm-members-custom-fields-form', function( $content, $uid, $id ){
unset( $_REQUEST['glm_action'] );
// echo "CONTENT: " . $content . " UID: " . $uid . " ID: " . $id . '<br>';
- $content = $this->controller( 'entity', 'fields', array( 'uid' => $uid, 'memberId' => $id ), true);
+ $content = $this->controller( 'entity', 'fields', array( 'uid' => $uid, 'entityID' => $id ), true);
return $content;
}, 10, 3 );
/**
return $out;
},10,2);
-add_filter( 'glm-member-db-custom-fields-tab', function( $content, $memberId = '' ){
+add_filter( 'glm-member-db-custom-fields-tab', function( $content, $entityID = '' ){
unset( $_REQUEST['glm_action'] );
- $content = $this->controller( 'fields', 'fields', $memberId );
+ $content = $this->controller( 'fields', 'fields', $entityID );
return $content;
},1,2);
add_filter( 'glm-member-db-custom-filter-search', function ( $content ) {
$queryParts[] = " T.id IN (
SELECT mi.member
FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info mi, " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data cfd
- WHERE cfd.ref_dest = mi.id
+ WHERE cfd.entity_id = mi.id
AND cfd.field_data like '%" . esc_sql( $fieldValue ) . "%'
AND cfd.field_id = (SELECT id
FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
$queryParts[] = " T.id IN (
SELECT mi.member
FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info mi, " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data cfd
- WHERE cfd.ref_dest = mi.id
+ WHERE cfd.entity_id = mi.id
AND cfd.field_data = 'Yes'
AND cfd.field_id = (SELECT id
FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
}
return $queryParts;
});
-add_filter('glm-member-db-save-custom-fields', function( $entityId ) {
+add_filter('glm-member-db-save-custom-fields', function( $entityID ) {
require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
// this will save the member data
//echo "uid = $uid";
- customFieldsSaveFields( $entityId );
+ customFieldsSaveFields( $entityID );
return true;
},
10,
);
add_action(
'glm-member-db-clone-custom-fields',
- function( $memberInfoId, $newId ){
+ function( $entityID, $newId ){
require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
// this will clone the custom fields data
- customFieldsCloneFields( $memberInfoId, $newId );
+ customFieldsCloneFields( $entityID, $newId );
},
1,
2
field_order SMALLINT NOT NULL DEFAULT 0, -- Order for Field
admin_search BOOLEAN NOT NULL DEFAULT '0', -- If the field is added to member list filters.
required BOOLEAN NOT NULL DEFAULT '0', -- If the field is required.
- uid TINYTEXT NOT NULL DEFAULT '', -- id for the series of custom fields associated with an entity
- entity_id INT NULL, -- id for the specific field associated with an entity
+ uid varchar(255) NOT NULL DEFAULT '', -- id for the series of custom fields associated with an entity
+ entity_id INT NULL, -- id for the specific field associated with an entity
PRIMARY KEY (id),
INDEX(field_name(20))
);
-- Data Table
CREATE TABLE {prefix}custom_field_data (
id INT NOT NULL AUTO_INCREMENT,
- field_id INT NOT NULL DEFAULT 0, -- Field Id
- ref_dest INT NOT NULL DEFAULT 0, -- Member Info Id
+ field_id INT NOT NULL DEFAULT 0, -- Field Id -- Member Info Id
field_data TEXT NOT NULL DEFAULT '', -- Data for the field
entity_id INT NOT NULL DEFAULT 0, -- id for the specific field associated with an entity
PRIMARY KEY (id),
INDEX(field_id),
- INDEX(ref_dest)
+ INDEX(entity_id)
);
----
-ALTER TABLE {prefix}custom_fields ADD COLUMN uid TINYTEXT NOT NULL DEFAULT 'glm-member-db';
+ALTER TABLE {prefix}custom_fields ADD COLUMN uid varchar(255) NOT NULL DEFAULT 'glm-member-db';
----
-ALTER TABLE {prefix}custom_field_data ADD COLUMN entity_id INT NOT NULL DEFAULT 0;
+ALTER TABLE {prefix}custom_field_data CHANGE `ref_dest` `entity_id` INT NOT NULL;
----
ALTER TABLE {prefix}custom_fields ADD COLUMN entity_id INT NULL;
+
+----
+
+CREATE INDEX entity_id ON {prefix}custom_field_data(entity_id);
if ( isset( $_REQUEST[$field_name] ) && filter_var( $_REQUEST[$field_name], FILTER_SANITIZE_STRING ) ) {
$textSearch = $this->wpdb->esc_like( $_REQUEST[$field_name] );
$queryParts[] = " T.id IN (
- SELECT ref_dest
+ SELECT entity_id
FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data
WHERE field_data like '%" . $textSearch . "%'
AND field_id = (SELECT id
$field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
if ( isset( $_REQUEST[$field_name] ) && filter_var( $_REQUEST[$field_name], FILTER_VALIDATE_BOOLEAN ) ) {
$queryParts[] = " T.id IN (
- SELECT ref_dest
+ SELECT entity_id
FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data
WHERE field_data = 'Yes'
AND field_id = (SELECT id
global $wpdb;
$query = "SELECT D.field_data, F.field_type FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data D, ".GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX."custom_fields F "
- . "WHERE D.ref_dest = $id "
+ . "WHERE D.entity_id = $id "
. "AND D.field_id IN (SELECT id FROM ".GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX."custom_fields WHERE field_name LIKE '$attribute' ) "
. "AND F.field_name LIKE '$attribute'";
{foreach $customFields as $field}
<div class="glm-small-12 glm-large-2 glm-columns glm-custom-field-label">{$field.field_name}</div>
<div class="glm-small-12 glm-large-9 glm-columns glm-custom-field">
+ <input type="hidden" name="custom-required" value="{$field.required.value}">
{if $field.field_type.name == 'text'}
+
<input type="text" name="{$prefix}[{$field.id}]" value="{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape}{/if}">
{elseif $field.field_type.name == 'textarea'}
{php}
(text or checkbox only)
</td>
</tr>
+ <tr>
+ <th>Required?</th>
+ <td>
+ <input type="hidden" name="required" value="0" />
+ <input type="checkbox" id="editRequired" name="required" value="1" />
+ </td>
+ </tr>
</table>
<p><span class="glm-required">*</span> Required</p>
<a id="editFieldCancel" class="button button-primary glm-right">Cancel</a>
<td>{$t.id}</td>
<td>
<div>
- <a class="editField" data-fieldID="{$t.id}" data-fieldType="{$t.field_type.name|escape:'html'}" data-adminSearch="{$t.admin_search.value}">{$t.field_name}</a>
+ <a class="editField" data-fieldID="{$t.id}" data-fieldType="{$t.field_type.name|escape:'html'}" data-adminSearch="{$t.admin_search.value}" data-required="{$t.required.value}">{$t.field_name}</a>
</div>
</td>
<td id="editFieldType_{$t.id}">
var fieldName = $(this).text();
var fieldType = $(this).attr('data-fieldType');
var adminSearch = $(this).attr('data-adminSearch');
+ var required = $(this).attr('data-required');
+
$('#editFieldID').val(fieldID);
$('#editFieldName').val(fieldName.trim());
$('#editFieldType').val(fieldType);
- console.log(adminSearch);
+
if (adminSearch === '1') {
console.log('setting the checked to true');
$('#editAdminSearch').prop('checked', true);
console.log('setting the checked to false');
$('#editAdminSearch').prop('checked', false);
}
+ // check required fields
+ if (required === '1') {
+ $('#editRequired').prop('checked', true);
+ } else {
+ console.log('setting the checked to false');
+ $('#editRequired').prop('checked', false);
+ }
$("#editFieldDialog").dialog("open");
});
$('#editFieldCancel').click( function() {