4 * Class CRM_Import_ImportProcessor.
6 * Import processor class. This is intended to provide a sanitising wrapper around
7 * the form-oriented import classes. In particular it is intended to provide a clear translation
8 * between the saved mapping field format and the quick form & parser formats.
10 * In the first instance this is only being used in unit tests but the intent is to migrate
11 * to it on a trajectory similar to the ExportProcessor so it is not in the tests.
13 class CRM_Import_ImportProcessor
{
16 * An array of fields in the format used in the table civicrm_mapping_field.
20 protected $mappingFields = [];
23 * Get contact type being imported.
27 protected $contactType;
32 public function getContactType(): string {
33 return $this->contactType
;
37 * @param string $contactType
39 public function setContactType(string $contactType) {
40 $this->contactType
= $contactType;
46 public function getMappingFields(): array {
47 return $this->mappingFields
;
51 * @param array $mappingFields
53 public function setMappingFields(array $mappingFields) {
54 $this->mappingFields
= CRM_Utils_Array
::rekey($mappingFields, 'column_number');
55 ksort($this->mappingFields
);
56 $this->mappingFields
= array_values($this->mappingFields
);
60 * Get the names of the mapped fields.
62 public function getFieldNames() {
63 return CRM_Utils_Array
::collect('name', $this->getMappingFields());
67 * Get the location types of the mapped fields.
69 public function getFieldLocationTypes() {
70 return CRM_Utils_Array
::collect('location_type_id', $this->getMappingFields());
74 * Get the phone types of the mapped fields.
76 public function getFieldPhoneTypes() {
77 return CRM_Utils_Array
::collect('phone_type_id', $this->getMappingFields());
81 * Get the names of the im_provider fields.
83 public function getFieldIMProviderTypes() {
84 return CRM_Utils_Array
::collect('im_provider_id', $this->getMappingFields());
88 * Get the names of the website fields.
90 public function getFieldWebsiteTypes() {
91 return CRM_Utils_Array
::collect('im_provider_id', $this->getMappingFields());
95 * Get an instance of the importer object.
97 * @return CRM_Contact_Import_Parser_Contact
99 public function getImporterObject() {
100 $importer = new CRM_Contact_Import_Parser_Contact(
101 $this->getFieldNames(),
102 $this->getFieldLocationTypes(),
103 $this->getFieldPhoneTypes(),
104 $this->getFieldIMProviderTypes(),
105 // @todo - figure out related mappings.
106 // $mapperRelated = [], $mapperRelatedContactType = [], $mapperRelatedContactDetails = [], $mapperRelatedContactLocType = [], $mapperRelatedContactPhoneType = [], $mapperRelatedContactImProvider = [],
113 $this->getFieldWebsiteTypes()
114 // $mapperRelatedContactWebsiteType = []
117 $importer->_contactType
= $this->getContactType();