The discuz of the integration strategy and the implementation of the policy limitation

Source: Internet
Author: User

Ext.: Http://www.zlnxn.com/discuz%E4%B8%8B%E7%A7%AF%E5%88%86%E7%AD%96%E7%95%A5%E7%9A%84%E6%B7%BB%E5%8A%A0%E5%8F%8A %e7%ad%96%e7%95%a5%e9%99%90%e5%88%b6%e7%9a%84%e5%ae%9e%e7%8e%b0/

Recently the new project is mainly to do a points & Coins & Medal system, is based on the Discuz two times development, so it is inevitable to study the Discuz integral system. First to see the background of the integration settings, some integration strategy can be used after simple setup, but there are a number of integration strategies need to add their own, and implement the policy constraints. Add is not difficult, directly in the database to insert the appropriate data, the most critical is the implementation of policy constraints. Here is a brief introduction to what is the policy constraints, such as DZ (Discuz) The original integration strategy has such a: Log in once a day, points +2, Money +1, the number of rewards is 10 times, this is a complete integration strategy, the policy limit is: Log in every day-how to determine each login is on the same date Reward times 10 times-how to control this number of times.
The next step is to go deep into the code level to trace the analysis, the analysis found that the implementation of policy constraints is probably such a thought: (1) Read the background settings from the cache file integration strategy (method: Loadcache (' creditrule ')); (2) according to (1) The resulting array is then read from the database The Integration change log (method: Getrulelog ()), (3) based on (2) The results of the implementation of the integration strategy, the implementation of the limit is mainly through switch ($rule [' Cycletype ']) to control the branch direction, $ rule[' Cycletype ' is the period type of each integration strategy, the types of different periods correspond to different processing methods, and the logical part of each integration strategy action is implemented below. So to add a new integration strategy, after adding a record in the database, the implementation of the restriction will be done under this switch ($rule [' Cycletype ']) control statement, according to the period type of your newly added integration strategy, the corresponding increase case, It then implements the so-called restriction (the logical part of the action) below the case.
      Here are some of the most important ways to focus your integration strategy: Execrule ($action, $uid = 0, $needle = ", $coef = 1, $update = 1, $fid = 0), the method is located in/source/class/class_credit. Parameters: $action-integral action, such as daily login to the corresponding $action=daylogin, if you need to add a new integration strategy, the name is: 5 consecutive days of login, then $action can be taken as login_continuous; $uid-User ID, This is needless to say; $needle-basically unnecessary; $coef-integral coefficient; $update-Controls whether the write of the integral change log and the final execution of the integral change, usually using the default; $fid-Forum ID, which is used primarily to read the restrictions on individual forum points , the default is generally used. The method is mainly divided into three parts: (1) Getrule (), reading the integration strategy of background settings, the result is an array $rule, the array contains Rulename,cycletype,cycletime, Rewardnum, and some of the EXTCREDITS1-EXTCREDITS8, have two purposes: a. As an important parameter for the final implementation of integral changes in Updatemembercount (); b. Provide relevant data for the integration policy restrictions. (2) Getrulelog (), read the integral change log, as a pre-preparatory work to limit the implementation, but also include some initial decisions, (3) switch ($rule [' Cycletype ']), limiting the actual start of the implementation of the position, about this control statement above has been done, It is not known here that the control statement ultimately determines whether the value of the parameter $updatecredit is true or false, that is, the ability to perform an integral change: Updatecreditbyrule (). In essence, the method of achieving integral change is: Updatemembercount (). Here is a little trick, that is, if your integration strategy limit is simple, and do not need to cache, write logs and so on, can completely bypass the DZ complex processing process, only need to prepare an array $rule and $uid, such as Array (' extcredits2 ' = 1, ' Extcredits8 ' =>5), $uid = 1, then call Updatemembercount directly ($rule, $uid) to complete the operation of the integral change. However, if the efficiency of the execution of the program isTo see and analyze the changes in the integration, personal advice or the use of DZ processing process is better. Another point worth noting is: After adding the integration strategy in the background, be sure to remember to clear the cache, or call Getrule () will have problems, not get the correct $rule. Today is because did not notice the cache, only to waste a lot of time, then quite confused, and finally a step-by-step tracking code to find the reason.
It's a good idea to use die,exit,showmessage to set breakpoints when tracking code, and it's also recommended that you zend the IDE as a development tool, not just because it's an IDE, It is also important to use the shortcut key CTRL and mouse to quickly navigate to the next method or variable when tracking the code by pressing CTRL and then clicking on the relevant method or variable with the mouse to quickly locate it. This method is useful for code like DZ that does not have a bit of comment and is packaged exactly as your product ideas. Although DZ's code reads disgusting, has no annotations, and is completely encapsulated, there are plenty of places to learn, such as caching things, code handling, and so on. Recently, because of the relationship between the project and the Forum business will be more contact DZ, I hope to learn more valuable things, melt for their own use.
To sum up is how to add a new integral strategy under DZ, read this article of the children's shoes, if you feel inappropriate place also please correct, learn from each other, mutual reference, common progress.

The discuz of the integration strategy and the implementation of the policy limitation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.