From 48d47516a388ac985061a47b170a3c6fd2c2e03e Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Fri, 15 Sep 2017 15:36:06 -0400 Subject: [PATCH] setting up the model and views adding base model and view files to the plugin and hooking up them --- models/admin/buySell/index.php | 295 ++++++++++++++++++++++++++++++++ models/front/buySell/detail.php | 0 models/front/buySell/list.php | 0 setup/adminMenus.php | 6 +- setup/validActions.php | 4 +- views/admin/buySell/edit.html | 0 views/admin/buySell/list.html | 0 views/front/buySell/detail.html | 0 views/front/buySell/list.html | 0 9 files changed, 300 insertions(+), 5 deletions(-) create mode 100644 models/admin/buySell/index.php create mode 100644 models/front/buySell/detail.php create mode 100644 models/front/buySell/list.php create mode 100644 views/admin/buySell/edit.html create mode 100644 views/admin/buySell/list.html create mode 100644 views/front/buySell/detail.html create mode 100644 views/front/buySell/list.html diff --git a/models/admin/buySell/index.php b/models/admin/buySell/index.php new file mode 100644 index 0000000..deeb4e0 --- /dev/null +++ b/models/admin/buySell/index.php @@ -0,0 +1,295 @@ + + * @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 abstract +require_once GLM_MEMBERS_BUY_SELL_PLUGIN_CLASS_PATH .'/data/dataBuySell.php'; +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH .'/data/dataMembers.php'; + +class GlmMembersAdmin_buySell_index extends GlmDataBuySell +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Job ID + * + * @var $job ID + * @access public + */ + public $job_id = 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 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) + { + $members = new GlmDataMembers($this->wpdb, $this->config); + $member_list = $members->getList(); + + + $success_message = ""; + $haveJob = false; + $option = false; + $job = false; + $job_data = false; + $jobUpdated = false; + $jobUpdateError = false; + $jobAdded = false; + $jobAddError = false; + $view_file = 'index'; + $lockedToMember = false; + $isModerated = false; + $memberID = false; + $haveMember = false; + $where = ''; + + // Check if there's a logged in user who is locked to their own entity + $lockedToMember = apply_filters('glm_members_locked_to_member_id', false); + if ($lockedToMember) { + + $isModerated = apply_filters('glm_user_is_moderated', $lockedToMember); + $memberID = $lockedToMember; + + $this->fields['admin_name']['required'] = true; + $this->fields['admin_email']['required'] = true; + $this->fields['admin_phone']['required'] = true; + + // Check for Member Menu Use + } elseif (defined('GLM_JOB_MEMBER_MENU')) { + + // Try to get member ID + $memberID = (isset($_REQUEST['member']) ? $_REQUEST['member'] : 0); + + // If there's no valid member ID, we can't continue + if ($memberID == 0) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'No member ID was provided.' + ) + ); + } + } + + // If not a valid member ID + if ($memberID > 0) { + + // Get base member information + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'; + + $memberData = $members->getEntry($memberID); + $where .= "member = $memberID"; + if (!$memberData) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'No member data found for provided member ID.' + ) + ); + } else{ + $haveMember = true; + $memberName = $memberData['name']; + } + + } + + if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') { + $option = $_REQUEST['option']; + } + + // get the Job id for use in the edit, add and delete options + // Get obit ID if supplied + if (isset($_REQUEST['job'])) { + + // Make sure it's numeric + $this->job_id= ($_REQUEST['job'] - 0); + + if ($this->job_id <= 0) { + $this->job_id = false; + } + } + + $job_data = $this->getList($where); + +// echo '
', print_r($this->getList()), '
'; + // echo '
', print_r($_REQUEST), '
'; + + switch ($option) { + + case 'add': + $job = $this->newEntry(); + $view_file = 'edit'; + + break; + + case 'insert': + $job = $this->insertEntry(); + $this->job_id = $job['fieldData']['id']; + + if ($job['status']) { + $haveJob = true; + $jobAdded = true; + + // Update created timestamp and name slug for URLs + //$this->updateSlug($this->JobID); + + // Get this again so we have the created date + $job = $this->editEntry($this->job_id); + + $option = 'edit'; + $jobAdded = true; + + } else { + $option = 'add'; + $jobAddError = true; + } + + $view_file = 'edit'; + + break; + + case 'edit': + $job = $this->editEntry($this->job_id); + + // If we have a good Job + if ($job['status']) { + $haveJob = true; + } + + $view_file = 'edit'; + break; + + case 'update': + // Try to update this Job + $job = $this->updateEntry($this->job_id); + + // Check if that was successful + if ($job['status']) { + $jobUpdated = true; + + $job = $this->editEntry($this->job_id); + + } else { + $jobUpdateError = true; + } + + $haveJob = true; + $view_file = 'edit'; + + break; + + case 'delete': + $job = $this->deleteEntry($this->job_id,true); + + if ($job) { + $jobDeleted = true; + } else { + $jobDeleteError = true; + } + $view_file = "list"; + $job_data = $this->getList(); + break; + default: + $job_data = $this->getList($where); + $view_file = 'list'; + break; + } +// echo '
', print_r($this->getList()), '
'; + // Compile template data + $templateData = array( + 'jobData' => $job_data, + 'memberList' => $member_list, + 'lockedToMember' => $lockedToMember, + 'haveMember' => $haveMember, + 'memberID' => $memberID, + 'jobID' => $this->job_id, + 'haveJob' => $haveJob, + 'jobUpdated' => $jobUpdated, + 'jobUpdateError' => $jobUpdateError, + 'jobAdded' => $jobAdded, + 'jobAddError' => $jobAddError, + 'option' => $option, + 'job' => $job, + 'assetsUrl' => GLM_MEMBERS_BUY_SELL_PLUGIN_URL . 'assets/', + + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'admin/buySell/'.$view_file.'.html', + 'data' => $templateData + ); + } +} diff --git a/models/front/buySell/detail.php b/models/front/buySell/detail.php new file mode 100644 index 0000000..e69de29 diff --git a/models/front/buySell/list.php b/models/front/buySell/list.php new file mode 100644 index 0000000..e69de29 diff --git a/setup/adminMenus.php b/setup/adminMenus.php index fd9efd8..14e5d55 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -56,7 +56,7 @@ 'Buy Sell', 'glm_members_edit_my_entity', 'glm-members-admin-menu-buy-sell-index', - function(){$this->controller('buy-sell');} + function(){$this->controller('buySell');} ); } else { add_submenu_page( @@ -64,7 +64,7 @@ 'Buy Sell', 'Buy Sell', 'edit_posts', - 'glm-members-admin-menu-buy-sell-index', - function(){$this->controller('buy-sell');} + 'glm-members-admin-menu-buySell-index', + function(){$this->controller('buySell');} ); } diff --git a/setup/validActions.php b/setup/validActions.php index ab4adb0..2c04887 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -60,12 +60,12 @@ $glmMembersBuySellAddOnValidActions = array( 'adminActions' => array( - 'BuySell' => array( + 'buySell' => array( 'index' => GLM_MEMBERS_BUY_SELL_PLUGIN_SLUG, ), ), 'frontActions' => array( - 'BuySell' => array( + 'buySell' => array( 'list' => GLM_MEMBERS_BUY_SELL_PLUGIN_SLUG, 'detail' => GLM_MEMBERS_BUY_SELL_PLUGIN_SLUG, ), diff --git a/views/admin/buySell/edit.html b/views/admin/buySell/edit.html new file mode 100644 index 0000000..e69de29 diff --git a/views/admin/buySell/list.html b/views/admin/buySell/list.html new file mode 100644 index 0000000..e69de29 diff --git a/views/front/buySell/detail.html b/views/front/buySell/detail.html new file mode 100644 index 0000000..e69de29 diff --git a/views/front/buySell/list.html b/views/front/buySell/list.html new file mode 100644 index 0000000..e69de29 -- 2.17.1