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_Activity_Import_Form_Preview
extends CRM_Import_Form_Preview
{
24 * Set variables up before form is built.
26 public function preProcess() {
27 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
29 // Get the data from the session.
30 $dataValues = $this->get('dataValues');
31 $mapper = $this->get('mapper');
32 $invalidRowCount = $this->get('invalidRowCount');
33 $conflictRowCount = $this->get('conflictRowCount');
34 $mismatchCount = $this->get('unMatchCount');
36 // Get the mapping name displayed if the mappingId is set.
37 $mappingId = $this->get('loadMappingId');
39 $mapDAO = new CRM_Core_DAO_Mapping();
40 $mapDAO->id
= $mappingId;
42 $this->assign('loadedMapping', $mappingId);
43 $this->assign('savedName', $mapDAO->name
);
46 if ($skipColumnHeader) {
47 $this->assign('skipColumnHeader', $skipColumnHeader);
48 $this->assign('rowDisplayCount', 3);
51 $this->assign('rowDisplayCount', 2);
54 if ($invalidRowCount) {
55 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Activity_Import_Parser';
56 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
59 if ($conflictRowCount) {
60 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Activity_Import_Parser';
61 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
65 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Activity_Import_Parser';
66 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
77 'downloadErrorRecordsUrl',
78 'downloadConflictRecordsUrl',
79 'downloadMismatchRecordsUrl',
81 $this->setStatusUrl();
83 foreach ($properties as $property) {
84 $this->assign($property, $this->get($property));
89 * Process the mapped fields and map it into the uploaded file.
91 * Preview the file and extract some summary statistics
93 public function postProcess() {
94 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
95 $seperator = $this->controller
->exportValue('DataSource', 'fieldSeparator');
96 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
97 $invalidRowCount = $this->get('invalidRowCount');
98 $conflictRowCount = $this->get('conflictRowCount');
99 $onDuplicate = $this->get('onDuplicate');
101 $mapper = $this->controller
->exportValue('MapField', 'mapper');
104 $mapperPhoneType = [];
106 foreach ($mapper as $key => $value) {
107 $mapperKeys[$key] = $mapper[$key][0];
109 if (!empty($mapper[$key][1]) && is_numeric($mapper[$key][1])) {
110 $mapperLocType[$key] = $mapper[$key][1];
113 $mapperLocType[$key] = NULL;
116 if (!empty($mapper[$key][2]) && (!is_numeric($mapper[$key][2]))) {
117 $mapperPhoneType[$key] = $mapper[$key][2];
120 $mapperPhoneType[$key] = NULL;
124 $parser = new CRM_Activity_Import_Parser_Activity($mapperKeys, $mapperLocType, $mapperPhoneType);
126 $mapFields = $this->get('fields');
128 foreach ($mapper as $key => $value) {
130 if (isset($mapFields[$mapper[$key][0]])) {
131 $header[] = $mapFields[$mapper[$key][0]];
133 $mapperFields[] = implode(' - ', $header);
135 $parser->run($fileName, $seperator,
138 CRM_Import_Parser
::MODE_IMPORT
,
140 $this->get('statusID'),
141 $this->get('totalRowCount')
144 // add all the necessary variables to the form
145 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
147 // check if there is any error occurred
149 $errorStack = CRM_Core_Error
::singleton();
150 $errors = $errorStack->getErrors();
153 if (is_array($errors)) {
154 foreach ($errors as $key => $value) {
155 $errorMessage[] = $value['message'];
158 $errorFile = $fileName['name'] . '.error.log';
160 if ($fd = fopen($errorFile, 'w')) {
161 fwrite($fd, implode('\n', $errorMessage));
165 $this->set('errorFile', $errorFile);
166 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Activity_Import_Parser';
167 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
168 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Activity_Import_Parser';
169 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
170 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Activity_Import_Parser';
171 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));