*/
public function update() {
$res = new Response();
- if (is_array($this->id)) {
+
+ if (is_array($this->params)) {
$res->data = array();
- foreach ($this->id as $idx => $id) {
- if ($rec = User::update($id, $this->params[$idx])) {
+ foreach ($this->params as $data) {
+ if ($rec = User::update($data->id, $data)) {
array_push($res->data, $rec->to_hash());
}
}
$res->success = true;
$res->message = "Updated " . count($res->data) . " records";
} else {
- if ($rec = User::update($this->id, $this->params)) {
+ if ($rec = User::update($this->params->id, $this->params)) {
$res->data = $rec->to_hash();
- $res->success = true;
- $res->message = "Updated record";
+
+ // SIMULATE ERROR: All records having odd-numbered ID have error.
+ if ($rec->id % 2) {
+ $res->success = false;
+ $res->message = "SIMULATED ERROR: Lorem ipsum dolor sit amet, placerat consectetuer, nec lacus imperdiet velit dui interdum vestibulum, sagittis lectus morbi, urna aliquet minus natoque commodo egestas non, libero libero arcu sed sed.";
+ } else {
+ $res->success = true;
+ $res->message = "Updated record";
+ }
} else {
- $res->message = "Failed to updated record";
- $res->success = false;
- }
- // SIMULATE ERROR: All records having odd-numbered ID have error.
- if ($this->id % 2) {
+ $res->message = "Failed to updated record " . $this->params->id;
$res->success = false;
- $res->message = "SIMULATED ERROR: Lorem ipsum dolor sit amet, placerat consectetuer, nec lacus imperdiet velit dui interdum vestibulum, sagittis lectus morbi, urna aliquet minus natoque commodo egestas non, libero libero arcu sed sed.";
}
+
}
return $res->to_json();
}
*/
public function destroy() {
$res = new Response();
-
if (is_array($this->params)) {
$destroyed = array();
- foreach ($this->params as $id) {
- if ($rec = User::destroy($id)) {
+ foreach ($this->params as $rec) {
+ if ($rec = User::destroy($rec->id)) {
array_push($destroyed, $rec);
}
}
$res->success = true;
$res->message = 'Destroyed ' . count($destroyed) . ' records';
} else {
- if ($rec = User::destroy($this->params)) {
+ if ($rec = User::destroy($this->params->id)) {
$res->message = "Destroyed User";
$res->success = true;
} else {