Removing references to "addNotice" function in glmPluginSupport that were causing...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 5 Oct 2017 21:04:19 +0000 (17:04 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 5 Oct 2017 21:04:19 +0000 (17:04 -0400)
Cart link widget is now working. Also have new filter to get cart stats that can be used for custom widgets.

15 files changed:
activate.php
classes/data/dataRegRequest.php
classes/regCartSupport.php
misc/documentation/AccountRestrictionsDescription.txt [new file with mode: 0644]
models/admin/management/registrations.php
models/admin/management/regterms.php
models/admin/settings/registrationsMisc.php
models/front/registrations/cartLinkWidget.php [new file with mode: 0644]
models/front/registrations/registration.php
setup/frontHooks.php
setup/hooksHelp.html
setup/shortcodes.php
setup/validActions.php
views/admin/management/registrations.html
views/front/registrations/cartLinkWidget.html [new file with mode: 0644]

index 11dbb5c..d7c13dc 100644 (file)
@@ -58,7 +58,6 @@ class glmMembersRegistrationsPluginActivate
 
         // Make sure the current user has this capability
         if (! current_user_can('activate_plugins')) {
-            $this->addNotice("Interesting, you don't have permission to activate plugins.");
             die();
         }
 
index e2546e2..fa8d9e1 100644 (file)
@@ -47,6 +47,14 @@ class GlmDataRegistrationsRegRequest extends GlmDataAbstract
      * @var $table
      * @access public
      */
+    /**
+     * Flag to post process results
+     *
+     * @var $postProcRegRequest
+     * @access public
+     */
+    public $postProcRegRequest = false;
+
     public $table;
     /**
      * Field definitions
@@ -135,7 +143,7 @@ class GlmDataRegistrationsRegRequest extends GlmDataAbstract
                 'required' => true,
                 'use' => 'gle'
             ),
-            
+
             // Account Last Name
             'account_lname' => array (
                 'field' => 'account',
@@ -147,7 +155,7 @@ class GlmDataRegistrationsRegRequest extends GlmDataAbstract
                 'required' => true,
                 'use' => 'gle'
             ),
-            
+
             // Flag that indicates if request passed last validation with checkRegistrationRequest()
             'validated' => array (
                 'field'     => 'validated',
@@ -340,11 +348,91 @@ class GlmDataRegistrationsRegRequest extends GlmDataAbstract
                 'field'     => 'user_trace_info',
                 'type'      => 'text',
                 'use'       => 'a'
+            ),
+
+            // Date/Time last updated
+            'last_update' => array (
+                'field'     => 'last_update',
+                'type'      => 'datetime',
+                'use'       => 'lged'
             )
+
         );
 
     }
 
+    /**
+     * 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( $result_data, $action )
+    {
+
+        // If postProcRegRequest option set
+        if ($this->postProcRegRequest) {
+
+            // Get number of events selected
+            $result_data['numb_events'] = $this->wpdb->get_var("
+                SELECT COUNT(id)
+                FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_event
+                WHERE reg_request = ".$result_data['id']."
+            ");
+
+            // Get number of registrants
+            $result_data['numb_registrants'] = $this->wpdb->get_var("
+                SELECT COUNT(id)
+                FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_registrant
+                WHERE reg_request = ".$result_data['id']."
+            ");
+
+        }
+
+        return $result_data;
+
+    }
+
+    /**
+     * Get registration request simplified
+     *
+     * @param integer $requestId ID of registration request
+     * @param boolean $getStats Flag to get additional stats for cart
+     *
+     * @return object Class object
+     */
+    public function getRegRequestSimplified($requestId = false, $getStats = false)
+    {
+
+        $savedFields = $this->fields;
+        $savedPostProcess = $this->postProcRegRequest;
+
+        if ($getStats) {
+            $this->postProcRegRequest = true;
+        }
+
+        $this->fields = array(
+            'id' => $savedFields['id'],
+            'account_fname' => $savedFields['account_fname'],
+            'account_lname' => $savedFields['account_lname'],
+            'status'        => $savedFields['status'],
+            'last_update'   => $savedFields['last_update']
+        );
+
+        $requestSimplified = $this->getEntry($requestId);
+        $this->fields = $savedFields;
+        $this->postProcRegRequest = $savedPostProcess;
+
+        return $requestSimplified;
+
+    }
+
+
 }
 
 ?>
\ No newline at end of file
index 3ec5a59..2c3933c 100644 (file)
@@ -461,7 +461,7 @@ class GlmRegCartSupport
                     $totalCharges       += $eventCharges;
                     $totalRegistrants   += $eventRegistrants;
                     $totalDiscounts     += $eventDiscounts;
