*/
$this->table = GLM_MEMBERS_PLUGIN_DB_PREFIX . 'settings_general';
+ /**
+ * Grouping of Fields
+ */
+ $this->groups = array(
+ 'misc' => array(
+ 'name' => 'misc',
+ 'title' => 'Misc. Settings',
+ 'fields' => array(
+ 'admin_debug' => array(
+ 'name' => 'admin_debug',
+ 'prompt' => 'Admin Debug Information',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'admin_debug_verbose' => array(
+ 'name' => 'admin_debug_verbose',
+ 'prompt' => 'Admin Debug Verbose',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'front_debug' => array(
+ 'name' => 'front_debug',
+ 'prompt' => 'Admin Debug Information',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'front_debug_verbose' => array(
+ 'name' => 'front_debug_verbose',
+ 'prompt' => 'Admin Debug Verbose',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'enable_members' => array(
+ 'name' => 'enable_members',
+ 'prompt' => 'Enable Members',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'enable_contact_edit_only' => array(
+ 'name' => 'enable_contact_edit_only',
+ 'prompt' => 'Enable Contact Edits Only',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'enable_member_reports' => array(
+ 'name' => 'enable_member_reports',
+ 'prompt' => 'Enable Member Reports',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'enable_caching' => array(
+ 'name' => 'enable_caching',
+ 'prompt' => 'Enable Caching',
+ 'message' => '',
+ 'option' => ''
+ ),
+
+ 'enable_counties' => array(
+ 'name' => 'enable_counties',
+ 'prompt' => 'Enable Counties',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'enable_multiple_profiles' => array(
+ 'name' => 'enable_multiple_profiles',
+ 'prompt' => 'Enable Multiple Active Member Profile',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'enable_single_profile' => array(
+ 'name' => 'enable_single_profile',
+ 'prompt' => 'Enable Single Member Profile (members only)',
+ 'message' => '',
+ 'option' => ''
+ ),
+
+
+ 'memb_info_location' => array(
+ 'name' => 'memb_info_location',
+ 'prompt' => 'Address & Location',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'memb_info_contact' => array(
+ 'name' => 'memb_info_contact',
+ 'prompt' => 'Contact Info',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'memb_info_categories' => array(
+ 'name' => 'memb_info_categories',
+ 'prompt' => 'Categories & Amenities',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'memb_info_images' => array(
+ 'name' => 'memb_info_images',
+ 'prompt' => 'Images',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'memb_info_files' => array(
+ 'name' => 'memb_info_files',
+ 'prompt' => 'Files',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'memb_info_video' => array(
+ 'name' => 'memb_info_video',
+ 'prompt' => 'Video',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'memb_info_cam' => array(
+ 'name' => 'memb_info_cam',
+ 'prompt' => 'Live Cam',
+ 'message' => '',
+ 'option' => ''
+ ),
+
+
+ 'selected_map_interface' => array(
+ 'name' => 'selected_map_interface',
+ 'prompt' => 'Selected Map Interface',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'leaflet_tile_server' => array(
+ 'name' => 'leaflet_tile_server',
+ 'prompt' => 'Leaflet Tile Server',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'leaflet_tile_server_key' => array(
+ 'name' => 'leaflet_tile_server_key',
+ 'prompt' => 'Leaflet Tile Server Key',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'google_maps_api_key' => array(
+ 'name' => 'google_maps_api_key',
+ 'prompt' => 'Google Maps API Key',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'maps_default_zoom' => array(
+ 'name' => 'maps_default_zoom',
+ 'prompt' => 'Maps Default Zoom',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'maps_default_lat' => array(
+ 'name' => 'maps_default_lat',
+ 'prompt' => 'Lat',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'maps_default_lon' => array(
+ 'name' => 'maps_default_lon',
+ 'prompt' => 'Lon',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'file_library' => array(
+ 'name' => 'file_library',
+ 'prompt' => 'Enable File Library',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'time_zone' => array(
+ 'name' => 'time_zone',
+ 'prompt' => 'Time Zone',
+ 'message' => '',
+ 'option' => ''
+ ),
+
+ 'canonical_member_page' => array(
+ 'name' => 'canonical_member_page',
+ 'prompt' => 'Member Detail Page Permalink Name',
+ 'message' => '',
+ 'option' => ''
+ ),
+ 'phone_format' => array(
+ 'name' => 'phone_format',
+ 'prompt' => 'Phone # Formatting',
+ 'message' => '',
+ 'option' => ''
+ ),
+
+ 'default_state' => array(
+ 'name' => 'default_state',
+ 'prompt' => 'Default State',
+ 'message' => '',
+ 'option' => ''
+ ),
+
+ )
+ ),
+ );
+
/*
* Table Data Fields
*/
/**
* Groups Array
*
- * Used for Grouping the fields.
+ * Used to setup the Grouping of the fields.
*/
public $groups = array();
+ /**
+ * Group Select
+ *
+ * To select the groups of fields to use.
+ */
+ public $groupSelect = false;
+
+ /**
+ * Primary key for the Table.
+ */
+ public $primaryKey = 'id';
/*
* Field processing for various types of fields
*/
private function buildFieldsList($op = 'l', $options = false, $defaults = false)
{
+ // $this->selectGroupFields();
$this->fieldData = array();
$this->select = '';
$sep = ''; // Used as separator for $select list
}
+ // $this->restoreFields();
return;
}
public function getEntry($id, $idfield = 'id', $where = 'true', $fieldVals = false)
{
+ $this->selectGroupFields();
// If there's an ID supplied, add that to the query
$idWhere = '';
if ($id-0 > 0) {
// Process individual fields
$detail = $this->processOutputData($detail, 'g', $fieldVals);
+ $this->restoreFields();
return $detail;
}
}
+ public function selectGroupFields()
+ {
+ if ( $this->groupSelect && is_array( $this->groupSelect ) && !empty( $this->groupSelect ) ) {
+ $this->saveFields = $this->fields;
+ $this->fields = false;
+
+ // Add the primary key
+ $this->fields[] = $this->saveFields[$this->primaryKey];
+
+ foreach ( $this->groupSelect as $groupSelected ) {
+ // Find the group
+ if ( isset( $this->groups[$groupSelected] ) && $this->groups[$groupSelected] ) {
+ trigger_error( print_r( $this->groups[$groupSelected], true ), E_USER_NOTICE );
+ if ( isset( $this->groups[$groupSelected]['fields'] ) && is_array( $this->groups[$groupSelected]['fields'] ) ) {
+ foreach ( $this->groups[$groupSelected]['fields'] as $fieldKey => $field ) {
+ trigger_error( print_r( $field, true ), E_USER_NOTICE );
+ $this->fields[] = $this->saveFields[$field['name']];
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public function restoreFields()
+ {
+ $this->fields = $this->saveFields;
+ $this->saveFields = false;
+ }
}
-?>
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members Misc Routes For API
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release adminHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+/**
+ * Require the Contact Data Class.
+ */
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/settings/dataSettingsGeneral.php';
+
+/**
+ * Documentation for Wordpress API and adding custom endpoints.
+ * https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
+ */
+class glmAssoc_Controller_Contacts
+{
+ /**
+ * __construct
+ *
+ * Class Constructor
+ *
+ * @param $wpdb Wordpress wpdb Database Object
+ * @param $config GlmAssociate config array
+ */
+ public function __construct( $wpdb, $config )
+ {
+ $this->namespace = '/glm/v1/';
+ $this->resource_name = 'settings';
+
+ // Setup wpdb and config
+ $this->wpdb = $wpdb;
+ $this->config = $config;
+ }
+
+ /**
+ * register_routes
+ *
+ * Registers the routes for this class.
+ *
+ * @return void
+ */
+ public function register_routes()
+ {
+ register_rest_route(
+ 'glm/v1', // namespace
+ 'settings', // route
+ array( // array of arrays for multiple methods. Add more arrays for different endpoints.
+ array( // endpoint for getting settings
+ 'methods' => WP_REST_Server::READABLE,
+ 'callback' => function( $request ) {
+ // Callback function can be a lot shorter.
+ // You could just create a new model to get the results in an array
+ // and use return rest_ensure_response( $data );
+ $settingsData = new GlmDataSettingsGeneral( $this->wpdb, $this->config );
+
+ $settingsData->groupSelect = array( 'misc' );
+ // $settingsData->selectGroupFields();
+ $settings = $settingsData->getEntry( 1 );
+ // $settingsData->restoreFields();
+
+ return rest_ensure_response( $settings );
+ },
+ 'permission_callback' => function(){ // can require capability for this rest endpoint.
+ if ( ! current_user_can( 'glm_members_members' ) ) {
+ return new WP_Error( 'rest_forbidden', esc_html__( 'You cannot view the post resource.' ), array( 'status' => $this->authorization_status_code() ) );
+ }
+ return true;
+ },
+ )
+ )
+ );
+ }
+
+ public function authorization_status_code()
+ {
+ $status = 401;
+
+ if ( is_user_logged_in() ) {
+ $status = 403;
+ }
+
+ return $status;
+ }
+
+}
+
+/**
+ * Create Action for the REST API Route.
+ */
+add_action(
+ 'rest_api_init',
+ function(){
+ $controller = new glmAssoc_Controller_Contacts( $this->wpdb, $this->config );
+ $controller->register_routes();
+ }
+);