dshgdhdfcas30210 2013-07-25 22:14
浏览 69

根据mongodb(查询)触发事件发送电子邮件

So I've created a program in PHP and MongoDB for my website in which I can see useful data about my members, and filter through them.

A query could for example look like: Show me everybody who's Male, between 20 and 30, has visited the site in the past 7 days, and logged in to the site at least 10 times.

With the query above, I would get for example 100 people, and I want to set an automated email (I have the email functions) specific to the filters.

So, in this case, 100 emails would be sent, but every time a member triggers the above query (when a user logs in and matches the above query, for example the person could change his sex from Male to Female and perhaps now meet the query), the event would be triggered and an email would be sent.

How would you go about 'storing' these kind of queries, and actually testing them against the members when they visit the site?

Ps. The queries can be unknown to me, as other people could be using my website, so I cannot run an "if" logic when users login, as I don't know the query criteria of other people.

  • 写回答

1条回答 默认 最新

  • douyinbo3361 2013-08-19 20:17
    关注

    A rules engine would be most appropriate for this task. Since you're using PHP, I would suggest taking a look at the Ruler project from Justin Hileman. This, and rules engines in general, allows you to define rules (conceptually similar to DB query criteria), which in evaluate a context (one or more values) and return a boolean result. Most engines will allow you to programmatically construct rules, which means that you can store their configurations in a database (ideal if users are creating their own criteria).

    An excellent blog post on implementing Ruler can be found on Jon Wage's blog, wherein he describes how Ruler is in use at e-commerce shop OpenSky. They make heavy use of it for analytics and customer rewards (e.g. if a user refers a friend, who then purchases a product within X days, the original user receipts a credit).

    Although not covered heavily the blog post, OpenSky does have a backend UI for creating and managing rules. Individual conditions such as "is user from Facebook" are implemented in PHP, but a web UI allows complex rules to be crafted, and that configuration is, in turn, stored in the database.

    评论

报告相同问题?

悬赏问题

  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题