/** * */ private function parse_appointment($end = true) { $data = $this->parse_input_data(); if (!$end) { $this->data = $data; } $table = 'ea_appointments'; $fields = 'ea_fields'; $app_fields = array('id', 'location', 'service', 'worker', 'date', 'start', 'end', 'status', 'user', 'price'); $app_data = array(); foreach ($app_fields as $value) { if (array_key_exists($value, $data)) { $app_data[$value] = $data[$value]; } } $meta_fields = $this->models->get_all_rows('ea_meta_fields'); $meta_data = array(); foreach ($meta_fields as $value) { if (array_key_exists($value->slug, $data)) { $meta_data[] = array('app_id' => null, 'field_id' => $value->id, 'value' => $data[$value->slug]); } } $response = array(); switch ($this->type) { case 'GET': $id = (int) $_GET['id']; $response = $this->models->get_row($table, $id); break; case 'UPDATE': $response = $this->models->replace($table, $app_data, true); $this->models->delete($fields, array('app_id' => $app_data['id']), true); foreach ($meta_data as $value) { $value['app_id'] = $app_data['id']; $this->models->replace($fields, $value, true); } break; case 'NEW': $response = $this->models->replace($table, $app_data, true); foreach ($meta_data as $value) { $value['app_id'] = $response->id; $this->models->replace($fields, $value, true); } break; case 'DELETE': $data = $_GET; $response = $this->models->delete($table, $data, true); $this->models->delete($table, array('app_id' => $app_data['id']), true); break; } if ($response == false) { $this->send_err_json_result('{"err":true}'); } if ($end) { $this->send_ok_json_result($response); } else { return $response; } }