From: Chuck Scott Date: Mon, 4 Jan 2016 19:13:28 +0000 (-0500) Subject: Saving files before switching to do a separate hotfix X-Git-Tag: v1.0.19^2~1^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=b2699b3b44c844baf9b935b6e8d58daec812b7e7;p=WP-Plugins%2Fglm-member-db-packaging.git Saving files before switching to do a separate hotfix --- diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php new file mode 100644 index 0000000..bcfc301 --- /dev/null +++ b/classes/data/dataManagement.php @@ -0,0 +1,133 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataPackagingManagement.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataManagementPackaging class + * + * PHP version 5 + * + * @category Data + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataPackagingManagement.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmDataPackagingManagement 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_PACKAGING_PLUGIN_DB_PREFIX . 'management'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Canonical Page Slug + 'canonical_package_page' => array ( + 'field' => 'canonical_package_page', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ) + + ); + + } + + +} + +?> \ No newline at end of file diff --git a/classes/data/dataPackages.php b/classes/data/dataPackages.php index 6328ebc..f366f59 100644 --- a/classes/data/dataPackages.php +++ b/classes/data/dataPackages.php @@ -141,6 +141,14 @@ class GlmDataPackages extends GlmDataAbstract 'use' => 'a' ), + // Package Slug + 'package_slug' => array ( + 'field' => 'package_slug', + 'type' => 'text', + 'required' => true, + 'use' => 'gle' + ), + // Description 'descr' => array ( 'field' => 'descr', @@ -231,7 +239,6 @@ class GlmDataPackages extends GlmDataAbstract 'type' => 'pointer', 'p_table' => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', 'p_field' => 'name', - 'p_orderby' => 'name', 'p_blank' => true, 'required' => true, 'use' => 'lged' @@ -280,6 +287,36 @@ class GlmDataPackages extends GlmDataAbstract return $r; } + /* + * Update package slug - should be called after a package record is added or updated + * + * @param integer id ID of package that needs the slug updated + * @access public + */ + public function updateSlug($id = false) + { + + if ($id == false) { + return false; + } + + $p = $this->getEntry($id); + + $slug = sanitize_title($p['title']); + + // Update the slug + $sql = " + UPDATE ".GLM_MEMBERS_PACKAGING_PLUGIN_DB_PREFIX."packages + SET package_slug = '$slug' + WHERE id = $id + ;"; + $this->wpdb->query($sql); + + return $slug; + + } + + } ?> \ No newline at end of file diff --git a/glm-member-db-packaging.php b/glm-member-db-packaging.php index 373f60a..8581a40 100644 --- a/glm-member-db-packaging.php +++ b/glm-member-db-packaging.php @@ -34,7 +34,7 @@ * version nunmber of that release for the DB version. */ define('GLM_MEMBERS_PACKAGING_PLUGIN_VERSION', '1.0.5'); -define('GLM_MEMBERS_PACKAGING_PLUGIN_DB_VERSION', '0.0.2'); +define('GLM_MEMBERS_PACKAGING_PLUGIN_DB_VERSION', '1.1.0'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_PACKAGING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.48'); @@ -130,6 +130,10 @@ require_once(GLM_MEMBERS_PACKAGING_PLUGIN_SETUP_PATH.'/validActions.php'); require_once(GLM_MEMBERS_PACKAGING_PLUGIN_SETUP_PATH.'/shortcodes.php'); require_once(GLM_MEMBERS_PACKAGING_PLUGIN_DB_SCRIPTS.'/dbVersions.php'); +// Load Packaging Management Settings data +$packagingManagementSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_PACKAGING_PLUGIN_DB_PREFIX."management WHERE id = 1", ARRAY_A ); +unset($packagingManagementSettings['id']); + function glmMembersRegisterPackaging($addOns) { // Add this add-on to the add-ons array @@ -139,6 +143,9 @@ function glmMembersRegisterPackaging($addOns) { 'short_name' => GLM_MEMBERS_PACKAGING_PLUGIN_SHORT_NAME, 'slug' => GLM_MEMBERS_PACKAGING_PLUGIN_SLUG, 'actions' => $GLOBALS['glmMembersPackagingAddOnValidActions'], + 'config' => array( + 'settings' => $GLOBALS['packagingManagementSettings'] + ), 'shortcodes' => $GLOBALS['glmMembersPackagingShortcodes'], 'shortcodesDescription' => $GLOBALS['glmMembersPackagingShortcodesDescription'], 'database' => array( diff --git a/misc/documentation/AddAnAdminTab.txt b/misc/documentation/AddAnAdminTab.txt new file mode 100644 index 0000000..c697b47 --- /dev/null +++ b/misc/documentation/AddAnAdminTab.txt @@ -0,0 +1,15 @@ +Add an admin tab + +* Add a new section in setup/adminTabs.php + +* Add a model file - models/admin/{menu}/{action}.php + +* Add a view file - views/admin/{menu}/{action}.html + +* Add action to setup/validActions.php + +* If needed add a database table to the create_database_V...sql file + and update name to current database version, add an + update_database_V....sql file, and/or update dbVersions.php + +* If required add a data definition for any new tables diff --git a/models/admin/management/packaging.php b/models/admin/management/packaging.php new file mode 100644 index 0000000..a0c454d --- /dev/null +++ b/models/admin/management/packaging.php @@ -0,0 +1,158 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release packaging.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Management Packaging data abstract +require_once(GLM_MEMBERS_PACKAGING_PLUGIN_CLASS_PATH.'/data/dataManagement.php'); + +/** + * GlmMembersAdmin_management_packaging + * + * 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_packaging extends GlmDataPackagingManagement +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + + /* + * 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); + + } + + public function modelAction($actionData = false) + { + $settingsUpdated = false; + + // Determine if current user can edit configurations + if (!current_user_can('glm_members_configure')) { + 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 + $option = ''; + if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'submit') { + $option = $_REQUEST['option']; + } + + switch($option) { + + // Update the settings and redisplay the form + case 'submit': + + // Update the package management settings + $packageSettings = $this->updateEntry(1); + if ($packageSettings['status']) { + $settingsUpdated = true; + } + + // Display admin message that the data has been updated + glmMembersAdmin::addNotice('Packaging Settings for the '.GLM_MEMBERS_PACKAGING_PLUGIN_NAME.' plugin have been updated.', 'AdminNotice'); + + 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. + $packageSettings = $this->editEntry(1); + + if ($packageSettings === false) { + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice("  /models/admin/management/packaging.php: Unable to load packaging management settings.", 'Alert'); + } + + } + + break; + + } + + // Compile template data + $templateData = array( + 'reason' => '', + 'packagingSettings' => $packageSettings, + 'settingsUpdated' => $settingsUpdated + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/management/packaging.html', + 'data' => $templateData + ); + + + } +} + +?> \ No newline at end of file diff --git a/models/admin/member/packaging.php b/models/admin/member/packaging.php index a0c7ee2..6ceb1cd 100644 --- a/models/admin/member/packaging.php +++ b/models/admin/member/packaging.php @@ -170,6 +170,9 @@ class GlmMembersAdmin_member_packaging extends GlmDataPackages // If the package inserted successfully if ($packageInfo && $packageInfo['status']) { + // Update the package title slug + $this->updateSlug($packageInfo['fieldData']['id']); + // Get the new package ID $packageID = $packageInfo['fieldData']['id']; @@ -213,8 +216,11 @@ class GlmMembersAdmin_member_packaging extends GlmDataPackages // If it updated successfully if ($packageInfo && $packageInfo['status']) { + // Update the package title slug + $this->updateSlug($packageID); + // Get the package data again prepared for editing - $packages = $this->editEntry($packageID); + $packageInfo = $this->editEntry($packageID); // Tell the template the package was updated $packageUpdated = true; diff --git a/models/admin/members/packaging.php b/models/admin/members/packaging.php index 7ca37d9..d49f66a 100644 --- a/models/admin/members/packaging.php +++ b/models/admin/members/packaging.php @@ -217,7 +217,8 @@ class GlmMembersAdmin_members_packaging extends GlmDataPackages default: // Get the list of packages - $packages = $this->getList("T.ref_type = 0"); +// $packages = $this->getList("T.ref_type = 0"); + $packages = $this->getList(); // If we have some, tell the template if ($packages && count($packages) > 0) { diff --git a/setup/adminTabs.php b/setup/adminTabs.php index d0bb894..3c3a3b5 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -65,4 +65,21 @@ if (apply_filters('glm_members_permit_admin_members_packages_tab', true)) { ); } +if (apply_filters('glm_members_permit_admin_members_packages_tab', true)) { + add_filter('glm-member-db-add-tab-for-management', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Packaging', + 'menu' => 'management', + 'action' => 'packaging' + ) + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } + ); +} + + ?> \ No newline at end of file diff --git a/setup/databaseScripts/create_database_V1.1.0.sql b/setup/databaseScripts/create_database_V1.1.0.sql new file mode 100644 index 0000000..cf097c3 --- /dev/null +++ b/setup/databaseScripts/create_database_V1.1.0.sql @@ -0,0 +1,70 @@ +-- Gaslight Media Members Database - Packaging +-- File Created: 12/02/15 15:27:15 +-- Database Version: 0.0.2 +-- Database Creation Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Packages +CREATE TABLE {prefix}packages ( + id INT NOT NULL AUTO_INCREMENT, + active BOOLEAN NULL, -- Package is active + title TINYTEXT NULL, -- Title of package + package_slug TINYTEXT NULL, -- Package name slug for canonical URLs (lowercase, "-" for spaces, no punctuation) + descr TEXT NULL, -- Description of package + short_descr TINYTEXT NULL, -- Short description of package + image TINYTEXT NULL, -- Package image + start_date TIMESTAMP NULL, -- Date display of this package starts + end_date TIMESTAMP NULL, -- Date display of this package ends (last date of display) + expire_date TIMESTAMP NULL, -- Date package expires (first date it's expired) + position INT NULL, -- Display order position + pricing TINYTEXT NULL, -- Pricing, descriptive + ref_type INT NULL, -- Type of entity this package is associated with + ref_dest INT NULL, -- Pointer to the specific entity + PRIMARY KEY (id), + INDEX(ref_type), + INDEX(ref_dest), + INDEX(start_date), + INDEX(end_date), + INDEX(expire_date) +); + +---- + +-- Package Elements - Items in a package +CREATE TABLE {prefix}package_elements ( + id INT NOT NULL AUTO_INCREMENT, + package INT NULL, -- Pointer to the package + active BOOLEAN NULL, -- Package is active + title TINYTEXT NULL, -- Title of element + descr TEXT NULL, -- Description for this entity's participation in the package + short_descr TEXT NULL, -- Short description for this entity's participation in the package + image TINYTEXT NULL, -- Element image + position INT NULL, -- Display order position + ref_type INT NULL, -- Type of entity this element is association with + ref_dest INT NULL, -- Pointer to the specific entity + PRIMARY KEY (id), + INDEX(package), + INDEX(ref_type), + INDEX(ref_dest) +); + +---- + +-- Package Management Settings +CREATE TABLE {prefix}management ( + id INT NOT NULL AUTO_INCREMENT, + canonical_package_page TINYTEXT NULL, -- Canonical page slug for package detail + PRIMARY KEY (id) +); + +---- + +-- Set default package management entry +INSERT INTO {prefix}management + ( id, canonical_package_page ) + VALUES + ( 1, 'package-detail' ) +; + diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 5451371..6a74c96 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -14,6 +14,7 @@ */ $glmMembersPackagingDbVersions = array( - '0.0.2' => array('version' => '0.0.2', 'tables' => 2) + '0.0.2' => array('version' => '0.0.2', 'tables' => 2), + '1.1.0' => array('version' => '1.1.0', 'tables' => 3) ); diff --git a/setup/databaseScripts/update_database_V1.1.0.php b/setup/databaseScripts/update_database_V1.1.0.php new file mode 100644 index 0000000..b71f50c --- /dev/null +++ b/setup/databaseScripts/update_database_V1.1.0.php @@ -0,0 +1,38 @@ +wpdb->get_results('SELECT id, title FROM '.GLM_MEMBERS_PACKAGING_PLUGIN_DB_PREFIX.'packages;', ARRAY_A); + +// If there's any package records +if ($packageRecords && count($packageRecords) > 0) { + + // For each package record + foreach ($packageRecords as $p) { + + // Create a slug from the title + $slug = sanitize_title($p['title']); + + // Store this value back into the record + $this->wpdb->update( + GLM_MEMBERS_PACKAGING_PLUGIN_DB_PREFIX.'packages', + array( + 'package_slug' => $slug + ), + array( 'id' => $p['id'] ), + array( '%s' ), + array( '%d') + ); + } + +} + +?> \ No newline at end of file diff --git a/setup/databaseScripts/update_database_V1.1.0.sql b/setup/databaseScripts/update_database_V1.1.0.sql new file mode 100644 index 0000000..a699971 --- /dev/null +++ b/setup/databaseScripts/update_database_V1.1.0.sql @@ -0,0 +1,30 @@ +-- Gaslight Media Members Database +-- File Created: 12/09/14 15:27:15 +-- Database Version: 1.0.28 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashses + +-- Package Management Settings +CREATE TABLE {prefix}management ( + id INT NOT NULL AUTO_INCREMENT, + canonical_package_page TINYTEXT NULL, -- Canonical page slug for package detail + PRIMARY KEY (id) +); + +---- + +-- Set default package management entry +INSERT INTO {prefix}management + ( id, canonical_package_page ) + VALUES + ( 1, 'package-detail' ) +; + +---- + +ALTER TABLE {prefix}packages ADD COLUMN package_slug TINYTEXT; + + + diff --git a/setup/validActions.php b/setup/validActions.php index f427686..0d5a336 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -37,6 +37,9 @@ $glmMembersPackagingAddOnValidActions = array( ), 'member' => array( 'packaging' => GLM_MEMBERS_PACKAGING_PLUGIN_SLUG + ), + 'management' => array( + 'packaging' => GLM_MEMBERS_PACKAGING_PLUGIN_SLUG ) ), 'frontActions' => array( diff --git a/views/admin/management/packaging.html b/views/admin/management/packaging.html new file mode 100644 index 0000000..a722756 --- /dev/null +++ b/views/admin/management/packaging.html @@ -0,0 +1,36 @@ +{include file='admin/management/header.html'} + + + {if $settingsUpdated}

