From 9f59ed384e7d8eecf9f0377a4bb86ecddf412128 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 5 May 2016 16:32:07 -0400 Subject: [PATCH] Completed specified dates selection --- classes/data/dataRecurrences.php | 72 ++++++--- index.php | 2 +- models/admin/events/list.php | 27 +++- ...0.0.16.sql => create_database_V0.0.17.sql} | 1 + setup/databaseScripts/dbVersions.php | 3 +- .../update_database_V0.0.17.sql | 9 ++ views/admin/events/edit.html | 150 +++++++++++++----- views/admin/events/editSchedule.html | 32 +++- 8 files changed, 219 insertions(+), 77 deletions(-) rename setup/databaseScripts/{create_database_V0.0.16.sql => create_database_V0.0.17.sql} (98%) create mode 100644 setup/databaseScripts/update_database_V0.0.17.sql diff --git a/classes/data/dataRecurrences.php b/classes/data/dataRecurrences.php index 0ea6051..93a0df6 100644 --- a/classes/data/dataRecurrences.php +++ b/classes/data/dataRecurrences.php @@ -206,29 +206,29 @@ class GlmDataEventsRecurrences extends GlmDataAbstract // Month of Year - multi-pick (bitmap) 'month_of_year' => array( - 'field' => 'month_of_year', - 'type' => 'bitmap', - 'bitmap' => $this->config['month'], - 'default' => 4095, // All months selected - 'use' => 'a' + 'field' => 'month_of_year', + 'type' => 'bitmap', + 'bitmap' => $this->config['month'], + 'default' => 4095, // All months selected + 'use' => 'a' ), // Week of Month - multi-pick (bitmap) 'week_of_month' => array( - 'field' => 'week_of_month', - 'type' => 'bitmap', - 'bitmap' => $this->config['week'], - 'default' => 63, // no weeks selected - 'use' => 'a' + 'field' => 'week_of_month', + 'type' => 'bitmap', + 'bitmap' => $this->config['week'], + 'default' => 63, // no weeks selected + 'use' => 'a' ), // Day of Week - multi-pick (bitmap) 'day_of_week' => array( - 'field' => 'day_of_week', - 'type' => 'bitmap', - 'bitmap' => $this->config['day'], - 'default' => 127, // no days selected - 'use' => 'a' + 'field' => 'day_of_week', + 'type' => 'bitmap', + 'bitmap' => $this->config['day'], + 'default' => 127, // no days selected + 'use' => 'a' ), // Select by Days of the Month Flag @@ -241,11 +241,11 @@ class GlmDataEventsRecurrences extends GlmDataAbstract // Day of Month - multi-pick (bitmap) 'day_of_month' => array( - 'field' => 'day_of_month', - 'type' => 'bitmap', - 'bitmap' => $this->config['day_of_month'], - 'default' => 0, // no day selected - 'use' => 'a' + 'field' => 'day_of_month', + 'type' => 'bitmap', + 'bitmap' => $this->config['day_of_month'], + 'default' => 0, // no day selected + 'use' => 'a' ), // Last Day of Month @@ -256,6 +256,21 @@ class GlmDataEventsRecurrences extends GlmDataAbstract 'use' => 'a' ), + // Specific Dates - serialized array of additional dates + 'specific_dates' => array ( + 'field' => 'specific_dates', + 'type' => 'text', + 'use' => 'gl' + ), + + // Specific Dates that will not be unserialized by post processing + 'specific_dates_unserialized' => array ( + 'field' => 'specific_dates', + 'as' => 'specified_dates_unserialized', + 'type' => 'text', + 'use' => 'gl' + ), + /* * Following included for future Holiday feature */ @@ -294,6 +309,10 @@ class GlmDataEventsRecurrences extends GlmDataAbstract */ public function entryPostProcessing($r, $a) { + if (in_array($a, array('g','l'))) { + $r['specific_dates'] = unserialize($r['specific_dates']); + } + return $r; } @@ -422,7 +441,7 @@ class GlmDataEventsRecurrences extends GlmDataAbstract // Otherwise we'll use the rest of the recurrence schedule data } else { - +echo "-------------- recurring"; // For each year in recurrence range for ($year = $fromYear ; $year <= $toYear ; $year++ ) { @@ -469,6 +488,15 @@ class GlmDataEventsRecurrences extends GlmDataAbstract } // Year + // Now add any specific dates entered by the pop-up calendar + if (is_array($recurData['specific_dates']) && count($recurData['specific_dates']) > 0) { + foreach ($recurData['specific_dates'] as $sd) { + $t = new DateTime(date('m/d/Y ', strtotime($sd)).$time); + $t->specified = true; // Mark as a specified date so it avoides the date limits below + $dates[$t->getTimestamp()] = $t; + } + } + } // Create From and to timestamp for comparison - To date is already + 1 day @@ -487,7 +515,7 @@ class GlmDataEventsRecurrences extends GlmDataAbstract foreach ($dates as $k=>$v) { // If date is within from and to range (we may not have checked this above) - if ($v >= $from && $v < $to ) { + if (($v >= $from && $v < $to) || $v->specified) { // Create text start date and time of this instance $thisStartTime = $v->format('Y/m/d H:i:s'); diff --git a/index.php b/index.php index 89e0cb8..e2e3aa0 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.16'); +define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.17'); // 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 9e33770..add2d0a 100644 --- a/models/admin/events/list.php +++ b/models/admin/events/list.php @@ -209,6 +209,8 @@ class GlmMembersAdmin_events_list extends GlmDataEvents // Check for new cities and get a table to match the submitted ID with the new city ID $newCityID = $this->checkNewCities(); + // Check for specific_dates submission + // Do selected option switch ($option) { @@ -292,6 +294,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents } + } // Update our recurrences @@ -432,14 +435,32 @@ class GlmMembersAdmin_events_list extends GlmDataEvents if ($recurID[0] == 'n') { // Add the new recurrence - $x = $Recurrences->insertEntry(true, $recurID.'_'); + $r = $Recurrences->insertEntry(true, $recurID.'_'); + $thisRecurID = $r['fieldData']['id']; // And create time entries - $Recurrences->createRecurrenceTimesEntries($x['fieldData']['id'], true, true); + $Recurrences->createRecurrenceTimesEntries($thisRecurID, true, true); // Otherwise it's an existing recurrence } else { - $Recurrences->updateEntry($recurID, 'id', true, 'Recur'.$recurID.'_'); + $r = $Recurrences->updateEntry($recurID, 'id', true, 'Recur'.$recurID.'_'); + $thisRecurID = $recurID; + } + + // Check for any specific dates and if so serialize the array sorted by date + $specDates = serialize(array()); + if (isset($_REQUEST['Recur'.$recurID.'_specDate'])) { + asort($_REQUEST['Recur'.$recurID.'_specDate']); + $specDates = serialize($_REQUEST['Recur'.$recurID.'_specDate']); + } + + // If there's any difference, then update the specific_dates field + if ($specDates != $r['fieldData']['specified_dates_unserialized']) { + $this->wpdb->query(" + UPDATE ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences + SET specific_dates = '$specDates' + WHERE id = $thisRecurID; + "); } } diff --git a/setup/databaseScripts/create_database_V0.0.16.sql b/setup/databaseScripts/create_database_V0.0.17.sql similarity index 98% rename from setup/databaseScripts/create_database_V0.0.16.sql rename to setup/databaseScripts/create_database_V0.0.17.sql index d810e2a..89432a8 100644 --- a/setup/databaseScripts/create_database_V0.0.16.sql +++ b/setup/databaseScripts/create_database_V0.0.17.sql @@ -54,6 +54,7 @@ CREATE TABLE {prefix}recurrences ( 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 + specific_dates TEXT NULL, -- Serialized array of specific dates added to the recurrence holiday INT NULL, -- Pointer to holidays list (for future development) holiday_offset TINYINT, -- Offset from holiday (from -128 to +127 days) PRIMARY KEY (id), diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 7b9bc2e..212bf88 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -27,6 +27,7 @@ $glmMembersEventsDbVersions = array( '0.0.11' => array('version' => '0.0.11', 'tables' => 7), '0.0.12' => array('version' => '0.0.12', 'tables' => 7), '0.0.15' => array('version' => '0.0.15', 'tables' => 7, 'date' => '4/11/2016'), - '0.0.16' => array('version' => '0.0.16', 'tables' => 7, 'date' => '4/11/2016') + '0.0.16' => array('version' => '0.0.16', 'tables' => 7, 'date' => '4/11/2016'), + '0.0.17' => array('version' => '0.0.17', 'tables' => 7, 'date' => '5/5/2016') ); diff --git a/setup/databaseScripts/update_database_V0.0.17.sql b/setup/databaseScripts/update_database_V0.0.17.sql new file mode 100644 index 0000000..11cb741 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.17.sql @@ -0,0 +1,9 @@ +-- Gaslight Media Members Database - Events Add-On +-- Database Version: 0.0.12 +-- 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 a specific dates field to recurrences +ALTER TABLE {prefix}recurrences ADD COLUMN specific_dates TEXT; diff --git a/views/admin/events/edit.html b/views/admin/events/edit.html index 2e00c78..1123e9e 100644 --- a/views/admin/events/edit.html +++ b/views/admin/events/edit.html @@ -69,6 +69,9 @@
+

