From 49761bb0d82d9b65ca4036db284f0b5496850b1f Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Fri, 9 Mar 2018 10:32:37 -0500 Subject: [PATCH] adding index and list models / views and valid actions setting up the front end actions, models and views for assets --- models/front/assets/index.php | 119 ++++++++++++++++++++- models/front/assets/list.php | 194 ++++++++++++++++++++++++++++++++++ setup/validActions.php | 3 +- views/front/assets/list.html | 16 +++ 4 files changed, 327 insertions(+), 5 deletions(-) create mode 100644 models/front/assets/list.php create mode 100644 views/front/assets/list.html diff --git a/models/front/assets/index.php b/models/front/assets/index.php index 3ac00fa..c06e23b 100644 --- a/models/front/assets/index.php +++ b/models/front/assets/index.php @@ -1,8 +1,119 @@ 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 index 0000000..f17cc7d --- /dev/null +++ b/models/front/assets/list.php @@ -0,0 +1,194 @@ +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 '
$listResult: ' . print_r( $listResult, true ) . '
'; + + // 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 + ); + + } + } diff --git a/setup/validActions.php b/setup/validActions.php index f3f4656..b0917b9 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -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 index 0000000..c627c24 --- /dev/null +++ b/views/front/assets/list.html @@ -0,0 +1,16 @@ + + + + + TODO supply a title + + + + +
TODO write content
+ + -- 2.17.1