/**
  * Create and queue a new import from Omeka.net or with mixed records.
  */
 public function omekaCsvAction()
 {
     $elementDelimiter = $this->session->elementDelimiter;
     $tagDelimiter = $this->session->tagDelimiter;
     $fileDelimiter = $this->session->fileDelimiter;
     $itemTypeId = $this->session->itemTypeId;
     $collectionId = $this->session->collectionId;
     $isPublic = $this->session->recordsArePublic;
     $isFeatured = $this->session->recordsAreFeatured;
     $isHtml = $this->session->elementsAreHtml;
     $identifierField = $this->session->identifierField;
     $containsExtraData = $this->session->containsExtraData;
     if ($containsExtraData == 'manual') {
         $containsExtraData = 'no';
     }
     $headings = $this->session->columnNames;
     $columnMaps = array();
     $isSetIdentifier = false;
     $unknowColumns = array();
     foreach ($headings as $heading) {
         switch ($heading) {
             case 'Identifier':
                 $columnMaps[] = new CsvImport_ColumnMap_Identifier($heading);
                 $isSetIdentifier = true;
                 break;
             case 'Action':
                 $columnMaps[] = new CsvImport_ColumnMap_Action($heading, $action);
                 break;
             case 'Identifier Field':
             case 'IdentifierField':
                 $columnMaps[] = new CsvImport_ColumnMap_IdentifierField($heading, $identifierField);
                 break;
             case 'Record Type':
             case 'RecordType':
                 $columnMaps[] = new CsvImport_ColumnMap_RecordType($heading);
                 break;
             case 'Item Type':
             case 'ItemType':
                 $columnMaps[] = new CsvImport_ColumnMap_ItemType($heading, $itemTypeId);
                 break;
             case 'Item':
                 $columnMaps[] = new CsvImport_ColumnMap_Item($heading);
                 break;
             case 'Collection':
                 $columnMaps[] = new CsvImport_ColumnMap_Collection($heading, $collectionId);
                 break;
             case 'Public':
                 $columnMaps[] = new CsvImport_ColumnMap_Public($heading, $isPublic);
                 break;
             case 'Featured':
                 $columnMaps[] = new CsvImport_ColumnMap_Featured($heading, $isFeatured);
                 break;
             case 'Tags':
                 $columnMaps[] = new CsvImport_ColumnMap_Tag($heading, $tagDelimiter);
                 break;
             case 'File':
             case 'Files':
                 $columnMaps[] = new CsvImport_ColumnMap_File($heading, $fileDelimiter);
                 break;
                 // Default can be a normal element or, if not, an extra data
                 // element that can be added via the hook csv_import_extra_data.
             // Default can be a normal element or, if not, an extra data
             // element that can be added via the hook csv_import_extra_data.
             default:
                 // Here, column names are already checked.
                 $columnMap = new CsvImport_ColumnMap_MixElement($heading, $elementDelimiter);
                 // If this is an element.
                 $columnElementId = $columnMap->getElementId();
                 if ($columnElementId) {
                     $options = array('columnNameDelimiter' => $columnMap::DEFAULT_COLUMN_NAME_DELIMITER, 'elementDelimiter' => $elementDelimiter, 'isHtml' => $isHtml);
                 } elseif ($containsExtraData == 'yes') {
                     $columnMap = new CsvImport_ColumnMap_ExtraData($heading, $elementDelimiter);
                     $options = array('columnNameDelimiter' => $columnMap::DEFAULT_COLUMN_NAME_DELIMITER, 'elementDelimiter' => $elementDelimiter);
                 } elseif ($containsExtraData == 'no') {
                     $unknowColumns[] = $heading;
                 }
                 // Else ignore the column.
                 // Memorize the identifier if needed, after cleaning.
                 if ($isSetIdentifier === false) {
                     $cleanHeading = explode(CsvImport_ColumnMap_MixElement::DEFAULT_COLUMN_NAME_DELIMITER, $heading);
                     $cleanHeading = implode(CsvImport_ColumnMap_MixElement::DEFAULT_COLUMN_NAME_DELIMITER, array_map('trim', $cleanHeading));
                     if ($identifierField == $cleanHeading) {
                         $isSetIdentifier = null;
                         $identifierHeading = $heading;
                     }
                 }
                 $columnMap->setOptions($options);
                 $columnMaps[] = $columnMap;
                 break;
         }
     }
     if ($unknowColumns) {
         $msg = __('Columns "%s" are unknown.', implode('", "', $unknowColumns));
         $this->_helper->flashMessenger($msg, 'error');
         $this->_helper->redirector->goto('index');
     }
     // A column for identifier is required. It can be any column, specially
     // Dublin Core:Identifier.
     if ($isSetIdentifier === null) {
         $columnMaps[] = new CsvImport_ColumnMap_Identifier($identifierHeading);
         $isSetIdentifier = true;
     }
     if (!$isSetIdentifier) {
         $msg = __('There is no "Identifier" or identifier field "%s" column.', $identifierField);
         $this->_helper->flashMessenger($msg, 'error');
         $this->_helper->redirector->goto('index');
     }
     $this->session->columnMaps = $columnMaps;
     $this->_launchImport();
 }
