2018-09-18 11:45:45 +03:00
|
|
|
<?php
|
2018-09-19 09:23:39 +03:00
|
|
|
declare (strict_types = 1);
|
2018-09-18 11:45:45 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
|
|
|
|
*
|
|
|
|
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Richdocuments;
|
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
use OCP\Files\File;
|
2018-09-18 11:45:45 +03:00
|
|
|
use OCP\Files\Folder;
|
2018-09-18 19:47:14 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
use OCP\Files\Node;
|
2018-09-18 11:45:45 +03:00
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
use OCP\IConfig;
|
2018-10-26 16:40:32 +03:00
|
|
|
use OCP\IL10N;
|
2018-09-18 11:45:45 +03:00
|
|
|
use OCP\IPreview;
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OC\Files\AppData\Factory;
|
|
|
|
|
|
|
|
class TemplateManager {
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $appName;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $userId;
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
/** @var IRootFolder */
|
|
|
|
private $rootFolder;
|
2018-09-18 11:45:45 +03:00
|
|
|
|
2018-10-26 16:40:32 +03:00
|
|
|
/** @var IL10N */
|
|
|
|
private $l;
|
|
|
|
|
2018-09-18 11:45:45 +03:00
|
|
|
/** Accepted templates mime types */
|
2018-09-19 18:00:05 +03:00
|
|
|
const MIMES_DOCUMENTS = [
|
2018-10-08 16:22:47 +03:00
|
|
|
'application/vnd.oasis.opendocument.text-template'
|
2018-09-18 11:45:45 +03:00
|
|
|
];
|
2018-09-19 18:00:05 +03:00
|
|
|
const MIMES_SHEETS = [
|
2018-10-08 16:22:47 +03:00
|
|
|
'application/vnd.oasis.opendocument.spreadsheet-template'
|
2018-09-18 11:45:45 +03:00
|
|
|
];
|
2018-09-19 18:00:05 +03:00
|
|
|
const MIMES_PRESENTATIONS = [
|
2018-10-08 16:22:47 +03:00
|
|
|
'application/vnd.oasis.opendocument.presentation-template'
|
2018-09-18 11:45:45 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
/** @var array Template mime types match */
|
|
|
|
static public $tplTypes = [
|
2018-09-19 18:00:05 +03:00
|
|
|
'document' => self::MIMES_DOCUMENTS,
|
|
|
|
'spreadsheet' => self::MIMES_SHEETS,
|
|
|
|
'presentation' => self::MIMES_PRESENTATIONS
|
2018-09-18 11:45:45 +03:00
|
|
|
];
|
|
|
|
|
2018-10-26 16:40:32 +03:00
|
|
|
const EMPTY_TEMPLATE_ID_TYPE = [
|
|
|
|
-1 => 'document',
|
|
|
|
-2 => 'spreadsheet',
|
|
|
|
-3 => 'presentation',
|
|
|
|
];
|
|
|
|
const EMPTY_TEMPLATE_TYPE_ID = [
|
|
|
|
'document' => -1,
|
|
|
|
'spreadsheet' => -2,
|
|
|
|
'presentation' => -3,
|
|
|
|
];
|
2018-11-09 11:10:36 +03:00
|
|
|
const TYPE_EXTENTION = [
|
|
|
|
'document' => 'odt',
|
|
|
|
'spreadsheet' => 'ods',
|
|
|
|
'presentation' => 'odp',
|
|
|
|
];
|
2018-10-26 16:40:32 +03:00
|
|
|
|
|
|
|
|
2018-09-18 11:45:45 +03:00
|
|
|
/**
|
|
|
|
* Template manager
|
|
|
|
*
|
|
|
|
* @param string $appName
|
|
|
|
* @param string $userId
|
|
|
|
* @param IConfig $config
|
|
|
|
* @param Factory $appDataFactory
|
|
|
|
* @param IURLGenerator $urlGenerator
|
|
|
|
* @param IRootFolder $rootFolder
|
2018-10-26 16:40:32 +03:00
|
|
|
* @param IL10N $l
|
|
|
|
* @throws \OCP\Files\NotPermittedException
|
2018-09-18 11:45:45 +03:00
|
|
|
*/
|
2018-10-08 21:44:52 +03:00
|
|
|
public function __construct($appName,
|
|
|
|
$userId,
|
2018-09-19 18:00:05 +03:00
|
|
|
IConfig $config,
|
|
|
|
Factory $appDataFactory,
|
|
|
|
IURLGenerator $urlGenerator,
|
2018-10-26 16:40:32 +03:00
|
|
|
IRootFolder $rootFolder,
|
|
|
|
IL10N $l) {
|
2018-09-18 11:45:45 +03:00
|
|
|
$this->appName = $appName;
|
|
|
|
$this->userId = $userId;
|
|
|
|
$this->config = $config;
|
2018-10-08 15:52:25 +03:00
|
|
|
$this->rootFolder = $rootFolder;
|
2018-09-18 11:45:45 +03:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
/*
|
|
|
|
* Init the appdata folder
|
|
|
|
* We need an actual folder for the fileid and previews.
|
|
|
|
* TODO: Fix this at some point
|
|
|
|
*/
|
|
|
|
$appData = $appDataFactory->get($appName);
|
2018-09-18 11:45:45 +03:00
|
|
|
try {
|
2018-10-08 15:52:25 +03:00
|
|
|
$appData->getFolder('templates');
|
2018-09-18 11:45:45 +03:00
|
|
|
} catch (NotFoundException $e) {
|
2018-10-08 15:52:25 +03:00
|
|
|
$appData->newFolder('templates');
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|
2018-10-26 16:40:32 +03:00
|
|
|
try {
|
|
|
|
$appData->getFolder('empty_templates');
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
$appData->newFolder('empty_templates');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->l = $l;
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-19 09:23:39 +03:00
|
|
|
* Get template ISimpleFile|Node
|
2018-09-18 11:45:45 +03:00
|
|
|
*
|
2018-10-08 15:52:25 +03:00
|
|
|
* @param int $fileId
|
|
|
|
* @return File
|
2018-09-18 11:45:45 +03:00
|
|
|
*/
|
2018-10-08 15:52:25 +03:00
|
|
|
public function get($fileId) {
|
2018-10-26 16:40:32 +03:00
|
|
|
// is this a global template ?
|
|
|
|
$files = $this->getEmptyTemplateDir()->getDirectoryListing();
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file->getId() === $fileId) {
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
// is this a global template ?
|
|
|
|
$files = $this->getSystemTemplateDir()->getDirectoryListing();
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file->getId() === $fileId) {
|
|
|
|
return $file;
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
$templateDir = $this->getUserTemplateDir();
|
|
|
|
// finally get the template file
|
|
|
|
$files = $templateDir->getById($fileId);
|
|
|
|
if ($files !== []) {
|
|
|
|
return $files[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new NotFoundException();
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
2018-10-08 21:44:52 +03:00
|
|
|
/**
|
|
|
|
* @param File[] $templates
|
|
|
|
* @return File[]
|
|
|
|
*/
|
2018-10-28 23:05:47 +03:00
|
|
|
private function filterTemplates($templates, $type = null) {
|
2018-10-26 16:40:32 +03:00
|
|
|
return array_filter($templates, function (Node $templateFile) use ($type) {
|
2018-10-08 16:56:20 +03:00
|
|
|
if (!($templateFile instanceof File)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-28 23:05:47 +03:00
|
|
|
if ($type !== null && !in_array($templateFile->getMimeType(), self::$tplTypes[$type])) {
|
2018-10-26 16:40:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-08 16:56:20 +03:00
|
|
|
//Todo validate mimetypes etc
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-28 23:05:47 +03:00
|
|
|
private function getEmpty($type = null) {
|
2018-10-26 16:40:32 +03:00
|
|
|
$folder = $this->getEmptyTemplateDir();
|
|
|
|
|
|
|
|
$templateFiles = $folder->getDirectoryListing();
|
|
|
|
|
|
|
|
if ($templateFiles === []) {
|
|
|
|
// Empty so lets copy over the basic templates
|
|
|
|
$templates = [
|
|
|
|
'document.ott',
|
|
|
|
'spreadsheet.ots',
|
|
|
|
'presentation.otp',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($templates as $template) {
|
|
|
|
$file = $folder->newFile($template);
|
2018-11-08 15:03:18 +03:00
|
|
|
$file->putContent(file_get_contents(__DIR__ . '/../assets/' . $template));
|
2018-10-26 16:40:32 +03:00
|
|
|
$templateFiles[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->filterTemplates($templateFiles, $type);
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:45:45 +03:00
|
|
|
/**
|
|
|
|
* Get all global templates
|
2018-09-19 09:23:39 +03:00
|
|
|
*
|
2018-10-08 16:56:20 +03:00
|
|
|
* @return File[]
|
2018-09-18 11:45:45 +03:00
|
|
|
*/
|
2018-10-28 23:05:47 +03:00
|
|
|
public function getSystem($type = null) {
|
2018-10-08 15:52:25 +03:00
|
|
|
$folder = $this->getSystemTemplateDir();
|
2018-09-18 11:45:45 +03:00
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
$templateFiles = $folder->getDirectoryListing();
|
2018-10-26 16:40:32 +03:00
|
|
|
return $this->filterTemplates($templateFiles, $type);
|
2018-10-08 16:56:20 +03:00
|
|
|
}
|
|
|
|
|
2018-10-08 21:44:52 +03:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-11-08 15:01:27 +03:00
|
|
|
public function getSystemFormatted($type = null) {
|
2018-10-26 16:40:32 +03:00
|
|
|
$empty = $this->getEmpty($type);
|
|
|
|
$system = $this->getSystem($type);
|
2018-10-08 16:56:20 +03:00
|
|
|
|
2018-10-26 16:40:32 +03:00
|
|
|
$emptyFormatted = array_map(function(File $file) {
|
|
|
|
return $this->formatEmpty($file);
|
|
|
|
}, $empty);
|
|
|
|
|
|
|
|
$systemFormatted = array_map(function(File $file) {
|
2018-10-08 16:56:20 +03:00
|
|
|
return $this->formatNodeReturn($file);
|
2018-10-26 16:40:32 +03:00
|
|
|
}, $system);
|
|
|
|
|
|
|
|
return array_merge($emptyFormatted, $systemFormatted);
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
2018-09-19 09:23:39 +03:00
|
|
|
/**
|
|
|
|
* Get all user templates
|
|
|
|
*
|
2018-10-08 21:44:52 +03:00
|
|
|
* @return File[]
|
2018-09-19 09:23:39 +03:00
|
|
|
*/
|
2018-10-28 23:05:47 +03:00
|
|
|
public function getUser($type = null) {
|
2018-09-20 09:38:36 +03:00
|
|
|
try {
|
|
|
|
$templateDir = $this->getUserTemplateDir();
|
|
|
|
$templateFiles = $templateDir->getDirectoryListing();
|
|
|
|
|
2018-10-26 16:40:32 +03:00
|
|
|
return $this->filterTemplates($templateFiles, $type);
|
2018-09-20 09:38:36 +03:00
|
|
|
} catch(NotFoundException $e) {
|
|
|
|
return [];
|
|
|
|
}
|
2018-09-19 09:23:39 +03:00
|
|
|
}
|
|
|
|
|
2018-10-08 21:44:52 +03:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-10-26 16:40:32 +03:00
|
|
|
public function getUserFormatted($type) {
|
|
|
|
$templates = $this->getUser($type);
|
2018-10-08 16:56:20 +03:00
|
|
|
|
|
|
|
return array_map(function(File $file) {
|
|
|
|
return $this->formatNodeReturn($file);
|
|
|
|
}, $templates);
|
|
|
|
}
|
|
|
|
|
2018-09-19 10:27:18 +03:00
|
|
|
/**
|
|
|
|
* Get all templates
|
|
|
|
*
|
2018-10-08 16:56:20 +03:00
|
|
|
* @return File[]
|
2018-09-19 10:27:18 +03:00
|
|
|
*/
|
2018-10-26 16:40:32 +03:00
|
|
|
public function getAll($type = 'document') {
|
2018-09-19 10:27:18 +03:00
|
|
|
$system = $this->getSystem();
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
2018-10-08 16:56:20 +03:00
|
|
|
if (!array_key_exists($type, self::$tplTypes)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2018-10-08 16:22:47 +03:00
|
|
|
return array_values(array_filter(array_merge($user, $system), function (File $template) use ($type) {
|
2018-10-08 16:56:20 +03:00
|
|
|
foreach (self::$tplTypes[$type] as $mime) {
|
|
|
|
if ($template->getMimeType() === $mime) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-09-20 11:07:26 +03:00
|
|
|
}));
|
2018-09-19 10:27:18 +03:00
|
|
|
}
|
|
|
|
|
2018-10-26 16:40:32 +03:00
|
|
|
public function getAllFormatted($type) {
|
|
|
|
if (!array_key_exists($type, self::$tplTypes)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$system = $this->getSystemFormatted($type);
|
|
|
|
$user = $this->getUserFormatted($type);
|
|
|
|
|
|
|
|
return array_merge($system, $user);
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:45:45 +03:00
|
|
|
/**
|
|
|
|
* Add a template to the global template folder
|
|
|
|
*
|
|
|
|
* @param string $templateName
|
|
|
|
* @param string $templateFile
|
2018-09-19 09:23:39 +03:00
|
|
|
* @return array
|
2018-09-18 11:45:45 +03:00
|
|
|
*/
|
2018-10-08 15:52:25 +03:00
|
|
|
public function add($templateName, $templateFile) {
|
|
|
|
$folder = $this->getSystemTemplateDir();
|
|
|
|
|
2018-09-18 11:45:45 +03:00
|
|
|
try {
|
2018-10-08 15:52:25 +03:00
|
|
|
$template = $folder->get($templateName);
|
2018-09-18 11:45:45 +03:00
|
|
|
} catch (NotFoundException $e) {
|
2018-10-08 15:52:25 +03:00
|
|
|
$template = $folder->newFile($templateName);
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|
|
|
|
$template->putContent($templateFile);
|
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
return $this->formatNodeReturn($this->get($template->getId()));
|
2018-09-18 19:47:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a template to the global template folder
|
|
|
|
*
|
2018-10-08 15:52:25 +03:00
|
|
|
* @param int $fileId
|
2018-09-19 09:23:39 +03:00
|
|
|
* @return boolean
|
|
|
|
* @throws NotFoundException
|
2018-09-18 19:47:14 +03:00
|
|
|
*/
|
2018-10-08 15:52:25 +03:00
|
|
|
public function delete($fileId) {
|
|
|
|
$files = $this->getSystemTemplateDir()->getDirectoryListing();
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file->getId() === $fileId) {
|
|
|
|
$file->delete();
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-18 19:47:14 +03:00
|
|
|
}
|
2018-09-19 09:23:39 +03:00
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
throw new NotFoundException();
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-18 19:47:14 +03:00
|
|
|
* Flip $tplTypes to retrieve types by mime
|
2018-09-18 11:45:45 +03:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-10-08 15:52:25 +03:00
|
|
|
private function flipTypes() {
|
|
|
|
$result = [];
|
2018-09-19 18:00:05 +03:00
|
|
|
foreach ($this::$tplTypes as $type => $mime) {
|
|
|
|
$result = array_merge($result, array_fill_keys($mime, $type));
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2018-09-18 19:47:14 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the user template directory
|
|
|
|
*
|
2018-10-08 15:52:25 +03:00
|
|
|
* @return Folder
|
2018-09-18 19:47:14 +03:00
|
|
|
* @throws NotFoundException
|
|
|
|
*/
|
2018-10-08 15:52:25 +03:00
|
|
|
private function getUserTemplateDir() {
|
2018-10-08 21:44:52 +03:00
|
|
|
if ($this->userId === null) {
|
|
|
|
throw new NotFoundException('userId not set');
|
|
|
|
}
|
|
|
|
|
2018-09-18 19:47:14 +03:00
|
|
|
// has the user manually set a directory as the default template dir ?
|
2018-11-08 19:18:24 +03:00
|
|
|
$templateDirPath = $this->config->getUserValue($this->userId, $this->appName, 'templateFolder', false);
|
2018-10-08 15:52:25 +03:00
|
|
|
$userFolder = $this->rootFolder->getUserFolder($this->userId);
|
2018-09-18 19:47:14 +03:00
|
|
|
|
2018-11-08 19:18:24 +03:00
|
|
|
if ($templateDirPath !== false) {
|
|
|
|
$templateDir = $userFolder->get($templateDirPath);
|
2018-09-18 19:47:14 +03:00
|
|
|
} else {
|
|
|
|
// fallback to default template dir
|
|
|
|
try {
|
2018-10-08 15:52:25 +03:00
|
|
|
$templateDir = $userFolder->get('Templates');
|
2018-09-18 19:47:14 +03:00
|
|
|
} catch (NotFoundException $e) {
|
2018-09-19 09:23:39 +03:00
|
|
|
throw new NotFoundException($e->getMessage());
|
2018-09-18 19:47:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
if (!($templateDir instanceof Folder)) {
|
|
|
|
throw new NotFoundException('Template dir points to a file');
|
|
|
|
}
|
|
|
|
|
2018-09-18 19:47:14 +03:00
|
|
|
return $templateDir;
|
|
|
|
}
|
|
|
|
|
2018-10-08 15:52:25 +03:00
|
|
|
/**
|
|
|
|
* @return Folder
|
|
|
|
*/
|
|
|
|
private function getSystemTemplateDir() {
|
|
|
|
return $this->rootFolder->get('appdata_' . $this->config->getSystemValue('instanceid', null))
|
|
|
|
->get('richdocuments')
|
|
|
|
->get('templates');
|
|
|
|
}
|
|
|
|
|
2018-10-26 16:40:32 +03:00
|
|
|
/**
|
|
|
|
* @return Folder
|
|
|
|
*/
|
|
|
|
private function getEmptyTemplateDir() {
|
|
|
|
return $this->rootFolder->get('appdata_' . $this->config->getSystemValue('instanceid', null))
|
|
|
|
->get('richdocuments')
|
|
|
|
->get('empty_templates');
|
|
|
|
}
|
|
|
|
|
2018-09-18 19:47:14 +03:00
|
|
|
/**
|
|
|
|
* Format template file for json return object
|
|
|
|
*
|
2018-10-08 15:52:25 +03:00
|
|
|
* @param File $template
|
2018-09-18 19:47:14 +03:00
|
|
|
* @return array
|
|
|
|
*/
|
2018-10-08 16:56:20 +03:00
|
|
|
public function formatNodeReturn(File $template) {
|
2018-09-18 19:47:14 +03:00
|
|
|
return [
|
2018-10-08 15:52:25 +03:00
|
|
|
'id' => $template->getId(),
|
2018-09-18 19:47:14 +03:00
|
|
|
'name' => $template->getName(),
|
2018-10-08 16:22:47 +03:00
|
|
|
'preview' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $template->getId()]),
|
|
|
|
'type' => $this->flipTypes()[$template->getMimeType()],
|
2018-11-09 11:10:36 +03:00
|
|
|
'delete' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.delete', ['fileId' => $template->getId()]),
|
|
|
|
'ext' => self::TYPE_EXTENTION[$this->flipTypes()[$template->getMimeType()]],
|
2018-09-18 19:47:14 +03:00
|
|
|
];
|
|
|
|
}
|
2018-10-08 21:44:52 +03:00
|
|
|
|
|
|
|
public function isTemplate($fileId) {
|
2018-11-08 15:08:09 +03:00
|
|
|
$empty = $this->getEmpty();
|
2018-10-08 21:44:52 +03:00
|
|
|
$system = $this->getSystem();
|
|
|
|
$user = $this->getUser();
|
|
|
|
/** @var File[] $all */
|
2018-11-08 15:08:09 +03:00
|
|
|
$all = array_merge($empty, $system, $user);
|
2018-10-08 21:44:52 +03:00
|
|
|
|
|
|
|
foreach ($all as $template) {
|
|
|
|
if ($template->getId() === $fileId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-26 16:40:32 +03:00
|
|
|
|
|
|
|
public function formatEmpty(File $template) {
|
|
|
|
return [
|
|
|
|
'id' => $template->getId(),
|
|
|
|
'name' => $this->l->t('Empty'),
|
|
|
|
'type' => $this->flipTypes()[$template->getMimeType()],
|
2018-11-09 11:10:36 +03:00
|
|
|
'ext' => self::TYPE_EXTENTION[$this->flipTypes()[$template->getMimeType()]],
|
2018-10-26 16:40:32 +03:00
|
|
|
];
|
|
|
|
}
|
2018-09-18 11:45:45 +03:00
|
|
|
}
|