corrected class name in old FSF code
[civicrm-core.git] / CRM / Member / Import / Form / DataSource.php
index 3218606dedd24e91f5ec7343d57da8f88ab15239..494da4154549f906940a43846f9b9267d5c6a367 100644 (file)
@@ -24,6 +24,15 @@ class CRM_Member_Import_Form_DataSource extends CRM_Import_Form_DataSource {
 
   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.
    *
@@ -32,17 +41,29 @@ class CRM_Member_Import_Form_DataSource extends CRM_Import_Form_DataSource {
   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,
     ]);
@@ -51,19 +72,15 @@ class CRM_Member_Import_Form_DataSource extends CRM_Import_Form_DataSource {
   }
 
   /**
-   * 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;
   }
 
 }