-                    $totalTotal         += $eventTotal;
+                    $grandTotal         += $eventTotal;
 
                 } // Each event
 
@@ -702,5 +702,46 @@ class GlmRegCartSupport
 
     }
 
+    /*
+     * Get a quick summary of a registration request (cart)
+     *
+     * This function collects basic info on a registration request (cart)
+     *
+     * Returns an array of the following information
+     *  'name'          Name of person (account) who is submitting the cart
+     *  'cartPageURL'   URL to take the user to the cart page for this request
+     *  'registrants'   Number of registrants in the cart
+     *
+     * If no requestId is supplied, this function will attempt to get the ID from the current session.
+     *
+     * @param integer $requestId ID of the registration request desired
+     *
+     * @return array As per return results listed above and false if no request ID or not found.
+     *
+     * @access public
+     */
+    public function regCartSummary($requestId = false)
+    {
+
+        // If we haven't been supplied a request (cart) ID
+        if (!$requestId) {
+
+           // Try to get the ID from the current session
+           $requestId = $_SESSION['glm_reg_cart_id'];
+
+        }
+
+        // If we don't have a request ID
+        if (!$requestId) {
+           return false;
+        }
+
+        // Try to get the base cart info
+        $RegRequest = new GlmDataRegistrationsRegRequest($this->wpdb, $this->config);
+        $cartSummary = $RegRequest->getRegRequestSimplified($requestId, true);
+
+        return $cartSummary;
+
+    }
 
 }
diff --git a/misc/documentation/AccountRestrictionsDescription.txt b/misc/documentation/AccountRestrictionsDescription.txt
new file mode 100644 (file)
index 0000000..e300824
--- /dev/null
@@ -0,0 +1,63 @@
+Description of how Accounts may be managed
+------------------------------------------
+
+Premise:
+
+* Accounts are used to store information for people who may enter a registration and/or be registered for an event.
+* Account data must be secured so only authorized people can obtain any information on an account other than account name.
+* A person trying to register someone else who does not already have an "account" should be allowed to enter their information.
+* An account may or may not include an E-Mail address. 
+* Accounts without E-Mail addresses may be used to register minors (or similar) where the account can only be accessed by the person who created the account. 
+* If it does include an E-Mail address the account can be validated by the owner of that E-Mail address.
+* Once an account has been validated, nobody else may access any of the information in that account other than first and last name.
+* An account that has not be validated may only be accessed and edited by the person who first entered that account until it is validated.
+* Accounts that do not have an E-Mail address cannot be validated until the person who entered that account enters an E-Mail address to that account.
+
+Processes:
+
+Create account directly using "Register" button.
+    * This REQUIRES an E-Mail address and must be validated for the person to access anything under that account again.
+    * Person who created an account directly may continue to enter registrations as long as the session exists. After that, the account must be validated for access.
+    
+Add a registrant
+    
+    If an E-Mail address is entered when adding a registrant...
+
+        If there's already an account matching the E-Mail address and it has been validated...
+            * The account ID, E-Mail address, and name are provided for display but there is no other access to the account.
+    
+        If there's no matching account for that E-Mail address...
+            * An account is created with "registered_by" field containing the account ID of the person submitting the regsitration.
+            * An E-Mail is sent to the E-Mail address to request validation.
+            * The person submitting this registrant can access and update the account until it's validated.
+        
+    If no E-Mail address is provided (possibly registering a minor)...
+        * The account is created anyway with "registered_by" field containing the account ID of the person submitting the registration.
+        * No E-Mail is sent
+        * The person submitting this registrant can access and update the account.
+        * An E-mail may be entered into this account at a later time so it can be validated.
+                
+Register an existing account for an event by E-Mail address
+
+    If account has not been validated and the account of the person submitting the registration matches the "registered_by" field of the account...
+        * The full account information may be displayed and/or edited and updated
+        
+    If the account has been validated or the account of the person submitting the registration DOES NOT match the "registered_by" field of the account...
+        * Only the E_Mail and name may be displayed
+        * The account may not be edited / updated
+        
+Validating an account - When an account with an E-Mail address is created, or an E-Mail address is added to an existing account...
+
+    * An E-Mail is sent to the E-Mail address with a validation code
+              
+
+So...
+
+    * Until an account is validated, only the person creating that account can see or modify the information
+    * Accounts without an E-Mail address may be used for minors or people without an E-Mail account
+    * Once an account is validated, only the E-Mail address holder may access it. 
+    
+    
+
+            
+    
index 742c718..8768340 100644 (file)
@@ -12,7 +12,7 @@
  * @release  registrations.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
  * @link     http://dev.gaslightmedia.com/
  */
