corrected class name in old FSF code
[civicrm-core.git] / CRM / Member / Import / Form / DataSource.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * This class gets the name of the file to upload
38 */
81c3812a 39class CRM_Member_Import_Form_DataSource extends CRM_Import_Form_DataSource {
6a488035 40
81c3812a
CW
41 const PATH = 'civicrm/member/import';
42
43 const IMPORT_ENTITY = 'Membership';
6a488035
TO
44
45 /**
fe482240 46 * Build the form object.
6a488035 47 *
355ba699 48 * @return void
6a488035
TO
49 */
50 public function buildQuickForm() {
81c3812a 51 parent::buildQuickForm();
6a488035 52
71b59e6d
RR
53 //Setting Upload File Size
54 $config = CRM_Core_Config::singleton();
55
da27d4e6 56 $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
71b59e6d
RR
57 $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
58
59 $this->assign('uploadSize', $uploadSize);
60
61 $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
62 $this->setMaxFileSize($uploadFileSize);
63 $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(
64 1 => $uploadSize,
65 2 => $uploadFileSize,
66 )), 'maxfilesize', $uploadFileSize);
67 $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
68 $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
69
70 $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
71
be2fb01f 72 $duplicateOptions = [];
6a488035 73 $duplicateOptions[] = $this->createElement('radio',
a05662ef 74 NULL, NULL, ts('Insert new Membership'), CRM_Import_Parser::DUPLICATE_SKIP
6a488035
TO
75 );
76 $duplicateOptions[] = $this->createElement('radio',
a05662ef 77 NULL, NULL, ts('Update existing Membership'), CRM_Import_Parser::DUPLICATE_UPDATE
6a488035
TO
78 );
79
80 $this->addGroup($duplicateOptions, 'onDuplicate',
81 ts('Import mode')
82 );
be2fb01f 83 $this->setDefaults([
9d72cede 84 'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
be2fb01f 85 ]);
6a488035 86
81c3812a 87 $this->addContactTypeSelector();
6a488035
TO
88 }
89
90 /**
fe482240 91 * Process the uploaded file.
6a488035
TO
92 *
93 * @return void
6a488035
TO
94 */
95 public function postProcess() {
be2fb01f 96 $this->storeFormValues([
81c3812a
CW
97 'onDuplicate',
98 'contactType',
99 'dateFormats',
100 'savedMapping',
be2fb01f 101 ]);
6a488035 102
81c3812a 103 $this->submitFileForMapping('CRM_Member_Import_Parser_Membership');
6a488035 104 }
96025800 105
6a488035 106}