From b01b607c0be498bed3910755f404c7769198f452 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 17 Feb 2017 17:04:14 -0500 Subject: [PATCH] WIP for list and edit obits page. Work on the list and index models for listing and editing obits. --- classes/data/dataObits.php | 37 +- models/admin/obits/index.php | 113 ++++++ models/admin/obits/list.php | 324 ++++++++++++++++++ setup/adminMenus.php | 4 +- .../create_database_V0.0.1.sql | 8 +- setup/validActions.php | 6 +- views/admin/obits/edit.html | 260 ++++++++++++++ views/admin/obits/header.html | 9 + views/admin/obits/index.html | 71 ++++ views/admin/obits/list.html | 163 +++++++++ 10 files changed, 981 insertions(+), 14 deletions(-) create mode 100644 models/admin/obits/index.php create mode 100644 models/admin/obits/list.php create mode 100644 views/admin/obits/edit.html create mode 100644 views/admin/obits/header.html create mode 100644 views/admin/obits/index.html create mode 100644 views/admin/obits/list.html diff --git a/classes/data/dataObits.php b/classes/data/dataObits.php index e607f73..f29e397 100644 --- a/classes/data/dataObits.php +++ b/classes/data/dataObits.php @@ -24,7 +24,7 @@ * @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott * Exp $ */ -class GlmDataObitsManagement extends GlmDataAbstract +class GlmDataObits extends GlmDataAbstract { /** @@ -139,6 +139,7 @@ class GlmDataObitsManagement extends GlmDataAbstract 'b_year' => array( 'field' => 'b_year', 'type' => 'integer', + 'default' => '', 'required' => true, 'use' => 'a', ), @@ -146,13 +147,15 @@ class GlmDataObitsManagement extends GlmDataAbstract 'b_yr_range' => array( 'field' => 'b_yr_range', 'type' => 'integer', - 'default' => true, + 'default' => '', + 'required' => true, 'use' => 'a', ), 'd_year' => array( 'field' => 'd_year', 'type' => 'integer', + 'default' => '', 'required' => true, 'use' => 'a', ), @@ -160,6 +163,7 @@ class GlmDataObitsManagement extends GlmDataAbstract 'd_yr_range' => array( 'field' => 'd_yr_range', 'type' => 'integer', + 'default' => '', 'required' => false, 'use' => 'a', ), @@ -250,9 +254,6 @@ class GlmDataObitsManagement extends GlmDataAbstract * * Perform post-processing for all result entries. * - * In this case we're using it to append an array of category - * data to each member result and also sort by member name. - * * @param array $r Array of field result data for a single entry * @param string $a Action being performed (l, i, g, ...) * @@ -264,6 +265,28 @@ class GlmDataObitsManagement extends GlmDataAbstract 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'], + 'last_name' => $savedFields['last_name'] + ); + + $r = $this->getList($where); + + $this->fields = $savedFields; + return $r; + + } + +} diff --git a/models/admin/obits/index.php b/models/admin/obits/index.php new file mode 100644 index 0000000..374a916 --- /dev/null +++ b/models/admin/obits/index.php @@ -0,0 +1,113 @@ + + * @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/dataObits.php'; + +class GlmMembersAdmin_obits_index extends GlmDataObits +{ + + /** + * 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; + + // Get number of obits + $numbObits = $this->getStats(); + + // Compile template data + $templateData = array( + 'numbObits' => $numbObits, + 'namesList' => $namesList, + ); + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'admin/obits/index.html', + 'data' => $templateData + ); + + } + + +} diff --git a/models/admin/obits/list.php b/models/admin/obits/list.php new file mode 100644 index 0000000..09f0334 --- /dev/null +++ b/models/admin/obits/list.php @@ -0,0 +1,324 @@ + + * @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 class +require_once GLM_MEMBERS_OBITS_PLUGIN_CLASS_PATH.'/data/dataObits.php'; + +class GlmMembersAdmin_obits_list extends GlmDataObits +{ + + /** + * 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 constructor 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 __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) + { + + $numbObits = 0; + $option = 'list'; + $obits = false; + $haveObits = false; + $obit = false; + $haveObit = false; + $this->obitID = false; + $obitUpdated = false; + $obitUpdateError = false; + $obitAdded = false; + $obitAddError = false; + $view = 'list'; + $fromDate = false; + $toDate = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $namesList = false; + $obitDeleted = false; + $obitDeleteError = false; + + // Get any provided option + if (isset($_REQUEST['option'])) { + $option = $_REQUEST['option']; + } + + // Get obit ID if supplied + if (isset($_REQUEST['obit'])) { + + // Make sure it's numeric + $this->obitID = ($_REQUEST['obit'] - 0); + + if ($this->obitID <= 0) { + $this->obitID = false; + } + + } + + // Check for specific_dates submission + + // Do selected option + switch ($option) { + + case 'add': + + $obit = $this->newEntry(); + + $view = 'edit'; + + break; + + case 'insert': + + $obit = $this->insertEntry(); + + $this->obitID = $obit['fieldData']['id']; + + if ($obit['status']) { + $haveObit = true; + $obitAdded = true; + + // Update created timestamp and name slug for URLs + $this->updateTimestamp('created', $this->obitID); + $this->updateSlug($this->obitID); + + // Get this again so we have the created date + $obit = $this->editEntry($this->obitID); + + $option = 'edit'; + $obitAdded = true; + + } else { + $option = 'add'; + $obitAddError = true; + } + + $view = 'edit'; + + break; + + case 'edit': + + + + $obit = $this->editEntry($this->obitID); + + // If we have a good obit + if ($obit['status']) { + $haveObit = true; + } + + $view = 'edit'; + break; + + case 'update': + + // Try to update this obit + $obit = $this->updateEntry($this->obitID); + + // Check if that was successful + if ($obit['status']) { + $obitUpdated = true; + + $obit = $this->editEntry($this->obitID); + } else { + $obitUpdateError = true; + } + + $haveObit = true; + $view = 'edit'; + + break; + + case 'delete': + + $obit = $this->deleteObit($this->obitID); + + if ($obit) { + $obitDeleted = true; + } else { + $obitDeleteError = true; + } + + case 'list': + default: + + $where = 'true'; + + // Check if we have a Text Search string + if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch']) != '') { + $textSearch = trim($_REQUEST['textSearch']); + $where .= " AND last_name LIKE '%$textSearch%'"; + } + + // Get the total number of obits listed + $numbObits = $this->getStats($where); + + // If the number of obits is less than a page, don't do paging + if ($numbObits <= $limit) { + $paging = false; + } + + // Get full list of names matching this where clause for search box + $namesList = $this->getIdName($where); + + // Check if we're doing paging + if (isset($_REQUEST['pageSelect'])) { + + // If request is for Next + if ($_REQUEST['pageSelect'][0] == 'N') { + $newStart = $_REQUEST['nextStart'] - 0; + + // Otherwise it must be Previous + } else { + $newStart = $_REQUEST['prevStart'] - 0; + } + + if ($newStart > 0) { + $start = $newStart; + } + } + + // Get the list of obits and determine number of obits in list + $obitsResult = $this->getList($where, 'last_name', true, 'id', $start, $limit); + + // Get paging results + $numbDisplayed = $obitsResult['returned']; + $lastDisplayed = $obitsResult['last']; + if ($start == 1) { + $prevStart = false; + } else { + $prevStart = $start - $limit; + if ($start < 1) { + $start = 1; + } + } + if ($obitsResult['returned'] == $limit) { + $nextStart = $start + $limit; + } + + // since we're doing paging, we have to break out just the obits data + $obits = $obitsResult['list']; + if (count($obits)>0) { + $haveObits = true; + } + unset($obitsResult); + + break; + + } + + $templateData = array( + 'option' => $option, + 'obits' => $obits, + 'haveObits' => $haveObits, + 'obit' => $obit, + 'haveObit' => $haveObit, + 'obitID' => $this->obitID, + 'obitUpdated' => $obitUpdated, + 'obitUpdateError' => $obitUpdateError, + 'obitAdded' => $obitAdded, + 'obitAddError' => $obitAddError, + 'numbObits' => $numbObits, + 'fromDate' => $fromDate, + 'toDate' => $toDate, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start = 1, + 'limit' => $limit, + 'namesList' => $namesList, + 'obitDeleted' => $obitDeleted, + 'obitDeleteError' => $obitDeleteError, + + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => "admin/obits/$view.html", + 'data' => $templateData + ); + + } + + +} diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 32a56c5..57f7142 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -55,8 +55,8 @@ add_submenu_page( 'Obits', 'Obits', 'edit_posts', - 'glm-members-admin-menu-obits-list', - function(){$this->controller('obits', 'list');} + 'glm-members-admin-menu-obits-index', + function(){$this->controller('obits');} ); add_submenu_page( 'glm-members-admin-menu-members', diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql index eff0892..49e7fde 100644 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -17,10 +17,10 @@ CREATE TABLE {prefix}obits ( id INT NOT NULL AUTO_INCREMENT, last_name TINYTEXT NOT NULL DEFAULT '', first_mid TINYTEXT NOT NULL DEFAULT '', - b_year TINYINT NOT NULL DEFAULT 0, -- Birth Year - b_yr_range TINYINT NOT NULL DEFAULT 0, -- Birth Year Range (use the start of the decade like 2010 or 2000) - d_year TINYINT NOT NULL DEFAULT 0, -- Death Year - d_yr_range TINYINT NOT NULL DEFAULT 0, -- Death Year Range (use the start of the decade like 2010 or 2000) + b_year SMALLINT NOT NULL DEFAULT 0, -- Birth Year + b_yr_range SMALLINT NOT NULL DEFAULT 0, -- Birth Year Range (use the start of the decade like 2010 or 2000) + d_year SMALLINT NOT NULL DEFAULT 0, -- Death Year + d_yr_range SMALLINT NOT NULL DEFAULT 0, -- Death Year Range (use the start of the decade like 2010 or 2000) maiden_other TINYTEXT NULL DEFAULT '', spouse_partner TINYTEXT NULL DEFAULT '', obit_article TINYTEXT NULL DEFAULT '', diff --git a/setup/validActions.php b/setup/validActions.php index 6a97e8c..999cc5e 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -59,9 +59,13 @@ $glmMembersObitsAddOnValidActions = array( 'adminActions' => array( + 'obits' => array( + 'index' => GLM_MEMBERS_OBITS_PLUGIN_SLUG, + 'list' => GLM_MEMBERS_OBITS_PLUGIN_SLUG, + ), ), 'frontActions' => array( ) ); -?> \ No newline at end of file +?> diff --git a/views/admin/obits/edit.html b/views/admin/obits/edit.html new file mode 100644 index 0000000..e972c8d --- /dev/null +++ b/views/admin/obits/edit.html @@ -0,0 +1,260 @@ +{include file='admin/obits/header.html'} + +{if apply_filters('glm_members_permit_admin_member_obit', true) && ($option == 'add' || $haveObit)} + + Return to Obits List + + {if $option == 'edit' || $option == 'update'} + Delete this Obit +

Edit Obit + {else} +

Add new Obit + {/if} +     + {if $obitUpdated}Obit Updated{/if} + {if $obitUpdateError}Obit Update Error{/if} + {if $obitAdded}Obit Added{/if} + {if $obitAddError}Obit Add Error{/if} +

+ + {if $obitUpdateError || $obitAddError} +

NOTICE: Your obit has not yet been submitted.
Please select the tabs indicating a problem, correct the indicated fields and resubmit.

+ {else} + {/if} + +
+ + + {if $haveObit} + + + {else} + + {/if} + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Last Name: + + {if $obit.fieldFail.last_name}

{$obit.fieldFail.last_name}

{/if}
+
First and Middle Name: + + {if $obit.fieldFail.first_mid}

{$obit.fieldFail.first_mid}

{/if}
+
Birth Year: + + {if $obit.fieldFail.b_year}

{$obit.fieldFail.b_year}

{/if}
+
Birth Year Range: + + {if $obit.fieldFail.b_yr_range}

{$obit.fieldFail.b_yr_range}

{/if}
+
Death Year: + + {if $obit.fieldFail.d_year}

{$obit.fieldFail.d_year}

{/if}
+
Death Year Range: + + {if $obit.fieldFail.d_yr_range}

{$obit.fieldFail.d_yr_range}

{/if}
+
+ + + +
+ +{else} + +

Sorry, no obit found or permission not granted.

+ +{/if} + + + +
+
+

Cancel

+

+
+
+

WARNING:

+

+ Clicking the "Delete this Obit" button above will + delete all of the data and images associated with this obit. + +

+

+ + Once deleted, this information will no longer be available and cannot be retrieved! + If you are unsure that you want to completely remove this data, consider changing the status + of this obit to "Archived" instead. + +

+
+
+ + + +{include file='admin/footer.html'} diff --git a/views/admin/obits/header.html b/views/admin/obits/header.html new file mode 100644 index 0000000..b9b9bca --- /dev/null +++ b/views/admin/obits/header.html @@ -0,0 +1,9 @@ +
+

All Obits

+ +
+ + diff --git a/views/admin/obits/index.html b/views/admin/obits/index.html new file mode 100644 index 0000000..b37b2fc --- /dev/null +++ b/views/admin/obits/index.html @@ -0,0 +1,71 @@ +{include file='admin/obits/header.html'} + +{if apply_filters('glm_members_permit_admin_obits_index_add_obit', true)} + Add A New Obit +{/if} + + + + + + +{if $numbObits == 0} + + + + + +{/if} +
+ + Obits Search: +
 
You do not have any obits listed.Click here to create your first obit.
+ + + +
Number of Obits Listed: {$numbObits}
+ +{if $namesList} + +{/if} + +{include file='admin/footer.html'} + diff --git a/views/admin/obits/list.html b/views/admin/obits/list.html new file mode 100644 index 0000000..043519b --- /dev/null +++ b/views/admin/obits/list.html @@ -0,0 +1,163 @@ +{include file='admin/obits/header.html'} + +{if apply_filters('glm_members_permit_admin_obits_index_add_obit', true)} +

+ Add A New Obit + {if $obitDeleted}Obit Deleted{/if} + {if $obitDeleteError}Obit Delete Error{/if} +

+{/if} + +
+ + + + +
+

+ + From Date: + To Date: + + + Text Search: + + +

+

+
+ +

Total found: {$numbObits}  

+ + + {if $paging} + + + {/if} + + + + + + + + + + + + + + + {if $haveObits} + {assign var="i" value="0"} + {foreach $obits as $e} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + + + + + + {/foreach} + {else} + + {/if} + +
IDObit Name{$terms.term_member_cap}StatusFirst DateLast Date
+ {$e.id} + + {$e.name} + + {$e.ref_dest} + + {$e.status.name} + + {$e.firstDate} + + {$e.lastDate} + + View Obit +
(no obits listed)
+ + {if $paging} + + + {/if} + +
+ + + + +{include file='admin/footer.html'} -- 2.17.1