-
+echo "SSDDSDSDSDSDS";
 // Load Management Registrations data abstract
 require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataManagement.php';
 
@@ -108,6 +108,7 @@ class GlmMembersAdmin_management_registrations extends GlmDataRegistrationsManag
      */
     public function modelAction($actionData = false)
     {
+
         $option                 = false;
         $settingsUpdated        = false;
         $settingsUpdateError    = false;
@@ -149,9 +150,6 @@ class GlmMembersAdmin_management_registrations extends GlmDataRegistrationsManag
                     $settingsUpdated = true;
                     $regSettings = $this->editEntry( $id );
 
-                    // Display admin message that the data has been updated
-                    glmMembersAdmin::addNotice('Management Settings for the '.GLM_MEMBERS_REGISTRATIONS_PLUGIN_NAME.' plugin have been updated.', 'AdminNotice');
-
                 } else {
                     $settingsUpdateError = true;
                 }
index ea58c69..b346ba0 100644 (file)
@@ -137,9 +137,6 @@ class GlmMembersAdmin_management_regterms extends GlmDataRegistrationsSettingsTe
                     $settingsUpdated = true;
                     $regSettings = $this->editEntry( $id );
 
-                    // Display admin message that the data has been updated
-                    glmMembersAdmin::addNotice('Terms Settings for the '.GLM_MEMBERS_REGISTRATIONS_PLUGIN_NAME.' plugin have been updated.', 'AdminNotice');
-
                 } else {
                     $settingsUpdateError = true;
                 }
index df11b46..ec587d8 100644 (file)
@@ -138,9 +138,6 @@ class GlmMembersAdmin_settings_registrationsMisc extends GlmDataRegistrationsMis
 
                     $regMisc = $this->editEntry( $id );
 
-                    // Display admin message that the data has been updated
-                    glmMembersAdmin::addNotice('Misc Settings for the '.GLM_MEMBERS_REGISTRATIONS_PLUGIN_NAME.' plugin have been updated.', 'AdminNotice');
-
                 } else {
                     $miscUpdateError = true;
                 }
diff --git a/models/front/registrations/cartLinkWidget.php b/models/front/registrations/cartLinkWidget.php
new file mode 100644 (file)
index 0000000..2bacefc
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+
+/*
+ * This class is a shortcode that displays a registrations request (cart) link widget
+ *
+ */
+class GlmMembersFront_registrations_cartLinkWidget
+{
+    /**
+    * WordPress Database Object
+    *
+    * @var $wpdb
+    * @access public
+    */
+    public $wpdb;
+    /**
+    * Plugin Configuration Data
+    *
+    * @var $config
+    * @access public
+    */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contractor sets up this model. At this time that only includes
+     * storing away the WordPress data object and GLM associate plugin configuration array.
+     *
+     * @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 determines which registrations page is requested, loads and runs that
+     * model, then returns the result array back to the controller.
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successful 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 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.
+     *
+     */
+    public function modelAction($actionData = false)
+    {
+
+        $haveCart = false;
+
+        $cartData = apply_filters('glm_members_registrations_cart_summary_data', false, false);
+
+        if (is_array($cartData)) {
+            $haveCart = true;
+        }
+
+        // Compile template data
+        $templateData = $cartData;
+        $templateData['haveCart'] = $haveCart;
+
+        //echo "<pre>".print_r($templateData,1)."</pre>";
+
+        $view = 'cartLinkWidget';
+
+        // Return status, any suggested view, and any data to controller
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => 'front/registrations/' . $view . '.html',
+            'data'          => $templateData
+        );
+
+    }
+ }
index 0623890..88994cf 100644 (file)
@@ -88,7 +88,7 @@
         $view = 'registration';
 
         // Load cart support class
-        include GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH . '/regCartSupport.php';
+        require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH . '/regCartSupport.php';
         $RegCart = new GlmRegCartSupport( $this->wpdb, $this->config );
 
         // Check if there's a current session
index 49e91aa..9e95a53 100644 (file)
  *
  *  *** Also note that parameters will be in the context of the main front controller constructor. ***
  */
+
+/*
+ * Start Session before output - For Registrations Request (cart) activities
+ */
 add_action('init', function(){
     if ( !session_id() ) {
         session_start();
     }
 });
