WIP referred by tab
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 24 May 2018 20:35:37 +0000 (16:35 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 24 May 2018 20:35:37 +0000 (16:35 -0400)
for the edit leads page.

classes/data/dataLeadsReferredBy.php [new file with mode: 0644]
classes/data/dataReferredBy.php
models/admin/ajax/travelReferredby.php [new file with mode: 0644]
setup/validActions.php
views/admin/travel/edit.html

diff --git a/classes/data/dataLeadsReferredBy.php b/classes/data/dataLeadsReferredBy.php
new file mode 100644 (file)
index 0000000..e4e2b0f
--- /dev/null
@@ -0,0 +1,163 @@
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Data Class Leads
+ *
+ * PHP version 5.3
+ *
+ * @category Data
+ * @package  GLM Member-DB
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  SVN: $Id: dataLeads.php,v 1.0 2011/01/25 19:31:47 cscott Exp $
+ */
+
+/**
+ * GlmDataLeads class
+ *
+ * PHP version 5
+ *
+ * @category Data
+ * @package GLM Member DB
+ * @author  Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *          @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott
+ *          Exp $
+ */
+class GlmDataTravelLeadsReferredBy 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;
+
+    /**
+     * 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_TRAVEL_PLUGIN_DB_PREFIX . 'leads_referredby';
+
+        /*
+         * Table Data Fields
+         */
+
+        $this->fields = array(
+
+            'id' => array(
+                'field'     => 'id',
+                'type'      => 'integer',
+                'view_only' => true,
+                'use'       => 'a',
+            ),
+
+            'lead' => array(
+                'field'     => 'lead',
+                'type'      => 'pointer',
+                'p_table'   => GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'leads',
+                'p_field'   => 'id',
+                'p_id'      => 'id',
+                'p_orderby' => 'lname,fname',
+                'required'  => true,
+                'use'       => 'a',
+            ),
+
+            'referredby' => array(
+                'field'     => 'referredby',
+                'type'      => 'pointer',
+                'p_table'   => GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'referredby',
+                'p_field'   => 'name',
+                'p_orderby' => 'name',
+                'p_blank'   => true,
+                'required'  => true,
+                '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;
+    }
+
+}
index ce1d611..c0db7ef 100644 (file)
@@ -168,133 +168,6 @@ class GlmDataReferredBy extends GlmDataAbstract
     }
 
 
