Fixes for Activity import
[civicrm-core.git] / CRM / Import / Form / Summary.php
index e12cbb4fa1b484632e064e5e8a33e8876a095350..461990ce017fe462ac36910323003014415610b1 100644 (file)
  * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
+use Civi\Api4\UserJob;
+
 /**
  * This class summarizes the import results.
  *
  * TODO: CRM-11254 - if preProcess and postProcess functions can be reconciled between the 5 child classes,
  * those classes can be removed entirely and this class will not need to be abstract
  */
-abstract class CRM_Import_Form_Summary extends CRM_Core_Form {
+abstract class CRM_Import_Form_Summary extends CRM_Import_Forms {
+
+  /**
+   * Set variables up before form is built.
+   *
+   * @return void
+   */
+  public function preProcess() {
+    $this->assignOutputURLs();
+  }
 
   /**
    * Build the form object.
@@ -45,4 +56,33 @@ abstract class CRM_Import_Form_Summary extends CRM_Core_Form {
     return ts('Summary');
   }
 
+  protected function assignOutputURLs(): void {
+    $this->assign('totalRowCount', $this->getRowCount());
+    $this->assign('validRowCount', $this->getRowCount(CRM_Import_Parser::VALID) + $this->getRowCount(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
+    $this->assign('invalidRowCount', $this->getRowCount(CRM_Import_Parser::ERROR));
+    $this->assign('duplicateRowCount', $this->getRowCount(CRM_Import_Parser::DUPLICATE));
+    $this->assign('unMatchCount', $this->getRowCount(CRM_Import_Parser::NO_MATCH));
+    $this->assign('unparsedAddressCount', $this->getRowCount(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
+    $this->assign('downloadDuplicateRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::DUPLICATE));
+    $this->assign('downloadErrorRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::ERROR));
+    $this->assign('downloadMismatchRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::NO_MATCH));
+    $this->assign('downloadAddressRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
+    $userJobID = CRM_Utils_Request::retrieve('user_job_id', 'String', $this, TRUE);
+    $userJob = UserJob::get(TRUE)->addWhere('id', '=', $userJobID)->execute()->first();
+    $onDuplicate = (int) $userJob['metadata']['submitted_values']['onDuplicate'];
+    $this->assign('dupeError', FALSE);
+    if ($onDuplicate === CRM_Import_Parser::DUPLICATE_UPDATE) {
+      $dupeActionString = ts('These records have been updated with the imported data.');
+    }
+    elseif ($onDuplicate === CRM_Import_Parser::DUPLICATE_FILL) {
+      $dupeActionString = ts('These records have been filled in with the imported data.');
+    }
+    else {
+      // Skip by default.
+      $dupeActionString = ts('These records have not been imported.');
+      $this->assign('dupeError', TRUE);
+    }
+    $this->assign('dupeActionString', $dupeActionString);
+  }
+
 }