setting up the model and views
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 15 Sep 2017 19:36:06 +0000 (15:36 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 15 Sep 2017 19:36:06 +0000 (15:36 -0400)
adding base model and view files to the plugin and hooking up them

models/admin/buySell/index.php [new file with mode: 0644]
models/front/buySell/detail.php [new file with mode: 0644]
models/front/buySell/list.php [new file with mode: 0644]
setup/adminMenus.php
setup/validActions.php
views/admin/buySell/edit.html [new file with mode: 0644]
views/admin/buySell/list.html [new file with mode: 0644]
views/front/buySell/detail.html [new file with mode: 0644]
views/front/buySell/list.html [new file with mode: 0644]

diff --git a/models/admin/buySell/index.php b/models/admin/buySell/index.php
new file mode 100644 (file)
index 0000000..deeb4e0
--- /dev/null
@@ -0,0 +1,295 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Job Postings
+ *
+ * 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 Contacts data abstract
+require_once GLM_MEMBERS_BUY_SELL_PLUGIN_CLASS_PATH .'/data/dataBuySell.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH .'/data/dataMembers.php';
+
+class GlmMembersAdmin_buySell_index extends GlmDataBuySell
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Job ID
+     *
+     * @var $job ID
+     * @access public
+     */
+    public $job_id = 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 Contacts 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)
+    {
+        $members     = new GlmDataMembers($this->wpdb, $this->config);
+        $member_list = $members->getList();
+    
+        
+        $success_message    = "";
+        $haveJob            = false;
+        $option             = false;
+        $job                = false;
+        $job_data           = false;
+        $jobUpdated         = false;
+        $jobUpdateError     = false;
+        $jobAdded           = false;
+        $jobAddError        = false;
+        $view_file          = 'index';
+        $lockedToMember     = false;
+        $isModerated        = false;
+        $memberID           = false;
+        $haveMember         = false;
+        $where              = '';
+
+        // Check if there's a logged in user who is locked to their own entity
+        $lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
+        if ($lockedToMember) {
+
+            $isModerated = apply_filters('glm_user_is_moderated', $lockedToMember);
+            $memberID = $lockedToMember;
+       
+            $this->fields['admin_name']['required']  = true;
+            $this->fields['admin_email']['required'] = true;
+            $this->fields['admin_phone']['required'] = true;
+
+            // Check for Member Menu Use
+        } elseif (defined('GLM_JOB_MEMBER_MENU')) {
+
+            // Try to get member ID
+            $memberID = (isset($_REQUEST['member']) ? $_REQUEST['member'] : 0);
+
+            // If there's no valid member ID, we can't continue
+            if ($memberID == 0) {
+                return array(
+                    'status'           => false,
+                    'menuItemRedirect' => 'error',
+                    'modelRedirect'    => 'index',
+                    'view'             => 'admin/error/index.html',
+                    'data'             => array(
+                        'reason' => 'No member ID was provided.'
+                    )
+                );
+            }
+        }
+
+        // If not a valid member ID
+        if ($memberID > 0) {
+
+            // Get base member information
+            require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
+        
+            $memberData = $members->getEntry($memberID);
+            $where .= "member = $memberID";
+            if (!$memberData) {
+                return array(
+                    'status'           => false,
+                    'menuItemRedirect' => 'error',
+                    'modelRedirect'    => 'index',
+                    'view'             => 'admin/error/index.html',
+                    'data'             => array(
+                        'reason' => 'No member data found for provided member ID.'
+                    )
+                );
+            } else{
+                $haveMember = true;
+                $memberName = $memberData['name'];
+            }
+
+        }
+
+        if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') {
+            $option = $_REQUEST['option'];
+        }
+        
+        // get the Job id for use in the edit, add and delete options
+        // Get obit ID if supplied
+        if (isset($_REQUEST['job'])) {
+
+            // Make sure it's numeric
+            $this->job_id= ($_REQUEST['job'] - 0);
+
+            if ($this->job_id <= 0) {
+                $this->job_id = false;
+            }
+        }
+
+        $job_data = $this->getList($where);
+        
+//        echo '<pre>', print_r($this->getList()), '</pre>';
+        // echo '<pre>', print_r($_REQUEST), '</pre>';
+        
+        switch ($option) {
+
+            case 'add':
+                $job = $this->newEntry();
+                $view_file = 'edit';
+                
+                break;
+
+            case 'insert':
+                $job = $this->insertEntry();
+                $this->job_id = $job['fieldData']['id'];
+
+                if ($job['status']) {
+                    $haveJob = true;
+                    $jobAdded = true;
+
+                    // Update created timestamp and name slug for URLs
+                    //$this->updateSlug($this->JobID);
+
+                    // Get this again so we have the created date
+                    $job = $this->editEntry($this->job_id);
+                    
+                    $option = 'edit';
+                    $jobAdded = true;
+
+                } else {
+                    $option = 'add';
+                    $jobAddError = true;
+                }
+
+                $view_file = 'edit';
+
+                break;
+
+            case 'edit':
+                $job = $this->editEntry($this->job_id);
+                
+                // If we have a good Job
+                if ($job['status']) {
+                    $haveJob = true;
+                }
+
+                $view_file = 'edit';
+                break;
+
+            case 'update':
+                // Try to update this Job
+                $job = $this->updateEntry($this->job_id);
+      
+                // Check if that was successful
+                if ($job['status']) {
+                    $jobUpdated = true;
+
+                    $job = $this->editEntry($this->job_id);
+                } else {
+                    $jobUpdateError = true;
+                }
+
+                $haveJob = true;
+                $view_file     = 'edit';
+                
+                break;
+
+            case 'delete':
+                $job = $this->deleteEntry($this->job_id,true);
+
+                if ($job) {
+                    $jobDeleted = true;
+                } else {
+                    $jobDeleteError = true;
+                }
+                $view_file = "list";
+                $job_data = $this->getList();
+                break;
+            default:
+                $job_data = $this->getList($where);
+                $view_file = 'list';
+                break;
+        }
+//        echo '<pre>', print_r($this->getList()), '</pre>';
+        // Compile template data
+        $templateData = array(
+            'jobData'        => $job_data,
+            'memberList'     => $member_list,
+            'lockedToMember' => $lockedToMember,
+            'haveMember'     => $haveMember,
+            'memberID'       => $memberID,
+            'jobID'          => $this->job_id,
+            'haveJob'        => $haveJob,
+            'jobUpdated'     => $jobUpdated,
+            'jobUpdateError' => $jobUpdateError,
+            'jobAdded'       => $jobAdded,
+            'jobAddError'    => $jobAddError,
+            'option'         => $option,
+            'job'            => $job,
+            'assetsUrl'      => GLM_MEMBERS_BUY_SELL_PLUGIN_URL . 'assets/',
+            
+        );
+
+        // Return status, any suggested view, and any data to controller
+        return array(
+                'status' => true,
+                'modelRedirect' => false,
+                'view' => 'admin/buySell/'.$view_file.'.html',
+                'data' => $templateData
+        );
+    }
+}
diff --git a/models/front/buySell/detail.php b/models/front/buySell/detail.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/models/front/buySell/list.php b/models/front/buySell/list.php
new file mode 100644 (file)
index 0000000..e69de29
index fd9efd8..14e5d55 100644 (file)
@@ -56,7 +56,7 @@
         'Buy Sell',
         'glm_members_edit_my_entity',
         'glm-members-admin-menu-buy-sell-index',