Exemplo n.º 2
0
 /**
  * Create and queue a new import from Omeka.net or with mixed records.
  */
 public function omekaCsvAction()
 {
     $format = $this->session->format;
     // Specify the export format's file and tag delimiters.
     switch ($format) {
         case 'Manage':
             $elementDelimiter = $this->session->elementDelimiter;
             $tagDelimiter = $this->session->tagDelimiter;
             $fileDelimiter = $this->session->fileDelimiter;
             $itemTypeId = $this->session->itemTypeId;
             $collectionId = $this->session->collectionId;
             $isPublic = $this->session->recordsArePublic;
             $isFeatured = $this->session->recordsAreFeatured;
             $isHtml = $this->session->elementsAreHtml;
             $identifierField = $this->session->identifierField;
             $createCollections = true;
             $containsExtraData = $this->session->containsExtraData;
             if ($containsExtraData == 'manual') {
                 $containsExtraData = 'no';
             }
             break;
         case 'Report':
             // Do not allow the user to specify it.
             $tagDelimiter = ',';
             $fileDelimiter = ',';
             $itemTypeId = null;
             $collectionId = null;
             $action = null;
             $identifierField = null;
             $isPublic = null;
             $isFeatured = null;
             // Nevertheless, user can choose to import all elements as html
             // or as raw text.
             $isHtml = (bool) $this->session->elementsAreHtml;
             $createCollections = false;
             $containsExtraData = 'no';
             break;
             // Deprecated.
         // Deprecated.
         case 'Mix':
         case 'Update':
             $elementDelimiter = $this->session->elementDelimiter;
             $tagDelimiter = $this->session->tagDelimiter;
             $fileDelimiter = $this->session->fileDelimiter;
             $itemTypeId = $this->session->itemTypeId;
             $collectionId = $this->session->collectionId;
             $isPublic = $this->session->recordsArePublic;
             $isFeatured = $this->session->recordsAreFeatured;
             $isHtml = $this->session->elementsAreHtml;
             $action = null;
             $identifierField = null;
             $createCollections = $this->session->createCollections;
             $containsExtraData = $this->session->containsExtraData;
             if ($containsExtraData == 'manual') {
                 $containsExtraData = 'no';
             }
             break;
         default:
             $this->_helper->flashMessenger(__('Invalid call.'), 'error');
             $this->_helper->redirector->goto('index');
     }
     $headings = $this->session->columnNames;
     $columnMaps = array();
     $isSetIdentifier = false;
     foreach ($headings as $heading) {
         switch ($heading) {
             case 'Identifier':
                 $columnMaps[] = new CsvImport_ColumnMap_Identifier($heading);
                 $isSetIdentifier = true;
                 break;
                 // Deprecated.
             // Deprecated.
             case 'sourceItemId':
                 $columnMaps[] = new CsvImport_ColumnMap_SourceItemId($heading);
                 break;
                 // Deprecated.
             // Deprecated.
             case 'updateMode':
                 $columnMaps[] = new CsvImport_ColumnMap_UpdateMode($heading);
                 break;
             case 'Action':
                 $columnMaps[] = new CsvImport_ColumnMap_Action($heading, $action);
                 break;
             case 'IdentifierField':
                 $columnMaps[] = new CsvImport_ColumnMap_IdentifierField($heading, $identifierField);
                 break;
                 // Deprecated.
             // Deprecated.
             case 'updateIdentifier':
                 $columnMaps[] = new CsvImport_ColumnMap_UpdateIdentifier($heading);
                 break;
             case 'RecordType':
                 // Deprecated.
             // Deprecated.
             case 'recordType':
                 $columnMaps[] = new CsvImport_ColumnMap_RecordType($heading);
                 break;
                 // Deprecated.
             // Deprecated.
             case 'recordIdentifier':
                 $columnMaps[] = new CsvImport_ColumnMap_RecordIdentifier($heading);
                 break;
             case 'ItemType':
                 // Used by Csv Report.
             // Used by Csv Report.
             case 'itemType':
                 $columnMaps[] = new CsvImport_ColumnMap_ItemType($heading, $itemTypeId);
                 break;
             case 'Item':
                 $columnMaps[] = new CsvImport_ColumnMap_Item($heading);
                 break;
             case 'Collection':
                 // Used by Csv Report, Mixed and Update.
             // Used by Csv Report, Mixed and Update.
             case 'collection':
                 $columnMaps[] = new CsvImport_ColumnMap_Collection($heading, $collectionId, $createCollections, $format == 'Manage');
                 break;
             case 'Public':
                 // Used by Csv Report.
             // Used by Csv Report.
             case 'public':
                 $columnMaps[] = new CsvImport_ColumnMap_Public($heading, $isPublic);
                 break;
             case 'Featured':
                 // Used by Csv Report.
             // Used by Csv Report.
             case 'featured':
                 $columnMaps[] = new CsvImport_ColumnMap_Featured($heading, $isFeatured);
                 break;
             case 'Tags':
                 // Used by Csv Report.
             // Used by Csv Report.
             case 'tags':
                 $columnMaps[] = new CsvImport_ColumnMap_Tag($heading, $tagDelimiter);
                 break;
                 // Deprecated.
             // Deprecated.
             case 'fileUrl':
                 $columnMaps[] = new CsvImport_ColumnMap_File($heading, '', true);
                 break;
             case 'File':
                 // Used by Csv Report.
             // Used by Csv Report.
             case 'file':
                 $columnMaps[] = new CsvImport_ColumnMap_File($heading, $fileDelimiter);
                 break;
                 // Default can be a normal element or, if not, an extra data
                 // element that can be added via the hook csv_import_extra_data.
                 // This doesn't work with "Report" format.
             // Default can be a normal element or, if not, an extra data
             // element that can be added via the hook csv_import_extra_data.
             // This doesn't work with "Report" format.
             default:
                 switch ($format) {
                     case 'Report':
                         $columnMap = new CsvImport_ColumnMap_ExportedElement($heading);
                         $options = array('columnNameDelimiter' => $columnMap::DEFAULT_COLUMN_NAME_DELIMITER, 'elementDelimiter' => $elementMap::DEFAULT_ELEMENT_DELIMITER, 'isHtml' => $isHtml);
                         break;
                     case 'Manage':
                         // Deprecated.
                     // Deprecated.
                     case 'Mix':
                     case 'Update':
                         $columnMap = new CsvImport_ColumnMap_MixElement($heading, $elementDelimiter);
                         // If extra data are not used or if this is an element.
                         if ($containsExtraData != 'yes' || $columnMap->getElementId()) {
                             $options = array('columnNameDelimiter' => $columnMap::DEFAULT_COLUMN_NAME_DELIMITER, 'elementDelimiter' => $elementDelimiter, 'isHtml' => $isHtml);
                         } else {
                             $columnMap = new CsvImport_ColumnMap_ExtraData($heading, $elementDelimiter);
                             $options = array('columnNameDelimiter' => $columnMap::DEFAULT_COLUMN_NAME_DELIMITER, 'elementDelimiter' => $elementDelimiter);
                         }
                         // Memorize the identifier if needed, after cleaning.
                         if ($format == 'Manage' && $isSetIdentifier === false) {
                             $cleanHeading = explode(CsvImport_ColumnMap_MixElement::DEFAULT_COLUMN_NAME_DELIMITER, $heading);
                             $cleanHeading = implode(CsvImport_ColumnMap_MixElement::DEFAULT_COLUMN_NAME_DELIMITER, array_map('trim', $cleanHeading));
                             if ($identifierField == $cleanHeading) {
                                 $isSetIdentifier = null;
                                 $identifierHeading = $heading;
                             }
                         }
                         break;
                 }
                 $columnMap->setOptions($options);
                 $columnMaps[] = $columnMap;
                 break;
         }
     }
     // Manage requires et special check;
     if ($format == 'Manage') {
         // Manage format require that a column for identifier, but this
         // canbe any column, specially Dublin Core:Identifier.
         if ($isSetIdentifier === null) {
             $columnMaps[] = new CsvImport_ColumnMap_Identifier($identifierHeading);
             $isSetIdentifier = true;
         }
         if (!$isSetIdentifier) {
             $msg = __('There is no "Identifier" or identifier field "%s" column.', $identifierField);
             $this->_helper->flashMessenger($msg, 'error');
             $this->_helper->redirector->goto('index');
         }
     }
     $this->session->columnMaps = $columnMaps;
     $this->_launchImport();
 }