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');
37 //get the mapping name displayed if the mappingId is set
38 $mappingId = $this->get('loadMappingId');
40 $mapDAO = new CRM_Core_DAO_Mapping();
41 $mapDAO->id
= $mappingId;
44 $this->assign('savedMappingName', $mappingId ?
$mapDAO->name
: NULL);
46 if ($invalidRowCount) {
47 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser_Participant';
48 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
58 'downloadErrorRecordsUrl',
61 foreach ($properties as $property) {
62 $this->assign($property, $this->get($property));
67 * Process the mapped fields and map it into the uploaded file
68 * preview the file and extract some summary statistics
72 public function postProcess() {
73 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
74 $separator = $this->controller
->exportValue('DataSource', 'fieldSeparator');
75 $invalidRowCount = $this->get('invalidRowCount');
76 $onDuplicate = $this->get('onDuplicate');
78 $mapper = $this->controller
->exportValue('MapField', 'mapper');
81 foreach ($mapper as $key => $value) {
82 $mapperKeys[$key] = $mapper[$key][0];
85 $parser = new CRM_Event_Import_Parser_Participant($mapperKeys);
87 $mapFields = $this->get('fields');
89 foreach ($mapper as $key => $value) {
91 if (isset($mapFields[$mapper[$key][0]])) {
92 $header[] = $mapFields[$mapper[$key][0]];
94 $mapperFields[] = implode(' - ', $header);
96 $parser->run($fileName, $separator,
98 $this->getSubmittedValue('skipColumnHeader'),
99 CRM_Import_Parser
::MODE_IMPORT
,
100 $this->get('contactType'),
104 // add all the necessary variables to the form
105 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
107 // check if there is any error occurred
109 $errorStack = CRM_Core_Error
::singleton();
110 $errors = $errorStack->getErrors();
113 if (is_array($errors)) {
114 foreach ($errors as $key => $value) {
115 $errorMessage[] = $value['message'];
118 $errorFile = $fileName['name'] . '.error.log';
120 if ($fd = fopen($errorFile, 'w')) {
121 fwrite($fd, implode('\n', $errorMessage));
125 $this->set('errorFile', $errorFile);
126 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser_Participant';
127 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));