Merge pull request #23620 from bugfolder/8_move_session_start
[civicrm-core.git] / CRM / Contribute / Import / Form / DataSource.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * This class gets the name of the file to upload
20 */
81c3812a 21class CRM_Contribute_Import_Form_DataSource extends CRM_Import_Form_DataSource {
6a488035 22
81c3812a
CW
23 const PATH = 'civicrm/contribute/import';
24
25 const IMPORT_ENTITY = 'Contribution';
6a488035 26
08a76614
EM
27 /**
28 * Get the name of the type to be stored in civicrm_user_job.type_id.
29 *
30 * @return string
31 */
32 public function getUserJobType(): string {
33 return 'contribution_import';
34 }
35
6a488035 36 /**
fe482240 37 * Build the form object.
6a488035
TO
38 */
39 public function buildQuickForm() {
81c3812a 40 parent::buildQuickForm();
6a488035 41
39405208
SL
42 $this->addRadio('onDuplicate', ts('Import mode'), [
43 CRM_Import_Parser::DUPLICATE_SKIP => ts('Insert new contributions'),
44 CRM_Import_Parser::DUPLICATE_UPDATE => ts('Update existing contributions'),
45 ]);
6a488035 46
be2fb01f 47 $this->setDefaults(['onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP]);
6a488035 48
cbd83dde
AH
49 $this->addElement('xbutton', 'loadMapping', ts('Load Mapping'), [
50 'type' => 'submit',
51 'onclick' => 'checkSelect()',
52 ]);
6a488035 53
81c3812a 54 $this->addContactTypeSelector();
6a488035
TO
55 }
56
57 /**
fe482240 58 * Process the uploaded file.
6a488035
TO
59 */
60 public function postProcess() {
be2fb01f 61 $this->storeFormValues([
81c3812a
CW
62 'onDuplicate',
63 'contactType',
64 'dateFormats',
65 'savedMapping',
be2fb01f 66 ]);
6a488035 67
81c3812a 68 $this->submitFileForMapping('CRM_Contribute_Import_Parser_Contribution');
6a488035 69 }
96025800 70
83a1c234
EM
71 /**
72 * @return \CRM_Contribute_Import_Parser_Contribution
73 */
74 protected function getParser(): CRM_Contribute_Import_Parser_Contribution {
75 if (!$this->parser) {
76 $this->parser = new CRM_Contribute_Import_Parser_Contribution();
77 $this->parser->setUserJobID($this->getUserJobID());
78 $this->parser->init();
79 }
80 return $this->parser;
81 }
82
6a488035 83}