function _action_submit_intervals() { // parse results from response $ruleId = _post('id'); $rule = $this->getRuleManager()->getRule($ruleId); // new intervals object $intervals = new ReminderIntervals(); $change = false; foreach (ReminderIntervalType::values() as $type) { foreach (ReminderIntervalRange::values() as $range) { $amtKey = $type->code . "-" . $range->code; $timeKey = $amtKey . "-timeunit"; $amt = _post($amtKey); $timeUnit = TimeUnit::from(_post($timeKey)); if ($amt && $timeUnit) { $detail = new ReminderIntervalDetail($type, $range, $amt, $timeUnit); $intervals->addDetail($detail); $change = true; } } } if ($change) { $this->getRuleManager()->updateIntervals($rule, $intervals); } $this->redirect("index.php?action=detail!view&id={$ruleId}"); }
/** * * @param Rule $rule * @param ReminderIntervals $intervals */ function updateIntervals($rule, $intervals) { // remove old intervals sqlStatement(self::SQL_REMOVE_INTERVALS, array($rule->id)); // insert new intervals foreach ($intervals->getTypes() as $type) { $typeDetails = $intervals->getDetailFor($type); foreach ($typeDetails as $detail) { sqlStatement(self::SQL_INSERT_INTERVALS, array($rule->id, $type->code . "_reminder_" . $detail->intervalRange->code, $detail->timeUnit->code, $detail->amount)); } } }