]> git.mxchange.org Git - mailer.git/commitdiff
Rewritten to use filter and wrapper
authorRoland Häder <roland@mxchange.org>
Sat, 30 Jul 2011 02:23:27 +0000 (02:23 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 30 Jul 2011 02:23:27 +0000 (02:23 +0000)
DOCS/TODOs.txt
inc/extensions/ext-coupon.php
inc/filter/coupon_filter.php
inc/language/coupon_de.php
inc/libs/coupon_functions.php
inc/modules/admin/what-config_coupon.php
inc/modules/member/what-cash_coupon.php
templates/de/html/admin/admin_config_coupon.tpl

index 6db624ffc43bd1f0d34c8ca7bee58e352bb57ac5..9ed35e04591e1150b3da26cf7c4a93ba204de02e 100644 (file)
@@ -80,9 +80,9 @@
 ./inc/libs/task_functions.php:247:             // @TODO These can be rewritten to filter
 ./inc/libs/task_functions.php:51:// @TODO Move all extension-dependent queries into filters
 ./inc/libs/theme_functions.php:93:     // @TODO Can't this be rewritten to an API function?
-./inc/libs/user_functions.php:221:// @TODO Double-check configuration entry here
-./inc/libs/user_functions.php:312:                     // @TODO Make this filter working: $ADDON = runFilterChain('post_login_update', $content);
-./inc/libs/user_functions.php:341:                     // @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
+./inc/libs/user_functions.php:227:// @TODO Double-check configuration entry here
+./inc/libs/user_functions.php:318:                     // @TODO Make this filter working: $ADDON = runFilterChain('post_login_update', $content);
+./inc/libs/user_functions.php:347:                     // @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
 ./inc/libs/yoomedia_functions.php:114: $response = YOOMEDIA_QUERY_API('out_textmail.php', true); // @TODO Ask Yoo!Media for test script
 ./inc/load_config.php:75:      // @TODO Rewrite them to avoid this else block
 ./inc/loader/load-extension.php:13: * @TODO Rewrite this whole file                                        *
 ./inc/modules/admin/what-mem_add.php:63:               // @TODO Cant this be rewritten?
 ./inc/modules/admin/what-mem_add.php:79:               // @TODO This can be somehow rewritten to a function
 ./inc/modules/admin/what-unlock_emails.php:84:                                 // @TODO Rewrite these if-blocks to a filter
-./inc/modules/admin/what-usage.php:87: // @TODO This code is double, see loadTemplate() and loadEmailTemplate() in functions.php
+./inc/modules/admin/what-usage.php:89: // @TODO This code is double, see loadTemplate() and loadEmailTemplate() in functions.php
 ./inc/modules/admin/what-usr_online.php:49:    // @TODO Add a filter for sponsor
 ./inc/modules/guest/what-beg.php:51:// @TODO No more needed? define('__BEG_USERID_TIMEOUT', createFancyTime(getBegUseridTimeout()));
 ./inc/modules/guest/what-login.php:125:        // @TODO Move this HTML code into a template
index 2e4acb34b00e99b214a42fc194ca62170f1eb584..18cb42983559d0a588581659ed57ff1128a318a5 100644 (file)
@@ -43,10 +43,10 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Version number
-setThisExtensionVersion('0.0.2');
+setThisExtensionVersion('0.0.3');
 
 // Version history array (add more with , '0.1' and so on)
-setExtensionVersionHistory(array('0.0.0', '0.0.1', '0.0.2'));
+setExtensionVersionHistory(array('0.0.0', '0.0.1', '0.0.2', '0.0.3'));
 
 switch (getExtensionMode()) {
        case 'register': // Do stuff when installtion is running
@@ -114,6 +114,7 @@ UNIQUE (`coupon_code`)",
 
                // Remove all filters
                unregisterFilter(__FUNCTION__, __LINE__, 'determine_points_column_name', 'COUPON_CHANGE_POINTS_COLUMN_NAME', true, isExtensionDryRun());
+               unregisterFilter(__FUNCTION__, __LINE__, 'post_cash_coupon', 'POST_CASH_COUPON', true, isExtensionDryRun());
                break;
 
        case 'activate': // Do stuff when admin activates this extension
@@ -149,7 +150,14 @@ UNIQUE (`coupon_code`)",
                                addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_points_data` SET `subject`='coupon_cashed' WHERE `subject`='coupon' LIMIT 1");
 
                                // Update notes (these will be set as task text!)
-                               setExtensionUpdateNotes('');
+                               setExtensionUpdateNotes('Eintrag in <strong>{CONFIG_OPEN}_MYSQL_PREFIX{CONFIG_CLOSE}_points_data</strong> umbenannt.');
+                               break;
+
+                       case '0.0.3': // SQL queries for v0.0.3
+                               registerFilter('post_cash_coupon', 'POST_CASH_COUPON', false, true, isExtensionDryRun());
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Filter zum Post- und Pre-Filter hinzugef&uuml;gt.');
                                break;
                } // END - switch
                break;
index 44f7ff921bf0716d30aa6d0cf0656b6b3494e253..1a1fea8454f666a10e0701b4b1fcde2bd5f2a739 100644 (file)
@@ -51,5 +51,30 @@ function FILTER_COUPON_CHANGE_POINTS_COLUMN_NAME ($filterData) {
        return $filterData;
 }
 
+// Filter to do generic post-coupon-cash things
+function FILTER_POST_CASH_COUPON ($filterData) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
+       // Now we just need to book that points on the user's account
+       initReferalSystem();
+       addPointsThroughReferalSystem('coupon_cashed', $filterData['userid'], $filterData['points']);
+
+       // Subtract points from member account if the admin has selected one
+       if (isValidUserId(getCouponUserid())) {
+               // Subtract from this account and ignore return status
+               subtractPoints('cashed_coupon', getCouponUserid(), $filterData['points']);
+       } // END - if
+
+       // Translate some data
+       $filterData['coupon_expired'] = generateDateTime($filterData['coupon_expired'], '0');
+       $filterData['coupon_created'] = generateDateTime($filterData['coupon_created'], '0');
+
+       // Send admin notification
+       sendAdminNotification('{--ADMIN_COUPON_CASHED_SUBJECT--}', 'admin_coupon_cashed', $filterData, $filterData['userid']);
+
+       // Return data
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
+       return $filterData;
+}
+
 // [EOF]
 ?>
index 7bf55211de8e8a220e539195ce6ef39f7458b178..08738e7f2fefa3153cd3cd46110f5e20ec7008b9 100644 (file)
@@ -46,7 +46,7 @@ addMessages(array(
        'ADMIN_CONFIG_COUPON_TITLE' => "Allgemeine Einstellungen zu den Gutscheinen",
        'ADMIN_CONFIG_COUPON_DEFAULT_TIME' => "Zeit, bis Gutscheine ablaufen sollen. Sie k&ouml;nnen diesen Ausgangswert beim Erstellen von neuen Gutscheinen nachtr&auml;glich anpassen.",
        'ADMIN_CONFIG_COUPON_DEFAULT_POINTS' => "Ausgangsverg&uuml;tung in {?POINTS?}. Sie k&ouml;nnen diesen Ausgangswert beim Erstellen von neuen Gutscheinen nachtr&auml;glich anpassen.",
-       'ADMIN_CONFIG_COUPON_AUTOPURGE_TIME' => "Dauer bis abgelaufene Gutscheine aus der Datenbank entfernt werden",
+       'ADMIN_CONFIG_COUPON_AUTOPURGE_TIME' => "Dauer bis abgelaufene Gutscheine aus der Datenbank entfernt werden:",
        'ADMIN_CONFIG_COUPON_USERID' => "Mitgliederaccount, von dem die eingel&ouml;sten {?POINTS?} abgebucht werden sollen:",
 
        // Admin - Send coupon to members
index c61c2c5a0268b99f16b0590a5f6761dd8393088f..b5b2a911e333f2468fa1091be6658f2943e86173 100644 (file)
@@ -64,5 +64,17 @@ function getCouponAutopurgeTime () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// Wrapper function for 'coupon_userid'
+function getCouponUserid () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Get config entry
+               $GLOBALS[__FUNCTION__] = getConfig('coupon_userid');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // [EOF]
 ?>
index cfd0aa9bf82fad33edbc968bd0d41c67d74d19aa..dc549151333d654c14d6f94ff937054039b815ae 100644 (file)
@@ -51,7 +51,7 @@ if (isFormSent()) {
        adminSaveSettingsFromPostData();
 } else {
        // Add userid selection
-       $content['coupon_userid'] = addMemberSelectionBox(getConfig('coupon_userid'), false, true, true, 'coupon_userid');
+       $content['coupon_userid'] = addMemberSelectionBox(getCouponUserid(), false, true, true, 'coupon_userid');
 
        // Prepare some template data
        $content['coupon_default_time_selection']   = createConfigurationTimeSelections('coupon_default_time'  , 'WDh');
index bbc77f1aabeb68e5254e682fca838b748b5d9e72..925b0587a5a9856b2ac9fe0dbdfe1b29fffec8f1 100644 (file)
@@ -58,6 +58,8 @@ if (isFormSent()) {
                // Search for the coupon
                $result = SQL_QUERY_ESC("SELECT
        c.`coupon_id`,
+       c.`userid`,
+       c.`coupon_code`,
        UNIX_TIMESTAMP(d.`coupon_created`) AS `coupon_created`,
        UNIX_TIMESTAMP(d.`coupon_expired`) AS `coupon_expired`,
        d.`coupon_type`,
@@ -87,6 +89,9 @@ LIMIT 1",
                        // Load data
                        $content = SQL_FETCHARRAY($result);
 
+                       // Run pre-filter
+                       $content = runFilterChain('pre_cash_coupon', $content);
+
                        // Mark it as "cashed"
                        SQL_QUERY_ESC("UPDATE
        `{?_MYSQL_PREFIX?}_user_coupons`
@@ -118,22 +123,8 @@ LIMIT 1",
                                debug_report_bug(__FILE__, __LINE__, 'Coupon data cannot be updated! coupon_id=' . $content['coupon_id']);
                        } // END - if
 
-                       // Now we just need to book that points on the user's account
-                       initReferalSystem();
-                       addPointsThroughReferalSystem('coupon_cashed', getMemberId(), $content['points']);
-
-                       // Subtract points from member account if the admin has selected one
-                       if (isValidUserId(getConfig('coupon_userid'))) {
-                               // Subtract from this account and ignore return status
-                               subtractPoints('cashed_coupon', getConfig('coupon_userid'), $content['points']);
-                       } // END - if
-
-                       // Translate some data
-                       $content['coupon_expired'] = generateDateTime($content['coupon_expired'], '0');
-                       $content['coupon_created'] = generateDateTime($content['coupon_created'], '0');
-
-                       // Send admin notification
-                       sendAdminNotification('{--ADMIN_COUPON_CASHED_SUBJECT--}', 'admin_coupon_cashed', $content, getMemberId());
+                       // Run post filter chain
+                       $content = runFilterChain('post_cash_coupon', $content);
 
                        // Display message
                        displayMessage('{%message,MEMBER_COUPON_CODE_CASHED=' . $content['points'] . '%}');
index 014a32cf9ce5ab3f888b4bf96cca8d500f036f16..6f5ca04471801fad7ed03e9aa5f044d367935f61 100644 (file)
@@ -3,30 +3,30 @@
 <table border="0" cellspacing="0" cellpadding="0" class="table dashed">
        <tr>
                <td class="table_header bottom" colspan="2" align="center">
-                       <strong>{--ADMIN_CONFIG_COUPON_TITLE--}:</strong>
+                       <strong>{--ADMIN_CONFIG_COUPON_TITLE--}</strong>
                </td>
        </tr>
        <tr>
-               <td class="bottom" align="right">{--ADMIN_CONFIG_COUPON_DEFAULT_TIME--}:</td>
+               <td class="bottom" align="right">{--ADMIN_CONFIG_COUPON_DEFAULT_TIME--}</td>
                <td class="bottom" align="center">
                        $content[coupon_default_time_selection]
                </td>
        </tr>
        <tr>
-               <td class="bottom" align="right">{--ADMIN_CONFIG_COUPON_AUTOPURGE_TIME--}:</td>
+               <td class="bottom" align="right">{--ADMIN_CONFIG_COUPON_AUTOPURGE_TIME--}</td>
                <td class="bottom" align="center">
                        $content[coupon_autopurge_time_selection]
                </td>
        </tr>
        <tr>
-               <td class="bottom" align="right">{--ADMIN_CONFIG_COUPON_DEFAULT_POINTS--}:</td>
+               <td class="bottom" align="right">{--ADMIN_CONFIG_COUPON_DEFAULT_POINTS--}</td>
                <td class="bottom" align="center">
                        <input type="input" name="coupon_default_points" class="form_field" value="{%config,translateComma=coupon_default_points%}" size="5" maxlength="20" />
                        <span class="tiny">({?POINTS?})</span>
                </td>
        </tr>
        <tr>
-               <td class="bottom" align="right">{--ADMIN_CONFIG_COUPON_USERID--}:</td>
+               <td class="bottom" align="right">{--ADMIN_CONFIG_COUPON_USERID--}</td>
                <td class="bottom" align="center">
                        $content[coupon_userid]
                </td>