3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
37 * This class previews the uploaded file and returns summary
40 class CRM_Member_Import_Form_Preview
extends CRM_Import_Form_Preview
{
43 * Set variables up before form is built.
47 public function preProcess() {
48 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
50 //get the data from the session
51 $dataValues = $this->get('dataValues');
52 $mapper = $this->get('mapper');
53 $invalidRowCount = $this->get('invalidRowCount');
54 $conflictRowCount = $this->get('conflictRowCount');
55 $mismatchCount = $this->get('unMatchCount');
57 //get the mapping name displayed if the mappingId is set
58 $mappingId = $this->get('loadMappingId');
60 $mapDAO = new CRM_Core_DAO_Mapping();
61 $mapDAO->id
= $mappingId;
63 $this->assign('loadedMapping', $mappingId);
64 $this->assign('savedName', $mapDAO->name
);
67 if ($skipColumnHeader) {
68 $this->assign('skipColumnHeader', $skipColumnHeader);
69 $this->assign('rowDisplayCount', 3);
72 $this->assign('rowDisplayCount', 2);
75 if ($invalidRowCount) {
76 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Member_Import_Parser';
77 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
80 if ($conflictRowCount) {
81 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Member_Import_Parser';
82 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
86 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Member_Import_Parser';
87 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
98 'downloadErrorRecordsUrl',
99 'downloadConflictRecordsUrl',
100 'downloadMismatchRecordsUrl',
102 $this->setStatusUrl();
104 foreach ($properties as $property) {
105 $this->assign($property, $this->get($property));
110 * Process the mapped fields and map it into the uploaded file
111 * preview the file and extract some summary statistics
115 public function postProcess() {
116 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
117 $seperator = $this->controller
->exportValue('DataSource', 'fieldSeparator');
118 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
119 $invalidRowCount = $this->get('invalidRowCount');
120 $conflictRowCount = $this->get('conflictRowCount');
121 $onDuplicate = $this->get('onDuplicate');
123 $mapper = $this->controller
->exportValue('MapField', 'mapper');
124 $mapperKeys = array();
125 $mapperLocType = array();
126 $mapperPhoneType = array();
127 // Note: we keep the multi-dimension array (even thought it's not
128 // needed in the case of memberships import) so that we can merge
129 // the common code with contacts import later and subclass contact
130 // and membership imports from there
131 foreach ($mapper as $key => $value) {
132 $mapperKeys[$key] = $mapper[$key][0];
134 if (!empty($mapper[$key][1]) && is_numeric($mapper[$key][1])) {
135 $mapperLocType[$key] = $mapper[$key][1];
138 $mapperLocType[$key] = NULL;
141 if (!empty($mapper[$key][2]) && (!is_numeric($mapper[$key][2]))) {
142 $mapperPhoneType[$key] = $mapper[$key][2];
145 $mapperPhoneType[$key] = NULL;
149 $parser = new CRM_Member_Import_Parser_Membership($mapperKeys, $mapperLocType, $mapperPhoneType);
151 $mapFields = $this->get('fields');
153 foreach ($mapper as $key => $value) {
155 if (isset($mapFields[$mapper[$key][0]])) {
156 $header[] = $mapFields[$mapper[$key][0]];
158 $mapperFields[] = implode(' - ', $header);
160 $parser->run($fileName, $seperator,
163 CRM_Import_Parser
::MODE_IMPORT
,
164 $this->get('contactType'),
166 $this->get('statusID'),
167 $this->get('totalRowCount')
170 // add all the necessary variables to the form
171 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
173 // check if there is any error occurred
174 $errorStack = CRM_Core_Error
::singleton();
175 $errors = $errorStack->getErrors();
176 $errorMessage = array();
178 if (is_array($errors)) {
179 foreach ($errors as $key => $value) {
180 $errorMessage[] = $value['message'];
183 $errorFile = $fileName['name'] . '.error.log';
185 if ($fd = fopen($errorFile, 'w')) {
186 fwrite($fd, implode('\n', $errorMessage));
190 $this->set('errorFile', $errorFile);
191 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Member_Import_Parser';
192 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
193 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Member_Import_Parser';
194 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
195 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Member_Import_Parser';
196 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));