+
+/*
+ * Add a filter to provide access to an existing request (cart) and info about it
+ *
+ * Returns an array of request summary data, status, and link to the cart page.
+ * Returns false if no active request in the current session.
+ *
+ *
+ *
+ */
+add_filter(
+    'glm_members_registrations_cart_summary_data',
+    function(){
+
+        // Get cart summary data
+        require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/regCartSupport.php';
+        $RegCartSupport = new GlmRegCartSupport($this->wpdb, $this->config);
+        $regCartSummary = $RegCartSupport->regCartSummary();
+
+        // Add in the current link url for the cart page
+        $regCartSummary['cartUrl'] = GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/?page=cart';
+
+        return $regCartSummary;
+    },
+    10,
+    2
+);
index b77f9ba..ce39d9c 100644 (file)
@@ -1,3 +1,22 @@
 <!-- Hooks Help from glm-member-db-registrations Add-On -->
 
         <tr><th colspan="3" class="glm-notice"><p>Registrations Add-On</p></th></tr>
+
+        <tr>
+            <td>glm_members_registrations_cart_summary_data</td>
+            <td>Filter</td>
+            <td></td>
+            <td>Filter that returns status and summary information for an active registrations cart (request).
+<pre>Array
+(
+    [id]                => ID of the reg_request record for a request that is specified in the current session
+    [account_fname]     => First name of account that created the request (cart)
+    [account_lname]     => Last name
+    [status]            => Status of this cart (see submission_status in config/plugin.ini for this plugin)
+    [numb_events]       => Number of events in request
+    [numb_registrants]  => Number of registrants in request
+    [last_update]       => Date/Time this request (cart) was updated 
+    [cartUrl]           => Current link URL to the cart page
+)</pre>
+            </td>
+        </tr>
index 4e33675..216eb26 100644 (file)
@@ -104,6 +104,16 @@ $glmMembersRegistrationsShortcodes = array(
             'account'       => false,
 
         )
+    ),
+
+    // Short code that displays a default cart link widget
+    'glm-members-registrations-cart-link-widget' => array(
+        'plugin'     => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+        'menu'       => 'registrations',
+        'action'     => 'cartLinkWidget',
+        'table'      => false,
+        'attributes' => array(
+        )
     )
 
 );
@@ -202,4 +212,13 @@ $glmMembersRegistrationsShortcodesDescription = '
             that is not currently logged in may be permitted in some restricted cases.
         </td>
     </tr>
+    <tr>
+        <th>[glm-members-registrations-cart-link-widget]</th>
+        <td>&nbsp;</td>
+        <td width="50%">
+            This shortcode outputs a generic cart link widget that indicates cart status and content.<br>
+            A customer cart link widget may be created using the "glm_members_registrations_cart_summary_data"
+            filter to obtain all of the needed data.
+        </td>
+    </tr>
 ';
index 37e248e..2e6834a 100644 (file)
@@ -82,10 +82,10 @@ $glmMembersRegistrationsAddOnValidActions = array(
     ),
     'frontActions' => array(
         'registrations' => array(
-            'index'                     => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG
-
+            'index'                     => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+            'cartLinkWidget'            => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG
         )
-    ),
+    )
 );
 
 ?>
index 0331205..6ebbb29 100644 (file)
@@ -24,7 +24,7 @@
                         <th>{$terms.reg_term_registrations_name} Page Permalink Name:</th>
                         <td>
                             <input type="text" name="canonical_reg_page" value="{$regSettings.fieldData.canonical_reg_page}">
-                            <br>Use only the page name at the end of the permalink for the member detail page.
+                            <br>Use only the page name at the end of the permalink for the registrations detail page.
                         </td>
                     </tr>
                     <tr>
diff --git a/views/front/registrations/cartLinkWidget.html b/views/front/registrations/cartLinkWidget.html
new file mode 100644 (file)
index 0000000..cc3eb70
--- /dev/null
@@ -0,0 +1,23 @@
+<div id="registrations-cart-link-widget">
+
+    <h3>Registrations Cart</h3>
+
+    {if $haveCart}
+        <a href="{$cartUrl}">
+        <div style="border: 1px solid black;">
+            <p>
+                Hi {$account_fname} {$account_lname}, you have {$numb_registrants} registrants for {$numb_events} events currently selected.
+                Click this box to view your registration request cart.
+            </p>
+            <p>
+                This is a temporary cart link widget - see views/front/registrations/cartLinkWiget.html
+                or build your own using data from the glm_members_registrations_cart_summary_data filter.
+            </p>
+        </div>  
+        </a>
+    {else}
+        <p>No current cart</p>
+    {/if}
+
+
+</div>
\ No newline at end of file