2023-03-23 18:08:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2022 Varun Patil <radialapps@gmail.com>
|
|
|
|
* @author Varun Patil <radialapps@gmail.com>
|
|
|
|
* @license AGPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* 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\Memories\ClustersBackend;
|
|
|
|
|
2023-03-23 23:58:49 +00:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
|
2023-03-23 18:08:36 +00:00
|
|
|
abstract class Backend
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* A human-readable name for the app.
|
|
|
|
* Used for error messages.
|
|
|
|
*/
|
2023-03-24 20:55:47 +00:00
|
|
|
abstract public static function appName(): string;
|
2023-03-24 11:17:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get name of the cluster type.
|
|
|
|
*/
|
2023-03-24 20:55:47 +00:00
|
|
|
abstract public static function clusterType(): string;
|
2023-03-23 18:08:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the app is enabled for the current user.
|
|
|
|
*/
|
|
|
|
abstract public function isEnabled(): bool;
|
|
|
|
|
2023-03-23 23:58:49 +00:00
|
|
|
/**
|
|
|
|
* Apply query transformations for days query.
|
2023-03-24 00:19:05 +00:00
|
|
|
*
|
|
|
|
* @param IQueryBuilder $query Query builder
|
|
|
|
* @param bool $aggregate Whether this is an aggregate query
|
2023-03-23 23:58:49 +00:00
|
|
|
*/
|
2023-03-24 00:19:05 +00:00
|
|
|
abstract public function transformDayQuery(&$query, bool $aggregate): void;
|
2023-03-23 23:58:49 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-24 00:19:05 +00:00
|
|
|
* Apply post-query transformations for the given photo object.
|
2023-03-23 23:58:49 +00:00
|
|
|
*/
|
2023-09-12 17:56:59 +00:00
|
|
|
public function transformDayPost(array &$row): void {}
|
2023-03-23 23:58:49 +00:00
|
|
|
|
2023-03-23 18:08:36 +00:00
|
|
|
/**
|
|
|
|
* Get the cluster list for the current user.
|
2023-08-04 01:56:51 +00:00
|
|
|
*
|
2023-08-04 02:43:57 +00:00
|
|
|
* If the signature of this function changes, the
|
|
|
|
* getClusters function must be updated to match.
|
|
|
|
*
|
2023-08-04 01:56:51 +00:00
|
|
|
* @param int $fileid Filter clusters by file ID (optional)
|
2023-03-23 18:08:36 +00:00
|
|
|
*/
|
2023-08-04 02:56:32 +00:00
|
|
|
abstract public function getClustersInternal(int $fileid = 0): array;
|
2023-03-23 18:08:36 +00:00
|
|
|
|
2023-03-24 11:17:54 +00:00
|
|
|
/**
|
|
|
|
* Get a cluster ID for the given cluster.
|
2023-10-14 09:07:18 +00:00
|
|
|
*
|
2023-10-14 09:13:34 +00:00
|
|
|
* @return int|string
|
2023-03-24 11:17:54 +00:00
|
|
|
*/
|
2023-03-24 20:55:47 +00:00
|
|
|
abstract public static function getClusterId(array $cluster);
|
2023-03-24 11:17:54 +00:00
|
|
|
|
2023-03-23 18:08:36 +00:00
|
|
|
/**
|
|
|
|
* Get a list of photos with any extra parameters for the given cluster
|
|
|
|
* Used for preview generation and download.
|
|
|
|
*
|
|
|
|
* @param string $name Identifier for the cluster
|
|
|
|
* @param int $limit Maximum number of photos to return
|
|
|
|
*/
|
|
|
|
abstract public function getPhotos(string $name, ?int $limit = null): array;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Human readable name for the cluster.
|
|
|
|
*/
|
2023-10-14 08:25:50 +00:00
|
|
|
public function clusterName(string $name): string
|
2023-03-23 18:08:36 +00:00
|
|
|
{
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put the photo objects in priority list.
|
|
|
|
* Works on the array in place.
|
|
|
|
*/
|
2023-10-14 08:25:50 +00:00
|
|
|
public function sortPhotosForPreview(array &$photos): void
|
2023-03-23 18:08:36 +00:00
|
|
|
{
|
|
|
|
shuffle($photos);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quality to use for the preview file.
|
|
|
|
*/
|
|
|
|
public function getPreviewQuality(): int
|
|
|
|
{
|
|
|
|
return 512;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform any post processing and get the blob from the preview file.
|
|
|
|
*
|
|
|
|
* @param \OCP\Files\SimpleFS\ISimpleFile $file Preview file
|
|
|
|
* @param array $photo Photo object
|
|
|
|
*
|
2023-03-24 00:19:05 +00:00
|
|
|
* @return array [Blob, mimetype] of data
|
2023-03-23 18:08:36 +00:00
|
|
|
*/
|
|
|
|
public function getPreviewBlob($file, $photo): array
|
|
|
|
{
|
|
|
|
return [$file->getContent(), $file->getMimeType()];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the file ID for a photo object.
|
|
|
|
*/
|
|
|
|
public function getFileId(array $photo): int
|
|
|
|
{
|
|
|
|
return (int) $photo['fileid'];
|
|
|
|
}
|
2023-03-24 11:17:54 +00:00
|
|
|
|
2023-08-04 02:43:57 +00:00
|
|
|
/**
|
|
|
|
* Calls the getClusters implementation and appends the
|
|
|
|
* result with the cluster_id and cluster_type values.
|
|
|
|
*
|
|
|
|
* @param int $fileid Filter clusters by file ID (optional)
|
|
|
|
*/
|
2023-08-04 02:56:32 +00:00
|
|
|
final public function getClusters(int $fileid): array
|
|
|
|
{
|
|
|
|
$list = $this->getClustersInternal($fileid);
|
2023-08-04 02:43:57 +00:00
|
|
|
|
|
|
|
foreach ($list as &$cluster) {
|
|
|
|
$cluster['cluster_id'] = $this->getClusterId($cluster);
|
|
|
|
$cluster['cluster_type'] = $this->clusterType();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
2023-03-24 11:17:54 +00:00
|
|
|
/**
|
|
|
|
* Register the backend. Do not override.
|
|
|
|
*/
|
2023-08-04 02:56:32 +00:00
|
|
|
final public static function register(): void
|
2023-03-24 11:17:54 +00:00
|
|
|
{
|
|
|
|
Manager::register(static::clusterType(), static::class);
|
|
|
|
}
|
2023-03-23 18:08:36 +00:00
|
|
|
}
|