|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* @copyright Copyright (c) 2021 Julius Härtl <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Julius Härtl <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
declare(strict_types=1); |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
namespace OCA\Richdocuments\Template; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
use OCA\Richdocuments\TemplateManager; |
|
31
|
|
|
use OCP\Files\File; |
|
32
|
|
|
use OCP\Files\Template\ICustomTemplateProvider; |
|
33
|
|
|
use OCP\Files\Template\Template; |
|
34
|
|
|
use OCP\Files\Template\TemplateFileCreator; |
|
35
|
|
|
use OCP\IURLGenerator; |
|
36
|
|
|
|
|
37
|
|
|
class CollaboraTemplateProvider implements ICustomTemplateProvider { |
|
38
|
|
|
|
|
39
|
|
|
/** @var TemplateManager */ |
|
40
|
|
|
private $templateManager; |
|
41
|
|
|
/** @var IURLGenerator */ |
|
42
|
|
|
private $urlGenerator; |
|
43
|
|
|
|
|
44
|
|
|
public function __construct(TemplateManager $templateManager, IURLGenerator $urlGenerator) { |
|
45
|
|
|
$this->templateManager = $templateManager; |
|
46
|
|
|
$this->urlGenerator = $urlGenerator; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getTemplateType(): string { |
|
50
|
|
|
return CollaboraTemplateProvider::class; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getCustomTemplates(string $mimetype): array { |
|
54
|
|
|
if (in_array($mimetype, TemplateManager::MIMES_DOCUMENTS)) { |
|
55
|
|
|
$type = 'document'; |
|
56
|
|
|
} else if (in_array($mimetype, TemplateManager::MIMES_SHEETS)) { |
|
57
|
|
|
$type = 'spreadsheet'; |
|
58
|
|
|
} else if (in_array($mimetype, TemplateManager::MIMES_PRESENTATIONS)) { |
|
59
|
|
|
$type = 'presentation'; |
|
60
|
|
|
} else { |
|
61
|
|
|
return []; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return array_map(function(File $file) { |
|
65
|
|
|
$template = new Template(CollaboraTemplateProvider::class, (string)$file->getId(), $file); |
|
66
|
|
|
$template->setCustomPreviewUrl($this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $file->getId()])); |
|
67
|
|
|
return $template; |
|
68
|
|
|
}, $this->templateManager->getAll($type)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getCustomTemplate(string $template): File { |
|
72
|
|
|
return $this->templateManager->get((int)$template); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function createFromTemplate(File $template, File $target): void { |
|
|
|
|
|
|
76
|
|
|
// TODO: Implement createFromTemplate() method. |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.