From cb32bb9e6fc2ab82d5d4fec87aaab3b820e1770c Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 30 Mar 2017 16:42:22 -0400 Subject: [PATCH] Add Counties Adding Counties table. Adding Counties into Settings. Adding County to member info record. --- classes/data/dataCounties.php | 191 ++++++++++++++++++++++++++++ classes/data/dataMemberInfo.php | 13 ++ models/admin/settings/counties.php | 195 +++++++++++++++++++++++++++++ setup/validActions.php | 1 + views/admin/settings/counties.html | 174 +++++++++++++++++++++++++ views/admin/settings/header.html | 1 + 6 files changed, 575 insertions(+) create mode 100644 classes/data/dataCounties.php create mode 100644 models/admin/settings/counties.php create mode 100644 views/admin/settings/counties.html diff --git a/classes/data/dataCounties.php b/classes/data/dataCounties.php new file mode 100644 index 00000000..767b81f6 --- /dev/null +++ b/classes/data/dataCounties.php @@ -0,0 +1,191 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMemberType.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * EventManagementDataCounties 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 GlmDataCounties 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 . 'counties'; + + /* + * Table Data Fields + */ + $this->fields = array( + + 'id' => array( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Name + 'name' => array( + 'field' => 'name', + 'type' => 'text', + 'required' => true, + 'unique' => true, + 'use' => 'a' + ), + + // Description + 'descr' => array( + 'field' => 'descr', + 'type' => 'text', + 'use' => 'a' + ), + + // Short Description + 'short_descr' => array( + 'field' => 'short_descr', + 'type' => 'text', + 'use' => 'a' + ) + + + ); + + if (is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + glmMembersAdmin::addNotice($this->fields, 'DataBlock', 'Table Fields: '.$this->table); + } + + } + + + /** + * Get counties list sorted by alpha + * + * @param boolean $forActiveMembers Return only counties that are referenced in active members + * + * @return array Array of categories + * @access public + */ + + public function getListForSearch($forActiveMembers = false) { + + $where = ''; + + // If we only want counties for active and visible members + if ($forActiveMembers) { + $where = "T.id in ( + SELECT DISTINCT(MI.county) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M + WHERE MI.status = ".$this->config['status_numb']['Active']." + AND M.id = MI.member + AND M.access IN ( + ".$this->config['access_numb']['NoAccess'].", + ".$this->config['access_numb']['Moderated'].", + ".$this->config['access_numb']['Full']." + ) + ) + "; + } + + // Get a list of all counties (optionally for active members only) + $counties = $this->getList($where); + + return $counties; + + } + + +} + +?> diff --git a/classes/data/dataMemberInfo.php b/classes/data/dataMemberInfo.php index 339e0a41..1d1220fe 100644 --- a/classes/data/dataMemberInfo.php +++ b/classes/data/dataMemberInfo.php @@ -299,6 +299,18 @@ class GlmDataMemberInfo extends GlmDataAbstract 'use' => 'a' ), + // County + 'county' => array( + 'field' => 'county', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'counties', + 'p_field' => 'name', + 'p_orderby' => 'name', + 'p_blank' => true, + // 'force_list' => true, + 'use' => 'a' + ), + // Phone 'phone' => array( 'field' => 'phone', @@ -770,6 +782,7 @@ class GlmDataMemberInfo extends GlmDataAbstract 'email' => $f['email'], 'url' => $f['url'], 'region' => $f['region'], + 'county' => $f['county'], 'cc_type' => $f['cc_type'], 'logo' => $f['logo'], 'descr' => $f['descr'], diff --git a/models/admin/settings/counties.php b/models/admin/settings/counties.php new file mode 100644 index 00000000..a13267e6 --- /dev/null +++ b/models/admin/settings/counties.php @@ -0,0 +1,195 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load Member Types data abstract +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCounties.php'; + +/* + * This class performs the work for the default action of the "Members" menu + * option, which is to display the members dashboard. + * + */ +class GlmMembersAdmin_settings_counties extends GlmDataCounties +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for members data class + parent::__construct(false, false); + + } + + /* + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + */ + public function modelAction ($actionData = false) + { + + $success = true; + $haveCounties = false; + $counties = false; + $error = false; + $enable_members = $this->config['settings']['enable_members']; + + // Check for county id + $id = 0; + if (isset($_REQUEST['id'])) { + $id = $_REQUEST['id']-0; + } + + // If there's an action option + if (isset($_REQUEST['option'])) { + + switch($_REQUEST['option']) { + + case 'addNew': + $this->insertEntry(); + break; + + case 'update': + if ($id > 0) { + $this->updateEntry($id); + } + break; + + case 'delete': + if ($id > 0) { + $this->deleteEntry($id, true); + } + break; + + } + + } + + // Get a current list of members + $counties = $this->getList('', 'name'); + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + glmMembersAdmin::addNotice($counties, 'DataBlock', 'County Data'); + } + + // If we have list entries - even if it's an empty list + $success = true; + $haveCounties = false; + if ($counties !== false) { + + $success = true; + + // If we have any entries + if (count($counties) > 0) { + $haveCounties = true; + } + } + + // If we had a fatal error, redirect to the error page + if ($error) { + return array( + 'status' => $success, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => false + ); + } + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + glmMembersAdmin::addNotice($counties, 'DataBlock', 'Counties Data'); + } + + // Compile template data + $templateData = array( + 'enable_members' => $enable_members, + 'haveCounties' => $haveCounties, + 'counties' => $counties + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/settings/counties.html', + 'data' => $templateData + ); + + } + + +} + +?> diff --git a/setup/validActions.php b/setup/validActions.php index 4ba560d0..eab646d4 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -65,6 +65,7 @@ $glmMembersValidActions = array( 'categories' => 'glm-member-db', 'cities' => 'glm-member-db', 'regions' => 'glm-member-db', + 'counties' => 'glm-member-db', 'amenities' => 'glm-member-db', ), 'management' => array( diff --git a/views/admin/settings/counties.html b/views/admin/settings/counties.html new file mode 100644 index 00000000..5222b273 --- /dev/null +++ b/views/admin/settings/counties.html @@ -0,0 +1,174 @@ +{include file='admin/settings/header.html'} + + +
Add a County
+
+
+ + + + + + + + + + + + + + + +
County Name: + +
Description: + +
Short Description: + +
+

* Required

+ Cancel + +
+
+ + +
+
+

Are you sure you want to delete this county?

+

Yes, delete this county

+

Cancel

+
+
+ + +
+
+ + + + + + + + + + + + + + + + +
County Name: + +
Description: + +
Short Description: + +
+

* Required

+ Cancel + +
+
+ +

Counties

+ + + + + + + + + + + + +{if $haveCounties} + {assign var="i" value="0"} + {foreach $counties as $t} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + + + + {/foreach} +{else} + +{/if} + +
IDCountyDescriptionShort Description 
{$t.id} + {$t.name} + + {$t.descr} + + {$t.short_descr} + +
Delete
+
(no counties listed)
+ + + +{include file='admin/footer.html'} diff --git a/views/admin/settings/header.html b/views/admin/settings/header.html index a0bfe90a..95ccbe80 100644 --- a/views/admin/settings/header.html +++ b/views/admin/settings/header.html @@ -11,6 +11,7 @@ Cities {if $enable_members} Regions + Counties {/if} {foreach $addOnTabs as $a} {$a.text} -- 2.17.1