I would like to create an action to create and send email when a user has certain amount of hours each week. Is this possible?

Comments

chertzog’s picture

Status: Active » Closed (won't fix)

If you install the Conditional Rules (https://www.drupal.org/project/rules_conditional) module you most certainly can.

Here is a rules export that implements this type of functionality. It shows a message after a user has logged more then 40 hours in the current week.

{ "rules_time_logged" : {
    "LABEL" : "Show Message After 40 Hours in 1 Week",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_conditional", "time_tracker" ],
    "ON" : { "time_tracker_new_node-article_entry" : [] },
    "DO" : [
      { "variable_add" : {
          "USING" : { "type" : "decimal", "value" : "0" },
          "PROVIDE" : { "variable_added" : { "tracked_time_sum" : "Tracked Time Sum" } }
        }
      },
      { "entity_query" : {
          "USING" : {
            "type" : "time_tracker_entry",
            "property" : "uid",
            "value" : [ "user" ]
          },
          "PROVIDE" : { "entity_fetched" : { "loaded_entries" : "Time Entries" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "loaded-entries" ] },
          "ITEM" : { "time_entry" : "Current time_entry" },
          "DO" : [
            { "CONDITIONAL" : [
                {
                  "IF" : { "data_is" : {
                      "data" : [ "time-entry:timestamp" ],
                      "op" : "\u003E",
                      "value" : "sunday this week"
                    }
                  },
                  "DO" : [
                    { "data_calc" : {
                        "USING" : {
                          "input_1" : [ "tracked-time-sum" ],
                          "op" : "+",
                          "input_2" : [ "time-entry:duration" ]
                        },
                        "PROVIDE" : { "result" : { "calculated_result" : "Calculation result" } }
                      }
                    },
                    { "data_set" : { "data" : [ "tracked-time-sum" ], "value" : [ "calculated-result" ] } }
                  ]
                }
              ]
            }
          ]
        }
      },
      { "CONDITIONAL" : [
          {
            "IF" : { "data_is" : { "data" : [ "tracked-time-sum" ], "op" : "\u003E", "value" : "40" } },
            "DO" : [ { "drupal_message" : { "message" : "OVER 40 HOURS!!" } } ]
          }
        ]
      }
    ]
  }
}
Mo Omar’s picture

Thank you a lot. In your example, the week starts on Monday and ends Sunday?

chertzog’s picture

the week would start on sunday at midnight and run through saturday at 11:59:59pm. it uses php's strtotime for "sunday this week".

Mo Omar’s picture

Thank you Chertzog.

Mo Omar’s picture

I tried to import but I got this message:

"Integrity check for the imported configuration failed. Error message: Data selector user for parameter value is invalid.."

Any ideas how to solve this?