From 408c5d116e16f1c99ab232b44c494e89695588ab Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 23 Jun 2016 12:09:02 -0400 Subject: [PATCH] Adding functionality for interest and interest groups. Started with copying the amenities and groups from the main glm-member-db plugin and working with that. Made the Group a select drop down. --- classes/data/dataInterestGroups.php | 152 +++++++++++ classes/data/dataInterests.php | 164 ++++++++++++ classes/data/dataLeads.php | 8 +- models/admin/settings/leads.php | 149 +++++++++-- views/admin/settings/leads.html | 375 +++++++++++++++++++++++++++- 5 files changed, 819 insertions(+), 29 deletions(-) create mode 100644 classes/data/dataInterestGroups.php create mode 100644 classes/data/dataInterests.php diff --git a/classes/data/dataInterestGroups.php b/classes/data/dataInterestGroups.php new file mode 100644 index 0000000..fe26b6c --- /dev/null +++ b/classes/data/dataInterestGroups.php @@ -0,0 +1,152 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataLeads.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataLeads 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 GlmDataInterestGroups 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; + + /** + * 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_LEADS_PLUGIN_DB_PREFIX . 'interest_groups'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + 'title' => array( + 'field' => 'title', + 'type' => 'text', + 'required' => true, + 'unique' => 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/classes/data/dataInterests.php b/classes/data/dataInterests.php new file mode 100644 index 0000000..c107adf --- /dev/null +++ b/classes/data/dataInterests.php @@ -0,0 +1,164 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataLeads.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataLeads 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 GlmDataInterests 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; + + /** + * 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_LEADS_PLUGIN_DB_PREFIX . 'interests'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a', + ), + + 'title' => array( + 'field' => 'title', + 'type' => 'text', + 'required' => true, + 'unique' => true, + 'use' => 'a', + ), + + // Parent - for adding, deleting and editing, has selection Tables + 'group_id' => array( + 'field' => 'group_id', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'interest_groups', + 'p_field' => 'title', + 'p_orderby' => 'title', + 'p_blank' => true, + 'force_list' => true, + 'required' => false, + '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/classes/data/dataLeads.php b/classes/data/dataLeads.php index 363537a..82d4677 100644 --- a/classes/data/dataLeads.php +++ b/classes/data/dataLeads.php @@ -109,10 +109,10 @@ class GlmDataLeads extends GlmDataAbstract $this->fields = array ( 'id' => array ( - 'field' => 'id', - 'type' => 'integer', + 'field' => 'id', + 'type' => 'integer', 'view_only' => true, - 'use' => 'a' + 'use' => 'a' ) /* MORE STUFF GOES HERE */ @@ -141,5 +141,3 @@ class GlmDataLeads extends GlmDataAbstract } } - -?> \ No newline at end of file diff --git a/models/admin/settings/leads.php b/models/admin/settings/leads.php index 2805073..bac5237 100644 --- a/models/admin/settings/leads.php +++ b/models/admin/settings/leads.php @@ -12,7 +12,8 @@ * @release leads.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ * @link http://dev.gaslightmedia.com/ */ - +require_once GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataInterests.php'; +require_once GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataInterestGroups.php'; /** * GlmMembersAdmin_settings_leads * @@ -25,7 +26,7 @@ * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott * Exp $ */ -class GlmMembersAdmin_settings_leads // extends GlmDataLeadsSettings +class GlmMembersAdmin_settings_leads extends GlmDataInterests { /** @@ -49,22 +50,6 @@ class GlmMembersAdmin_settings_leads // extends GlmDataLeadsSettings * @access public */ public $settings = array(); - /** - * categories - * - * @var bool - * @access public - */ - public $categories = array(); - public $oldCatMap = array(); - /** - * events - * - * @var bool - * @access public - */ - public $events = array(); - public $image_owner; /** * Constructor @@ -101,7 +86,7 @@ class GlmMembersAdmin_settings_leads // extends GlmDataLeadsSettings $this->config = $config; // Run constructor for members data class -// parent::__construct(false, false); + parent::__construct(false, false); } @@ -112,24 +97,142 @@ class GlmMembersAdmin_settings_leads // extends GlmDataLeadsSettings * @access public * @return void */ - public function modelAction($actionData = false) + public function modelAction ( $actionData = false ) { + $success = true; + $haveInterests = false; + $haveGroups = false; + $interests = false; + $error = false; + $option2 = ''; + $newInterest = $this->newEntry(); + + // Check if a category ID is supplied + $id = 0; + if ( isset( $_REQUEST['id'] ) ) { + $id = $_REQUEST['id'] - 0; + } + + $groupData = new GlmDataInterestGroups( $this->wpdb, $this->config ); + + // If there's an action option + if ( isset( $_REQUEST['option'] ) ) { + switch( $_REQUEST['option'] ) { + case 'addNew': + $return = $this->insertEntry(); + $id = $return['fieldData']['id']; + break; + + case 'update': + if ( $id > 0 ) { + $this->updateEntry( $id ); + } + break; + + case 'delete': + if ( $id > 0 ) { + $this->deleteEntry( $id, true ); + } + break; + + case 'addNewGroup': + $groupData->insertEntry(); + break; + + case 'updateGroup': + if ( $id > 0 ) { + $groupData->updateEntry( $id ); + } + break; + + case 'deleteGroup': + if ( $id > 0 ) { + $groupData->deleteEntry( $id, true ); + } + break; + + default: + $option2 = false; + break; + + } + } + + if ( isset( $_REQUEST['option2'] ) ) { + $option2 = $_REQUEST['option2']; + } + + // Get a current list of interests + $interests = $this->getList(); + //echo '
$interests: ' . print_r($interests, true) . '
'; + + if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) { + glmMembersAdmin::addNotice( $interests, 'DataBlock', 'Interests Data' ); + } + + // If we have list entries - even if it's an empty list + $success = true; + $haveInterests = false; + if ( $interests !== false ) { + + $success = true; + + // If we have any entries + if ( count( $interests ) > 0 ) { + $haveInterests = true; + } + } + + $groups = $groupData->getList(); + + if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) { + glmMembersAdmin::addNotice( $groups, 'DataBlock', 'Interest Groups Data' ); + } + + if ( $groups !== false ) { + $success = true; + + // If we have any entries. + if ( count( $groups ) > 0 ) { + $haveGroups = 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( $interests, 'DataBlock', 'Interests Data' ); + } // Compile template data $templateData = array( + 'haveInterests' => $haveInterests, + 'haveGroups' => $haveGroups, + 'interests' => $interests, + 'groups' => $groups, + 'option2' => $option2, + 'newInterest' => $newInterest, ); // Return status, suggested view, and data to controller return array( - 'status' => true, + 'status' => $success, 'menuItemRedirect' => false, 'modelRedirect' => false, 'view' => 'admin/settings/leads.html', - 'data' => $templateData + 'data' => $templateData, ); - } } diff --git a/views/admin/settings/leads.html b/views/admin/settings/leads.html index 89fbcd4..b84d14a 100644 --- a/views/admin/settings/leads.html +++ b/views/admin/settings/leads.html @@ -1,3 +1,376 @@ {include file='admin/settings/header.html'} -

ADMIN LEADS SETTINGS VIEW STUFF GOES HERE

\ No newline at end of file + + + + +
+ +
Add an Interest
+
+
+ + + + + + + + + + + + + + + +
Interest Name: + +
Group: + +
+

* Required

+ Cancel + + +
+
+ + +
+
+

Are you sure you want to delete this interest?

+

Yes, delete this interest

+

Cancel

+
+
+ + +
+
+ + + + + + + + + + + + + + + + +
Interest Name: + +
Group: + +
+

* Required

+ Cancel + + +
+
+ + +

Interests

+ + + + + + + + + + + + {if $haveInterests} + {assign var="i" value="0"} + {foreach $interests as $t} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + + + {/foreach} + {else} + + {/if} + +
InterestUsed WithGroups 
+ {$t.title} + + {$t.ref_type.title} + + {foreach $t.group_id.list as $group} + {if $group.default} + {$group.name} + {/if} + {/foreach} + +
Delete
+
(no interests listed)
+
+ + + + +
+ +
Add a Group
+
+
+ + + + + + + + + + + + +
Group Name: + +
+

* Required

+ Cancel + + +
+
+ + +
+
+

Are you sure you want to delete this group?

+

Yes, delete this group

+

Cancel

+
+
+ + +
+
+ + + + + + + + + + + + + +
Group Name: + +
+

* Required

+ Cancel + + +
+
+ +

Groups

+ + + + + + + + + {if $haveGroups} + {assign var="i" value="0"} + {foreach $groups as $t} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + {/foreach} + {else} + + {/if} + +
Group 
+ {$t.title} + +
Delete
+
(no groups listed)
+ +
+ + + +{include file='admin/footer.html'} -- 2.17.1