3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class previews the uploaded file and returns summary statistics.
37 class CRM_Activity_Import_Form_Preview
extends CRM_Import_Form_Preview
{
40 * Set variables up before form is built.
42 public function preProcess() {
43 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
45 // Get the data from the session.
46 $dataValues = $this->get('dataValues');
47 $mapper = $this->get('mapper');
48 $invalidRowCount = $this->get('invalidRowCount');
49 $conflictRowCount = $this->get('conflictRowCount');
50 $mismatchCount = $this->get('unMatchCount');
52 // Get the mapping name displayed if the mappingId is set.
53 $mappingId = $this->get('loadMappingId');
55 $mapDAO = new CRM_Core_DAO_Mapping();
56 $mapDAO->id
= $mappingId;
58 $this->assign('loadedMapping', $mappingId);
59 $this->assign('savedName', $mapDAO->name
);
62 if ($skipColumnHeader) {
63 $this->assign('skipColumnHeader', $skipColumnHeader);
64 $this->assign('rowDisplayCount', 3);
67 $this->assign('rowDisplayCount', 2);
70 if ($invalidRowCount) {
71 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Activity_Import_Parser';
72 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
75 if ($conflictRowCount) {
76 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Activity_Import_Parser';
77 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
81 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Activity_Import_Parser';
82 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
93 'downloadErrorRecordsUrl',
94 'downloadConflictRecordsUrl',
95 'downloadMismatchRecordsUrl',
97 $this->setStatusUrl();
99 foreach ($properties as $property) {
100 $this->assign($property, $this->get($property));
105 * Process the mapped fields and map it into the uploaded file.
107 * Preview the file and extract some summary statistics
109 public function postProcess() {
110 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
111 $seperator = $this->controller
->exportValue('DataSource', 'fieldSeparator');
112 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
113 $invalidRowCount = $this->get('invalidRowCount');
114 $conflictRowCount = $this->get('conflictRowCount');
115 $onDuplicate = $this->get('onDuplicate');
117 $mapper = $this->controller
->exportValue('MapField', 'mapper');
118 $mapperKeys = array();
119 $mapperLocType = array();
120 $mapperPhoneType = array();
122 foreach ($mapper as $key => $value) {
123 $mapperKeys[$key] = $mapper[$key][0];
125 if (!empty($mapper[$key][1]) && is_numeric($mapper[$key][1])) {
126 $mapperLocType[$key] = $mapper[$key][1];
129 $mapperLocType[$key] = NULL;
132 if (!empty($mapper[$key][2]) && (!is_numeric($mapper[$key][2]))) {
133 $mapperPhoneType[$key] = $mapper[$key][2];
136 $mapperPhoneType[$key] = NULL;
140 $parser = new CRM_Activity_Import_Parser_Activity($mapperKeys, $mapperLocType, $mapperPhoneType);
142 $mapFields = $this->get('fields');
144 foreach ($mapper as $key => $value) {
146 if (isset($mapFields[$mapper[$key][0]])) {
147 $header[] = $mapFields[$mapper[$key][0]];
149 $mapperFields[] = implode(' - ', $header);
151 $parser->run($fileName, $seperator,
154 CRM_Import_Parser
::MODE_IMPORT
,
156 $this->get('statusID'),
157 $this->get('totalRowCount')
160 // add all the necessary variables to the form
161 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
163 // check if there is any error occurred
165 $errorStack = CRM_Core_Error
::singleton();
166 $errors = $errorStack->getErrors();
167 $errorMessage = array();
169 if (is_array($errors)) {
170 foreach ($errors as $key => $value) {
171 $errorMessage[] = $value['message'];
174 $errorFile = $fileName['name'] . '.error.log';
176 if ($fd = fopen($errorFile, 'w')) {
177 fwrite($fd, implode('\n', $errorMessage));
181 $this->set('errorFile', $errorFile);
182 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Activity_Import_Parser';
183 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
184 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Activity_Import_Parser';
185 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
186 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Activity_Import_Parser';
187 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));