I am creating a Rule in D6 to notify a person when "approved" volunteer hours reach a multiple of 8. Hours are logged as a custom content type with a numeric CCK field, and "approved" is a Flag. I was doing a modulo 8 calculation but realized that won't suffice. If a user has 7 hours approved and puts in another 2, the Rule returns false and the notification isn't sent. Here is the current Rule code that fires whenever a node is flagged:
$result = db_result(db_query("SELECT
SUM(vol_hours.field_hours_worked_value) AS TotalHours
FROM node
INNER JOIN content_type_volunteer_log vol_hours ON node.vid = vol_hours.vid
INNER JOIN flag_content ON node.vid = flag_content.content_id AND flag_content.fid = 3
WHERE node.uid = '%d'
AND YEAR(field_date_worked_value) = YEAR(NOW())" , $node->uid));
if ($result % 8 == 0) {
return TRUE;
}
else {
return FALSE;
}
Any advice for how to solve this? Do I need an additional Flag type of "multiple of 8" that increments 开发者_运维技巧after each threshold is passed, maybe as a scheduled Rule instead of a triggering Rule?
i'd store the "last_checked_value" and trigger an event when floor(current_value/8) > floor(last_checked_value/8)
精彩评论