From b6edd942d2d948e93b8297a1ede0d5a5b38e4798 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Mon, 4 Apr 2016 16:28:53 -0400 Subject: [PATCH] A bunch of requested changes. Not fully debugged --- classes/data/dataEvents.php | 100 ++++++++++++++++-- index.php | 2 +- ..._V0.0.8.sql => create_database_V0.0.9.sql} | 6 +- setup/databaseScripts/dbVersions.php | 3 +- .../update_database_V0.0.3.sql | 2 +- .../update_database_V0.0.4.sql | 2 +- .../update_database_V0.0.5.sql | 2 +- .../update_database_V0.0.7.sql | 2 +- .../update_database_V0.0.8.sql | 2 +- .../update_database_V0.0.9.sql | 32 ++++++ views/admin/events/edit.html | 44 ++++++-- ...ditSettings.html => editAdminContact.html} | 30 +----- views/admin/events/editLocation.html | 54 ++++++---- views/admin/events/editSchedule.html | 2 +- views/admin/events/editStatus.html | 45 +++++++- 15 files changed, 254 insertions(+), 74 deletions(-) rename setup/databaseScripts/{create_database_V0.0.8.sql => create_database_V0.0.9.sql} (95%) create mode 100644 setup/databaseScripts/update_database_V0.0.9.sql rename views/admin/events/{editSettings.html => editAdminContact.html} (55%) diff --git a/classes/data/dataEvents.php b/classes/data/dataEvents.php index 7d0b1c6..e258e8b 100644 --- a/classes/data/dataEvents.php +++ b/classes/data/dataEvents.php @@ -301,9 +301,23 @@ class GlmDataEvents extends GlmDataAbstract 'use' => 'a' ), - // Event Phone - 'phone' => array ( - 'field' => 'phone', + // Contact name + 'contact_name' => array ( + 'field' => 'contact_name', + 'type' => 'text', + 'use' => 'a' + ), + + // Contact email + 'contact_email' => array ( + 'field' => 'contact_email', + 'type' => 'text', + 'use' => 'a' + ), + + // Contact Phone + 'contact_phone' => array ( + 'field' => 'contact_phone', 'type' => 'text', 'use' => 'a' ), @@ -322,6 +336,13 @@ class GlmDataEvents extends GlmDataAbstract 'use' => 'a' ), + // Free + 'free' => array( + 'field' => 'free', + 'type' => 'checkbox', + 'use' => 'a' + ), + // Cost (description) 'cost' => array ( 'field' => 'cost', @@ -329,6 +350,14 @@ class GlmDataEvents extends GlmDataAbstract 'use' => 'a' ), + // Use Member Location rather than location table + 'use_member_location' => array ( + 'field' => 'use_member_location', + 'type' => 'checkbox', + 'default' => false, + 'use' => 'a' + ), + // Admin Reference Type 'admin_ref_type' => array ( 'field' => 'admin_ref_type', @@ -452,33 +481,86 @@ class GlmDataEvents extends GlmDataAbstract } /** - * Update event slug - should be called after an event record is added or updated + * Update event slug - should be called after an event record is added or updated. + * + * Since slugs must be unique, if there's already a slug matching the slug directly + * derived from the event name, then append "-n" where n is a sequential number + * that makes the slug unique. + * + * This function will try numbers from 1 to $maxTries to get a unique slug. * * @param integer id ID of event that needs the slug updated + * @param integer maxTries Maximum number of tries to create a unique slug + * default 100 * + * @return string Slug stored in this event record + * If this function fails, it will return false. * @access public */ - public function updateSlug($id = false) + public function updateSlug($id = false, $maxTries = 100) { if ($id == false) { return false; } + // Get the event entry $e = $this->getEntry($id); + if (!$e) { + return false; + } + // Make a slug out of the event name $slug = sanitize_title($e['name']); - // Update the city selected for this memberInfo record + // If slug is the same as it was then do nothing + if ($e['name_slug'] == $slug) { + return $slug; + } + + // Loop until we have a unique slug - limit loops to 50 just in case + $saveSlug = $slug; + for ($loop = 1 ; $loop <= $maxTries ; $loop++) { + + // New Slug - Check if the new slug is unique + $matchingSlugs = $this->wpdb->get_results( + " + SELECT id, name_slug + FROM ".$this->table." + WHERE name_slug = '$slug' + AND id != $id + ", + ARRAY_A + ); + + // If there's no matching results then we're good to use this one + if (!is_array($matchingSlugs) || count($matchingSlugs) == 0) { + + // Write new slug and return + $sql = " + UPDATE ".$this->table." + SET name_slug = '$slug' + WHERE id = $id + ;"; + $this->wpdb->query($sql); + + return $slug; + + } + + $slug = $saveSlug."-$loop"; + + } // for + + // Unable to create unique slug $sql = " UPDATE ".$this->table." - SET name_slug = '$slug' + SET name_slug = '' WHERE id = $id ;"; $this->wpdb->query($sql); - return $slug; - + return false; } /** diff --git a/index.php b/index.php index e9eb14e..187bdf9 100644 --- a/index.php +++ b/index.php @@ -39,7 +39,7 @@ * version from this plugin. */ define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.8'); +define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.9'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_EVENTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.58'); diff --git a/setup/databaseScripts/create_database_V0.0.8.sql b/setup/databaseScripts/create_database_V0.0.9.sql similarity index 95% rename from setup/databaseScripts/create_database_V0.0.8.sql rename to setup/databaseScripts/create_database_V0.0.9.sql index b22ddf4..ca61b55 100644 --- a/setup/databaseScripts/create_database_V0.0.8.sql +++ b/setup/databaseScripts/create_database_V0.0.9.sql @@ -128,7 +128,6 @@ CREATE TABLE {prefix}events ( descr TEXT NULL, -- Full description text image TINYTEXT NULL, -- Image file name url TINYTEXT NULL, -- Event URL - phone TINYTEXT NULL, -- Event Phone ticket_url TINYTEXT NULL, -- Ticket URL cost TINYTEXT NULL, -- Description of event cost admin_ref_type INT NULL, -- Type of admin contact if using a member contact @@ -137,6 +136,11 @@ CREATE TABLE {prefix}events ( admin_org TINYTEXT NULL, -- Admin Contact Organization if not using a member contact admin_email TINYTEXT NULL, -- Admin Contact E-Mail if not using a member contact admin_phone TINYTEXT NULL, -- Admin Contact Phone if not using a member contact + free BOOLEAN NULL, -- Event is Free + contact_email TINYTEXT NULL, -- Contact E-mail address + contact_name TINYTEXT NULL, -- Contact name + contact_phone TINYTEXT NULL, -- Event Phone + use_member_location BOOLEAN NULL, -- Use location of the member (if provided) rather than location table data old_event_id INT NULL, -- ID of event from old site for reference notes TEXT NULL, -- Internal notes for this event PRIMARY KEY (id), diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index b324373..3a8ef3b 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -21,6 +21,7 @@ $glmMembersEventsDbVersions = array( '0.0.5' => array('version' => '0.0.5', 'tables' => 7), '0.0.6' => array('version' => '0.0.6', 'tables' => 7), '0.0.7' => array('version' => '0.0.7', 'tables' => 7), - '0.0.8' => array('version' => '0.0.8', 'tables' => 7) + '0.0.8' => array('version' => '0.0.8', 'tables' => 7), + '0.0.9' => array('version' => '0.0.9', 'tables' => 7), ); diff --git a/setup/databaseScripts/update_database_V0.0.3.sql b/setup/databaseScripts/update_database_V0.0.3.sql index f20d3ac..7a192a2 100644 --- a/setup/databaseScripts/update_database_V0.0.3.sql +++ b/setup/databaseScripts/update_database_V0.0.3.sql @@ -1,6 +1,6 @@ -- Gaslight Media Members Database - Events Add-On -- File Created: 12/09/14 15:27:15 --- Database Version: 0.0.2 +-- Database Version: 0.0.3 -- Database Update From Previous Version Script -- -- To permit each query below to be executed separately, diff --git a/setup/databaseScripts/update_database_V0.0.4.sql b/setup/databaseScripts/update_database_V0.0.4.sql index 090bf25..c059470 100644 --- a/setup/databaseScripts/update_database_V0.0.4.sql +++ b/setup/databaseScripts/update_database_V0.0.4.sql @@ -1,6 +1,6 @@ -- Gaslight Media Members Database - Events Add-On -- File Created: 12/09/14 15:27:15 --- Database Version: 0.0.2 +-- Database Version: 0.0.4 -- Database Update From Previous Version Script -- -- To permit each query below to be executed separately, diff --git a/setup/databaseScripts/update_database_V0.0.5.sql b/setup/databaseScripts/update_database_V0.0.5.sql index a8d1c49..cd63193 100644 --- a/setup/databaseScripts/update_database_V0.0.5.sql +++ b/setup/databaseScripts/update_database_V0.0.5.sql @@ -1,6 +1,6 @@ -- Gaslight Media Members Database - Events Add-On -- File Created: 12/09/14 15:27:15 --- Database Version: 0.0.2 +-- Database Version: 0.0.5 -- Database Update From Previous Version Script -- -- To permit each query below to be executed separately, diff --git a/setup/databaseScripts/update_database_V0.0.7.sql b/setup/databaseScripts/update_database_V0.0.7.sql index ef060ef..4a4e071 100644 --- a/setup/databaseScripts/update_database_V0.0.7.sql +++ b/setup/databaseScripts/update_database_V0.0.7.sql @@ -1,6 +1,6 @@ -- Gaslight Media Members Database - Events Add-On -- File Created: 12/09/14 15:27:15 --- Database Version: 0.0.6 +-- Database Version: 0.0.7 -- Database Update From Previous Version Script -- -- To permit each query below to be executed separately, diff --git a/setup/databaseScripts/update_database_V0.0.8.sql b/setup/databaseScripts/update_database_V0.0.8.sql index 9166d69..7a7ed46 100644 --- a/setup/databaseScripts/update_database_V0.0.8.sql +++ b/setup/databaseScripts/update_database_V0.0.8.sql @@ -1,6 +1,6 @@ -- Gaslight Media Members Database - Events Add-On -- File Created: 12/09/14 15:27:15 --- Database Version: 0.0.6 +-- Database Version: 0.0.8 -- Database Update From Previous Version Script -- -- To permit each query below to be executed separately, diff --git a/setup/databaseScripts/update_database_V0.0.9.sql b/setup/databaseScripts/update_database_V0.0.9.sql new file mode 100644 index 0000000..1ba8cb2 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.9.sql @@ -0,0 +1,32 @@ +-- Gaslight Media Members Database - Events Add-On +-- File Created: 12/09/14 15:27:15 +-- Database Version: 0.0.9 +-- 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 + + +-- Add Free event flag +ALTER TABLE {prefix}events ADD COLUMN free BOOLEAN; + +---- + +-- Add event E-Mail address +ALTER TABLE {prefix}events ADD COLUMN contact_email TINYTEXT; + +---- + +-- Add event Name +ALTER TABLE {prefix}events ADD COLUMN contact_name TINYTEXT; + +---- + +-- Rename event phone to contact phone +ALTER TABLE {prefix}events CHANGE phone contact_phone TINYTEXT; + +---- + +-- Use Member Location +ALTER TABLE {prefix}events ADD COLUMN use_member_location TINYTEXT; + diff --git a/views/admin/events/edit.html b/views/admin/events/edit.html index 0f527b1..318cb77 100644 --- a/views/admin/events/edit.html +++ b/views/admin/events/edit.html @@ -38,10 +38,10 @@