From: <gem...@li...> - 2013-03-18 13:14:15
|
Revision: 1190 http://sourceforge.net/p/gemstracker/code/1190 Author: matijsdejong Date: 2013-03-18 13:14:10 +0000 (Mon, 18 Mar 2013) Log Message: ----------- First working copy for SSN double input checks Modified Paths: -------------- trunk/library/classes/Gems/Snippets/RespondentFormSnippet.php Modified: trunk/library/classes/Gems/Snippets/RespondentFormSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/RespondentFormSnippet.php 2013-03-18 12:58:11 UTC (rev 1189) +++ trunk/library/classes/Gems/Snippets/RespondentFormSnippet.php 2013-03-18 13:14:10 UTC (rev 1190) @@ -47,6 +47,18 @@ class Gems_Snippets_RespondentFormSnippet extends Gems_Snippets_ModelFormSnippetGeneric { /** + * + * @var Zend_Db_Adapter_Abstract + */ + protected $db; + + /** + * + * @var Gems_Loader + */ + protected $loader; + + /** * When true a tabbed form is used. * * @var boolean @@ -62,10 +74,66 @@ { parent::loadFormData(); - if ($this->createData && $this->request->isPost()) { + if ($this->request->isPost()) { if ((! $this->_saveButton) || (! $this->_saveButton->isChecked())) { if ($this->formData['grs_ssn']) { - // $this->formData['grs_first_name'] = 'Jan'; + $filter = array( + 'grs_ssn' => $this->formData['grs_ssn'], + 'gr2o_id_organization' => true, // Make sure all organisations are checked in RespModel + ); + + if ($this->formData['gr2o_id_organization']) { + $orgId = $this->formData['gr2o_id_organization']; + } else { + $orgId = $this->model->get('gr2o_id_organization', 'default'); + } + $order = array( + $this->db->quoteInto( + "CASE WHEN gr2o_id_organization = ? THEN 1 ELSE 2 END", + $orgId + ) => SORT_ASC + ); + + $data = $this->model->loadFirst($filter, $order); + + if ($data && (! isset($this->formData[$this->saveButtonId]))) { + // MUtil_Echo::track($this->formData); + // MUtil_Echo::track($data); + // Do not use this value + unset($data['grs_ssn']); + + if ($data['gr2o_id_organization'] == $orgId) { + // gr2o_patient_nr + // gr2o_id_organization + + $this->addMessage($this->_('Known respondent.')); + + //* + foreach ($data as $name => $value) { + if ((substr($name, 0, 4) == 'grs_') || (substr($name, 0, 5) == 'gr2o_')) { + if (array_key_exists($name, $this->formData)) { + $this->formData[$name] = $value; + } + $cname = $this->model->getKeyCopyName($name); + if (array_key_exists($cname, $this->formData)) { + $this->formData[$cname] = $value; + } + } + } // */ + } else { + $org = $this->loader->getOrganization($data['gr2o_id_organization']); + $this->addMessage(sprintf( + $this->_('Respondent data retrieved from %s.'), + $org->getName() + )); + + foreach ($data as $name => $value) { + if ((substr($name, 0, 4) == 'grs_') && array_key_exists($name, $this->formData)) { + $this->formData[$name] = $value; + } + } + } + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |