Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crm 20376 - Fix field names on PDF/Print vesion of survey report #10096

Merged
merged 2 commits into from
Apr 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions CRM/Report/Form/Campaign/SurveyDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class CRM_Report_Form_Campaign_SurveyDetails extends CRM_Report_Form {

private static $_surveyRespondentStatus;

// Survey Question titles are overridden when in print or pdf mode to
// say Q1, Q2 instead of the full title - to save space.
private $_columnTitleOverrides = array();

/**
*/
/**
Expand Down Expand Up @@ -203,7 +207,7 @@ public function __construct() {
),
'grouping' => 'survey-activity-fields',
),
) + $this->addAddressFields();
) + $this->getAddressColumns();
parent::__construct();
}

Expand Down Expand Up @@ -239,9 +243,16 @@ public function select() {
}

$select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";

// Set default title
$title = CRM_Utils_Array::value('title', $field);
// Check for an override.
if (!empty($this->_columnTitleOverrides["{$tableName}_{$fieldName}"])) {
$title = $this->_columnTitleOverrides["{$tableName}_{$fieldName}"];
}
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $title;

$this->_selectAliases[] = "{$tableName}_{$fieldName}";
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
}
}
}
Expand Down Expand Up @@ -737,7 +748,7 @@ private function _addSurveyResponseColumns() {
WHERE cf.id IN ( ' . implode(' , ', $responseFieldIds) .
' ) ORDER BY cf.weight';
$response = CRM_Core_DAO::executeQuery($query);
$fildCnt = 1;
$fieldCnt = 1;
while ($response->fetch()) {
$resTable = $response->table_name;
$fieldName = "custom_{$response->cfId}";
Expand All @@ -754,20 +765,22 @@ private function _addSurveyResponseColumns() {
if (!is_array(CRM_Utils_Array::value('fields', $this->_columns[$resTable]))) {
$this->_columns[$resTable]['fields'] = array();
}
if (array_key_exists($fieldName, $this->_columns[$resTable]['fields'])) {
$this->_columns[$resTable]['fields'][$fieldName]['required'] = TRUE;
$this->_columns[$resTable]['fields'][$fieldName]['isSurveyResponseField'] = TRUE;
continue;
}

$title = $responseFields[$fieldName]['title'];
if (in_array($this->_outputMode, array(
'print',
'pdf',
))) {
$title = 'Q' . $fildCnt++;
$this->_columnTitleOverrides["{$resTable}_{$fieldName}"] = 'Q' . $fieldCnt;
$fieldCnt++;
}

if (array_key_exists($fieldName, $this->_columns[$resTable]['fields'])) {
$this->_columns[$resTable]['fields'][$fieldName]['required'] = TRUE;
$this->_columns[$resTable]['fields'][$fieldName]['isSurveyResponseField'] = TRUE;
continue;
}

$title = $responseFields[$fieldName]['title'];
$fldType = 'CRM_Utils_Type::T_STRING';
if ($response->time_format) {
$fldType = CRM_Utils_Type::T_TIMESTAMP;
Expand Down