/** * Creates Xslt_transformer injecting dependencies. * Input params must be the same as in the __construct * * @access public * @static * * @param $file_path * The path to the file to convert. * * @return Xslt_transformer */ public static function build($file_path) { $xslt_transformer = new Xslt_transformer($file_path); $CI = get_instance(); $xslt_transformer->set_enketo_xslt_lib_location($CI->config->item('aw_enketo_xslt_lib')); return $xslt_transformer; }
/** * Converting a valid file. */ public function test_xslt_transformer_valid() { $xslt_transformer = new Xslt_transformer('tests/test_resources/surveys/super_simple_survey.xml'); $xslt_transformer->set_enketo_xslt_lib_location('./application/third_party/enketo-xslt/'); $result = $xslt_transformer->get_transform_result_sxe(); $errors = $xslt_transformer->get_errors(); // Every error group should be empty. foreach ($errors as $error_group) { $this->assertEmpty($error_group); } $this->assertInstanceOf('SimpleXMLElement', $result); }
/** * Enketo API * Converts the survey xml file to html for enketo to use * * @param int $sid * The survey id * * JSON output: * status : { * code : , * message: * }, * xml_form : the xml form */ public function api_survey_xslt_transform($sid) { $survey = $this->survey_model->get($sid); if (!$survey) { return $this->api_output(404, 'Invalid survey.', array('xml_form' => NULL)); } if (!$survey->has_xml()) { return $this->api_output(500, 'Xml file not present.', array('xml_form' => NULL)); } if (!has_permission('enketo collect data any') && !has_permission('enketo testrun any')) { if (!has_permission('enketo collect data assigned') && !has_permission('enketo testrun assigned')) { return $this->api_output(403, 'Not allowed.', array('xml_form' => NULL)); } else { if (!$survey->is_assigned_agent(current_user()->uid)) { return $this->api_output(403, 'Not allowed.', array('xml_form' => NULL)); } } } // Since the xslt transform is used both for testrun and collect // there's no way to tell them apart. if (!$survey->status_allows('enketo collect data') && !$survey->status_allows('enketo testrun')) { return $this->api_output(403, 'Not allowed.', array('xml_form' => NULL)); } $this->load->helper('xslt_transformer'); $xslt_transformer = Xslt_transformer::build($survey->get_xml_full_path()); $result = $xslt_transformer->get_transform_result_sxe()->asXML(); return $this->api_output(200, 'Ok!', array('xml_form' => $result)); }