From 9fcfdc25cf7345014155a7564abe2f5ff5275151 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Wed, 9 Mar 2016 15:53:44 -0500 Subject: [PATCH] More admin enhancements to Events - First live data --- activate.php | 10 +- classes/data/dataRecurrences.php | 60 ++- classes/data/dataTimes.php | 11 + index.php | 2 +- models/admin/events/list.php | 105 ++++- ..._V0.0.2.sql => create_database_V0.0.3.sql} | 1 + setup/databaseScripts/dbVersions.php | 3 +- .../update_database_V0.0.3.sql | 16 + views/admin/events/calendar.html | 43 +- views/admin/events/edit.html | 381 +++++++++++++----- views/admin/settings/eventCategories.html | 3 - 11 files changed, 477 insertions(+), 158 deletions(-) rename setup/databaseScripts/{create_database_V0.0.2.sql => create_database_V0.0.3.sql} (98%) create mode 100644 setup/databaseScripts/update_database_V0.0.3.sql diff --git a/activate.php b/activate.php index 97ac9a9..bd0f669 100644 --- a/activate.php +++ b/activate.php @@ -84,15 +84,7 @@ class glmMembersEventsPluginActivate // Set Roles and Capabilities for this plugin require_once(GLM_MEMBERS_EVENTS_PLUGIN_SETUP_PATH.'/rolesAndCapabilities.php'); - wp_enqueue_script('jquery'); - wp_enqueue_script('jquery-style'); - wp_enqueue_script('jquery-ui-core'); - wp_enqueue_script('jquery-ui-dialog'); - wp_enqueue_script('jquery-ui-autocomplete'); - - // Jquery DatePicker - wp_enqueue_script('jquery-ui-datepicker'); - wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); + } /* diff --git a/classes/data/dataRecurrences.php b/classes/data/dataRecurrences.php index 8fa8ff7..e3e6b22 100644 --- a/classes/data/dataRecurrences.php +++ b/classes/data/dataRecurrences.php @@ -134,6 +134,7 @@ class GlmDataEventsRecurrences extends GlmDataAbstract 'start_time' => array ( 'field' => 'start_time', 'type' => 'datetime', + 'format' => 'm/d/Y H:i', 'required' => true, 'use' => 'a' ), @@ -152,6 +153,7 @@ class GlmDataEventsRecurrences extends GlmDataAbstract 'end_time' => array ( 'field' => 'end_time', 'type' => 'datetime', + 'format' => 'm/d/Y H:i', 'use' => 'a' ), @@ -206,6 +208,14 @@ class GlmDataEventsRecurrences extends GlmDataAbstract 'use' => 'a' ), + // Select by Days of the Month Flag + 'by_day_of_month' => array ( + 'field' => 'by_day_of_month', + 'type' => 'checkbox', + 'default' => false, + 'use' => 'a' + ), + // Day of Month - multi-pick (bitmap) 'day_of_month' => array( 'field' => 'day_of_month', @@ -293,8 +303,8 @@ class GlmDataEventsRecurrences extends GlmDataAbstract if ($recurData && $recurData['event'] > 0) { $this->wpdb->query(" DELETE FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."events - WHERE root_event = $recurID - ;"); + WHERE root_event = ".$recurData['event']." + "); } // Otherwise don't delete times for the custom events @@ -352,41 +362,53 @@ class GlmDataEventsRecurrences extends GlmDataAbstract $fromYear = $from->format('Y'); $toYear = $to->format('Y'); + // Determine time each event starts at + $time = $start->format('H:i'); + // For each year in recurrence range for ($year = $fromYear ; $year <= $toYear ; $year++ ) { - // For each Month selected + // For each month selected foreach ($recurData['month_of_year']['names'] as $km=>$month) { - // For each week selected - foreach ($recurData['week_of_month']['names'] as $kw=>$week) { - - // For each day selected - foreach ($recurData['day_of_week']['names'] as $kd=>$day) { + // If selecting by days of the month + if ($recurData['by_day_of_month']['value']) { - $dates[] = new DateTime("$week $day of $month $year"); + // For each specified days of the month ($dom is day of month) + foreach ($recurData['day_of_month']['names'] as $kdom=>$dom) { + $t = new DateTime("$month $dom $year $time"); + $dates[$t->getTimestamp()] = $t; + } - } // Day of Week + // If last day of month is selected + if ($recurData['last_day_of_month']['value']) { + $t = new DateTime("last day of $month $year $time"); + $dates[$t->getTimestamp()] = $t; + } - } // Week of Month + } else { - // For each specifi days of the month - foreach ($recurData['day_of_month']['names'] as $kdom=>$dom) { + // For each week selected + foreach ($recurData['week_of_month']['names'] as $kw=>$week) { - $dates[] = new DateTime("$month $dom $year"); + // For each day selected + foreach ($recurData['day_of_week']['names'] as $kd=>$day) { + $t = new DateTime("$week $day of $month $year $time"); + $dates[$t->getTimestamp()] = $t; + } - } + } - // If last day of month is selected - if ($recurData['last_day_of_month']['value']) { - $dates[] = new DateTime("last day of $month $year"); } - } // Month of Year } // Year + // Check if the recurrences caught the "First Occurance" + if (!isset($dates[$start->getTimestamp()])) { + $dates[$start->getTimestamp()] = $start; + } // Create From and to timestamp for comparison $fromTime = $from->getTimestamp(); diff --git a/classes/data/dataTimes.php b/classes/data/dataTimes.php index 7298781..d8205a8 100644 --- a/classes/data/dataTimes.php +++ b/classes/data/dataTimes.php @@ -130,6 +130,17 @@ class GlmDataEventsTimes extends GlmDataAbstract 'use' => 'glei' ), + // Event Name + 'event_name' => array ( + 'field' => 'event', + 'as' => 'event_name', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events', + 'p_field' => 'name', + 'p_static' => true, + 'use' => 'a' + ), + // Custom Event ID 'custom_event' => array( 'field' => 'custom_event', diff --git a/index.php b/index.php index 822fd64..3ed99fa 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.2'); +define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.3'); // 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/models/admin/events/list.php b/models/admin/events/list.php index c3d3fd3..535c2e3 100644 --- a/models/admin/events/list.php +++ b/models/admin/events/list.php @@ -108,8 +108,12 @@ class GlmMembersAdmin_events_list extends GlmDataEvents $eventDeleted = false; $eventDeleteError = false; $recurrences = false; + $haveRecurrences = false; + $numbRecurrences = 0; $times = false; $haveTimes = false; + $firstTime = false; + $lastTime = false; // Get a list of categories $Categories = new GlmDataEventsCategories($this->wpdb, $this->config); @@ -133,15 +137,9 @@ class GlmMembersAdmin_events_list extends GlmDataEvents if ($this->eventID <= 0) { $this->eventID = false; - } else { - - // Get recurrences for this event - $recurrences = $Recurrences->getList("T.event = ".$this->eventID); - } - } - + } /* * PLACE TEMPORARY TEST DATA FOR CALENDARS HERE @@ -251,6 +249,67 @@ class GlmMembersAdmin_events_list extends GlmDataEvents $eventUpdateError = true; } + // Look for recurrence deletes + if (isset($_REQUEST['deleteRecur']) && count($_REQUEST['deleteRecur'] > 0)) { + foreach ($_REQUEST['deleteRecur'] as $d) { + + // If this was not a new entry that was deleted (in which case it was never added) + if ($d[0] != 'n') { + $Recurrences->deleteTimeEntriesForRecurrance($d, true); + $Recurrences->deleteEntry($d, true); + } + + } + } + + // Look for recurrence data + if (isset($_REQUEST['recurID'])) { + + // For each recurrence + foreach ($_REQUEST['recurID'] as $recurID) { + + // first check if the event is an all-day event + if (isset($_REQUEST[$recurID.'_all_day'])) { + + // Then take the event date (date only) and stick it into the start time + $red = explode(' ', $_REQUEST[$recurID.'_event_date']); + $_REQUEST[$recurID.'_start_time'] = $red[0]." 00:00"; + $_REQUEST[$recurID.'_end_time'] = $$red[0]." 00:00"; + + } + + // Check if it's a new Recurrence + if ($recurID[0] == 'n') { + + // Add the new recurrence + $x = $Recurrences->insertEntry(true, $recurID.'_'); + + // And create time entries + $Recurrences->createRecurrenceTimesEntries($x['fieldData']['id'], true, true); + + // Otherwise it's an existing recurrence + } else { + $Recurrences->updateEntry($recurID, 'id', true, $recurID.'_'); + } + + } + + // Update our recurrences + $recurrences = $Recurrences->getList("T.event = ".$this->eventID); + + // Check for any updated recurrences + if (isset($_REQUEST['recurUpdated']) && count($_REQUEST['recurUpdated']) > 0) { + foreach ($_REQUEST['recurUpdated'] as $r) { + + // If we have a recurID as a value, then update this recurrence times + if ($r) { + $Recurrences->createRecurrenceTimesEntries($r, true, true); + } + } + } + + } + $haveEvent = true; $view = 'edit'; @@ -285,6 +344,34 @@ class GlmMembersAdmin_events_list extends GlmDataEvents } + // If we have an event ID + if ($this->eventID) { + + // Get recurrences for this event + $recurrences = $Recurrences->getList("T.event = ".$this->eventID); + + // Check if we have recurrences + if ($recurrences) { + $haveRecurrences = true; + $numbRecurrences = count($recurrences); + + // Get list of times + require_once(GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataTimes.php'); + $Times = new GlmDataEventsTimes($this->wpdb, $this->config); + $times = $Times->getList('T.event = '.$this->eventID, 'start_time'); + + if ($times && count($times) > 0) { + $haveTimes = true; + + // Get the first event date/time + $firstTime = current($times); + $lastTime = end($times); + + } + + } + } + $templateData = array( 'option' => $option, 'events' => $events, @@ -302,9 +389,13 @@ class GlmMembersAdmin_events_list extends GlmDataEvents 'eventDeleted' => $eventDeleted, 'eventDeleteError' => $eventDeleteError, 'recurrences' => $recurrences, + 'haveRecurrences' => $haveRecurrences, + 'numbRecurrences' => $numbRecurrences, 'newRecurrence' => $newRecurrence, 'times' => $times, 'haveTimes' => $haveTimes, + 'firstTime' => $firstTime, + 'lastTime' => $lastTime ); // Return status, any suggested view, and any data to controller diff --git a/setup/databaseScripts/create_database_V0.0.2.sql b/setup/databaseScripts/create_database_V0.0.3.sql similarity index 98% rename from setup/databaseScripts/create_database_V0.0.2.sql rename to setup/databaseScripts/create_database_V0.0.3.sql index 221caf6..b8c6d19 100644 --- a/setup/databaseScripts/create_database_V0.0.2.sql +++ b/setup/databaseScripts/create_database_V0.0.3.sql @@ -47,6 +47,7 @@ CREATE TABLE {prefix}recurrences ( month_of_year SMALLINT UNSIGNED NULL, -- Month of year (bitmap) week_of_month TINYINT UNSIGNED NULL, -- Week of the month (bitmap) day_of_week TINYINT UNSIGNED NULL, -- Day of the week (bitmap) + by_day_of_month BOOLEAN NULL, -- Flag indicating if selecting by days of the month day_of_month INTEGER UNSIGNED NULL, -- Day of the month (bitmap) last_day_of_month BOOLEAN NULL, -- Last day of the month holiday INT NULL, -- Pointer to holidays list (for future development) diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 919ea67..beeccc5 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -15,6 +15,7 @@ $glmMembersEventsDbVersions = array( '0.0.1' => array('version' => '0.0.1', 'tables' => 6), - '0.0.2' => array('version' => '0.0.2', 'tables' => 7) + '0.0.2' => array('version' => '0.0.2', 'tables' => 7), + '0.0.3' => array('version' => '0.0.3', 'tables' => 7) ); diff --git a/setup/databaseScripts/update_database_V0.0.3.sql b/setup/databaseScripts/update_database_V0.0.3.sql new file mode 100644 index 0000000..f20d3ac --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.3.sql @@ -0,0 +1,16 @@ +-- Gaslight Media Members Database - Events Add-On +-- File Created: 12/09/14 15:27:15 +-- Database Version: 0.0.2 +-- 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 by_day_of_month flag field +ALTER TABLE {prefix}recurrences ADD COLUMN by_day_of_month BOOLEAN; + + + + + diff --git a/views/admin/events/calendar.html b/views/admin/events/calendar.html index 88098d4..929bae8 100644 --- a/views/admin/events/calendar.html +++ b/views/admin/events/calendar.html @@ -6,25 +6,30 @@ --> -Place Calendar View HTML/Scripts here +
calendar goes here
-{if $haveTimes} - - {foreach $times as $v} - - Time ID: {$v.id}
- Event ID: {$v.event}
- Custom Event Data: {$v.custom_event}
- Recurrence ID: {$v.recur_id}
- Active: {$v.active}
- Start Time - timestamp: {$v.start_time.timestamp}
- Start Time - date time: {$v.start_time.datetime}
- End Time - timestamp: {$v.end_time.timestamp}
- End Time - date time: {$v.end_time.datetime}
- {$v.all_day} + \ No newline at end of file diff --git a/views/admin/events/edit.html b/views/admin/events/edit.html index 007d01e..22c78c6 100644 --- a/views/admin/events/edit.html +++ b/views/admin/events/edit.html @@ -248,21 +248,152 @@ - @@ -273,7 +404,7 @@
+ Add an Event Schedule
- - +
{if $recurrences} - {foreach $recurrences as $v} + {foreach $recurrences as $r} + + + + + + + {/foreach} + {else} + {/if} -

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
First occurrence of event
All Day Event: + +
Start Date & Time: + +
End Date & Time: + +
Event Date: + +

