开发者

implementing a point system

开发者 https://www.devze.com 2023-03-21 21:48 出处:网络
I\'m trying to put together a Yahoo! Answers style point system where contributing certain content gains you (the user) a certain number of points. I\'m thinking about ways of implementing this system

I'm trying to put together a Yahoo! Answers style point system where contributing certain content gains you (the user) a certain number of points. I'm thinking about ways of implementing this system.

I'm k开发者_Python百科ind of a n00b when it comes to PHP (thank you CodeIgniter!) so I'm just looking for advice on how to go about this.

I have two ideas. The first is having a column in my user table that is added to and subtracted from a certain number of points when users perform certain actions. I imagine that this would be lighter code, but possibly less secure than the next idea.

The other idea is to do the math whenever the user's points are being called. I wonder how this will affect performance or if it's a good idea at all.

For example a person logging in to the site will get a couple points (limited once per day) (maybe it's not possible without storing the points in a table). Another example is when they submit a definition they get 15 points and log entries get them 10 points. I also want to give them badges relative to their number of points.

I'm guessing that having the points stored in a table is the best route, but I want to get a better idea of how I can approach this before I jump into it. Any help is greatly appreciated.

*edit: I should add that it's only the users that have points assigned to them (at least that's the plan).


Certain actions contribute to points, and part of the action (submission, login, comment) is just changing the value. Then just secure those actions - you'll need to secure them anyway...


My data schema would look like this:

Content:
  id: PK
  user_id: integer    # The author
  title: string
  contents: string
  voteCount: integer

User:
  id: PK
  name: string
  votesLeft: integer
  rating: integer

Votes:
  content_id: PK
  user_id: PK
  is_positive: boolean

And then, keep record of the votes both in the Contents table (to keep performance going well) as well as in the Votes table (so you can undo votes, and keep track of what user voted on what article.) If a user has a limited amount of votes, it can be stored in votesLeft.


you might want to take a look at the patterns:

  • Account
  • AccountingEntry
  • Snapshot

So you can have snapshots as backups (maybe once a day or once a week), and then manage the account with accounting entries :) essentially, in your use case, points = money, they are accountable for

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号