Skip to content

Commit

Permalink
feat: add more conversion possibilities
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Jan 21, 2025
1 parent be5f99a commit 7b8730d
Showing 1 changed file with 78 additions and 5 deletions.
83 changes: 78 additions & 5 deletions lib/Conversion/ConversionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,60 @@ public function __construct(
}

public function getSupportedMimeTypes(): array {
$toPdf = array_merge(
$documents = self::MIME_TYPES['documents'];
$sheets = self::MIME_TYPES['sheets'];
$presentations = self::MIME_TYPES['presentations'];

$pdfConversions = array_merge(
[],
self::MIME_TYPES['documents'],
self::MIME_TYPES['sheets'],
self::MIME_TYPES['presentations'],
self::MIME_TYPES['drawings'],
);

return [...$this->getMimeProvidersFor($toPdf, 'application/pdf')];
$documentConversions = [
// OpenDocument Text to Word Document
'docx' => [$documents['odt']],

// Word Document to OpenDocument Text
'odt' => [$documents['doc'], $documents['docx']],
];

$spreadsheetConversions = [
// OpenDocument Spreadsheet to Excel Workbook
'xlsx' => [$sheets['ods']],

// Excel Workbook to OpenDocument Spreadsheet
'ods' => [$sheets['xls'], $sheets['xlsx']],
];

$presentationConversions = [
// OpenDocument Presentation to PowerPoint Presentation
'pptx' => [$presentations['odp']],

// PowerPoint Presentation to OpenDocument Presentation
'odp' => [$presentations['ppt'], $presentations['pptx']],
];



return [
// PDF conversions
...$this->getMimeProvidersFor($toPdf, 'application/pdf'),

Check failure on line 101 in lib/Conversion/ConversionProvider.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedVariable

lib/Conversion/ConversionProvider.php:101:34: UndefinedVariable: Cannot find referenced variable $toPdf (see https://psalm.dev/024)

// Document conversions
...$this->getMimeProvidersFor($documentConversions['docx'], $documents['docx']),
...$this->getMimeProvidersFor($documentConversions['odt'], $documents['odt']),

// Spreadsheet conversions
...$this->getMimeProvidersFor($spreadsheetConversions['xlsx'], $sheets['xlsx']),
...$this->getMimeProvidersFor($spreadsheetConversions['ods'], $sheets['ods']),

// Presentation conversions
...$this->getMimeProvidersFor($presentationConversions['pptx'], $presentations['pptx']),
...$this->getMimeProvidersFor($presentationConversions['odp'], $presentations['odp']),
];
}

public function convertFile(File $file, string $targetMimeType): mixed {
Expand Down Expand Up @@ -113,18 +158,46 @@ private function getMimeInfoFor(string $targetMimeType): ?array {
}

private function getTargetMimeTypes(): array {
$documents = self::MIME_TYPES['documents'];
$sheets = self::MIME_TYPES['sheets'];
$presentations = self::MIME_TYPES['presentations'];

return [
'application/pdf' => [
'extension' => 'pdf',
'displayName' => $this->l10n->t('Portable Document Format (.pdf)'),
],
$documents['docx'] => [
'extension' => 'docx',
'displayName' => $this->l10n->t('Word Document (.docx)'),
],
$documents['odt'] => [
'extension' => 'odt',
'displayName' => $this->l10n->t('OpenDocument Text (.odt)'),
],
$sheets['xlsx'] => [
'extension' => 'xlsx',
'displayName' => $this->l10n->t('Excel Workbook (.xlsx)'),
],
$sheets['ods'] => [
'extension' => 'ods',
'displayName' => $this->l10n->t('OpenDocument Spreadsheet (.ods)'),
],
$presentations['pptx'] => [
'extension' => 'pptx',
'displayName' => $this->l10n->t('PowerPoint Presentation (.pptx)'),
],
$presentations['odp'] => [
'extension' => 'odp',
'displayName' => $this->l10n->t('OpenDocument Presentation (.odp)'),
],
];
}

private function getExtensionForMimeType(string $mimeType): ?string {
foreach ($this->getTargetMimeTypes() as $targetMimeType) {
if ($targetMimeType['mime_type'] === $mimeType) {
return $targetMimeType['extension'];
foreach ($this->getTargetMimeTypes() as $targetMimeType => $targetMimeInfo) {
if ($targetMimeType === $mimeType) {
return $targetMimeInfo['extension'];
}
}

Expand Down

0 comments on commit 7b8730d

Please sign in to comment.