adding index and list models / views and valid actions
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 9 Mar 2018 15:32:37 +0000 (10:32 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 9 Mar 2018 15:32:37 +0000 (10:32 -0500)
setting up the front end actions, models and views for assets

models/front/assets/index.php
models/front/assets/list.php [new file with mode: 0644]
setup/validActions.php
views/front/assets/list.html [new file with mode: 0644]

index 3ac00fa..c06e23b 100644 (file)
@@ -1,8 +1,119 @@
 <?php
 
-/* 
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
+/*
+ * This class determines which assets page to run
+ * then calls it and returns the result back to the controller.
+ *
  */
+class GlmMembersFront_assets_index
+{
+    /**
+    * WordPress Database Object
+    *
+    * @var $wpdb
+    * @access public
+    */
+    public $wpdb;
+    /**
+    * Plugin Configuration Data
+    *
+    * @var $config
+    * @access public
+    */
+    public $config;
 
+    /*
+     * Constructor
+     *
+     * This contractor sets up this model. At this time that only includes
+     * storing away the WordPress data object and GLM associate plugin configuration array.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This method determines which assets page is requested, loads and runs that
+     * model, then returns the result array back to the controller.
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successful and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller 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.
+     *
+     */
+    public function modelAction($actionData = false)
+    {
+        global $wp_scripts;
+        $page = false;
+        $ui = $wp_scripts->query('jquery-ui-core');
+        wp_enqueue_style(
+            'jquery-ui-smoothness',
+            "//ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.min.css",
+            false,
+            null
+        );
+
+        // Check for valid page - if not valid default to "list"
+        $page = (isset($actionData['request']['page']) ? $actionData['request']['page']: "list");
+        if (!$page && isset( $_REQUEST['page'] ) && trim($_REQUEST['page']) != '') {
+            $page = trim($_REQUEST['page']);
+        }
+
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            trigger_error("Sub-controller Page: $page ", E_USER_NOTICE);
+        }
+
+        // Load the specified model
+        $pageFile = GLM_MEMBERS_ASSETS_PLUGIN_PATH.'/models/front/assets/'.$page.'.php';
+        require_once $pageFile;
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            trigger_error("Sub-Controller Model: $pageFile", E_USER_NOTICE);
+        }
+
+        // load and run the model
+        $assetsClass = 'GlmMembersFront_assets_'.$page;
+        $assetsModel = new $assetsClass($this->wpdb, $this->config);
+        $assetsResult = $assetsModel->modelAction($actionData);
+
+        return $assetsResult;
+
+    }
+ }
diff --git a/models/front/assets/list.php b/models/front/assets/list.php
new file mode 100644 (file)
index 0000000..f17cc7d
--- /dev/null
@@ -0,0 +1,194 @@
+<?php
+ require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataAssetItems.php';
+
+ class GlmMembersFront_assets_list extends GlmDataAssetsAssetItems {
+    /**
+    * 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 the Registrations 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);
+    }
+
+    /**
+     * Constructor
+     *
+     * This contructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successful and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller 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 modelAction($actionData = false)
+    {
+        $start          = 1;
+        $limit          = 20;
+        $where          = '';
+        $alphaWhere     = '';
+        $alphaList      = '';
+        $paging         = '';
+        $nextStart      = '';
+        $alphaSelected  = false;
+        $haveAssetsCount  = false;
+        $assetsCount = false;
+
+        // Start by checking if we need to purge any old data - Once per hour
+//        $lastPurgeTime = get_option('glmMembersRegistrationsPluginLastPurgeTime');
+//        if (!$lastPurgeTime && (time() - $lastPurgeTime) > 3600) {
+//
+//            // Update last purge time to stop any other users from triggering this
+//            update_option('glmMembersRegistrationsPluginLastPurgeTime', time());
+//
+//            // Call purge method
+//            require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/regCartSupport.php';
+//            $CartSupport = new GlmRegCartSupport($this->wpdb, $this->config);
+//            $CartSupport->purgeOldData();
+//
+//        }
+
+
+
+        // Get misc texts
+//        require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataMisc.php';
+//        $Misc = new GlmDataRegistrationsMisc($this->wpdb, $this->config);
+//        $misc = $Misc->getEntry(1);
+
+        // Get any provided option
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        // Get account ID if supplied
+        if (isset($_REQUEST['account'])) {
+
+            // Make sure it's numeric
+            $this->accountID = ($_REQUEST['account'] - 0);
+
+            if ($this->accountID <= 0) {
+                $this->accountID = false;
+            }
+        }
+
+
+
+        $view = 'list';
+
+        switch ( $option ) {
+
+        default:
+
+            // Build Where clause to select only active future reg events
+            $where .= "T.active AND T.last_datetime > now()";
+
+           // Get a current list of reg events
+//            $listResult = $this->getSimpleAssetsCountList($where.$alphaWhere, 'event_name', true, 'id', $start, $limit, true);
+            // echo '<pre>$listResult: ' . print_r( $listResult, true ) . '</pre>';
+
+            // Get paging results
+            $numbDisplayed = $listResult['returned'];
+            $lastDisplayed = $listResult['last'];
+            if ($start == 1) {
+                $prevStart = false;
+            } else {
+                $prevStart = $start - $limit;
+                if ($start < 1) {
+                    $start = 1;
+                }
+            }
+            if ($listResult['returned'] == $limit) {
+                $nextStart = $start + $limit;
+            }
+
+            // since we're doing paging, we have to break out just the event data
+            $list = $listResult['list'];
+            unset($listResult);
+
+            // If we have list entries - even if it's an empty list
+            $success       = true;
+            $haveAssetsCount = false;
+            if ($list !== false) {
+
+                $success = true;
+
+                // If we have any entries
+                if (count($list) > 0) {
+                    $haveAssetsCount = true;
+                }
+            }
+            break;
+        }
+
+        // including test data for now
+//        include GLM_MEMBERS_ASSETS_PLUGIN_PATH . '/data/events.php';
+
+        // Compile template data
+        $templateData = array(
+            'page'              => 'list',
+            'assetsCount'       => $assetsCount,
+            'haveAssets'        => $haveAssetsCount,
+            'assetsList'        => $list,
+            'alphaList'         => $alphaList,
+            'alphaSelected'     => $alphaSelected,
+            'numbDisplayed'     => $numbDisplayed,
+            'lastDisplayed'     => $lastDisplayed,
+            'paging'            => $paging,
+            'prevStart'         => $prevStart,
+            'nextStart'         => $nextStart,
+            'start'             => $start,
+            'limit'             => $limit,
+            'assetsUrl'            => GLM_MEMBERS_ASSETS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/',
+            'loggedIn'          => ( isset( $_SESSION['LoginAccount'] ) ) ? $_SESSION['LoginAccount']: false,
+        );
+
+             // Return status, any suggested view, and any data to controller
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => 'front/assets/' . $view . '.html',
+            'data'          => $templateData
+        );
+
+    }
+ }
index f3f4656..b0917b9 100644 (file)
@@ -71,7 +71,8 @@ $glmMembersAssetsAddOnValidActions = array(
     ),
     'frontActions' => array(
         'assets' => array(
-            'index' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG
+            'index' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG,
+            'list' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG
         ),
     )
 );
diff --git a/views/front/assets/list.html b/views/front/assets/list.html
new file mode 100644 (file)
index 0000000..c627c24
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!--
+To change this license header, choose License Headers in Project Properties.
+To change this template file, choose Tools | Templates
+and open the template in the editor.
+-->
+<html>
+    <head>
+        <title>TODO supply a title</title>
+        <meta charset="UTF-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    </head>
+    <body>
+        <div>TODO write content</div>
+    </body>
+</html>