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}"); }
/** * Creates a ReminderIntervals object from rows in the rule_reminder table, * and sets it in the supplied Rule. * @param Rule $rule */ private function fillRuleReminderIntervals($rule) { $stmt = sqlStatement(self::SQL_RULE_REMINDER_INTERVAL, array($rule->id)); $reminderInterval = new ReminderIntervals(); for ($iter = 0; $row = sqlFetchArray($stmt); $iter++) { $amount = $row['value']; $unit = TimeUnit::from($row['method_detail']); $methodParts = explode('_', $row['method']); $type = ReminderIntervalType::from($methodParts[0]); $range = ReminderIntervalRange::from($methodParts[2]); if (!is_null($type) && !is_null($range) && !is_null($unit)) { $detail = new ReminderIntervalDetail($type, $range, $amount, $unit); $reminderInterval->addDetail($detail); } } $rule->setReminderIntervals($reminderInterval); }