corrected class name in old FSF code
[civicrm-core.git] / CRM / Member / 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_Member_Import_Form_DataSource extends CRM_Import_Form_DataSource {
6a488035 22
81c3812a
CW
23 const PATH = 'civicrm/member/import';
24
25 const IMPORT_ENTITY = 'Membership';
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 'membership_import';
34 }
35
6a488035 36 /**
fe482240 37 * Build the form object.
6a488035 38 *
355ba699 39 * @return void
6a488035
TO
40 */
41 public function buildQuickForm() {
81c3812a 42 parent::buildQuickForm();
6a488035 43
a4aea745
RR
44 //Setting Upload File Size
45 $config = CRM_Core_Config::singleton();
46
09dc0e71 47 $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
a4aea745
RR
48 $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
49
50 $this->assign('uploadSize', $uploadSize);
51
52 $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
53 $this->setMaxFileSize($uploadFileSize);
54 $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(
55 1 => $uploadSize,
56 2 => $uploadFileSize,
57 )), 'maxfilesize', $uploadFileSize);
58 $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
59 $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
60
61 $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
62
39405208
SL
63 $this->addRadio('onDuplicate', ts('Import mode'), [
64 CRM_Import_Parser::DUPLICATE_SKIP => ts('Insert new Membership'),
65 CRM_Import_Parser::DUPLICATE_UPDATE => ts('Update existing Membership'),
66 ]);
be2fb01f 67 $this->setDefaults([
9d72cede 68 'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
be2fb01f 69 ]);
6a488035 70
81c3812a 71 $this->addContactTypeSelector();
6a488035
TO
72 }
73
83a1c234
EM
74 /**
75 * @return \CRM_Member_Import_Parser_Membership
76 */
77 protected function getParser(): CRM_Member_Import_Parser_Membership {
78 if (!$this->parser) {
79 $this->parser = new CRM_Member_Import_Parser_Membership();
80 $this->parser->setUserJobID($this->getUserJobID());
81 $this->parser->init();
82 }
83 return $this->parser;
84 }
85
6a488035 86}