public function testMapWithElementDelimiter() { $columnName = 'title'; $isHtml = false; $elementId = 1; $defaultElementDelimiter = ''; $this->assertEquals($defaultElementDelimiter, CsvImport_ColumnMap_Element::getDefaultElementDelimiter()); $elementDelimiter = ','; $beforeElementArray = array('a', 'B', 'c D '); $afterElementArray = array(array('element_id' => $elementId, 'html' => $isHtml ? 1 : 0, 'text' => 'a'), array('element_id' => $elementId, 'html' => $isHtml ? 1 : 0, 'text' => 'B'), array('element_id' => $elementId, 'html' => $isHtml ? 1 : 0, 'text' => 'c D ')); $elementString = implode($elementDelimiter, $beforeElementArray); $row = array($columnName => $elementString); $map = new CsvImport_ColumnMap_Element($columnName, $elementDelimiter); $map->setOptions(array('isHtml' => $isHtml, 'elementId' => $elementId)); $this->assertInstanceOf('CsvImport_ColumnMap_Element', $map); $this->assertEquals($afterElementArray, $map->map($row, array())); }
/** * Get the mappings from one column in the CSV file. * * Some columns can have multiple mappings; these are represented as an * array of maps. * * @param int $index The subform row index * @param string $columnName The name of the CSV file column * @return CsvImport_ColumnMap|array|null A ColumnMap or an array of ColumnMaps */ protected function _getColumnMap($index, $columnName) { $columnMap = array(); if ($this->_isTagMapped($index)) { $columnMap[] = new CsvImport_ColumnMap_Tag($columnName, $this->_tagDelimiter); } if ($this->_isFileMapped($index)) { $columnMap[] = new CsvImport_ColumnMap_File($columnName, $this->_fileDelimiter); } if ($this->_isFileUrlMapped($index)) { $columnMap[] = new CsvImport_ColumnMap_File($columnName, '', true); } if ($this->_isExtraDataMapped($index)) { $columnMap[] = new CsvImport_ColumnMap_ExtraData($columnName, $this->_elementDelimiter); } $elementIds = $this->_getMappedElementId($index); $isHtml = $this->_getRowValue($index, 'html'); foreach ($elementIds as $elementId) { // Make sure to skip empty mappings. if (!$elementId) { continue; } $elementMap = new CsvImport_ColumnMap_Element($columnName, $this->_elementDelimiter); $elementMap->setOptions(array('elementId' => $elementId, 'isHtml' => $isHtml)); $columnMap[] = $elementMap; } $specialValue = $this->_getMappedSpecialValue($index); switch ($specialValue) { case 'Identifier': $columnMap[] = new CsvImport_ColumnMap_Identifier($columnName); break; // Deprecated. // Deprecated. case 'sourceItemId': $columnMap[] = new CsvImport_ColumnMap_SourceItemId($columnName); break; // Deprecated. // Deprecated. case 'updateMode': $columnMap[] = new CsvImport_ColumnMap_UpdateMode($columnName); break; case 'Action': $columnMap[] = new CsvImport_ColumnMap_Action($columnName, $this->_action); break; case 'IdentifierField': $columnMap[] = new CsvImport_ColumnMap_IdentifierField($columnName, $this->_identifierField); break; // Deprecated. // Deprecated. case 'updateIdentifier': $columnMap[] = new CsvImport_ColumnMap_UpdateIdentifier($columnName); break; case 'RecordType': $columnMap[] = new CsvImport_ColumnMap_RecordType($columnName); break; // Deprecated. // Deprecated. case 'recordIdentifier': $columnMap[] = new CsvImport_ColumnMap_RecordIdentifier($columnName); break; case 'ItemType': $columnMap[] = new CsvImport_ColumnMap_ItemType($columnName, $this->_itemTypeId); break; case 'Item': $columnMap[] = new CsvImport_ColumnMap_Item($columnName); break; case 'Collection': $columnMap[] = new CsvImport_ColumnMap_Collection($columnName, $this->_collectionId, $this->_createCollections, $this->_format == 'Manage'); break; case 'Public': $columnMap[] = new CsvImport_ColumnMap_Public($columnName, $this->_isPublic); break; case 'Featured': $columnMap[] = new CsvImport_ColumnMap_Featured($columnName, $this->_isFeatured); break; // Deprecated. // Deprecated. case 'fileUrl': $columnMap[] = new CsvImport_ColumnMap_File($columnName, '', true); break; case 'File': $columnMap[] = new CsvImport_ColumnMap_File($columnName, $this->_fileDelimiter); break; case 'Tags': $columnMap[] = new CsvImport_ColumnMap_Tag($columnName, $this->_tagDelimiter); break; } return $columnMap; }
/** * Get the mappings from one column in the CSV file. * * Some columns can have multiple mappings; these are represented * as an array of maps. * * @param int $index The subform row index * @param string $columnName The name of the CSV file column * @return CsvImport_ColumnMap|array|null A ColumnMap or an array of ColumnMaps */ protected function _getColumnMap($index, $columnName) { $columnMap = array(); if ($this->_isTagMapped($index)) { $columnMap[] = new CsvImport_ColumnMap_Tag($columnName, $this->_tagDelimiter); } if ($this->_isFileMapped($index)) { $columnMap[] = new CsvImport_ColumnMap_File($columnName, $this->_fileDelimiter); } $elementIds = $this->_getMappedElementId($index); $isHtml = $this->_getRowValue($index, 'html'); foreach ($elementIds as $elementId) { // Make sure to skip empty mappings if (!$elementId) { continue; } $elementMap = new CsvImport_ColumnMap_Element($columnName, $this->_elementDelimiter); $elementMap->setOptions(array('elementId' => $elementId, 'isHtml' => $isHtml)); $columnMap[] = $elementMap; } return $columnMap; }