From 75530dbb2c2f0d53f291c0249ad27dc8c22f257a Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Fri, 19 Oct 2018 17:08:42 -0400 Subject: [PATCH] Set up coupons for the new widget dashboard display --- setup/adminHooks.php | 156 +++++++++++++++++++++++++++++++++++++++++++ setup/adminMenus.php | 4 +- 2 files changed, 158 insertions(+), 2 deletions(-) diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 096b6d2..aee3b66 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -43,3 +43,159 @@ add_filter( 14, 1 ); +add_filter( + GLM_MEMBERS_COUPONS_PLUGIN_SLUG .'-dashboard-widget', + function ( $member = null ) { + require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php'; + $Coupons = new GlmDataCoupons($this->wpdb, $this->config); + + // Set default values for using getList() later, where the custom set of fields below will be used. + $where = ''; + $order = ''; + $fieldVals = true; + $idField = 'id'; + $start = false; + $limit = false; + + // Save the current fields array and make a copy + $fSave = $Coupons->fields; + + // Remove what we don't want from the copy and get the list + $Coupons->fields = array( + 'id' => $fSave['id'], + 'name' => $fSave['name'], + 'status' => $fSave['status'], + 'ref_dest_id' => $fSave['ref_dest_id'], + 'ref_dest' => $fSave['ref_dest'], + 'ref_type' => $fSave['ref_type'], + 'expire' => $fSave['expire'], + ); + + // $widgetResult = $Coupons->getList("expire_date < NOW()", "expire_date DESC", $fieldVals, $idField, $start, $limit); + // echo "
" . var_dump($widgetResult) . "

"; + + $couponsIndexPage = GLM_MEMBERS_COUPONS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-coupons-index'; + $couponsListPage = GLM_MEMBERS_COUPONS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-coupons-list&glm_action=list'; + $couponsTable = GLM_MEMBERS_COUPONS_PLUGIN_PREFIX . "coupons"; + $couponsMemberEditPage = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE . 'member&glm_action=coupons&option=edit'; + $couponsEditPage = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE . 'member&glm_action=coupons&option=edit'; + $couponsRefLink = GLM_MEMBERS_COUPONS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-member&glm_action=index'; + + /* + * For list components: pass ref_type and ref_dest as part of the 'fields' string if you want to + * make these options part of the href of each
  • link + * + */ + + $content = [ + 'title' => 'Coupons', + 'widgetButtons' => [ + [ + 'id' => 'add-coupon', + 'content' => 'Add', + 'url' => $couponsIndexPage . "&glm_action=list&option=add", + 'classes' => '', + 'styles' => '', + 'data' => '' + ], + [ + 'id' => 'export-button', + 'content' => 'Export', + 'url' => '#', + 'classes' => 'btn-small widget-export-btn waves-effect waves-light btn modal-trigger', + 'styles' => '', + 'data' => 'couponsExportModal' + ], + ], + 'components' => [ + [ + 'id' => 'quickLinks', + 'order' => -1, + 'template' => 'quickLinks', + 'quickLinks' => [ + 'dashboard' => [ + 'content' => 'Dashboard', + 'url' => $couponsIndexPage . "&option=dashboard", + ], + 'search' => [ + 'content' => 'Advanced Search', + 'url' => $couponsIndexPage . "&option=search", + ], + 'settings' => [ + 'content' => 'Settings', + 'url' => '#set', + ] + ], + ], + [ + 'id' => 'entityAmount', + 'title' => 'Number of Coupons', + 'order' => 1, + 'template' => 'entityAmount', + 'url' => $couponsListPage . "&option=search", + 'result' => $Coupons->getStats(), + ], + [ + 'id' => 'textSearch', + 'order' => 2, + 'template' => 'textSearch', + 'entityID' => 'coupon', + 'table' => $couponsTable, + 'fields' => "id, title as name, image", + 'where' => 'title', + 'resultUrl' => $couponsListPage . "&coupon=", + ], + [ + 'id' => 'pending', + 'title' => "Pending Coupons", + 'slug' => "pending-coupons", + 'order' => 4, + 'template' => 'list', + 'entityID' => 'coupon', + 'refLink' => $couponsRefLink, + 'url' => $couponsListPage . "&option=edit", + 'countUrl' => $couponsListPage . "&filterPending=on", + 'result' => $Coupons->getList("status=".$Coupons->config['status_numb']['Pending'], $order, $fieldVals, $idField, $start, $limit), + 'count' => $Coupons->getStats("status=".$Coupons->config['status_numb']['Pending']), + 'fieldMap' => [ + 'ID' => 'id', + 'name' => 'name', + 'status' => 'status', + 'refDestID' => 'ref_dest_id', + 'refDestName' => 'ref_dest', + 'refType' => 'ref_type', + ], + ], + [ + 'id' => 'expired', + 'title' => "Expired Coupons", + 'slug' => "expired-coupons", + 'order' => 5, + 'template' => 'list', + 'entityID' => 'coupon', + 'refLink' => $couponsRefLink, + 'url' => $couponsIndexPage . "&option=edit", + 'countUrl' => $couponsIndexPage . "&filtedExpired=on", + 'result' => $Coupons->getList("expire < NOW()", "expire DESC", $fieldVals, $idField, $start, $limit), + 'count' => $Coupons->getStats("expire < NOW()", "expire DESC"), + 'fieldMap' => [ + 'ID' => 'id', + 'name' => 'name', + 'status' => 'status', + 'refDestID' => 'ref_dest_id', + 'refDestName' => 'ref_dest', + 'refType' => 'ref_type', + 'expireDate' => 'expire' + ], + ], + ] + ]; + + // Restore the fields list + $Coupons->fields = $fSave; + + return $content; + }, + 13, + 1 +); \ No newline at end of file diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 7e6f0b3..8a69729 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -50,7 +50,7 @@ * */ add_submenu_page( - 'glm-members-admin-menu-members', // Parent slug + $mainMenuSlug, // Parent slug 'Coupons', // Page Title 'Coupons', // Menu Title 'glm_members_members', // Capability required @@ -58,7 +58,7 @@ add_submenu_page( function(){$this->controller('coupons');} ); add_submenu_page( - 'glm-members-admin-menu-members', // Parent slug + $mainMenuSlug, // Parent slug 'Coupon List', // Page title '    List', // Menu Title 'glm_members_members', // Capability required -- 2.17.1