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;
45 $this->assign('loadedMapping', $mappingId);
46 $this->assign('savedName', $mapDAO->name
);
49 if ($skipColumnHeader) {
50 $this->assign('skipColumnHeader', $skipColumnHeader);
51 $this->assign('rowDisplayCount', 3);
54 $this->assign('rowDisplayCount', 2);
57 if ($invalidRowCount) {
58 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
59 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
62 if ($conflictRowCount) {
63 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
64 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
68 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
69 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
80 'downloadErrorRecordsUrl',
81 'downloadConflictRecordsUrl',
82 'downloadMismatchRecordsUrl',
85 foreach ($properties as $property) {
86 $this->assign($property, $this->get($property));
91 * Process the mapped fields and map it into the uploaded file
92 * preview the file and extract some summary statistics
96 public function postProcess() {
97 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
98 $separator = $this->controller
->exportValue('DataSource', 'fieldSeparator');
99 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
100 $invalidRowCount = $this->get('invalidRowCount');
101 $conflictRowCount = $this->get('conflictRowCount');
102 $onDuplicate = $this->get('onDuplicate');
104 $mapper = $this->controller
->exportValue('MapField', 'mapper');
107 foreach ($mapper as $key => $value) {
108 $mapperKeys[$key] = $mapper[$key][0];
111 $parser = new CRM_Event_Import_Parser_Participant($mapperKeys);
113 $mapFields = $this->get('fields');
115 foreach ($mapper as $key => $value) {
117 if (isset($mapFields[$mapper[$key][0]])) {
118 $header[] = $mapFields[$mapper[$key][0]];
120 $mapperFields[] = implode(' - ', $header);
122 $parser->run($fileName, $separator,
125 CRM_Import_Parser
::MODE_IMPORT
,
126 $this->get('contactType'),
130 // add all the necessary variables to the form
131 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
133 // check if there is any error occurred
135 $errorStack = CRM_Core_Error
::singleton();
136 $errors = $errorStack->getErrors();
139 if (is_array($errors)) {
140 foreach ($errors as $key => $value) {
141 $errorMessage[] = $value['message'];
144 $errorFile = $fileName['name'] . '.error.log';
146 if ($fd = fopen($errorFile, 'w')) {
147 fwrite($fd, implode('\n', $errorMessage));
151 $this->set('errorFile', $errorFile);
152 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
153 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
154 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
155 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
156 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
157 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));