This repository has been archived on 2024-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
epubreader/lib/Db/ReaderEntity.php

56 lines
1.1 KiB
PHP
Raw Normal View History

2020-04-21 20:37:42 +00:00
<?php
/**
* @author Frank de Lange
* @copyright 2015 Frank de Lange
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Epubreader\Db;
2020-04-21 20:37:42 +00:00
use OCP\AppFramework\Db\Entity;
2023-06-16 19:31:46 +00:00
/**
* @psalm-type SerializedEntity = array<string|int|array>
*/
2023-06-16 19:20:03 +00:00
abstract class ReaderEntity extends Entity {
2020-04-21 20:37:42 +00:00
2023-06-16 19:20:03 +00:00
protected int $lastModified; // modification timestamp
2023-06-16 14:58:23 +00:00
2023-06-16 19:31:46 +00:00
/**
* returns decoded json if input is json, otherwise returns input
*
* @return string|array
*/
2023-06-16 23:17:29 +00:00
public function conditional_json_decode(string $el): mixed {
2023-06-16 19:31:46 +00:00
/** @var array $result */
2023-06-16 14:58:23 +00:00
$result = json_decode($el);
if (json_last_error() === JSON_ERROR_NONE) {
return $result;
} else {
return $el;
}
}
2023-06-16 19:20:03 +00:00
public function getLastModified(): int {
2023-06-16 14:58:23 +00:00
return $this->lastModified;
}
2020-04-21 20:37:42 +00:00
2023-06-16 19:20:03 +00:00
public function setLastModified(int $lastModified): void {
2023-06-16 14:58:23 +00:00
$this->lastModified = $lastModified;
2023-06-16 23:17:29 +00:00
$this->markFieldUpdated('lastModified');
2023-06-16 14:58:23 +00:00
}
2023-06-16 19:31:46 +00:00
/**
* @psalm-return SerializedEntity
*/
2023-06-16 19:20:03 +00:00
abstract public function toService(): array;
2023-06-16 19:31:46 +00:00
/**
* @psalm-return SerializedEntity
*/
abstract public function jsonSerialize(): array;
2023-06-16 14:58:23 +00:00
}