/** * Gets the custom form field values and * * meta information by incidentid */ private function _get_custom_form_fields() { $is_json = $this->_is_json(); if (!$this->api_service->verify_array_index($this->request, 'id')) { //Ensure that the incidentid is set, error out if not return $this->set_error_message(array("error" => $this->api_service->get_error_msg(01, 'id'))); } else { $incident_id = $this->request['id']; } //Retrieve the form_id from the incident object $incident = ORM::factory("incident")->select("form_id")->where("id", $this->check_id_value($incident_id))->find(); if (!$incident) { return $this->response(4); //We don't have this incident } $form_id = $incident->form_id; //Call the customforms helper method to return the field values $custom_form_fields = customforms::get_custom_form_fields($incident_id, $form_id, true); //Call the customforms helper method to return the field meta information $custom_form_field_meta = customforms::get_custom_form_fields($incident_id, $form_id, false); if (count($custom_form_fields) == 0) { return $this->response(4); //We don't have any forms for this incident. } if ($is_json) { $json_item = array(); $json = array(); } else { $xml = new XmlWriter(); $xml->openMemory(); $xml->startDocument('1.0', 'UTF-8'); $xml->startElement('response'); $xml->startElement('payload'); $xml->writeElement('domain', $this->domain); $xml->startElement('customforms'); $xml->startElement("fields"); } foreach ($custom_form_fields as $field_id => $field) { $field_value = $field; $field_meta = $custom_form_field_meta[$field_id]; // Always return values as array if (customforms::field_is_multi_value($field_meta)) { //This is a multi-select field, return it as an multi value array $field_value = explode(",", $field_value); } else { //This is either text or html, return as single array object $field_value = array($field_value); } if ($is_json) { $json_item["fields"][] = array("values" => $field_value, "meta" => $this->_meta_fields($field_meta)); } else { $xml->startElement("field"); $xml->startElement("values"); foreach ($field_value as $val) { $xml->writeElement("value", html::specialchars($val, FALSE)); //Write the field value } $xml->endElement(); //end values; $xml->startElement("meta"); $this->_meta_fields($field_meta, $xml); $xml->endElement(); //end meta $xml->endElement(); //field; } } if ($is_json) { $json = array("payload" => array("customforms" => $json_item), "error" => $this->api_service->get_error_msg(0)); $json_item = null; return $this->array_as_json($json); //Write the json array } else { $xml->endElement(); //End fields $xml->endElement(); //End customforms $xml->endElement(); //End payload $xml->startElement('error'); $xml->writeElement('code', 0); $xml->writeElement('message', 'No Error'); $xml->endElement(); //end error $xml->endElement(); //end response return $xml->outputMemory(true); //write out the xml stream } }