Add manufacturer and scale to album model

This commit is contained in:
Junior 2022-02-16 17:32:23 +00:00
parent 766d27301a
commit ce726c4539
2 changed files with 48 additions and 4 deletions

View File

@ -6,6 +6,8 @@ class Album implements JsonSerializable {
private $title = ""; private $title = "";
private $thumbnail = ""; private $thumbnail = "";
private $description = ""; private $description = "";
private $manufacturer = "";
private $scale = "";
private $createtime = ""; private $createtime = "";
public function getID() { public function getID() {
@ -87,6 +89,40 @@ class Album implements JsonSerializable {
} }
} }
public function getManufacturer($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->manufacturer);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->manufacturer, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->manufacturer);
break;
default:
return $this->manufacturer;
break;
}
}
public function getScale($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->scale);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->scale, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->scale);
break;
default:
return $this->scale;
break;
}
}
public function getCreateTime($flag = 0) { public function getCreateTime($flag = 0) {
switch ($flag) { switch ($flag) {
case TIMESTAMP: case TIMESTAMP:
@ -225,6 +261,8 @@ class Album implements JsonSerializable {
'thumburl' => ($this->getThumbnail() == "") ? "graphics/no-image-available_thm.gif" : THUMBNAILFOLDER . $this->getFolderName() . $this->getThumbnail(), 'thumburl' => ($this->getThumbnail() == "") ? "graphics/no-image-available_thm.gif" : THUMBNAILFOLDER . $this->getFolderName() . $this->getThumbnail(),
'title' => $this->getTitle(), 'title' => $this->getTitle(),
'description' => $this->getDescription(), 'description' => $this->getDescription(),
'manufacturer' => $this->getManufacturer(),
'scale' => $this->getScale(),
'createtime' => $this->getCreateTime(), 'createtime' => $this->getCreateTime(),
'images' => Image::getImagesForAlbum($this->getID()) 'images' => Image::getImagesForAlbum($this->getID())
]; ];
@ -249,16 +287,18 @@ class Album implements JsonSerializable {
global $globaldbh; global $globaldbh;
$query = "INSERT INTO " . AppDB::TABLE_ALBUMS . " "; $query = "INSERT INTO " . AppDB::TABLE_ALBUMS . " ";
$query .= "(id, foldername, title, thumbnail, description, createtime) "; $query .= "(id, foldername, title, thumbnail, description, manufacturer, scale, createtime) ";
$query .= "VALUES(NULL, :foldername, :title, :thumbnail, :description, NOW()) "; $query .= "VALUES(NULL, :foldername, :title, :thumbnail, :description, :manufacturer, :scale, NOW()) ";
$query .= "ON DUPLICATE KEY UPDATE "; $query .= "ON DUPLICATE KEY UPDATE ";
$query .= "foldername=:foldername, title=:title, thumbnail=:thumbnail, description=:description"; $query .= "foldername=:foldername, title=:title, thumbnail=:thumbnail, description=:description, manufacturer=:manufacturer, scale=:scale";
$sth = $globaldbh->prepare($query); $sth = $globaldbh->prepare($query);
$sth->bindValue(":id", (int) $this->getID(), PDO::PARAM_INT); $sth->bindValue(":id", (int) $this->getID(), PDO::PARAM_INT);
$sth->bindValue(":foldername", $this->getFolderName(), PDO::PARAM_STR); $sth->bindValue(":foldername", $this->getFolderName(), PDO::PARAM_STR);
$sth->bindValue(":title", $this->getTitle(), PDO::PARAM_STR); $sth->bindValue(":title", $this->getTitle(), PDO::PARAM_STR);
$sth->bindValue(":thumbnail", $this->getThumbnail(), PDO::PARAM_STR); $sth->bindValue(":thumbnail", $this->getThumbnail(), PDO::PARAM_STR);
$sth->bindValue(":description", $this->getDescription(), PDO::PARAM_STR); $sth->bindValue(":description", $this->getDescription(), PDO::PARAM_STR);
$sth->bindValue(":manufacturer", $this->getManufacturer(), PDO::PARAM_STR);
$sth->bindValue(":scale", $this->getScale(), PDO::PARAM_STR);
$sth->execute(); $sth->execute();
if ( $this->getID() == 0 ) { if ( $this->getID() == 0 ) {
$this->setID($globaldbh->lastInsertId()); $this->setID($globaldbh->lastInsertId());
@ -270,7 +310,7 @@ class Album implements JsonSerializable {
global $globaldbh; global $globaldbh;
$reqid = intval($reqid); $reqid = intval($reqid);
$query = "SELECT id, foldername, title, thumbnail, description, createtime " . $query = "SELECT id, foldername, title, thumbnail, description, manufacturer, scale, createtime " .
"FROM " . AppDB::TABLE_ALBUMS . " WHERE id=:id"; "FROM " . AppDB::TABLE_ALBUMS . " WHERE id=:id";
$sth = $globaldbh->prepare($query); $sth = $globaldbh->prepare($query);
$sth->bindValue(":id", $reqid, PDO::PARAM_INT); $sth->bindValue(":id", $reqid, PDO::PARAM_INT);
@ -281,6 +321,8 @@ class Album implements JsonSerializable {
$this->setTitle($row['title']); $this->setTitle($row['title']);
$this->setThumbnail($row['thumbnail']); $this->setThumbnail($row['thumbnail']);
$this->setDescription($row['description']); $this->setDescription($row['description']);
$this->setManufacturer($row['manufacturer']);
$this->setScale($row['scale']);
$this->createtime = $row['createtime']; $this->createtime = $row['createtime'];
} }
} }

View File

@ -103,6 +103,8 @@ CREATE TABLE `albums` (
`title` varchar(255) NOT NULL, `title` varchar(255) NOT NULL,
`thumbnail` varchar(255) NOT NULL DEFAULT "", `thumbnail` varchar(255) NOT NULL DEFAULT "",
`description` text NOT NULL, `description` text NOT NULL,
`manufacturer` varchar(255) NOT NULL DEFAULT "",
`scale` varchar(255) NOT NULL DEFAULT "",
`createtime` datetime NOT NULL, `createtime` datetime NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `al_foldername` (`foldername`) UNIQUE KEY `al_foldername` (`foldername`)