99ecc3641678c919a09d58ae7b58ec0da04ebb47
[civicrm-core.git] / CRM / Member / 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_Member_Import_Form_DataSource extends CRM_Import_Form_DataSource {
22
23 const PATH = 'civicrm/member/import';
24
25 const IMPORT_ENTITY = 'Membership';
26
27 /**
28 * Build the form object.
29 *
30 * @return void
31 */
32 public function buildQuickForm() {
33 parent::buildQuickForm();
34
35 //Setting Upload File Size
36 $config = CRM_Core_Config::singleton();
37
38 $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize . 'm', TRUE);
39 $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
40
41 $this->assign('uploadSize', $uploadSize);
42
43 $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
44 $this->setMaxFileSize($uploadFileSize);
45 $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(
46 1 => $uploadSize,
47 2 => $uploadFileSize,
48 )), 'maxfilesize', $uploadFileSize);
49 $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
50 $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
51
52 $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
53
54 $this->addRadio('onDuplicate', ts('Import mode'), [
55 CRM_Import_Parser::DUPLICATE_SKIP => ts('Insert new Membership'),
56 CRM_Import_Parser::DUPLICATE_UPDATE => ts('Update existing Membership'),
57 ]);
58 $this->setDefaults([
59 'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
60 ]);
61
62 $this->addContactTypeSelector();
63 }
64
65 /**
66 * Process the uploaded file.
67 *
68 * @return void
69 */
70 public function postProcess() {
71 $this->storeFormValues([
72 'onDuplicate',
73 'contactType',
74 'dateFormats',
75 'savedMapping',
76 ]);
77
78 $this->submitFileForMapping('CRM_Member_Import_Parser_Membership');
79 }
80
81 }