Index: branches/5.3.x/core/units/helpers/form_submission_helper.php =================================================================== diff -u -N -r15483 -r15698 --- branches/5.3.x/core/units/helpers/form_submission_helper.php (.../form_submission_helper.php) (revision 15483) +++ branches/5.3.x/core/units/helpers/form_submission_helper.php (.../form_submission_helper.php) (revision 15698) @@ -1,6 +1,6 @@ GetDBField('FormId'); + $field_name = $this->getFieldNameByRole($form_id, $role); - if (!array_key_exists($form_id, $cache)) { - $id_field = $this->Application->getUnitOption('formflds', 'IDField'); - $table_name = $this->Application->getUnitOption('formflds', 'TableName'); + if ( $field_name ) { + return $formatted ? $form_submission->GetField($field_name, $format) : $form_submission->GetDBField($field_name); + } - $sql = 'SELECT ' . $id_field . ', EmailCommunicationRole - FROM ' . $table_name . ' + return false; + } + + /** + * Returns submission field name based on given role + * + * @param int $form_id + * @param string $role + * @return string + * @access public + */ + public function getFieldNameByRole($form_id, $role) + { + static $cache = Array (); + + if ( !array_key_exists($form_id, $cache) ) { + $config = $this->Application->getUnitConfig('formflds'); + + $sql = 'SELECT ' . $config->getIDField() . ', EmailCommunicationRole + FROM ' . $config->getTableName() . ' WHERE FormId = ' . $form_id . ' AND EmailCommunicationRole <> 0'; $cache[$form_id] = $this->Conn->GetCol($sql, 'EmailCommunicationRole'); } // convert string representation of role to numeric - if (!is_numeric($role)) { + if ( !is_numeric($role) ) { $role = strtolower($role); $role = array_key_exists($role, $this->roleNames) ? $this->roleNames[$role] : false; } - // get field by role - $field_id = array_key_exists($role, $cache[$form_id]) ? $cache[$form_id][$role] : false; - - if ($field_id) { - return $formatted ? $form_submission->GetField('fld_' . $field_id, $format) : $form_submission->GetDBField('fld_' . $field_id); - } - - return false; + // get field name by role + return array_key_exists($role, $cache[$form_id]) ? 'fld_' . $cache[$form_id][$role] : false; } /** @@ -85,17 +97,19 @@ $form_id = $form_submission->GetDBField('FormId'); - if (!array_key_exists($form_id, $cache)) { - $id_field = $this->Application->getUnitOption('formflds', 'IDField'); - $table_name = $this->Application->getUnitOption('formflds', 'TableName'); + if ( !array_key_exists($form_id, $cache) ) { + $config = $this->Application->getUnitConfig('formflds'); - $sql = 'SELECT ' . $id_field . ', FieldName - FROM ' . $table_name . ' + $sql = 'SELECT ' . $config->getIDField() . ', FieldName + FROM ' . $config->getTableName() . ' WHERE FormId = ' . $form_id; $cache[$form_id] = $this->Conn->GetCol($sql, 'FieldName'); } - if ($field_id) { + // get field by name + $field_id = array_key_exists($name, $cache[$form_id]) ? $cache[$form_id][$name] : false; + + if ( $field_id ) { return $formatted ? $form_submission->GetField('fld_' . $field_id, $format) : $form_submission->GetDBField('fld_' . $field_id); }