Merge pull request #23707 from eileenmcnaughton/import_activity
[civicrm-core.git] / CRM / Event / Import / Form / DataSource.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 gets the name of the file to upload
20 */
21 class CRM_Event_Import_Form_DataSource extends CRM_Import_Form_DataSource {
22
23 const PATH = 'civicrm/event/import';
24
25 const IMPORT_ENTITY = 'Participant';
26
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 'participant_import';
34 }
35
36 /**
37 * Build the form object.
38 *
39 * @return void
40 */
41 public function buildQuickForm() {
42 parent::buildQuickForm();
43
44 $duplicateOptions = [];
45 $this->addRadio('onDuplicate', ts('On Duplicate Entries'), [
46 CRM_Import_Parser::DUPLICATE_SKIP => ts('Skip'),
47 CRM_Import_Parser::DUPLICATE_UPDATE => ts('Update'),
48 CRM_Import_Parser::DUPLICATE_NOCHECK => ts('No Duplicate Checking'),
49 ]);
50 $this->setDefaults(['onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP]);
51
52 $this->addContactTypeSelector();
53 }
54
55 /**
56 * Process the uploaded file.
57 *
58 * @return void
59 */
60 public function postProcess() {
61 $this->storeFormValues([
62 'onDuplicate',
63 'contactType',
64 'dateFormats',
65 'savedMapping',
66 ]);
67
68 $this->submitFileForMapping('CRM_Event_Import_Parser_Participant');
69 }
70
71 /**
72 * @return CRM_Event_Import_Parser_Participant
73 */
74 protected function getParser(): CRM_Event_Import_Parser_Participant {
75 if (!$this->parser) {
76 $this->parser = new CRM_Event_Import_Parser_Participant();
77 $this->parser->setUserJobID($this->getUserJobID());
78 $this->parser->init();
79 }
80 return $this->parser;
81 }
82
83 }