4in1_ws_web/lib/BookItem.php

88 lines
2.1 KiB
PHP

<?php
class BookItem extends model implements FilesItemInterface {
const DB_TABLE = 'books';
public int $id;
public int $parentId;
public string $author;
public string $title;
public string $subtitle;
public int $year;
public int $size;
public FilesItemType $type;
public BookFileType $fileType;
public string $path;
public bool $external;
public BookCategory $category;
use FilesItemSizeTrait;
use FilesItemTypeTrait;
public function getId(): string {
return $this->id;
}
public function getUrl(): string {
if ($this->isFolder() && !$this->external)
return '/files/'.$this->id.'/';
global $config;
$buf = 'https://'.$config['files_domain'];
if (!str_starts_with($this->path, '/'))
$buf .= '/';
$buf .= $this->path;
return $buf;
}
public function getTitleHtml(): ?string {
if ($this->isFolder() || !$this->author)
return null;
$buf = '<b class="is-author">'.htmlescape($this->author).'</b><span class="is-title">';
if (!str_ends_with($this->author, '.'))
$buf .= '.';
$buf .= ' '.htmlescape($this->title).'</span>';
return $buf;
}
public function getTitle(): string {
return $this->title;
}
public function getMeta(?string $hl_matched = null): array {
if ($this->isFolder())
return [];
$items = [
sizeString($this->size),
strtoupper($this->getExtension())
];
return [
'inline' => false,
'items' => $items
];
}
protected function getExtension(): string {
return extension(basename($this->path));
}
public function isAvailable(): bool {
return true;
}
public function isTargetBlank(): bool {
return $this->isFile() || $this->external;
}
public function getSubtitle(): ?string {
if (!$this->year && !$this->subtitle)
return null;
$buf = '(';
$buf .= $this->subtitle ?: $this->year;
$buf .= ')';
return $buf;
}
}