From bc829086ca075cf2bc35cc186cd0b78e7a77fd17 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 5 Aug 2016 17:04:37 -0400 Subject: [PATCH] WIP for the event feed import Working on adding deleting the entries in the feed import table. --- classes/data/dataFeedImport.php | 171 +++++++++++++++++++++++++++++ models/admin/management/events.php | 141 +++++++----------------- views/admin/management/events.html | 46 ++++++-- 3 files changed, 244 insertions(+), 114 deletions(-) create mode 100644 classes/data/dataFeedImport.php diff --git a/classes/data/dataFeedImport.php b/classes/data/dataFeedImport.php new file mode 100644 index 0000000..4444d18 --- /dev/null +++ b/classes/data/dataFeedImport.php @@ -0,0 +1,171 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataFeedImport class + * + * PHP version 5 + * + * @category Data + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmDataFeedImport 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; + /** + * MemberInfo DB object + * + * @var $MemberInfo + * @access public + */ + public $MemberInfo; + + /** + * 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_EVENTS_PLUGIN_DB_PREFIX . 'feed_import'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Feed URL + 'feed_url' => array ( + 'field' => 'feed_url', + 'type' => 'text', + 'use' => 'a' + ), + + // Created Date + 'name' => array ( + 'field' => 'created', + 'type' => 'text', + 'use' => 'a' + ), + + // Updated Date + 'phone' => array ( + 'field' => 'updated', + 'type' => 'text', + 'use' => 'a' + ), + + ); + + } + + /* + * Entry Post Processing Call-Back Method + * + * Perform post-processing for all result entries. + * + * In this case we're using it to append an array of category + * data to each member result and also sort by member name. + * + * @param array $r Array of field result data for a single entry + * @param string $a Action being performed (l, i, g, ...) + * + * @return object Class object + * + */ + public function entryPostProcessing($r, $a) + { + return $r; + } + +} + +?> diff --git a/models/admin/management/events.php b/models/admin/management/events.php index c8e8cdb..9913a2f 100644 --- a/models/admin/management/events.php +++ b/models/admin/management/events.php @@ -17,6 +17,7 @@ require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'; require_once(GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEvents.php'); require_once(GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php'); +require_once(GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataFeedImport.php'); /** * GlmMembersAdmin_management_events @@ -181,18 +182,24 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement public function modelAction($actionData = false) { - $option = false; - $test_result = false; + $option = false; + $test_result = false; $import_result = false; - $settings_updated = false; + $settings_updated = false; $settings_update_error = false; - $event_settings = false; + $event_settings = false; + $icalFeedResult = false; + $import_feeds = false; + $option2 = false; if (isset($_REQUEST['option'])) { $option = $_REQUEST['option']; } + $importFeeds = new GlmDataFeedImport( $this->wpdb, $this->config ); + switch ($option) { + case 'timelyImport': $import = false; if (isset($_REQUEST['import'])) { @@ -201,23 +208,28 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement $import_result = $this->importFromTimely(); break; - case 'tests': - - $test = false; - if (isset($_REQUEST['test'])) { - $test = $_REQUEST['test']; + case 'icalfeed': + if ( isset( $_REQUEST['option2'] ) ) { + $option2 = filter_var( $_REQUEST['option2'], FILTER_SANITIZE_STRING ); } - - switch ($test) { - - case 'recurrence': - - $test_result = $this->testRecurrence(); - - break; - - default: - break; + $icalFeedResult = ''; + if ( $option2 === 'delete' && $feed_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) { + $this->wpdb->delete( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "feed_import", + array( 'id' => $feed_id ), + '%d' + ); + } + if ( $feed_url = filter_var( $_REQUEST['feed_url'], FILTER_VALIDATE_URL ) ) { + // Add this feed url to the table + $this->wpdb->insert( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "feed_import", + array( + 'feed_url' => $feed_url, + 'created' => current_time( 'mysql' ) + ), + '%s' + ); } break; @@ -405,14 +417,18 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement } + $import_feeds = $importFeeds->getList(); + // 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, - 'eventsSettings' => $event_settings + 'eventsSettings' => $event_settings, + 'icalFeedResult' => $icalFeedResult, ); // Return status, suggested view, and data to controller @@ -473,89 +489,6 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement } } - /** - * Test Recurrance Calculation of Dates - * - * @return test Text of test results - */ - public function testRecurrence() - { - - $res = ''; - - // Load recurrences class - require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php'; - $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config); - - // Create sample recurrence entry - $start_time = '2016/2/27 08:00:00'; - $res .= "First event start date/time: $start_time
"; - $end_time = '2016/2/28 17:00:00'; - $res .= "First event end date/time: $end_time
"; - $from_date = '2016/2/1'; - $res .= "From date: $from_date
"; - $to_date = '2017/3/31'; - $res .= "To date: $to_date
"; - - $this->wpdb->insert( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences', - array( - 'event' => 999999999, - 'start_time' => $start_time, - 'end_time' => $end_time, - 'from_date' => $from_date, - 'to_date' => $to_date, - 'all_day' => false, - 'month_of_year' => - pow(2, $this->config['month_bit']['January']) + - pow(2, $this->config['month_bit']['June']), - 'week_of_month' => - pow(2, $this->config['week_bit']['Third']) + - pow(2, $this->config['week_bit']['First']), - 'day_of_week' => - pow(2, $this->config['day_bit']['Wednesday']) + - pow(2, $this->config['day_bit']['Friday']), - 'day_of_month' => - pow(2, 1) + pow(2, 13) + pow(2, 26) + pow(2, 30), - 'last_day_of_month' => true, - 'holiday' => 0, - 'holiday_offset' => 0 - ), - array( - '%d', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d' - ) - ); - $recurID = $this->wpdb->insert_id; - if (!$recurID) { - return 'Error inserting recurrence entry!'; - } - - // Run recurrence time function - $Recurrences->optionIncludeSelectListData = false; - $times = $Recurrences->createRecurrenceTimesEntries($recurID, true, true); - - // Delete test recurrence - $this->wpdb->delete( GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences', array( 'ID' => $recurID ) ); - $this->wpdb->delete( GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'times', array( 'recur_id' => $recurID ) ); - - $res .= "

Times Entries Generated

".print_r($times,1)."
"; - - return $res; - - } - /** * addCategories * diff --git a/views/admin/management/events.html b/views/admin/management/events.html index 7f3145a..2ce6480 100644 --- a/views/admin/management/events.html +++ b/views/admin/management/events.html @@ -2,7 +2,7 @@ @@ -82,23 +82,49 @@ - - {if $testResult} - +
Return to Test List
+ {if $icalFeedResult} - {else} + {/if} + + + - {/if}
- {$testResult} + {$icalFeedResult}
- +
+ + + +
+ + +
+
+ + + + + + + + + {foreach $import_feeds as $feed} + + + + + + + + {/foreach} +
 Feed UrlCreated DateUpdated Date 
Refresh{$feed.feed_url}{$feed.created}{$feed.updated}Delete
-- 2.17.1