From ca6c0c8e77dad4b3ace180737691a2e9e7772d37 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 25 Apr 2017 12:27:54 -0400 Subject: [PATCH] Setting up cloning for events. The member db has an update now that allows the files for the events to be cloned when the event is cloned. --- classes/glmEventClone.php | 158 +++++++++++++++++++++++++++++++++++ models/admin/events/list.php | 21 +++++ views/admin/events/list.html | 4 + 3 files changed, 183 insertions(+) create mode 100644 classes/glmEventClone.php diff --git a/classes/glmEventClone.php b/classes/glmEventClone.php new file mode 100644 index 0000000..300ec0d --- /dev/null +++ b/classes/glmEventClone.php @@ -0,0 +1,158 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release glmMemberInfoClone.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * This class provides facilities for cloning a complete event + * record including all associated information and images. + * + */ +class GlmEventClone +{ + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + + /** + * Constructor + * + * Clone a event record and anything associated with it + * to create a new complete event information record that is identical + * to the source except that it is set to "pending". + * + * @param object $wpdb Word Press database object + * @param array $config Configuration data + * @param integer $eventInfoID ID of the event info record to clone + * + * @return integer ID of the new cloned event information record + * @access public + **/ + function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + /* + * Clone Member Info + * + * @param integer $id ID of event to clone + * + * @return void + * @access public + */ + public function cloneEvent( $id ) + { + + // Load Member Info Data Class and get info data for later use + require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEvents.php'; + $Event = new GlmDataEvents( $this->wpdb, $this->config ); + $event = $Event->getEntry( $id ); + + // Create a new event record and get its ID - this also copies images to a new name + $newID = $Event->cloneEntry( $id ); + + // If the clone was successful + if ($newID != false) { + // Load recurrences data class to get a blank entry for the template + require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php'; + $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config); + + // Update create and update times to now and set event record to pending + $t = date( 'Y-m-d H:i:s', time() ); + $newReferenceName = "CLONED - ".$event['name']; + $sql = " + UPDATE ".$Event->table." + SET created = '$t', updated = '$t', status = ".$this->config['status_numb']['Pending'].", name = '".addslashes($newReferenceName)."' + WHERE id = $newID + ;"; + $this->wpdb->query( $sql ); + + // Duplicate all event_categories table entries + $sql = " + INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."event_categories + (category,event) + SELECT category, $newID + FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."event_categories + WHERE event = $id + ;"; + + $this->wpdb->query( $sql ); + + // Duplicate the locations + $sql = " + INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."locations + (event,name,address,city,state,zip,country,lat,lon,region,phone,url,email,contact_addon_id) + SELECT $newID,name,address,city,state,zip,country,lat,lon,region,phone,url,email,contact_addon_id + FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."locations + WHERE event = $id + "; + $this->wpdb->query( $sql ); + + // Duplicate the recurrences + $sql = " + INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."recurrences + (event,name,start_time,start_time_only,end_time,all_day,start_date,from_date,to_date,recurring,month_of_year, + week_of_month,day_of_week,by_day_of_month,day_of_month,specific_dates,holiday,holiday_offset) + SELECT $newID,name,start_time,start_time_only,end_time,all_day,start_date,from_date,to_date,recurring,month_of_year, + week_of_month,day_of_week,by_day_of_month,day_of_month,specific_dates,holiday,holiday_offset + FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."recurrences + WHERE event = $id + "; + $this->wpdb->query( $sql ); + // Duplicate the times + // Update our recurrences + $recurrences = $Recurrences->getList( "T.event = " . $newID ); + //echo '
$recurrences: ' . print_r( $recurrences, true ) . '
'; + //exit; + + // Check for any updated recurrences + if ( isset( $recurrences ) && count( $recurrences ) > 0 ) { + foreach ( $recurrences as $r ) { + + // If we have a recurID as a value, then update this recurrence times + if ( isset( $r['id'] ) ) { + $Recurrences->createRecurrenceTimesEntries( $r['id'], true, true ); + } + } + } + + + } + + return $newID; + + } + +} + +?> diff --git a/models/admin/events/list.php b/models/admin/events/list.php index ffccd52..3a737b3 100644 --- a/models/admin/events/list.php +++ b/models/admin/events/list.php @@ -569,6 +569,27 @@ class GlmMembersAdmin_events_list extends GlmDataEvents break; + case 'clone': + //echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + //exit; + // Load Event Clone Class + require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/glmEventClone.php'; + $ClonedEvent = new GlmEventClone( $this->wpdb, $this->config ); + + // Clone the current event + $this->eventID = $ClonedEvent->cloneEvent( $this->eventID ); + + // Update the name slug for this event + $this->updateSlug( $this->eventID ); + + // Reset the editEntry for this new event + $event = $this->editEntry( $this->eventID ); + + // Set the view file + $view = 'edit'; + $haveEvent = true; + break; + case 'delete': $event = $this->deleteEvent($this->eventID); diff --git a/views/admin/events/list.html b/views/admin/events/list.html index 4f019f0..b276465 100644 --- a/views/admin/events/list.html +++ b/views/admin/events/list.html @@ -76,6 +76,7 @@ First Date Last Date + @@ -113,6 +114,9 @@ {$e.lastDate} + + Clone + View Event -- 2.17.1