From d86c65197a78fdb540853e9c21386d8511497f13 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 22 Jul 2016 14:41:24 -0400 Subject: [PATCH] Added code to display issues with search management settings in the main dashboard widget. --- models/admin/dashboardWidget/search.php | 149 ++++++++++++++++++++++++ setup/adminHooks.php | 6 + setup/shortcodes.php | 6 +- setup/validActions.php | 3 + views/admin/dashboardWidget/search.html | 14 +++ 5 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 models/admin/dashboardWidget/search.php create mode 100644 views/admin/dashboardWidget/search.html diff --git a/models/admin/dashboardWidget/search.php b/models/admin/dashboardWidget/search.php new file mode 100644 index 0000000..22f6b63 --- /dev/null +++ b/models/admin/dashboardWidget/search.php @@ -0,0 +1,149 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +/* + * Check whether there's any notices that should be displayed + * in the main dashboard widget. + */ +class GlmMembersAdmin_dashboardWidget_search +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @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 does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successfull 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 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. + * + */ + public function modelAction ($actionData = false) + { + + // Get the Open Search Server parameters from management settings + $index = $this->config['settings']['search_index']; + $website = $this->config['settings']['website']; + $login = $this->config['settings']['login']; + $key = $this->config['settings']['login_key']; + + $displayNotice = false; + + $indexNotice = false; + if (trim($index) == '') { + $indexNotice = true; + $displayNotice = true; + } + + $websiteNotice = false; + if (trim($website) != GLM_MEMBERS_HOSTNAME) { + $websiteNotice = true; + $displayNotice = true; + } + + $loginNotice = false; + if (trim($website) == '') { + $loginNotice = true; + $displayNotice = true; + } + + $keyNotice = false; + if (trim($key) == '') { + $keyNotice = true; + $displayNotice = true; + } + + // Compile template data + $templateData = array( + 'displayNotice' => $displayNotice, + 'indexNotice' => $indexNotice, + 'websiteNotice' => $websiteNotice, + 'loginNotice' => $loginNotice, + 'keyNotice' => $keyNotice, + ); + + // Return status, suggested view, and data to controller - also return any modified settings + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/dashboardWidget/search.html', + 'data' => $templateData + ); + + } + + +} + +?> \ No newline at end of file diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 6e7ad8e..54ce2c3 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -25,3 +25,9 @@ * * Also note that parameters will be in the context of the main admin controller constructor. */ + +// Add warnings to the main dashboard widget by calling model with current controller (admin) +add_filter( 'glm-member-db-dashboard-widget-warnings', function( $content ) { + $content .= $this->controller('dashboardWidget', 'search'); + return $content; +}); diff --git a/setup/shortcodes.php b/setup/shortcodes.php index 61f7769..f3c2c51 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -21,7 +21,7 @@ * * This array is merged with the data from any registered add-ons * providing short-code features. The plugin providing the short-code - * is designated in the 'plugin' elemeent. + * is designated in the 'plugin' element. * * A shortcode is unique to a particular plugin. To provide additional * data and features to a short-code, an add-on should use filters @@ -120,7 +120,7 @@ $glmMembersSearchShortcodesDescription = '   - type="{search type}" + type="{search type}" NOT YET IMPLEMENTED The type of search

@@ -135,7 +135,7 @@ $glmMembersSearchShortcodesDescription = '   - order="{order type}" + order="{order type}" NOT YET IMPLEMENTED Order of search results

diff --git a/setup/validActions.php b/setup/validActions.php index c29e80e..28b06c4 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -42,6 +42,9 @@ $glmMembersSearchAddOnValidActions = array( 'adminActions' => array( 'management' => array( 'search' => GLM_MEMBERS_SEARCH_PLUGIN_SLUG + ), + 'dashboardWidget' => array( + 'search' => GLM_MEMBERS_SEARCH_PLUGIN_SLUG ) ), 'frontActions' => array( diff --git a/views/admin/dashboardWidget/search.html b/views/admin/dashboardWidget/search.html new file mode 100644 index 0000000..0787060 --- /dev/null +++ b/views/admin/dashboardWidget/search.html @@ -0,0 +1,14 @@ +{if $displayNotice} +

+

+ Required Search Add-On Settings   + Fix search settings +

+ {if $indexNotice}No Index set
{/if} + {if $websiteNotice}No Website set or does not match current site
{/if} + {if $loginNotice}No OSS Login set
{/if} + {if $keyNotice}No OSS Key set
{/if} + +

+

+{/if} \ No newline at end of file -- 2.17.1