From 51be3a468ac8417bd324120db55bed5fbc4007c3 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 18 Nov 2016 08:55:42 -0500 Subject: [PATCH] Adding the management setting models and views. Update the table name from settings to management. Update my table names and the create scripts for the names. Adding the default_date_range field. Setting up the management model and view. Setting up the data abstract class for management. --- classes/data/dataManagement.php | 9 +- models/admin/management/coupons.php | 215 ++++++++++++++++++ setup/adminTabs.php | 15 ++ .../create_database_V0.0.2.sql | 9 +- setup/validActions.php | 3 + views/admin/management/coupons.html | 91 ++++++++ 6 files changed, 337 insertions(+), 5 deletions(-) create mode 100644 models/admin/management/coupons.php create mode 100644 views/admin/management/coupons.html diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php index f23de95..bec335b 100644 --- a/classes/data/dataManagement.php +++ b/classes/data/dataManagement.php @@ -107,7 +107,7 @@ class GlmDataCouponsManagement extends GlmDataAbstract /* * Table Name */ - $this->table = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'settings'; + $this->table = GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . 'management'; /* * Table Data Fields @@ -143,6 +143,13 @@ class GlmDataCouponsManagement extends GlmDataAbstract 'required' => false, 'use' => 'a' ), + // Default Date Range + 'default_date_rang' => array( + 'field' => 'default_date_range', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), ); diff --git a/models/admin/management/coupons.php b/models/admin/management/coupons.php new file mode 100644 index 0000000..4b1d469 --- /dev/null +++ b/models/admin/management/coupons.php @@ -0,0 +1,215 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release coupons.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Management Coupons data abstract +require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'; +require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php'; + +/** + * GlmMembersAdmin_management_coupons + * + * PHP version 5 + * + * @category Model + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmMembersAdmin_management_coupons extends GlmDataCouponsManagement +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * dbh Postgres database connection + * + * @var mixed + * @access public + */ + public $dbh; + /** + * settings used for the schema and tablenames + * + * @var mixed + * @access public + */ + public $settings = array(); + + /** + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * '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. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + 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); + + } + + /** + * modelAction + * + * @param bool $actionData + * @access public + * @return void + */ + public function modelAction($actionData = false) + { + + $option = false; + $test_result = false; + $import_result = false; + $settings_updated = false; + $settings_update_error = false; + $coupon_settings = false; + $icalFeedResult = false; + $import_feeds = false; + $option2 = false; + + if (isset($_REQUEST['option'])) { + $option = $_REQUEST['option']; + } + + switch ($option) { + + case 'settings': + + default: + + // Make sure option is set if default + $option = 'settings'; + + // Determine if current user can edit configurations + if (!current_user_can('glm_members_management')) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'User does not have rights to make configuration changes.' + ) + ); + } + + // Check for submission option + $option2 = ''; + if (isset($_REQUEST['option2'])) { + $option2 = $_REQUEST['option2']; + } + + switch($option2) { + + // Update the settings and redisplay the form + case 'submit': + + // Update the coupon management settings + $coupon_settings = $this->updateEntry(1); + if ($coupon_settings['status']) { + $settings_updated = true; + } else { + $settings_update_error = true; + } + + break; + + // Default is to get the current settings and display the form + default: + + // Try to get the first (should be only) entry for general settings. + $coupon_settings = $this->editEntry(1); + //echo '
$coupon_settings: ' . print_r( $coupon_settings, true ) . '
'; + + if ($coupon_settings === false) { + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice("  /models/admin/management/coupons.php: Unable to load coupons management settings.", 'Alert'); + } + + } + + break; + + } + + break; + + } + + // Populate the state list for coupon default state selection + $coupon_settings['coupon_default_state'] = $this->config['states']; + + // Compile template data + $template_data = array( + 'import_feeds' => $import_feeds, + 'option' => $option, + 'testResult' => $test_result, + 'importResult' => $import_result, + 'settingsUpdated' => $settings_updated, + 'settingsUpdateError' => $settings_update_error, + 'couponsSettings' => $coupon_settings, + 'icalFeedResult' => $icalFeedResult, + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/management/coupons.html', + 'data' => $template_data + ); + + + } + +} + +?> diff --git a/setup/adminTabs.php b/setup/adminTabs.php index 3a0799a..c0efef6 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -48,4 +48,19 @@ if (current_user_can('glm_members_members')) { return $addOnTabs; } ); + if (apply_filters('glm_members_permit_admin_members_coupons_tab', true)) { + add_filter('glm-member-db-add-tab-for-management', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Coupons', + 'menu' => 'management', + 'action' => 'coupons' + ) + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } + ); + } } diff --git a/setup/databaseScripts/create_database_V0.0.2.sql b/setup/databaseScripts/create_database_V0.0.2.sql index d309c90..0c36e32 100644 --- a/setup/databaseScripts/create_database_V0.0.2.sql +++ b/setup/databaseScripts/create_database_V0.0.2.sql @@ -61,18 +61,19 @@ CREATE TABLE {prefix}coupon_categories ( ---- -- Settings -CREATE TABLE {prefix}settings ( +CREATE TABLE {prefix}management ( id INT NOT NULL AUTO_INCREMENT, notify_to TINYTEXT NULL, -- To for the notify email notify_from TINYTEXT NULL, -- From header for notify email notify_message TEXT NULL, -- Message to add to the notify email + default_date_range TINYTEXT NULL, -- Default span for start and end dates PRIMARY KEY (id) ); ---- -- Data for Settings -INSERT INTO {prefix}settings -(id,notify_to,notify_from,notify_message) +INSERT INTO {prefix}management +(id,notify_to,notify_from,notify_message,default_date_range) VALUES -(1, '', '', ''); +(1, '', '', '','6 months'); diff --git a/setup/validActions.php b/setup/validActions.php index 0129c0e..1716329 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -45,6 +45,9 @@ $glmMembersCouponsAddOnValidActions = array( 'settings' => array( 'couponCategories' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG, ), + 'management' => array( + 'coupons' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG + ), ), 'frontActions' => array( 'coupons' => array( diff --git a/views/admin/management/coupons.html b/views/admin/management/coupons.html new file mode 100644 index 0000000..153d3ba --- /dev/null +++ b/views/admin/management/coupons.html @@ -0,0 +1,91 @@ +{include file='admin/management/header.html'} + + + + + + + + + + + + +
+ {if $settingsUpdated}

Settings Updated

{/if} + {if $settingsUpdateError}Settings Update Error{/if} +

Management Settings

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default date range for start and end dates: + + {if $couponsSettings.fieldFail.default_date_range}

{$couponsSettings.fieldFail.default_date_range}

{/if} +
+

E-Mail Notification Settings

+
Recipient Email Address (comma separated)
Sender Email Address
Email Notification + +
+ +
+
+ + -- 2.17.1