Merge pull request #23715 from eileenmcnaughton/syntax
[civicrm-core.git] / CRM / Contribute / Import / Form / Preview.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class previews the uploaded file and returns summary statistics.
20 */
21 class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview {
22
23 /**
24 * Set variables up before form is built.
25 */
26 public function preProcess() {
27 parent::preProcess();
28 $invalidRowCount = $this->getRowCount(CRM_Import_Parser::VALID);
29
30 $downloadURL = '';
31 if ($invalidRowCount) {
32 $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contribute_Import_Parser_Contribution';
33 $downloadURL = CRM_Utils_System::url('civicrm/export', $urlParams);
34 }
35
36 $this->setStatusUrl();
37 $this->assign('downloadErrorRecordsUrl', $downloadURL);
38 }
39
40 /**
41 * Get the mapped fields as an array of labels.
42 *
43 * e.g
44 * ['First Name', 'Employee Of - First Name', 'Home - Street Address']
45 *
46 * @return array
47 * @throws \API_Exception
48 * @throws \CRM_Core_Exception
49 */
50 protected function getMappedFieldLabels(): array {
51 $mapper = [];
52 $parser = $this->getParser();
53 foreach ($this->getSubmittedValue('mapper') as $columnNumber => $mappedField) {
54 $mapper[$columnNumber] = $parser->getMappedFieldLabel($parser->getMappingFieldFromMapperInput($mappedField, 0, $columnNumber));
55 }
56 return $mapper;
57 }
58
59 /**
60 * @return \CRM_Contribute_Import_Parser_Contribution
61 */
62 protected function getParser(): CRM_Contribute_Import_Parser_Contribution {
63 if (!$this->parser) {
64 $this->parser = new CRM_Contribute_Import_Parser_Contribution();
65 $this->parser->setUserJobID($this->getUserJobID());
66 $this->parser->init();
67 }
68 return $this->parser;
69 }
70
71 }