-        function(){$this->controller('buy-sell');}
+        function(){$this->controller('buySell');}
     );
 } else {
     add_submenu_page(
@@ -64,7 +64,7 @@
         'Buy Sell',
         'Buy Sell',
         'edit_posts',
-        'glm-members-admin-menu-buy-sell-index',
-        function(){$this->controller('buy-sell');}
+        'glm-members-admin-menu-buySell-index',
+        function(){$this->controller('buySell');}
     );
 }
index ab4adb0..2c04887 100644 (file)
 
  $glmMembersBuySellAddOnValidActions = array(
     'adminActions' => array(
-        'BuySell' => array( 
+        'buySell' => array( 
             'index' => GLM_MEMBERS_BUY_SELL_PLUGIN_SLUG,
         ),
     ),
     'frontActions' => array(
-        'BuySell' => array( 
+        'buySell' => array( 
             'list' => GLM_MEMBERS_BUY_SELL_PLUGIN_SLUG,
             'detail'   => GLM_MEMBERS_BUY_SELL_PLUGIN_SLUG,
         ),
diff --git a/views/admin/buySell/edit.html b/views/admin/buySell/edit.html
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/views/admin/buySell/list.html b/views/admin/buySell/list.html
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/views/front/buySell/detail.html b/views/front/buySell/detail.html
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/views/front/buySell/list.html b/views/front/buySell/list.html
new file mode 100644 (file)
index 0000000..e69de29