const IMPORT_ENTITY = 'Membership';
+ /**
+ * Get the name of the type to be stored in civicrm_user_job.type_id.
+ *
+ * @return string
+ */
+ public function getUserJobType(): string {
+ return 'membership_import';
+ }
+
/**
* Build the form object.
*
public function buildQuickForm() {
parent::buildQuickForm();
- $duplicateOptions = [];
- $duplicateOptions[] = $this->createElement('radio',
- NULL, NULL, ts('Insert new Membership'), CRM_Import_Parser::DUPLICATE_SKIP
- );
- $duplicateOptions[] = $this->createElement('radio',
- NULL, NULL, ts('Update existing Membership'), CRM_Import_Parser::DUPLICATE_UPDATE
- );
+ //Setting Upload File Size
+ $config = CRM_Core_Config::singleton();
+
+ $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
+ $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
+
+ $this->assign('uploadSize', $uploadSize);
- $this->addGroup($duplicateOptions, 'onDuplicate',
- ts('Import mode')
- );
+ $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
+ $this->setMaxFileSize($uploadFileSize);
+ $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(
+ 1 => $uploadSize,
+ 2 => $uploadFileSize,
+ )), 'maxfilesize', $uploadFileSize);
+ $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
+ $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
+
+ $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
+
+ $this->addRadio('onDuplicate', ts('Import mode'), [
+ CRM_Import_Parser::DUPLICATE_SKIP => ts('Insert new Membership'),
+ CRM_Import_Parser::DUPLICATE_UPDATE => ts('Update existing Membership'),
+ ]);
$this->setDefaults([
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
]);
}
/**
- * Process the uploaded file.
- *
- * @return void
+ * @return \CRM_Member_Import_Parser_Membership
*/
- public function postProcess() {
- $this->storeFormValues([
- 'onDuplicate',
- 'contactType',
- 'dateFormats',
- 'savedMapping',
- ]);
-
- $this->submitFileForMapping('CRM_Member_Import_Parser_Membership');
+ protected function getParser(): CRM_Member_Import_Parser_Membership {
+ if (!$this->parser) {
+ $this->parser = new CRM_Member_Import_Parser_Membership();
+ $this->parser->setUserJobID($this->getUserJobID());
+ $this->parser->init();
+ }
+ return $this->parser;
}
}