From: <gem...@li...> - 2013-03-25 14:00:53
|
Revision: 1206 http://sourceforge.net/p/gemstracker/code/1206 Author: mennodekker Date: 2013-03-25 14:00:49 +0000 (Mon, 25 Mar 2013) Log Message: ----------- Some more fixes on handling openrosa forms, still needs more error checking on the form Modified Paths: -------------- trunk/library/classes/Gems/Default/OpenrosaAction.php trunk/library/classes/GemsEscort.php trunk/library/classes/OpenRosa/Tracker/Source/OpenRosa/Form.php Modified: trunk/library/classes/Gems/Default/OpenrosaAction.php =================================================================== --- trunk/library/classes/Gems/Default/OpenrosaAction.php 2013-03-25 11:53:12 UTC (rev 1205) +++ trunk/library/classes/Gems/Default/OpenrosaAction.php 2013-03-25 14:00:49 UTC (rev 1206) @@ -193,7 +193,7 @@ * this only handles storing form data and can be used for resubmission too. * * @param type $xmlFile - * @return string DeviceID or false on failure + * @return string ResultID or false on failure */ private function processReceivedForm($answerXmlFile) { @@ -214,10 +214,8 @@ ); if ($formData = $model->loadFirst($filter)) { $form = new OpenRosa_Tracker_Source_OpenRosa_Form($this->formDir . $formData['gof_form_xml']); - $form->saveAnswer($answerXmlFile); - - $deviceId = $xml->DeviceId[0]; - return $deviceId; + $answers = $form->saveAnswer($answerXmlFile); + return $answers['orf_id']; } else { return false; } @@ -279,6 +277,7 @@ $formCnt = 0; $addCnt = 0; + $files = array(); $rescan = $this->getRequest()->getParam('rescan', false); while (false !== ($filename = $eDir->read())) { $ext = substr($filename, -4); @@ -355,8 +354,8 @@ if ($upload->receive('xml_submission_file')) { $xmlFile = $upload->getFileInfo('xml_submission_file'); $answerXmlFile = $xmlFile['xml_submission_file']['tmp_name']; - $deviceId = $this->processReceivedForm($answerXmlFile); - if ($deviceId === false) { + $resultId = $this->processReceivedForm($answerXmlFile); + if ($resultId === false) { //form not accepted! foreach ($xml->children() as $child) { $log->log($child->getName() . ' -> ' . $child, Zend_Log::ERR); @@ -366,9 +365,9 @@ //$log->log($deviceId, Zend_Log::ERR); foreach ($upload->getFileInfo() as $file => $info) { if ($info['received'] != 1) { - //Rename to deviceid_md5(time)_filename + //Rename to responseid_filename //@@TODO: move to form subdir, for better separation - $upload->addFilter('Rename', $deviceId . '_' . md5(time()) . '_' . $info['name'], $file); + $upload->addFilter('Rename', $resultId . '_' . $info['name'], $file); } } Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2013-03-25 11:53:12 UTC (rev 1205) +++ trunk/library/classes/GemsEscort.php 2013-03-25 14:00:49 UTC (rev 1206) @@ -444,6 +444,9 @@ $this->getLoader()->addPrefixPath('OpenRosa', GEMS_LIBRARY_DIR . '/classes/OpenRosa', true); + $autoloader = Zend_Loader_Autoloader::getInstance(); + $autoloader->registerNamespace('OpenRosa_'); + /** * Add Source for OpenRosa */ Modified: trunk/library/classes/OpenRosa/Tracker/Source/OpenRosa/Form.php =================================================================== --- trunk/library/classes/OpenRosa/Tracker/Source/OpenRosa/Form.php 2013-03-25 11:53:12 UTC (rev 1205) +++ trunk/library/classes/OpenRosa/Tracker/Source/OpenRosa/Form.php 2013-03-25 14:00:49 UTC (rev 1206) @@ -108,7 +108,11 @@ foreach ($this->instance as $name => $element) { $bindName = str_replace('_', '/', '_data_' . $name); - $bindInfo = $this->bind[$bindName]; + if (array_key_exists($bindName, $this->bind)) { + $bindInfo = $this->bind[$bindName]; + } else { + $bindInfo['type'] = 'string'; + } $field = array(); switch ($bindInfo['type']) { @@ -247,6 +251,8 @@ $result['value'] = (string) $element; break; + case 'trigger': + case 'upload': case 'input': case 'select': case 'select1': @@ -381,7 +387,12 @@ $checkbox[0] = $this->translate->_('Not checked'); foreach ($this->instance as $name => $element) { $bindName = str_replace('_', '/', '_data_' . $name); - $bindInfo = $this->bind[$bindName]; + if (array_key_exists($bindName, $this->bind)) { + $bindInfo = $this->bind[$bindName]; + } else { + $bindInfo['type'] = 'string'; + } + switch ($bindInfo['type']) { case 'select': @@ -413,7 +424,7 @@ } $this->model = $model; } - + return $this->model; } @@ -460,7 +471,11 @@ //Now we should parse the response, extract the options given for a (multi)select foreach ($this->instance as $name => $element) { $bindName = str_replace('_', '/', '_data_' . $name); - $bindInfo = $this->bind[$bindName]; + if (array_key_exists($bindName, $this->bind)) { + $bindInfo = $this->bind[$bindName]; + } else { + $bindInfo['type'] = 'string'; + } if ($bindInfo['type'] == 'dateTime') { $answers[$name] = new Zend_Date($answers[$name], Zend_Date::ISO_8601); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |