From e78eede1b3ad977f89c45effc9a4ef1275d90214 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 30 Jul 2011 02:23:27 +0000 Subject: [PATCH] Rewritten to use filter and wrapper --- DOCS/TODOs.txt | 8 +++--- inc/extensions/ext-coupon.php | 14 ++++++++--- inc/filter/coupon_filter.php | 25 +++++++++++++++++++ inc/language/coupon_de.php | 2 +- inc/libs/coupon_functions.php | 12 +++++++++ inc/modules/admin/what-config_coupon.php | 2 +- inc/modules/member/what-cash_coupon.php | 23 ++++++----------- .../de/html/admin/admin_config_coupon.tpl | 10 ++++---- 8 files changed, 66 insertions(+), 30 deletions(-) diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index 6db624ffc4..9ed35e0459 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -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 * @@ -142,7 +142,7 @@ ./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 diff --git a/inc/extensions/ext-coupon.php b/inc/extensions/ext-coupon.php index 2e4acb34b0..18cb429835 100644 --- a/inc/extensions/ext-coupon.php +++ b/inc/extensions/ext-coupon.php @@ -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 {CONFIG_OPEN}_MYSQL_PREFIX{CONFIG_CLOSE}_points_data 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ügt.'); break; } // END - switch break; diff --git a/inc/filter/coupon_filter.php b/inc/filter/coupon_filter.php index 44f7ff921b..1a1fea8454 100644 --- a/inc/filter/coupon_filter.php +++ b/inc/filter/coupon_filter.php @@ -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] ?> diff --git a/inc/language/coupon_de.php b/inc/language/coupon_de.php index 7bf55211de..08738e7f2f 100644 --- a/inc/language/coupon_de.php +++ b/inc/language/coupon_de.php @@ -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önnen diesen Ausgangswert beim Erstellen von neuen Gutscheinen nachträglich anpassen.", 'ADMIN_CONFIG_COUPON_DEFAULT_POINTS' => "Ausgangsvergütung in {?POINTS?}. Sie können diesen Ausgangswert beim Erstellen von neuen Gutscheinen nachträ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östen {?POINTS?} abgebucht werden sollen:", // Admin - Send coupon to members diff --git a/inc/libs/coupon_functions.php b/inc/libs/coupon_functions.php index c61c2c5a02..b5b2a911e3 100644 --- a/inc/libs/coupon_functions.php +++ b/inc/libs/coupon_functions.php @@ -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] ?> diff --git a/inc/modules/admin/what-config_coupon.php b/inc/modules/admin/what-config_coupon.php index cfd0aa9bf8..dc54915133 100644 --- a/inc/modules/admin/what-config_coupon.php +++ b/inc/modules/admin/what-config_coupon.php @@ -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'); diff --git a/inc/modules/member/what-cash_coupon.php b/inc/modules/member/what-cash_coupon.php index bbc77f1aab..925b0587a5 100644 --- a/inc/modules/member/what-cash_coupon.php +++ b/inc/modules/member/what-cash_coupon.php @@ -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'] . '%}'); diff --git a/templates/de/html/admin/admin_config_coupon.tpl b/templates/de/html/admin/admin_config_coupon.tpl index 014a32cf9c..6f5ca04471 100644 --- a/templates/de/html/admin/admin_config_coupon.tpl +++ b/templates/de/html/admin/admin_config_coupon.tpl @@ -3,30 +3,30 @@ - + - + - + - + -- 2.39.5
- {--ADMIN_CONFIG_COUPON_TITLE--}: + {--ADMIN_CONFIG_COUPON_TITLE--}
{--ADMIN_CONFIG_COUPON_DEFAULT_TIME--}:{--ADMIN_CONFIG_COUPON_DEFAULT_TIME--} $content[coupon_default_time_selection]
{--ADMIN_CONFIG_COUPON_AUTOPURGE_TIME--}:{--ADMIN_CONFIG_COUPON_AUTOPURGE_TIME--} $content[coupon_autopurge_time_selection]
{--ADMIN_CONFIG_COUPON_DEFAULT_POINTS--}:{--ADMIN_CONFIG_COUPON_DEFAULT_POINTS--} ({?POINTS?})
{--ADMIN_CONFIG_COUPON_USERID--}:{--ADMIN_CONFIG_COUPON_USERID--} $content[coupon_userid]