Settings Updated

{/if} + +
+ + + + + + + + + + + + +

General Packaging Settings

Package Detail Page Permalink Name: + +
Use only the page name at the end of the permalink for the package detail page. +
+ +
+ + + +{include file='admin/footer.html'} diff --git a/views/admin/member/packaging.html b/views/admin/member/packaging.html index 6e57ded..3e66b15 100644 --- a/views/admin/member/packaging.html +++ b/views/admin/member/packaging.html @@ -57,6 +57,7 @@ {if $packageInfo.fieldFail.title}

{$packageInfo.fieldFail.title}

{/if} + Name for URLs:{$packageInfo.fieldData.package_slug}

Active: diff --git a/views/admin/members/packaging.html b/views/admin/members/packaging.html index 96e2bb2..ee211fb 100644 --- a/views/admin/members/packaging.html +++ b/views/admin/members/packaging.html @@ -210,6 +210,7 @@ + @@ -226,15 +227,27 @@ {else} {if apply_filters('glm_members_permit_admin_members_packaging_add_package', true)} -
Add a Package
+
  Add a Package
{/if} -

Multi-Member Packages

+ + + List Filters:   + All   + Member   + Multi-Member   + Search:    + +
+ + +

Packages

Title:{$packageInfo.fieldData.title}
Name for URLs:{$packageInfo.fieldData.package_slug}
Active:{$packageInfo.fieldData.active.name}
Description:{$packageInfo.fieldData.descr}
Short Description:{$packageInfo.fieldData.short_descr}
+ @@ -244,9 +257,12 @@ {if $havePackages} {foreach $packages as $p} - + @@ -299,42 +315,29 @@ {/if} /* - * Package Members Processing + * Do autocomplete search for package + * label: What will be searched + * value: What will be displayed when selected + * id: Package id added so we can go to the member while showing what was selected + * Also note that autocomplete does not properly render HTML codes, so we + * "unescape" them for HTML in Smarty. */ - - // Build a list of members for the autocomplete search - var availableTags = [ - {foreach $membersList as $m} - { label: "{$m.name|unescape:'html'}", value: "{$m.name|unescape:'html'}", id: '{$m.id}', name: "{$m.name}" }, - {/foreach} - ]; - - $( "#glmMembersList" ).autocomplete({ + var availableTags = [ + {if $havePackages} + {foreach $packages as $p} + { label: "{$p.title|unescape:'html'} - {$p.ref_dest_name|unescape:'html'}", id: '{$p.id}' }, + {/foreach} + {/if} + ]; + $( "#glmPackageSearch" ).autocomplete({ source: availableTags, html: true, select: function( event, ui ) { - - // get the member ID and Name - var memberID = ui.item.id; - var memberName = ui.item.name - - // Get a copy of the template - var memberTemplate = $('#glmGalleryItmeDataTemplate').html(); - - // Set the member data into the template copy - memberTemplate = memberTemplate.replace('{ id }', memberID).replace('{ memberName }', memberID); - - // Insert the selected member - $('#glmPackageMembersList').append(memberTemplate); - - {if !$havePackageMembers} - // Hide the no members selected message - $('#glmNoMembersSelected').hide(); - {/if} - + var packageID = ui.item.id; + window.location.replace("{$adminURL}?page=glm-members-admin-menu-members&glm_action=packaging&package=" + packageID ); } }); - + }); diff --git a/views/front/packaging/list.html b/views/front/packaging/list.html index 318df70..1ac0fce 100644 --- a/views/front/packaging/list.html +++ b/views/front/packaging/list.html @@ -39,7 +39,7 @@
{$p.url}
{/if} {if $p.email} -
+
{/if} @@ -86,7 +86,7 @@ {if $p.image} {/if} -

{$p.title}

+

{$p.title}

{if $p.descr} {$p.descr} {else if $p.short_descr}
PackageMember Start End Expire
+ {$p.title} + {$p.ref_dest_name} + {$p.start_date.date}