Example #1
0
 /**
  * Class constructor.
  *
  * @param $mapperKeys
  * @param null $mapperSoftCredit
  * @param null $mapperPhoneType
  * @param null $mapperSoftCreditType
  */
 public function __construct(&$mapperKeys, $mapperSoftCredit = NULL, $mapperPhoneType = NULL, $mapperSoftCreditType = NULL)
 {
     parent::__construct();
     $this->_mapperKeys =& $mapperKeys;
     $this->_mapperSoftCredit =& $mapperSoftCredit;
     $this->_mapperSoftCreditType =& $mapperSoftCreditType;
 }
 /**
  * class constructor
  */
 function CRM_Contribute_Import_Parser_Contribution(&$mapperKeys, $mapperLocType = null, $mapperPhoneType = null)
 {
     parent::CRM_Contribute_Import_Parser();
     $this->_mapperKeys =& $mapperKeys;
     //$this->_mapperLocType =& $mapperLocType;
     //$this->_mapperPhoneType =& $mapperPhoneType;
 }
Example #3
0
 /**
  * class constructor
  */
 function __construct(&$mapperKeys, $mapperSoftCredit = null, $mapperPhoneType = null)
 {
     parent::__construct();
     $this->_mapperKeys =& $mapperKeys;
     $this->_mapperSoftCredit =& $mapperSoftCredit;
 }
