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
21 * This class previews the uploaded file and returns summary
24 class CRM_Event_Import_Form_Preview
extends CRM_Import_Form_Preview
{
27 * Set variables up before form is built.
31 public function preProcess() {
32 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
34 //get the data from the session
35 $dataValues = $this->get('dataValues');
36 $mapper = $this->get('mapper');
37 $invalidRowCount = $this->get('invalidRowCount');
38 $conflictRowCount = $this->get('conflictRowCount');
39 $mismatchCount = $this->get('unMatchCount');
41 //get the mapping name displayed if the mappingId is set
42 $mappingId = $this->get('loadMappingId');
44 $mapDAO = new CRM_Core_DAO_Mapping();
45 $mapDAO->id
= $mappingId;
47 $this->assign('loadedMapping', $mappingId);
48 $this->assign('savedName', $mapDAO->name
);
51 if ($skipColumnHeader) {
52 $this->assign('skipColumnHeader', $skipColumnHeader);
53 $this->assign('rowDisplayCount', 3);
56 $this->assign('rowDisplayCount', 2);
59 if ($invalidRowCount) {
60 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
61 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
64 if ($conflictRowCount) {
65 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
66 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
70 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
71 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
82 'downloadErrorRecordsUrl',
83 'downloadConflictRecordsUrl',
84 'downloadMismatchRecordsUrl',
87 foreach ($properties as $property) {
88 $this->assign($property, $this->get($property));
93 * Process the mapped fields and map it into the uploaded file
94 * preview the file and extract some summary statistics
98 public function postProcess() {
99 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
100 $seperator = $this->controller
->exportValue('DataSource', 'fieldSeparator');
101 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
102 $invalidRowCount = $this->get('invalidRowCount');
103 $conflictRowCount = $this->get('conflictRowCount');
104 $onDuplicate = $this->get('onDuplicate');
106 $mapper = $this->controller
->exportValue('MapField', 'mapper');
109 foreach ($mapper as $key => $value) {
110 $mapperKeys[$key] = $mapper[$key][0];
113 $parser = new CRM_Event_Import_Parser_Participant($mapperKeys);
115 $mapFields = $this->get('fields');
117 foreach ($mapper as $key => $value) {
119 if (isset($mapFields[$mapper[$key][0]])) {
120 $header[] = $mapFields[$mapper[$key][0]];
122 $mapperFields[] = implode(' - ', $header);
124 $parser->run($fileName, $seperator,
127 CRM_Import_Parser
::MODE_IMPORT
,
128 $this->get('contactType'),
132 // add all the necessary variables to the form
133 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
135 // check if there is any error occurred
137 $errorStack = CRM_Core_Error
::singleton();
138 $errors = $errorStack->getErrors();
141 if (is_array($errors)) {
142 foreach ($errors as $key => $value) {
143 $errorMessage[] = $value['message'];
146 $errorFile = $fileName['name'] . '.error.log';
148 if ($fd = fopen($errorFile, 'w')) {
149 fwrite($fd, implode('\n', $errorMessage));
153 $this->set('errorFile', $errorFile);
154 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
155 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
156 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
157 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
158 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
159 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));