Setting up cloning for events.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 25 Apr 2017 16:27:54 +0000 (12:27 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 25 Apr 2017 16:27:54 +0000 (12:27 -0400)
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 [new file with mode: 0644]
models/admin/events/list.php
views/admin/events/list.html

diff --git a/classes/glmEventClone.php b/classes/glmEventClone.php
new file mode 100644 (file)
index 0000000..300ec0d
--- /dev/null
@@ -0,0 +1,158 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Clone Member Information Record
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 '<pre>$recurrences: ' . print_r( $recurrences, true ) . '</pre>';
+            //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;
+
+    }
+
+}
+
+?>
index ffccd52..3a737b3 100644 (file)
@@ -569,6 +569,27 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
 
                 break;
 
+            case 'clone':
+                //echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+                //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);
index 4f019f0..b276465 100644 (file)
@@ -76,6 +76,7 @@
                     <th>First Date</th>
                     <th>Last Date</th>
                     <th></th>
+                    <th></th>
                 </tr>
             </thead>
             <tbody>
                     <td>
                         {$e.lastDate}
                     </td>
+                    <td>
+                        <a class="button button-secondary glm-button-small glm-right" href="{$thisUrl}?page=glm-members-admin-menu-events-list&glm_action=list&member={$memberID}&option=clone&event={$e.id}">Clone</a>
+                    </td>
                     <td>
                         <a href="{$siteBaseUrl}event-detail/{$e.name_slug}/" target="_blank">View Event</a>
                     </td>