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
22 class CRM_Event_Import_Form_Preview
extends CRM_Import_Form_Preview
{
25 * Set variables up before form is built.
29 public function preProcess() {
30 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
32 //get the data from the session
33 $dataValues = $this->get('dataValues');
34 $mapper = $this->get('mapper');
35 $invalidRowCount = $this->get('invalidRowCount');
36 $conflictRowCount = $this->get('conflictRowCount');
37 $mismatchCount = $this->get('unMatchCount');
39 //get the mapping name displayed if the mappingId is set
40 $mappingId = $this->get('loadMappingId');
42 $mapDAO = new CRM_Core_DAO_Mapping();
43 $mapDAO->id
= $mappingId;
46 $this->assign('savedMappingName', $mappingId ?
$mapDAO->name
: NULL);
48 if ($skipColumnHeader) {
49 $this->assign('skipColumnHeader', $skipColumnHeader);
50 $this->assign('rowDisplayCount', 3);
53 $this->assign('rowDisplayCount', 2);
56 if ($invalidRowCount) {
57 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
58 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
61 if ($conflictRowCount) {
62 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
63 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
67 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
68 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
79 'downloadErrorRecordsUrl',
80 'downloadConflictRecordsUrl',
81 'downloadMismatchRecordsUrl',
84 foreach ($properties as $property) {
85 $this->assign($property, $this->get($property));
90 * Process the mapped fields and map it into the uploaded file
91 * preview the file and extract some summary statistics
95 public function postProcess() {
96 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
97 $separator = $this->controller
->exportValue('DataSource', 'fieldSeparator');
98 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
99 $invalidRowCount = $this->get('invalidRowCount');
100 $conflictRowCount = $this->get('conflictRowCount');
101 $onDuplicate = $this->get('onDuplicate');
103 $mapper = $this->controller
->exportValue('MapField', 'mapper');
106 foreach ($mapper as $key => $value) {
107 $mapperKeys[$key] = $mapper[$key][0];
110 $parser = new CRM_Event_Import_Parser_Participant($mapperKeys);
112 $mapFields = $this->get('fields');
114 foreach ($mapper as $key => $value) {
116 if (isset($mapFields[$mapper[$key][0]])) {
117 $header[] = $mapFields[$mapper[$key][0]];
119 $mapperFields[] = implode(' - ', $header);
121 $parser->run($fileName, $separator,
124 CRM_Import_Parser
::MODE_IMPORT
,
125 $this->get('contactType'),
129 // add all the necessary variables to the form
130 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
132 // check if there is any error occurred
134 $errorStack = CRM_Core_Error
::singleton();
135 $errors = $errorStack->getErrors();
138 if (is_array($errors)) {
139 foreach ($errors as $key => $value) {
140 $errorMessage[] = $value['message'];
143 $errorFile = $fileName['name'] . '.error.log';
145 if ($fd = fopen($errorFile, 'w')) {
146 fwrite($fd, implode('\n', $errorMessage));
150 $this->set('errorFile', $errorFile);
151 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
152 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
153 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
154 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
155 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
156 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));