protected function doExecute() { $id = $this->get('_id'); $condId = $this->get('condId'); $rule = Rule::findById($id); if ($rule) { //var_dump($rule); $exists = false; if (is_array($rule->conditions)) { foreach ($rule->conditions as $idx => $rc) { if ($rc->condId == $condId) { $exists = true; array_splice($rule->conditions, $idx, 1); break; } } } if ($exists) { $ret = $rule->save(); if ($ret) { return $this->success($ret); } else { return $this->error(ErrorInfo::ERROR_NO_DB_OPERATION_ERROR, 'add ruleCondition failed'); } } else { return $this->error(ErrorInfo::ERROR_NO_DATA_NOT_FOUND, 'ruleCondition not found for _id=' . $id . ' and condId=' . $condId); } } else { return $this->error(ErrorInfo::ERROR_NO_DATA_NOT_FOUND, 'rule not found for _id=' . $id); } }
protected function doExecute() { $id = $this->get('_id'); $rule = Rule::findById($id); if ($rule) { $ruleCondition = RuleCondition::create($this->get('ruleCondition')); $exists = false; if ($ruleCondition->condId) { if (is_array($rule->conditions)) { foreach ($rule->conditions as $key => $rc) { if ($rc->condId == $ruleCondition->condId) { $exists = true; $rule->conditions[$key] = $ruleCondition; break; } } } } else { $ruleCondition->condId = ObjectUtil::guid(); } if (!$exists) { $rule->conditions[] = $ruleCondition; } $ret = $rule->save(); if ($ret) { return $this->success($ret); } else { return $this->error(ErrorInfo::ERROR_NO_DB_OPERATION_ERROR, 'add ruleCondition failed'); } } else { return $this->error(ErrorInfo::ERROR_NO_DATA_NOT_FOUND, 'rule not found for _id=' . $id); } }
protected function doExecute() { $rule = Rule::findById($this->get('_id')); if ($rule) { $ret = $rule->delete(); if ($ret) { return $this->success($ret); } else { return $this->error(ErrorInfo::ERROR_NO_DB_OPERATION_ERROR, 'remove failed'); } } else { return $this->error(ErrorInfo::ERROR_NO_DATA_NOT_FOUND, 'data not found'); } }
private function findRule() { $rule = Rule::findById($this->getRequest()->get('_id')); return $this->success($rule); }
protected function doExecute() { return $this->success(Rule::findById($this->get('_id'))); }