+ NOTE: This calendar does not show changes you have made until you have + clicked on the "Update Event" button to save your changes. @@ -205,7 +208,8 @@ // alert('Event: ' + calEvent.title); $("#occurrences").dialog(); $(this).css('border-color', 'red'); - }, + } +/* , dayClick: function(date, allDay, jsEvent, view) { if (allDay) { @@ -228,6 +232,7 @@ } +*/ {/if} }); @@ -484,7 +489,6 @@ $('.start-time-only-checkbox').click( function() { startTimeOnlySetup(); }); -// startTimeOnlySetup(); } startTimeOnlyInit(); @@ -493,6 +497,7 @@ recurID = $(this).attr('data-id'); if ($("#recurringEvent_" + recurID)[0].checked) { $("#recurringExclude_" + recurID).removeClass('glm-hidden'); +// initCalendars(); } else { $("#recurringExclude_" + recurID).addClass('glm-hidden'); } @@ -526,78 +531,137 @@ $('#' + tableID + ' input:checkbox').attr('checked', false); }); + initCalendars(); + + } // Init Recurrence + + + // Initialize specific date selection calendards + function initCalendars() { + // Initialize Calendar for date selection + var renderedExistingEvents = 0; $('.recur-calendar').on('click', function() { recurID = $(this).attr('data-id'); - + recurName = $('#recurSchedName_' + recurID).val(); + if (recurName == undefined || recurName == '') { recurName = '(no schedule name)'; } $('#recurCalendarDialog_' + recurID).attr('title', 'Select Dates for ' + recurName); - + $('#recurCalendarDialog_' + recurID).dialog({ position: { my: 'top+75', of: '#recurSpecDates_' + recurID}, minWidth: 600 }); // Color to change calendar cell to (in rgb so it compares to our test below) var calClickColor = 'rgb(173, 216, 230)'; - $('#recurCalendar_' + recurID).fullCalendar({ + var newCalEventID = 0; + + var thisCal = $('#recurCalendar_' + recurID).fullCalendar({ header : { left: 'title', center: '', right: 'today prevYear,prev,next,nextYear', }, - events: [ - // Place existing manually entered calendar dates here from template data - ], + events: [], + editable: true, + eventStartEditable: false, height : 350, -// defaultDate : '{$firstTime.start_time.datetime}', + // defaultDate : '{$firstTime.start_time.datetime}', timeFormat : 'h:mma', fixedWeekCount : false, + + eventAfterAllRender: function(view) { + + // Since this will be called again when we add the events below, + // we have to detect if it's a second call + if (renderedExistingEvents != recurID) { + renderedExistingEvents = recurID; + + // Collect specified dates for this recurrence + $('.recur-spec-date-' + recurID).each(function() { + var date = $(this).val(); + var dateID = $(this).attr('data-id'); + + var e = { + id: dateID, + start: date, + title: 'Selected' + }; + $('#recurCalendar_' + recurID).fullCalendar( 'renderEvent', e, true); + + }); + } + }, + + // Event handler for when a date is clicked dayClick: function(date, allDay, jsEvent, view) { - c = $(this).css('background-color'); - var e = { - start: date, - title: 'New Date' - }; - if (c != calClickColor) { - $(this).css('background-color', calClickColor); + + var dateHasEvent = false; + + // Check if there's an event for this date + thisCal.fullCalendar('clientEvents', function (event) { + if (moment(event.start).isSame(date, 'day')) { + + // Say that we had an event already + dateHasEvent = true; + + // Remove the event from the calendar + thisCal.fullCalendar( 'removeEvents', event.id); + + // Remove the event from the selected dates list + $('#recurSpecDate_' + recurID + '_' + event.id).remove(); + + } + }); + + // If there wasn't an event already, add one now + if (!dateHasEvent) { + + // Create event for this date + var e = { + id: ++newCalEventID, + start: date, + title: 'Selected' + }; + + // Add an event to this date + thisCal.fullCalendar( 'renderEvent', e, true); + + // Add this edate to our selected dates list $('#recurSpecDates_' + recurID).append( - '' + date.format() + '' + '' + date.format() + '' ); - } else { - $('#recurSpecDate_' + recurID).remove(); - $(this).css('background-color', 'transparent'); + } - }, - viewRender:(function() { + + glmPageUpdateRequired(); - var lastViewName; - return function(view, element) { - - if(view.name === 'agendaDay' && lastViewName != view.name) { - - var newEvent = { - start: element.date, - title: 'My test meeting' - }; - $('#calendar').fullCalendar( 'renderEvent', newEvent); - } - - lastViewName = view.name; - } - })() + }, - }); - }); - + // Event handler for when an event is clicked + eventClick: function(calEvent, jsEvent, view) { + + var id = calEvent.id; + + // Remove the event from the calendar + thisCal.fullCalendar( 'removeEvents', id); + + // Remove the event from the selected dates list + $('#recurSpecDate_' + recurID + '_' + id).remove(); + + glmPageUpdateRequired(); + + } + }); // fullCalendar + }); // Click on "Show Calendar" - - } - + } + /* * Category Selection */ diff --git a/views/admin/events/editSchedule.html b/views/admin/events/editSchedule.html index 7491331..152cc06 100644 --- a/views/admin/events/editSchedule.html +++ b/views/admin/events/editSchedule.html @@ -146,17 +146,29 @@ +   Select with Calendar

Show Calendar
-

Click on Dates to select/remove those dates for this schedule.

+

Click on Dates to select/remove those dates for this schedule.

-

Save

+

+ NOTE: This calendar only shows these specific dates and does not include other dates from the schedule. + See the Summary Calendar to view all dates for this event. +

- Use to add specific dates to the schedule. Does not show other scheduled dates.
-

+ Use to add/delete specific dates to the schedule. +

+ + {$ncei = 1000} + {foreach $r.specific_dates as $sd} + {$sd} + {$ncei = $ncei+1} + {/foreach} + +

@@ -190,7 +202,7 @@ Schedule Name: - + @@ -318,6 +330,7 @@ +   Select with Calendar @@ -325,9 +338,14 @@

Click on Dates to select/remove those dates for this schedule.

-
Done
+

+ NOTE: This calendar only shows these specific dates and does not include other dates from the schedule. + See the Summary Calendar to view all dates for this event. +

- Use to add specific dates to the schedule. Does not show other scheduled dates. + Use to add/delete specific dates to the schedule. + + -- 2.17.1