Date range over which recurring event can take place

From Date: + +
To Date: + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Delete this Event Schedule + When the event recurrs +
Months + + + {foreach $r.month_of_year.bitmap as $v} + {if $v.value==6} + + {/if} + + {/foreach} + +
{$v.name}  
+
 
Days of month: + Check to select specific days of the month. +
Week of the Month + + + {foreach $r.week_of_month.bitmap as $v} + + {/foreach} + +
{$v.name}  
+
Day of the Week + + + {foreach $r.day_of_week.bitmap as $v} + + {/foreach} + +
{$v.name}
+
Day of the Month + + + {foreach $r.day_of_month.bitmap as $v} + {if in_array($v.value, array(7, 14, 21, 28))} + + {/if} + + {/foreach} + + +
+ {$v.name} + + Last day of the month +
+
+
(Add event schedules here)
- {include file='admin/events/calendar.html'} +
@@ -317,54 +448,57 @@ - - + + + +

New Event Schedule

+
- + + - + + + + - - - + + - - - + + - - - + + - - + - - + @@ -373,7 +507,13 @@ + - + - + - + - +

First ocurrence of event

New ScheduleFirst ocurrence of event
All Day Event: - +
Start Date & Time: - - {if $newRecurrence.fieldFail.start_time}

{$newRecurrence.fieldFail.start_time}

