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() {
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 ($invalidRowCount) {
49 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
50 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
53 if ($conflictRowCount) {
54 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
55 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
59 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
60 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
71 'downloadErrorRecordsUrl',
72 'downloadConflictRecordsUrl',
73 'downloadMismatchRecordsUrl',
76 foreach ($properties as $property) {
77 $this->assign($property, $this->get($property));
82 * Process the mapped fields and map it into the uploaded file
83 * preview the file and extract some summary statistics
87 public function postProcess() {
88 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
89 $separator = $this->controller
->exportValue('DataSource', 'fieldSeparator');
90 $invalidRowCount = $this->get('invalidRowCount');
91 $conflictRowCount = $this->get('conflictRowCount');
92 $onDuplicate = $this->get('onDuplicate');
94 $mapper = $this->controller
->exportValue('MapField', 'mapper');
97 foreach ($mapper as $key => $value) {
98 $mapperKeys[$key] = $mapper[$key][0];
101 $parser = new CRM_Event_Import_Parser_Participant($mapperKeys);
103 $mapFields = $this->get('fields');
105 foreach ($mapper as $key => $value) {
107 if (isset($mapFields[$mapper[$key][0]])) {
108 $header[] = $mapFields[$mapper[$key][0]];
110 $mapperFields[] = implode(' - ', $header);
112 $parser->run($fileName, $separator,
114 $this->getSubmittedValue('skipColumnHeader'),
115 CRM_Import_Parser
::MODE_IMPORT
,
116 $this->get('contactType'),
120 // add all the necessary variables to the form
121 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
123 // check if there is any error occurred
125 $errorStack = CRM_Core_Error
::singleton();
126 $errors = $errorStack->getErrors();
129 if (is_array($errors)) {
130 foreach ($errors as $key => $value) {
131 $errorMessage[] = $value['message'];
134 $errorFile = $fileName['name'] . '.error.log';
136 if ($fd = fopen($errorFile, 'w')) {
137 fwrite($fd, implode('\n', $errorMessage));
141 $this->set('errorFile', $errorFile);
142 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
143 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
144 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
145 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
146 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
147 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));