如何在 PHP 中建模和跟踪实现目标的需求

发布于 2024-09-12 22:37:03 字数 517 浏览 4 评论 0原文

我正在使用 Zend Framework 构建一个 Web 应用程序,我需要对逻辑进行建模或跟踪一些与跟踪目标进度有关的逻辑。

让我用一个示例目标来说明

用户需要完成全部以下三项:
A) 活动一
B) 活动二
C) 活动三
用户需要完成以下其中一项
D) 活动四
E) 活动五
F) 活动六

在完成第一组的全部三项和第二组的一项后,USER 已完成该目标。我将如何在 PHP 中对此进行建模,以便网络应用程序知道目标已经完成以及如何将数据存储在数据库中?

需要明确的是,像这样的目标会有很多不同类型,但它们本质上都非常相似。

I'm building a webapp using the Zend Framework, and I need to model logic or keep track of some logic that has to do with tracking progress towards a goal.

Let me illustrate with a sample goal.

USER Needs to Complete All Three of the following:
A) Activity One
B) Activity Two
C) Activity Three
USER Needs to Complete One of the following:
D) Activity Four
E) Activity Five
F) Activity Six

After completing all three from the first group and one from the second group the USER has completed that goal. How would I go about modeling this in PHP so that the webapp knows the goal has been completed and how would I store the data in the database?

To be clear, there will be many different types of goals like this, but all of them will be quite similar in nature.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白昼 2024-09-19 22:37:03

假设A、B& C 和 D、E 和 F 将始终属于目标中的特定组,我将这样设计:

Goal::isComplete()
{
  foreach (Group)
  {
    switch (Group::type())
    {
      case "all":
        TRUE if all complete
        break

      case "any":
        TRUE if any complete
        break;
    }
  }

  if all TRUE
    return TRUE
}

或者用英语...

然后,您可以将所有活动存储在活动表中,并将它们所属的组定义为对 Groups 表的简单 id 引用。当一个活动完成时,可以在数据库中对其进行标记。

要检查已完成的目标,您只需查找目标所需的每个组即可。每个组要么是“全部”,要么是“任意”(或其他此类选项,如“min-2”),这将告诉脚本要检查活动完成情况的内容。然后,每个组可以根据其活动返回 TRUE 或 FALSE。假设所有组都是必需的,那么目标就可以很容易地被识别为完成与否。

数据库可能如下所示:

Activities
- id
- group_id
- name
- completed
- [details about activitiy]

Groups
- id
- goal_id
- type  (ENUM: 'any', 'all')
- completed
- [details about group]

Goals
- id
- completed
- [details about goal]

每当活动更新时,组和目标中的已完成值都需要主动更新,或者忽略,并且它们的值始终动态计算。

这有意义并且符合您的要求吗?

Assuming that A, B & C and D, E, & F will always belong to a specific group within the goal, I would design it thus:

Goal::isComplete()
{
  foreach (Group)
  {
    switch (Group::type())
    {
      case "all":
        TRUE if all complete
        break

      case "any":
        TRUE if any complete
        break;
    }
  }

  if all TRUE
    return TRUE
}

Or in English...

You could then store all of your Activities within an Activities table and define the group they are a part of as a simple id reference to the Groups table. When an Activity is complete, it can be marked thus in the DB.

To check for completed goals, you simply need to look for each Group that is required for the Goal. Each group would either be "all" or "any" (or other such options, like "min-2"), and this would tell the script what to check for with the Activity completions. Each Group can then return TRUE or FALSE depending upon its Activities. Assuming that all Groups are required, the Goal would then easily be identified as Complete or not.

The database can look like:

Activities
- id
- group_id
- name
- completed
- [details about activitiy]

Groups
- id
- goal_id
- type  (ENUM: 'any', 'all')
- completed
- [details about group]

Goals
- id
- completed
- [details about goal]

The Completed values within Groups and Goals would need to be actively updated whenever Activities is updated, or left out and their values always dynamically worked out.

Does this make sense and do what you are requiring?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文