I'm doing a system to log users' actions, such as the purchases it made, friends it added, among anothers. For example, when a user purchase some products, the following message should appear in your profile:
Foo bought the products A, B, C, D and F.
I could save the whole string in the database, but the site will have more than one language, which will make unviable keep a record for each language. My idea is to have a string with the template of the action taken and pass it to the sprintf
function, however, the amount of products may change, so the number of arguments as well. In this situation, how should I proceed?
Edit #1: My question is not about the database schema, the schema I'm using is this: Databases: Making a Log of actions, how to handle various references?, The question is how to make a string to be used with sprintf that can receive as many arguments as needed.
Something like this: "%s bought the products [magic here]"
Have a unique code for each action. Store the action in a number of fields in a table called log
:
user action products
-----------------------------------
Foo BUY A|B|C|D
Map BUY
to human-readable descriptions in your application as required.
You could separate out the individual products if required, to achieve full normalisation... though if you don't need anything more with them and their representations are concise IDs (with no |
in them!) then tokenisation will do fine.