-   /**
-     * Add a category using supplied parameters
-     *
-     * @param string $name Category Name
-     * @param mixed $parent Existing Parent ID or name of parent to add
-     *
-     * @return integer ID of new category or false if failed
-     *
-     * @access public
-     */
-
-    public function addCategory($name, $parent) {
-
-        $categoryID = false;
-        $parentID = false;
-
-        // Filter new category name
-        $name = filter_var($name);
-        if ($name == false || trim($name) == '') {
-            return false;
-        }
-
-        // Determine parent supplied as an ID
-
-        $parentInt = $parent - 0;
-        if (is_int($parent) && $parentInt > 0) {
-
-            // If it's not positive, then fail
-            if ($parent <= 0) {
-                return false;
-            }
-
-            // Check that parent exists
-            $sql = "
-                SELECT COUNT(id) AS count
-                  FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
-                 WHERE id = $parent
-            ;";
-            $test = $this->wpdb->get_row($sql, ARRAY_A);
-
-            // Should be only one entry if the parent category exists
-            if ($test['count'] != 1) {
-                return false;
-            }
-
-            $parentID = $parent;
-
-        // Else check to see if parent was supplied as a name
-        } elseif ($parent != '') {
-
-            $parent = filter_var($parent);
-
-            // If the name didn't pass the filer then fail
-            if ($parent == false) {
-                return false;
-            }
-
-            // Check if the name already exists
-            $sql = "
-                SELECT id
-                  FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
-                 WHERE name = '$parent'
-            ;";
-            $parentCategory = $this->wpdb->get_row($sql, ARRAY_A);
-
-            // If we found the parent ID
-            if ($parentCategory['id']) {
-
-                // Set that as the parent ID for the new category
-                $parentID = $parentCategory['id'];
-
-            // Otherwise, try to add the parent category
-            } else {
-
-                // Add the parent as a new category
-                $sql = "
-                    INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
-                           ( name, parent )
-                    VALUES
-                           ( '".addslashes($parent)."', 0 )
-                ;";
-                $this->wpdb->query($sql);
-                $parentID = $this->wpdb->insert_id;
-
-                // Check if it didn't store properly
-                if (!$parentID) {
-                    return false;
-                }
-
-            }
-
-        // Otherwise the categroy being added has no parent
-        } else {
-            $parentID = 0;
-        }
-
-        // Check if the new category name/parent already exists
-        $sql = "
-            SELECT id
-              FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
-             WHERE name = '$name'
-               AND parent = $parentID
-        ;";
-        $existing = $this->wpdb->get_row($sql, ARRAY_A);
-
-        if ($existing['id']) {
-
-            $categoryID = $existing['id'];
-
-        } else {
-
-            // Try to add the new category
-            $sql = "
-                INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
-                       ( name, parent )
-                VALUES
-                       ( '".addslashes($name)."', $parentID )
-            ;";
-            $this->wpdb->query($sql);
-            $categoryID = $this->wpdb->insert_id;
-
-        }
-
-        return $categoryID;
-
-    }
-
     /**
      * Get categories list sorted by parent/child then alpha
      *
@@ -320,63 +193,6 @@ class GlmDataReferredBy extends GlmDataAbstract
 
     }
 
-    /**
-     * getCategoriesWithCurrentEvents
-     *
-     * Returns a list of categories ordered by name that have an event with
-     * current event times.
-     *
-     * @access public
-     * @return void
-     */
-    public function getCategoriesWithCurrentEvents()
-    {
-        $where = " T.id IN (
-        SELECT category
-          FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
-         WHERE event IN (
-                SELECT event
-                  FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
-                 WHERE active
-                   AND start_time >= NOW()
-            )
-            AND event IN (
-               SELECT id
-                 FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
-                WHERE status = 10
-            )
-        ) ";
-        $order = "T.name";
-        return $this->getList($where, $order);
-    }
-
-    /**
-     * Check other requirements
-     *
-     * When deleteing categories, check for references in sub-categories and set them to no parent.
-     *
-     */
-    function checkOther($r, $a)
-    {
-        // Required
-        parent::checkOther($r, $a);
-
-        // If there's a valid category ID
-        if (isset($r['id']) && $r['id'] > 0) {
-
-            // Set any parent references with this ID to 0
-            $sql = "
-                UPDATE ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
-                   SET parent = 0
-                 WHERE parent = ".$r['id']."
-            ;";
-            $this->wpdb->query($sql);
-
-        }
-
-        return $r;
-    }
-
     /**
      * Sort a database result array (from DataAbstract.php) by parent, child relationships
      *
diff --git a/models/admin/ajax/travelReferredby.php b/models/admin/ajax/travelReferredby.php
new file mode 100644 (file)
index 0000000..738ab45
--- /dev/null
@@ -0,0 +1,156 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load Members data abstract
+require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH . '/data/dataReferredBy.php';
+require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH . '/data/dataLeadReferredBy.php';
+
+/**
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_travelReferredBy // extends GlmDataReferredBy
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This constructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for data class
+        // parent::__construct(false, false);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This model checks to see if the credentials passed in are correct.
+     *
+     * This model action does not return, it simply does it's work then calls die();
+     *
+     * @param $actionData
+     *
+     * Output JSON string as response and does not return
+     */
+    public function modelAction( $actionData = false )
+    {
+        $return  = false;
+        $success =  true;
+
+        $option = isset($_REQUEST['option']) ? filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ) : '';
+        trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
+
+        switch ( $option ) {
+        case 'add':
+            if ( isset( $_REQUEST['id'] )
+                && isset( $_REQUEST['new_log'] )
+                && $lead_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT )
+                && $new_note = filter_var( $_REQUEST['new_log'], FILTER_SANITIZE_STRING )
+            ) {
+
+                $this->wpdb->insert(
+                    GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'lead_notes',
+                    array(
+                        'lead'    => $lead_id,
+                        'created' => date( 'Y-m-d H:i:s' ),
+                        'updated' => date( 'Y-m-d H:i:s' ),
+                        'notes'   => $new_note
+                    ),
+                    array(
+                        '%d',
+                        '%s',
+                        '%s',
+                        '%s'
+                    )
+                );
+
+            }
+            // Redirect back to the edit page
+            wp_redirect( admin_url() . 'admin.php?page=glm-members-admin-menu-glm-travel&glm_action=index&option=edit&id=' . $lead_id . '#ui-tabs-3' );
+            exit;
+            break;
+        case 'delete':
+            if ( isset( $_REQUEST['id'] )
+                && isset( $_REQUEST['note_id'] )
+                && $lead_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT )
+                && $note_id = filter_var( $_REQUEST['note_id'], FILTER_VALIDATE_INT )
+            ) {
+                $this->wpdb->delete(
+                    GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'lead_notes',
+                    array( 'lead' => $lead_id, 'id'   => $note_id ),
+                    array( '%d', '%d' )
+                );
+            }
+            // Redirect back to the edit page
+            wp_redirect( admin_url() . 'admin.php?page=glm-members-admin-menu-glm-travel&glm_action=index&option=edit&id=' . $lead_id . '#ui-tabs-3' );
+            exit;
+            break;
+        case 'list':
+        default:
+            $lead_id        = filter_var( $_REQUEST['lead_id'], FILTER_VALIDATE_INT );
+            // $allReferredBy  = $this->getList();
+            // $leadReferredBy = $this->getList( 'T.' );
+
+            $view = 'list.html';
+            break;
+        }
+
+        // Compile template data
+        $templateData = array(
+            'lead_id'  => $lead_id,
+            'notes'    => $notes,
+            'editPage' => 'glm-members-admin-menu-glm-travel',
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/ajax/referredby/'.$view,
+            'data'             => $templateData
+        );
+    }
+}
index 744dc39..d7e9f17 100644 (file)
@@ -60,9 +60,9 @@
 $glmMembersTravelAddOnValidActions = array(
     'adminActions' => array(
         'ajax' => array(
-            'travelContacts' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
-            'travelInterest' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
-            'travelNotes'    => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'travelContacts'   => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'travelReferredby' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'travelNotes'      => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
         ),
         'settings' => array(
             'referredBy' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
index 782369b..022a8b7 100644 (file)
@@ -16,7 +16,7 @@
         <li><a href="#tabs-1">Lead</a></li>
         {if isset($lead.fieldData) && isset($lead.fieldData.id)}
             <li><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=travelContacts&lead_id={$lead.fieldData.id}">Contacts</a></li>
-            <li><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=travelInterests&lead_id={$lead.fieldData.id}">Referred By</a></li>
+            <li><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=travelReferredby&lead_id={$lead.fieldData.id}">Referred By</a></li>
             <li><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=travelNotes&lead_id={$lead.fieldData.id}">Notes</a></li>
         {/if}
     </ul>