Example #4
0
 function run($fileName, $seperator = ',', &$mapper, $skipColumnHeader = false, $mode = CRM_CONTRIBUTE_IMPORT_PARSER_MODE_PREVIEW, $onDuplicate = CRM_CONTRIBUTE_IMPORT_PARSER_DUPLICATE_SKIP)
 {
     $this->init();
     $this->_haveColumnHeader = $skipColumnHeader;
     $this->_seperator = $seperator;
     $fd = fopen($fileName, "r");
     if (!$fd) {
         return false;
     }
     $this->_lineCount = $this->_warningCount = 0;
     $this->_invalidRowCount = $this->_validCount = 0;
     $this->_totalCount = $this->_conflictCount = 0;
     $this->_errors = array();
     $this->_warnings = array();
     $this->_conflicts = array();
     $this->_fileSize = number_format(filesize($fileName) / 1024.0, 2);
     if ($mode == CRM_CONTRIBUTE_IMPORT_PARSER_MODE_MAPFIELD) {
         $this->_rows = array();
     } else {
         $this->_activeFieldCount = count($this->_activeFields);
     }
     while (!feof($fd)) {
         $this->_lineCount++;
         $values = fgetcsv($fd, 8192, $seperator);
         if (!$values) {
             continue;
         }
         CRM_Contribute_Import_Parser::encloseScrub($values);
         // skip column header if we're not in mapfield mode
         if ($mode != CRM_CONTRIBUTE_IMPORT_PARSER_MODE_MAPFIELD && $skipColumnHeader) {
             $skipColumnHeader = false;
             continue;
         }
         /* trim whitespace around the values */
         $empty = true;
         foreach ($values as $k => $v) {
             $values[$k] = trim($v, " .\t\r\n");
         }
         if (CRM_Utils_System::isNull($values)) {
             continue;
         }
         $this->_totalCount++;
         if ($mode == CRM_CONTRIBUTE_IMPORT_PARSER_MODE_MAPFIELD) {
             $returnCode = $this->mapField($values);
         } else {
             if ($mode == CRM_CONTRIBUTE_IMPORT_PARSER_MODE_PREVIEW) {
                 $returnCode = $this->preview($values);
             } else {
                 if ($mode == CRM_CONTRIBUTE_IMPORT_PARSER_MODE_SUMMARY) {
                     $returnCode = $this->summary($values);
                 } else {
                     if ($mode == CRM_CONTRIBUTE_IMPORT_PARSER_MODE_IMPORT) {
                         $returnCode = $this->import($onDuplicate, $values);
                     } else {
                         $returnCode = CRM_CONTRIBUTE_IMPORT_PARSER_ERROR;
                     }
                 }
             }
         }
         // note that a line could be valid but still produce a warning
         if ($returnCode & CRM_CONTRIBUTE_IMPORT_PARSER_VALID) {
             $this->_validCount++;
             if ($mode == CRM_CONTRIBUTE_IMPORT_PARSER_MODE_MAPFIELD) {
                 $this->_rows[] = $values;
                 $this->_activeFieldCount = max($this->_activeFieldCount, count($values));
             }
         }
         if ($returnCode & CRM_CONTRIBUTE_IMPORT_PARSER_WARNING) {
             $this->_warningCount++;
             if ($this->_warningCount < $this->_maxWarningCount) {
                 $this->_warningCount[] = $line;
             }
         }
         if ($returnCode & CRM_CONTRIBUTE_IMPORT_PARSER_ERROR) {
             $this->_invalidRowCount++;
             if ($this->_invalidRowCount < $this->_maxErrorCount) {
                 $recordNumber = $this->_lineCount;
                 if ($this->_haveColumnHeader) {
                     $recordNumber--;
                 }
                 array_unshift($values, $recordNumber);
                 $this->_errors[] = $values;
             }
         }
         if ($returnCode & CRM_CONTRIBUTE_IMPORT_PARSER_CONFLICT) {
             $this->_conflictCount++;
             $recordNumber = $this->_lineCount;
             if ($this->_haveColumnHeader) {
                 $recordNumber--;
             }
             array_unshift($values, $recordNumber);
             $this->_conflicts[] = $values;
         }
         if ($returnCode & CRM_CONTRIBUTE_IMPORT_PARSER_DUPLICATE) {
             if ($returnCode & CRM_CONTRIBUTE_IMPORT_PARSER_MULTIPLE_DUPE) {
                 /* TODO: multi-dupes should be counted apart from singles
                  * on non-skip action */
             }
             $this->_duplicateCount++;
             $recordNumber = $this->_lineCount;
             if ($this->_haveColumnHeader) {
                 $recordNumber--;
             }
             array_unshift($values, $recordNumber);
             $this->_duplicates[] = $values;
             if ($onDuplicate != CRM_CONTRIBUTE_IMPORT_PARSER_DUPLICATE_SKIP) {
                 $this->_validCount++;
             }
         }
         // we give the derived class a way of aborting the process
         // note that the return code could be multiple code or'ed together
         if ($returnCode & CRM_CONTRIBUTE_IMPORT_PARSER_STOP) {
             break;
         }
         // if we are done processing the maxNumber of lines, break
         if ($this->_maxLinesToProcess > 0 && $this->_validCount >= $this->_maxLinesToProcess) {
             break;
         }
     }
     fclose($fd);
     if ($mode == CRM_CONTRIBUTE_IMPORT_PARSER_MODE_PREVIEW || $mode == CRM_CONTRIBUTE_IMPORT_PARSER_MODE_IMPORT) {
         $customHeaders = $mapper;
         $customfields =& CRM_Core_BAO_CustomField::getFields('Contribution');
         foreach ($customHeaders as $key => $value) {
             if ($id = CRM_Core_BAO_CustomField::getKeyID($value)) {
                 $customHeaders[$key] = $customfields[$id][0];
             }
         }
         if ($this->_invalidRowCount) {
             // removed view url for invlaid contacts
             $headers = array_merge(array(ts('Record Number'), ts('Reason')), $customHeaders);
             $this->_errorFileName = $fileName . '.errors';
             CRM_Contribute_Import_Parser::exportCSV($this->_errorFileName, $headers, $this->_errors);
         }
         if ($this->_conflictCount) {
             $headers = array_merge(array(ts('Record Number'), ts('Reason')), $customHeaders);
             $this->_conflictFileName = $fileName . '.conflicts';
             CRM_Contribute_Import_Parser::exportCSV($this->_conflictFileName, $headers, $this->_conflicts);
         }
         if ($this->_duplicateCount) {
             $headers = array_merge(array(ts('Record Number'), ts('View Contribution URL')), $customHeaders);
             $this->_duplicateFileName = $fileName . '.duplicates';
             CRM_Contribute_Import_Parser::exportCSV($this->_duplicateFileName, $headers, $this->_duplicates);
         }
     }
     //echo "$this->_totalCount,$this->_invalidRowCount,$this->_conflictCount,$this->_duplicateCount";
     return $this->fini();
 }