3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class previews the uploaded file and returns summary statistics.
21 class CRM_Contribute_Import_Form_Preview
extends CRM_Import_Form_Preview
{
24 * Set variables up before form is built.
26 public function preProcess() {
28 //get the data from the session
29 $dataValues = $this->get('dataValues');
30 $mapper = $this->get('mapper');
31 $softCreditFields = $this->get('softCreditFields');
32 $mapperSoftCreditType = $this->get('mapperSoftCreditType');
33 $invalidRowCount = $this->get('invalidRowCount');
34 $conflictRowCount = $this->get('conflictRowCount');
35 $mismatchCount = $this->get('unMatchCount');
37 //get the mapping name displayed if the mappingId is set
38 $mappingId = $this->get('loadMappingId');
40 $mapDAO = new CRM_Core_DAO_Mapping();
41 $mapDAO->id
= $mappingId;
44 $this->assign('savedMappingName', $mappingId ?
$mapDAO->name
: NULL);
46 if ($invalidRowCount) {
47 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Contribute_Import_Parser_Contribution';
48 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
51 if ($conflictRowCount) {
52 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Contribute_Import_Parser_Contribution';
53 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
57 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Contribute_Import_Parser_Contribution';
58 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
64 'mapperSoftCreditType',
71 'downloadErrorRecordsUrl',
72 'downloadConflictRecordsUrl',
73 'downloadMismatchRecordsUrl',
75 $this->setStatusUrl();
77 foreach ($properties as $property) {
78 $this->assign($property, $this->get($property));
83 * Process the mapped fields and map it into the uploaded file preview the file and extract some summary statistics.
85 public function postProcess() {
86 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
87 $invalidRowCount = $this->get('invalidRowCount');
88 $conflictRowCount = $this->get('conflictRowCount');
89 $onDuplicate = $this->get('onDuplicate');
90 $mapperSoftCreditType = $this->get('mapperSoftCreditType');
92 $mapper = $this->controller
->exportValue('MapField', 'mapper');
94 $mapperSoftCredit = [];
95 $mapperPhoneType = [];
97 foreach ($mapper as $key => $value) {
98 $mapperKeys[$key] = $mapper[$key][0];
99 if (isset($mapper[$key][0]) && $mapper[$key][0] == 'soft_credit' && isset($mapper[$key])) {
100 $mapperSoftCredit[$key] = $mapper[$key][1] ??
'';
101 $mapperSoftCreditType[$key] = $mapperSoftCreditType[$key]['value'];
104 $mapperSoftCredit[$key] = $mapperSoftCreditType[$key] = NULL;
108 $parser = new CRM_Contribute_Import_Parser_Contribution($mapperKeys, $mapperSoftCredit, $mapperPhoneType, $mapperSoftCreditType);
110 $mapFields = $this->get('fields');
112 foreach ($mapper as $key => $value) {
114 if (isset($mapFields[$mapper[$key][0]])) {
115 $header[] = $mapFields[$mapper[$key][0]];
117 $mapperFields[] = implode(' - ', $header);
120 $this->getSubmittedValue('uploadFile'),
121 $this->getSubmittedValue('fieldSeparator'),
123 $this->getSubmittedValue('skipColumnHeader'),
124 CRM_Import_Parser
::MODE_IMPORT
,
125 $this->get('contactType'),
127 $this->get('statusID'),
128 $this->get('totalRowCount')
131 // Add all the necessary variables to the form.
132 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
134 // Check if there is any error occurred.
136 $errorStack = CRM_Core_Error
::singleton();
137 $errors = $errorStack->getErrors();
140 if (is_array($errors)) {
141 foreach ($errors as $key => $value) {
142 $errorMessage[] = $value['message'];
145 $errorFile = $fileName['name'] . '.error.log';
147 if ($fd = fopen($errorFile, 'w')) {
148 fwrite($fd, implode('\n', $errorMessage));
152 $this->set('errorFile', $errorFile);
153 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Contribute_Import_Parser_Contribution';
154 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
155 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Contribute_Import_Parser_Contribution';
156 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
157 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Contribute_Import_Parser_Contribution';
158 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));