Switch contribution to use same error handling
[civicrm-core.git] / CRM / Import / Form / Summary.php
CommitLineData
52892e8b
CW
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
52892e8b 5 | |
bc77d7c0
TO
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 |
52892e8b 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
52892e8b
CW
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
52892e8b
CW
16 */
17
7eebbdaa
EM
18use Civi\Api4\UserJob;
19
52892e8b 20/**
2b4bc760 21 * This class summarizes the import results.
22 *
52892e8b
CW
23 * TODO: CRM-11254 - if preProcess and postProcess functions can be reconciled between the 5 child classes,
24 * those classes can be removed entirely and this class will not need to be abstract
25 */
99e3c5f7 26abstract class CRM_Import_Form_Summary extends CRM_Import_Forms {
52892e8b 27
992a3d9e
EM
28 /**
29 * Set variables up before form is built.
30 *
31 * @return void
32 */
33 public function preProcess() {
34 $this->assignOutputURLs();
35 }
36
52892e8b 37 /**
fe482240 38 * Build the form object.
52892e8b
CW
39 */
40 public function buildQuickForm() {
41 $this->addButtons(array(
42 array(
43 'type' => 'next',
44 'name' => ts('Done'),
45 'isDefault' => TRUE,
46 ),
971e129b 47 ));
52892e8b
CW
48 }
49
50 /**
2b4bc760 51 * Return a descriptive name for the page, used in wizard header.
52892e8b
CW
52 *
53 * @return string
52892e8b
CW
54 */
55 public function getTitle() {
56 return ts('Summary');
57 }
96025800 58
992a3d9e
EM
59 protected function assignOutputURLs(): void {
60 $this->assign('totalRowCount', $this->getRowCount());
61 $this->assign('validRowCount', $this->getRowCount(CRM_Import_Parser::VALID) + $this->getRowCount(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
62 $this->assign('invalidRowCount', $this->getRowCount(CRM_Import_Parser::ERROR));
63 $this->assign('duplicateRowCount', $this->getRowCount(CRM_Import_Parser::DUPLICATE));
64 $this->assign('unMatchCount', $this->getRowCount(CRM_Import_Parser::NO_MATCH));
58a65f77
EM
65 $this->assign('validSoftCreditRowCount', $this->getRowCount(CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT));
66 $this->assign('invalidSoftCreditRowCount', $this->getRowCount(CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT_ERROR));
67 $this->assign('validPledgePaymentRowCount', $this->getRowCount(CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT));
68 $this->assign('invalidPledgePaymentRowCount', $this->getRowCount(CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT_ERROR));
992a3d9e
EM
69 $this->assign('unparsedAddressCount', $this->getRowCount(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
70 $this->assign('downloadDuplicateRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::DUPLICATE));
71 $this->assign('downloadErrorRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::ERROR));
72 $this->assign('downloadMismatchRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::NO_MATCH));
73 $this->assign('downloadAddressRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
58a65f77
EM
74 $this->assign('downloadPledgePaymentErrorRecordsUrl', $this->getDownloadURL(CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT_ERROR));
75 $this->assign('downloadSoftCreditErrorRecordsUrl', $this->getDownloadURL(CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT_ERROR));
7eebbdaa
EM
76 $userJobID = CRM_Utils_Request::retrieve('user_job_id', 'String', $this, TRUE);
77 $userJob = UserJob::get(TRUE)->addWhere('id', '=', $userJobID)->execute()->first();
78 $onDuplicate = (int) $userJob['metadata']['submitted_values']['onDuplicate'];
79 $this->assign('dupeError', FALSE);
80 if ($onDuplicate === CRM_Import_Parser::DUPLICATE_UPDATE) {
81 $dupeActionString = ts('These records have been updated with the imported data.');
82 }
83 elseif ($onDuplicate === CRM_Import_Parser::DUPLICATE_FILL) {
84 $dupeActionString = ts('These records have been filled in with the imported data.');
85 }
86 else {
87 // Skip by default.
88 $dupeActionString = ts('These records have not been imported.');
89 $this->assign('dupeError', TRUE);
90 }
91 $this->assign('dupeActionString', $dupeActionString);
992a3d9e
EM
92 }
93
52892e8b 94}