adding newspaper settings data class, model and view. added admin.css file.
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 28 Feb 2017 18:41:35 +0000 (13:41 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 28 Feb 2017 18:41:35 +0000 (13:41 -0500)
new, update and delete functions for newspapers added

classes/data/dataNewspapers.php [new file with mode: 0644]
classes/data/dataObits.php
css/admin.css [new file with mode: 0644]
models/admin/settings/newspapers.php [new file with mode: 0644]
setup/adminTabs.php
setup/validActions.php
views/admin/settings/newspapers.html [new file with mode: 0644]

diff --git a/classes/data/dataNewspapers.php b/classes/data/dataNewspapers.php
new file mode 100644 (file)
index 0000000..1aab57c
--- /dev/null
@@ -0,0 +1,173 @@
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Data Class Management
+ *
+ * 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: dataObitss.php,v 1.0 2011/01/25 19:31:47 cscott Exp $
+ */
+
+/**
+ * GlmNewspapersclass
+ *
+ * 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 GlmDataNewspapers 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_OBITS_PLUGIN_DB_PREFIX . 'newspapers';
+
+        /*
+         * Table Data Fields
+         */
+
+        $this->fields = array (
+
+            'id' => array (
+                'field'     => 'id',
+                'type'      => 'integer',
+                'view_only' => true,
+                'use'       => 'a'
+            ),
+
+            'name' => array(
+                'field'    => 'name',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a',
+            ),
+         );
+    }
+
+    /*
+     * Entry Post Processing Call-Back Method
+     *
+     * Perform post-processing for all result entries.
+     *
+     * @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;
+    }
+
+
+    /**
+     * Get ID/Name list
+     *
+     * @param string $where
+     *
+     * @return array ID/Name pairs
+     */
+    public function getIdName($where = 'true')
+    {
+        $savedFields = $this->fields;
+
+        $this->fields = array(
+            'id' => $savedFields['id'],
+            'name' => $savedFields['name']
+        );
+
+        $r = $this->getList($where);
+
+        $this->fields = $savedFields;
+        return $r;
+
+    }
+
+}
\ No newline at end of file
index 0b4fe5b..cd668bf 100644 (file)
@@ -212,8 +212,10 @@ class GlmDataObits extends GlmDataAbstract
 
             'newspaper' => array(
                 'field'    => 'newspaper',
-                'type'     => 'text',
-                'required' => true,
+                'type' => 'pointer',
+                    'p_table' => GLM_MEMBERS_OBITS_PLUGIN_DB_PREFIX . 'newspapers',
+                    'p_field' => 'name',
+                    'p_orderby' => 'name',
                 'use'      => 'a',
             ),
 
diff --git a/css/admin.css b/css/admin.css
new file mode 100644 (file)
index 0000000..3ddcfb8
--- /dev/null
@@ -0,0 +1,3 @@
+.newspaper-record{
+    float: left;
+}
\ No newline at end of file
diff --git a/models/admin/settings/newspapers.php b/models/admin/settings/newspapers.php
new file mode 100644 (file)
index 0000000..dc7c0a9
--- /dev/null
@@ -0,0 +1,152 @@
+
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Obits Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Obits data abstract
+require_once GLM_MEMBERS_OBITS_PLUGIN_CLASS_PATH.'/data/dataNewspapers.php';
+
+class GlmMembersAdmin_settings_newspapers extends GlmDataNewspapers
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Obit ID
+     *
+     * @var $obitID
+     * @access public
+     */
+    public $obitID = false;
+
+    /**
+     * Constructor
+     *
+     * This contructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     * @wpdb object WordPress database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        /*
+         * Run constructor for the Obits data class
+         *
+         * Note, the third parameter is a flag that indicates to the Contacts
+         * data class that it should flag a group of fields as 'view_only'.
+         */
+        parent::__construct(false, false, true);
+
+    }
+
+    public function modelAction($actionData = false)
+    {
+
+        $numbObits       = 0;
+        $namesList       = false;
+        
+        // Check if an ID is supplied
+        $id = 0;
+        if ( isset( $_REQUEST['id'] ) ) {
+            $id = $_REQUEST['id'] - 0;
+            echo $id;
+        }
+        // If there's an action option
+        if ( isset( $_REQUEST['option'] ) ) {
+            switch( $_REQUEST['option'] ) {
+                
+                case 'addNew':
+                    $return = $this->insertEntry();
+                    $id = $return['fieldData']['id'];
+                    print_r($return);
+                    break;
+
+                case 'update':
+                    echo $_REQUEST['option'];
+                    if ( $id > 0 ) {
+                        $this->updateEntry( $id );
+                    }
+                    echo "no id";
+                    break;
+
+                case 'delete':
+                    echo $_REQUEST['option'];
+                    if ( $id > 0 ) {
+                        $this->deleteEntry( $id, true );
+                    }
+                    break;
+
+                default:
+                    $option2 = false;
+                    break;
+
+            }
+        }
+
+        // Get number of obits
+
+        $newspapers = $this->getList();
+
+        // Compile template data
+        $templateData = array(
+            'newspapers'      => $newspapers,
+        );
+             // Return status, any suggested view, and any data to controller
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => 'admin/settings/newspapers.html',
+            'data'          => $templateData
+        );
+
+    }
+
+
+}
index 591082e..a0088bf 100644 (file)
  * );
  *
  */
