Adding more functianality to site plugins.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 9 Oct 2019 20:55:47 +0000 (16:55 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 9 Oct 2019 20:55:47 +0000 (16:55 -0400)
Working on adding site plugin records.

models/admin/ajax/pluginListSites.php [new file with mode: 0644]
models/admin/plugins/plugins.php
setup/validActions.php
views/admin/plugins/plugin-detail.html
views/admin/plugins/plugin-site.html

diff --git a/models/admin/ajax/pluginListSites.php b/models/admin/ajax/pluginListSites.php
new file mode 100644 (file)
index 0000000..23b6a45
--- /dev/null
@@ -0,0 +1,99 @@
+<?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
+ */
+
+require_once GLM_MEMBERS_PLUGINS_PLUGIN_CLASS_PATH.'/data/dataSites.php';
+/**
+ * Steve Note
+ *
+ * You can get to this using the following URL.
+ *
+ *
+ {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runQueue
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+// Load Members data abstract
+// require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.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_pluginListSites extends GlmDataSites
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        parent::__construct( false, false );
+
+    }
+
+    public function modelAction( $actionData = false ) {
+
+        // $where  = "T.prod_server = 2"; // norax
+        $where  = "T.prod_server = 1"; // eleusis
+        $where .= "
+            AND T.id IN (SELECT site
+                           FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "site_plugins
+                          WHERE plugin = 7)
+        ";
+
+        $config = array(
+            'order' => 'name',
+            'where' => $where,
+        );
+
+        $sites = $this->getResults( $config );
+
+        $siteOut = array();
+        foreach ( $sites as $site ) {
+            $siteOut[] = $site['prod_url'];
+        }
+        echo implode( "\n", $siteOut );
+
+        exit;
+    }
+}
index f8c39f2..232ab75 100644 (file)
@@ -142,6 +142,12 @@ class GlmMembersAdmin_plugins_plugins extends GlmDataPlugins
                         )
                     );
                     $tData['sitePlugin'] = $SitePlugins->editEntry( $sitePluginId );
+                    $tData['newEntry']   = false;
+                } else {
+                    // Get plugin name.
+                    $tData['pluginName'] = $this->wpdb->get_var( "SELECT name FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "plugins WHERE id = $id" );
+                    $tData['sitePlugin'] = $SitePlugins->newEntry();
+                    $tData['newEntry']   = true;
                 }
             }
             break;
@@ -157,6 +163,12 @@ class GlmMembersAdmin_plugins_plugins extends GlmDataPlugins
                 $sitePlugin = $SitePlugins->updateEntry( $id );
             }
 
+        case 'addPluginSite':
+            $SitePlugins = new GlmDataSitePlugin( $this->wpdb, $this->config );
+            if ( !isset( $_REQUEST['id'] ) ) {
+                $sitePlugin = $SitePlugins->insertEntry();
+            }
+
         case 'view':
             $view    = 'plugin-detail';
             $orderBy = 'S.name';
index f08a238..7798060 100644 (file)
@@ -59,6 +59,9 @@
 
 $glmMemberPluginsAddOnValidActions = array(
     'adminActions' => array(
+        'ajax' => array(
+            'pluginListSites' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
+        ),
         'plugins' => array(
             'index' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
             'plugins' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
index e31ad5d..79031ce 100644 (file)
@@ -89,6 +89,7 @@
 {* Form End *}
 {include file='ui/f6/form-end.html'}
 
+
 <style>
     .row-green {
         background-color: rgb( 225, 250, 234 );
 {$baseUrl = "{$thisUrl}?page={$thisPage}&glm_action={$thisAction}&option=view&plugin_id={$plugin.fieldData.id}"}
 {$SitePluginUrl = "{$thisUrl}?page={$thisPage}&glm_action={$thisAction}plugin_id={$plugin.fieldData.id}"}
 
+<a class="button primary" href="{$baseUrl}&option=pluginSite{if !empty($smarty.request.order)}&order={$smarty.request.order}{/if}">Add Site</a>
+
 {if !empty($sites)}
     <table class="stack hover">
         <tr>
index c7550b0..2824de2 100644 (file)
@@ -2,7 +2,11 @@
 
 {* Header *}
 {include file="admin/header.html"}
-<h3> {$sitePlugin.fieldData.site.name} - {$sitePlugin.fieldData.plugin.name} </h3>
+{if $newEntry}
+    <h3> New Site - {$pluginName} </h3>
+{else}
+    <h3> {$sitePlugin.fieldData.site.name} - {$sitePlugin.fieldData.plugin.name} </h3>
+{/if}
 
 {* Grid Start *}
 {$ui = [
     {$data = $sitePlugin}
 
     <input type="hidden" name="glm_action" value="plugins">
-    <input type="hidden" name="option" value="savePluginSite">
-    <input type="hidden" name="id" value="{$data.fieldData.id}">
-    <input type="hidden" name="plugin_id" value="{$data.fieldData.plugin.value}">
-    <input type="hidden" name="plugin" value="{$data.fieldData.plugin.value}">
-    <input type="hidden" name="site" value="{$data.fieldData.site.value}">
+    {if $newEntry}
+        <input type="hidden" name="option" value="addPluginSite">
+        <input type="hidden" name="plugin_id" value="{$smarty.request.plugin_id}">
+        <input type="hidden" name="plugin" value="{$smarty.request.plugin_id}">
+
+        {* Site *}
+        {$ui = [
+            'value'     => $data.fieldData.site.value,
+            'field'     => 'site',
+            'label'     => 'Site',
+            'list'      => $data.fieldData.site.list,
+            'l_label'   => 'name',
+            'l_value'   => 'value',
+            'l_blank'   => false,
+            'required'  => $data.fieldRequired.site,
+            'errorText' => 'Site is Required',
+            'dataError' => $data.fieldFail.site
+        ]}
+        {include file='ui/f6/select.html'}
+
+    {else}
+        <input type="hidden" name="option" value="savePluginSite">
+        <input type="hidden" name="id" value="{$data.fieldData.id}">
+        <input type="hidden" name="plugin_id" value="{$data.fieldData.plugin.value}">
+        <input type="hidden" name="plugin" value="{$data.fieldData.plugin.value}">
+        <input type="hidden" name="site" value="{$data.fieldData.site.value}">
+    {/if}
     {if !empty($smarty.request.order)}
         <input type="hidden" name="order" value="{$smarty.request.order}">
     {/if}