From e6ee1cada02eea50314f52dca3778ce1230cf862 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 28 Feb 2017 13:41:35 -0500 Subject: [PATCH] adding newspaper settings data class, model and view. added admin.css file. new, update and delete functions for newspapers added --- classes/data/dataNewspapers.php | 173 +++++++++++++++++++++++++++ classes/data/dataObits.php | 6 +- css/admin.css | 3 + models/admin/settings/newspapers.php | 152 +++++++++++++++++++++++ setup/adminTabs.php | 21 ++++ setup/validActions.php | 3 + views/admin/settings/newspapers.html | 166 +++++++++++++++++++++++++ 7 files changed, 522 insertions(+), 2 deletions(-) create mode 100644 classes/data/dataNewspapers.php create mode 100644 css/admin.css create mode 100644 models/admin/settings/newspapers.php create mode 100644 views/admin/settings/newspapers.html diff --git a/classes/data/dataNewspapers.php b/classes/data/dataNewspapers.php new file mode 100644 index 0000000..1aab57c --- /dev/null +++ b/classes/data/dataNewspapers.php @@ -0,0 +1,173 @@ + + * @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 + * @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 diff --git a/classes/data/dataObits.php b/classes/data/dataObits.php index 0b4fe5b..cd668bf 100644 --- a/classes/data/dataObits.php +++ b/classes/data/dataObits.php @@ -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 index 0000000..3ddcfb8 --- /dev/null +++ b/css/admin.css @@ -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 index 0000000..dc7c0a9 --- /dev/null +++ b/models/admin/settings/newspapers.php @@ -0,0 +1,152 @@ + + + * @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 + ); + + } + + +} diff --git a/setup/adminTabs.php b/setup/adminTabs.php index 591082e..a0088bf 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -32,4 +32,25 @@ * ); * */ +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; + } + ); + + } +} + diff --git a/setup/validActions.php b/setup/validActions.php index 999cc5e..d496f24 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -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 index 0000000..91d5490 --- /dev/null +++ b/views/admin/settings/newspapers.html @@ -0,0 +1,166 @@ +{include file='admin/management/header.html'} + + + + +
+ +
Add Newspaper
+
+
+ + + + + + + + + +
Newspaper Name: + +
+

* Required

+ Cancel + + +
+
+ + +
+
+

Are you sure you want to delete this Newspaper?

+

Yes, delete this Newspaper

+

Cancel

+
+
+ + +
+
+ + + + + + + + + + + +
Newspaper Name: + +
+

* Required

+ Cancel + + +
+
+ + + + + + + + + + + {if $newspapers} + {assign var="i" value="0"} + {foreach $newspapers as $n} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + {/foreach} + {else} + + {/if} + +
Newspaper Name  
+
{$n.name}
+
Edit
+
Delete
+
(no newspapers listed)
+
+ + + -- 2.17.1