+if (current_user_can('glm_members_members')) {
+    if (apply_filters('glm_members_permit_admin_members_newspapers_tab', true)) {
+
+        add_filter('glm-member-db-add-tab-for-settings',
+            function($addOnTabs) {
+                $newTabs = array(
+                    array(
+                        'text'   => 'Newspapers',
+                        'menu'   => 'settings',
+                        'action' => 'newspapers'
+                    ),
+
+                );
+                $addOnTabs = array_merge($addOnTabs, $newTabs);
+                return $addOnTabs;
+            }
+        );
+
+    }
+}
+
 
index 999cc5e..d496f24 100644 (file)
@@ -63,6 +63,9 @@ $glmMembersObitsAddOnValidActions = array(
             'index' => GLM_MEMBERS_OBITS_PLUGIN_SLUG,
             'list'  => GLM_MEMBERS_OBITS_PLUGIN_SLUG,
         ),
+        'settings' => array(
+            'newspapers' => GLM_MEMBERS_OBITS_PLUGIN_SLUG,
+        ),
     ),
     'frontActions' => array(
     )
diff --git a/views/admin/settings/newspapers.html b/views/admin/settings/newspapers.html
new file mode 100644 (file)
index 0000000..91d5490
--- /dev/null
@@ -0,0 +1,166 @@
+{include file='admin/management/header.html'}
+
+<h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+    <a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=newspapers" class="glm-settings-tab nav-tab nav-tab-active">Newspapers</a>
+</h2>
+<table class="glm-admin-table glm-settings-table" style="width: 90%;">
+    <tr><td colspan="2">
+        <!-- Add Registration Payment Code Button and Dialog Box -->
+        <div id="newNewspaperButton" class="button button-primary glm-right">Add Newspaper</div>
+        <div id="newNewspaperDialog" class="glm-dialog-box" title="Ener a Newspaper">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                <input type="hidden" name="glm_action" value="newspapers">
+                <input type="hidden" name="option" value="addNew">
+
+                <!-- This is only temporary until we reinstate the "Used With" selection below -->
+                <table class="glm-admin-table">
+                    <tr>
+                        <th class="glm-required">Newspaper Name: </th>
+                        <td>
+                            <input id="edit-name" data-id="code" type="text" name="name" class="glm-form-text-input">
+                        </td>
+                    </tr>
+                </table>
+                <p><span class="glm-required">*</span> Required</p>
+                <a id="newNewspaperCancel" class="button button-primary glm-right">Cancel</a>
+                <input type="submit" value="Add new Newspaper" class="button button-primary">
+                
+            </form>
+        </div>
+
+        <!-- Delete Newspaper Button -->
+        <div id="deleteNewspaperDialog" class="glm-dialog-box" title="Delete Newspaper">
+            <center>
+                <p>Are you sure you want to delete this Newspaper?</p>
+                <p><div id="deleteNewspaperConfirm" class="button button-primary">Yes, delete this Newspaper</div></p>
+                <p><div id="deleteNewspaperCancel" class="button button-primary">Cancel</div></p>
+            </center>
+        </div>
+
+        <!-- Edit Registration Payment Code Dialog Box -->
+        <div id="editNewspaperDialog" class="glm-dialog-box" title="Edit This Newspaper">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                <input type="hidden" name="glm_action" value="newspapers">
+                <input type="hidden" name="option" value="update">
+                <input id="editNewspaperID" type="hidden" name="id" value="">
+
+                <!-- This is only temporary until we reinstate the "Used With" selection below -->
+                <table class="glm-admin-table">
+                      <tr>
+                        <th class="glm-required">Newspaper Name:</th>
+                        <td>
+                            <input id="edit-name" data-id="name" type="text" name="name" class="glm-form-text-input">
+                        </td>
+                    </tr>
+                    <tr>
+                </table>
+                <p><span class="glm-required">*</span> Required</p>
+                <a id="editNewspaperCancel" class="button button-primary glm-right">Cancel</a>
+                <input type="submit" value="Update this Newspaper">
+
+            </form>
+        </div>
+
+        <table class="wp-list-table wideFat fixed posts glm-admin-table" style="width: 90%;">
+            <thead>
+                <tr>
+                    <th> Newspaper Name </th>
+                    <th>&nbsp;</th>
+                </tr>
+            </thead>
+            <tbody>
+               
+            {if $newspapers}
+                {assign var="i" value="0"}
+                {foreach $newspapers as $n}
+                    {if $i++ is odd by 1}
+                        <tr>
+                    {else}
+                        <tr class="alternate">
+                    {/if}
+                            <td>
+                                <div class="newspaper-record" id="newspaper_{$n.id}" data-newspaperID="{$n.id}" >{$n.name}</div>
+                                <div class="editNewspaperButton editNewspaper button button-secondary glm-button-small glm-right" data-newspaperID="{$n.id}">Edit</div> 
+                                <div class="deleteNewspaperButton button button-secondary glm-button-small glm-right" data-newspaperID="{$n.id}">Delete</div>
+                            </td>
+                        </tr>
+                  
+                {/foreach}
+            {else}
+                <tr class="alternate"><td colspan="2">(no newspapers listed)</td></tr>
+            {/if}
+            </tbody>
+        </table>
+    </tr>
+</table>
+
+<script type="text/javascript">
+    jQuery(document).ready(function($) {
+
+        $("#newNewspaperDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+        $("#editNewspaperDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+        $("#deleteNewspaperDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+
+        $('#newNewspaperButton').click( function() {
+            $("#newNewspaperDialog").dialog("open");
+        });
+        $('.editNewspaper').click( function() {
+            var newspaperID        = $(this).attr('data-newspaperID');
+
+            $('#editNewspaperID').val(newspaperID);
+
+            $("#editNewspaperDialog").dialog("open");
+        });
+        $('#editNewspaperCancel').click( function() {
+            $("#editNewspaperDialog").dialog("close");
+        });
+        $('#newNewspaperCancel').click( function() {
+            $("#newNewspaperDialog").dialog("close");
+        });
+
+        var id = false;
+        $('.deleteNewspaperButton').click( function() {
+            id = $(this).attr('data-newspaperID');
+            $("#deleteNewspaperDialog").dialog("open");
+        });
+        $('#deleteNewspaperConfirm').click( function() {
+            $("#deleteNewspaperDialog").dialog("close");
+            window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=newspapers&option=delete&id=" + id;
+        });
+        $('#deleteNewspaperCancel').click( function() {
+            $("#deleteNewspaperDialog").dialog("close");
+        });
+
+        /*
+         * Edit area tabs
+         */
+        $('.glm-settings-tab').click( function() {
+
+            // Clear tabl highlights and hide all tables
+            $('.glm-settings-tab').removeClass('nav-tab-active');
+            $('.glm-settings-table').addClass('glm-hidden');
+
+            // Highlight selected tab
+            $(this).addClass('nav-tab-active');
+
+            // Show selected table
+            var table = $(this).attr('data-show-table');
+            $('#' + table).removeClass('glm-hidden');
+
+        });
+
+    });
+</script>
+