{/if} +
Start Date & Time: +
End Date & Time: - - {if $newRecurrence.fieldFail.end_time}

{$newRecurrence.fieldFail.end_time}

{/if} +
End Date & Time: +
Event Date: - - {if $newRecurrence.fieldFail.start_time}

{$newRecurrence.fieldFail.start_time}

{/if} +
Event Date: + +

Date range over which recurring event can take place

From Date: - - {if $newRecurrence.fieldFail.from_date}

{$newRecurrence.fieldFail.from_date}

{/if} +
From Date: +
To Date: - - {if $newRecurrence.fieldFail.to_date}

{$newRecurrence.fieldFail.to_date}

{/if} +
To Date: +
- + + + + {/if} - + {/foreach}

When the event recurrs

+ Delete this Event Schedule + When the event recurrs +
Months @@ -383,43 +523,44 @@ {if $v.value==6}
{$v.name}   {$v.name}  
 
Select by:
Days of month:
Days of month: - Check to select specific days of the month. + Check to select specific days of the month.
Week of the Month {foreach $newRecurrence.fieldData.week_of_month.bitmap as $v} - + {/foreach}
{$v.name}   {$v.name}  
Day of the Week {foreach $newRecurrence.fieldData.day_of_week.bitmap as $v} - + {/foreach}
{$v.name} {$v.name}
Day of the Month @@ -429,11 +570,11 @@ {/if} {/foreach}
- {$v.name} + {$v.name} - Last day of the month + Last day of the month
@@ -443,12 +584,12 @@
- - -